List of usage examples for javax.xml.datatype XMLGregorianCalendar add
public abstract void add(Duration duration);
From source file:DatatypeAPIUsage.java
public static void main(String[] args) { try {//from w w w. ja v a2 s .c o m DatatypeFactory df = DatatypeFactory.newInstance(); // my work number in milliseconds: Duration myPhone = df.newDuration(9054133519l); Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0); int compareVal = myPhone.compare(myLife); switch (compareVal) { case DatatypeConstants.LESSER: System.out.println("There are fewer milliseconds in my phone number than my lifespan."); break; case DatatypeConstants.EQUAL: System.out.println("The same number of milliseconds are in my phone number and my lifespan."); break; case DatatypeConstants.GREATER: System.out.println("There are more milliseconds in my phone number than my lifespan."); break; case DatatypeConstants.INDETERMINATE: System.out.println("The comparison could not be carried out."); } // create a yearMonthDuration Duration ymDuration = df.newDurationYearMonth("P12Y10M"); System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType()); // create a dayTimeDuration (really this time) Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S"); System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType()); // try to fool the factory! try { ymDuration = df.newDurationYearMonth("P12Y10M1D"); } catch (IllegalArgumentException e) { System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!"); } XMLGregorianCalendar xgc = df.newXMLGregorianCalendar(); xgc.setYear(1975); xgc.setMonth(DatatypeConstants.AUGUST); xgc.setDay(11); xgc.setHour(6); xgc.setMinute(44); xgc.setSecond(0); xgc.setMillisecond(0); xgc.setTimezone(5); xgc.add(myPhone); System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc); // adding a duration to XMLGregorianCalendar xgc.add(myLife); System.out.println("Adding the duration myLife to the above calendar:" + xgc); // create a new XMLGregorianCalendar using the string format of xgc. XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat()); // should be equal-if not what happened!! if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) { System.out.println("oooops!"); } else { System.out.println("Very good: " + xgc + " is equal to " + xgcCopy); } } catch (DatatypeConfigurationException dce) { System.err.println("error: Datatype error occurred - " + dce.getMessage()); dce.printStackTrace(System.err); } }
From source file:com.redhat.rhevm.api.powershell.util.PowerShellUtils.java
public static XMLGregorianCalendar getDate(int secondsAgo) { if (secondsAgo == 0) { return null; }//from w w w .j a v a 2 s. c o m XMLGregorianCalendar ret = getDatatypeFactory() .newXMLGregorianCalendar(new GregorianCalendar(TimeZone.getTimeZone("UTC"))); ret.add(getDatatypeFactory().newDuration(false, 0, 0, 0, 0, 0, secondsAgo)); return ret; }
From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java
public static XMLGregorianCalendar addDuration(XMLGregorianCalendar now, Duration duration) { XMLGregorianCalendar later = createXMLGregorianCalendar(toMillis(now)); later.add(duration); return later; }
From source file:com.evolveum.midpoint.schema.util.WfContextUtil.java
@NotNull private static XMLGregorianCalendar computeTriggerTime(Duration duration, WfTimeBaseType base, Date start, Date deadline) {/*from w w w . jav a 2 s .c o m*/ Date baseTime; if (base == null) { base = duration.getSign() <= 0 ? WfTimeBaseType.DEADLINE : WfTimeBaseType.WORK_ITEM_CREATION; } switch (base) { case DEADLINE: if (deadline == null) { throw new IllegalStateException("Couldn't set timed action relative to work item's deadline because" + " the deadline is not set. Requested interval: " + duration); } baseTime = deadline; break; case WORK_ITEM_CREATION: if (start == null) { throw new IllegalStateException("Task's start time is null"); } baseTime = start; break; default: throw new IllegalArgumentException("base: " + base); } XMLGregorianCalendar rv = XmlTypeConverter.createXMLGregorianCalendar(baseTime); rv.add(duration); return rv; }
From source file:com.evolveum.midpoint.schema.util.WfContextUtil.java
@NotNull public static List<TriggerType> createTriggers(int escalationLevel, Date workItemCreateTime, Date workItemDeadline, List<WorkItemTimedActionsType> timedActionsList, PrismContext prismContext, Trace logger, @Nullable String workItemId, @NotNull String handlerUri) throws SchemaException { List<TriggerType> triggers = new ArrayList<>(); for (WorkItemTimedActionsType timedActionsEntry : timedActionsList) { Integer levelFrom;/*from www . j av a 2 s. c om*/ Integer levelTo; if (timedActionsEntry.getEscalationLevelFrom() == null && timedActionsEntry.getEscalationLevelTo() == null) { levelFrom = levelTo = 0; } else { levelFrom = timedActionsEntry.getEscalationLevelFrom(); levelTo = timedActionsEntry.getEscalationLevelTo(); } if (levelFrom != null && escalationLevel < levelFrom) { logger.trace("Current escalation level is before 'escalationFrom', skipping timed actions {}", timedActionsEntry); continue; } if (levelTo != null && escalationLevel > levelTo) { logger.trace("Current escalation level is after 'escalationTo', skipping timed actions {}", timedActionsEntry); continue; } // TODO evaluate the condition List<TimedActionTimeSpecificationType> timeSpecifications = CloneUtil .cloneCollectionMembers(timedActionsEntry.getTime()); if (timeSpecifications.isEmpty()) { timeSpecifications.add(new TimedActionTimeSpecificationType()); } for (TimedActionTimeSpecificationType timeSpec : timeSpecifications) { if (timeSpec.getValue().isEmpty()) { timeSpec.getValue().add(XmlTypeConverter.createDuration(0)); } for (Duration duration : timeSpec.getValue()) { XMLGregorianCalendar mainTriggerTime = computeTriggerTime(duration, timeSpec.getBase(), workItemCreateTime, workItemDeadline); TriggerType mainTrigger = createTrigger(mainTriggerTime, timedActionsEntry.getActions(), null, prismContext, workItemId, handlerUri); triggers.add(mainTrigger); List<Pair<Duration, AbstractWorkItemActionType>> notifyInfoList = getNotifyBefore( timedActionsEntry); for (Pair<Duration, AbstractWorkItemActionType> notifyInfo : notifyInfoList) { XMLGregorianCalendar notifyTime = (XMLGregorianCalendar) mainTriggerTime.clone(); notifyTime.add(notifyInfo.getKey().negate()); TriggerType notifyTrigger = createTrigger(notifyTime, null, notifyInfo, prismContext, workItemId, handlerUri); triggers.add(notifyTrigger); } } } } return triggers; }
From source file:com.microsoft.exchange.ExchangeEventConverterImplTest.java
@Test public void convertedCalendarMatchesSubject() throws DatatypeConfigurationException { CalendarItemType calendarItem = new CalendarItemType(); String randomSubject = RandomStringUtils.random(32); calendarItem.setStart(DateHelp.convertDateToXMLGregorianCalendar(new Date())); Duration duration = DatatypeFactory.newInstance().newDuration(1000 * 60 * 60); XMLGregorianCalendar end = calendarItem.getStart(); end.add(duration); calendarItem.setEnd(end);/*from ww w . j av a 2 s . c o m*/ calendarItem.setSubject(randomSubject); log.info("created calendar item with subject=" + randomSubject); Calendar calendar = eventConverter.convertToCalendar(Collections.singleton(calendarItem), null); //calendar should not be null assertNotNull(calendar); ComponentList components = calendar.getComponents(); //calendar should have components assertNotNull(components); //calendar should have exactly one component assertEquals(1, components.size()); //components should be events assertEquals(components, calendar.getComponents(VEvent.VEVENT)); Object object = components.get(0); assertNotNull(object); assertTrue(object instanceof VEvent); VEvent event = (VEvent) object; assertNotNull(event); Summary summary = event.getSummary(); assertNotNull(summary); assertNotNull(summary.getValue()); assertEquals(randomSubject, summary.getValue()); log.info("converted event summary[" + summary.getValue() + "] matches calendar item sujbect[" + calendarItem.getSubject() + "]"); }
From source file:com.microsoft.exchange.ExchangeEventConverterImplTest.java
@Test public void convertedCalendarMatchesStartTime() throws DatatypeConfigurationException { CalendarItemType calendarItem = new CalendarItemType(); Date dateStartIn = new Date(); XMLGregorianCalendar xmlStartIn = DateHelp.convertDateToXMLGregorianCalendar(dateStartIn); calendarItem.setStart(xmlStartIn);// www .j a va 2s . co m Duration duration = DatatypeFactory.newInstance().newDuration(1000 * 60 * 60); XMLGregorianCalendar end = calendarItem.getStart(); end.add(duration); calendarItem.setEnd(end); log.info("created calendar item with start=" + calendarItem.getStart()); Calendar calendar = eventConverter.convertToCalendar(Collections.singleton(calendarItem), null); //calendar should not be null assertNotNull(calendar); ComponentList components = calendar.getComponents(); //calendar should have components assertNotNull(components); //calendar should have exactly one component assertEquals(1, components.size()); //components should be events assertEquals(components, calendar.getComponents(VEvent.VEVENT)); Object object = components.get(0); assertNotNull(object); assertTrue(object instanceof VEvent); VEvent event = (VEvent) object; assertNotNull(event); DtStart dtStart = event.getStartDate(); assertNotNull(dtStart); net.fortuna.ical4j.model.Date dateStartOut = dtStart.getDate(); assertNotNull(dateStartOut); XMLGregorianCalendar xmlStartOut = DateHelp.convertDateToXMLGregorianCalendar(dateStartOut); log.info("dateStartIn=" + dateStartIn); log.info("xmlStartIn=" + xmlStartIn); log.info("dateStartOut=" + dateStartOut); log.info("xmlStartOut+=" + xmlStartOut); assertEquals(dateStartIn, new Date(dateStartIn.getTime())); assertEquals(xmlStartIn, xmlStartOut); }
From source file:com.evolveum.midpoint.model.impl.sync.FocusValidityScannerTaskHandler.java
@Override protected ObjectQuery createQuery(AbstractScannerResultHandler<FocusType> handler, TaskRunResult runResult, Task coordinatorTask, OperationResult opResult) throws SchemaException { initProcessedOids(coordinatorTask);/*from w ww .j a va 2s . com*/ TimeValidityPolicyConstraintType validityConstraintType = getValidityPolicyConstraint(coordinatorTask); Duration activateOn = getActivateOn(validityConstraintType); Integer partition = getPartition(coordinatorTask); ObjectQuery query = new ObjectQuery(); ObjectFilter filter; XMLGregorianCalendar lastScanTimestamp = handler.getLastScanTimestamp(); XMLGregorianCalendar thisScanTimestamp = handler.getThisScanTimestamp(); if (activateOn != null) { ItemPathType itemPathType = validityConstraintType.getItem(); ItemPath path = itemPathType.getItemPath(); if (path == null) { throw new SchemaException("No path defined in the validity constraint."); } thisScanTimestamp.add(activateOn.negate()); if (lastScanTimestamp != null) { lastScanTimestamp.add(activateOn.negate()); } filter = createFilterFor(getType(coordinatorTask), path, lastScanTimestamp, thisScanTimestamp); } else { filter = createBasicFilter(lastScanTimestamp, thisScanTimestamp, partition); } query.setFilter(filter); return query; }
From source file:com.evolveum.midpoint.model.intest.TestEntitlements.java
/** * Assign role with entitlement. The assignment is not yet valid. *///from w w w . j a v a 2 s.co m @Test public void test630AssignRoleSwashbucklerToJackValidity() throws Exception { final String TEST_NAME = "test630AssignRoleSwashbucklerToJackValidity"; TestUtil.displayTestTile(this, TEST_NAME); Task task = taskManager.createTaskInstance(TestEntitlements.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); ActivationType activationType = new ActivationType(); XMLGregorianCalendar validFrom = clock.currentTimeXMLGregorianCalendar(); validFrom.add(XmlTypeConverter.createDuration(60 * 60 * 1000)); // one hour ahead activationType.setValidFrom(validFrom); XMLGregorianCalendar validTo = clock.currentTimeXMLGregorianCalendar(); validTo.add(XmlTypeConverter.createDuration(3 * 60 * 60 * 1000)); // three hours ahead activationType.setValidTo(validTo); // WHEN assignRole(USER_JACK_OID, ROLE_SWASHBUCKLER_OID, activationType, task, result); // THEN result.computeStatus(); TestUtil.assertSuccess(result); PrismObject<UserType> user = getUser(USER_JACK_OID); display("User jack", user); assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true); DummyGroup dummyGroup = dummyResource.getGroupByName(GROUP_DUMMY_SWASHBUCKLERS_NAME); assertNotNull("No group on dummy resource", dummyGroup); display("Group", dummyGroup); assertEquals("Wrong group description", GROUP_DUMMY_SWASHBUCKLERS_DESCRIPTION, dummyGroup.getAttributeValue(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION)); assertNoGroupMember(dummyGroup, ACCOUNT_JACK_DUMMY_USERNAME); assertDummyAccountAttribute(null, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "rum"); assertDummyAccountAttribute(null, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Bloody Pirate"); }
From source file:com.evolveum.midpoint.certification.impl.AccCertUpdateHelper.java
protected AccessCertificationStageType createStage(AccessCertificationCampaignType campaign, int requestedStageNumber) { AccessCertificationStageType stage = new AccessCertificationStageType(prismContext); stage.setNumber(requestedStageNumber); stage.setStart(XmlTypeConverter.createXMLGregorianCalendar(new Date())); AccessCertificationStageDefinitionType stageDef = CertCampaignTypeUtil.findStageDefinition(campaign, stage.getNumber());// w ww. j ava2 s. c o m XMLGregorianCalendar end = (XMLGregorianCalendar) stage.getStart().clone(); if (stageDef.getDays() != null) { end.add(XmlTypeConverter.createDuration(true, 0, 0, stageDef.getDays(), 0, 0, 0)); } end.setHour(23); end.setMinute(59); end.setSecond(59); end.setMillisecond(999); stage.setEnd(end); stage.setName(stageDef.getName()); stage.setDescription(stageDef.getDescription()); return stage; }