List of usage examples for javax.xml.datatype XMLGregorianCalendar add
public abstract void add(Duration duration);
From source file:com.evolveum.midpoint.certification.impl.AccCertUpdateHelper.java
void recordMoveToNextStage(AccessCertificationCampaignType campaign, AccessCertificationStageType newStage, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException, SecurityViolationException, ConfigurationException, CommunicationException { boolean campaignJustCreated; // some bureaucracy... stage#, state, start time, trigger List<AccessCertificationCaseType> caseList = queryHelper.searchCases(campaign.getOid(), null, null, task, result);//from w ww. j a v a2s . com List<ItemDelta> itemDeltaList = new ArrayList<>(); PropertyDelta<Integer> stageNumberDelta = createStageNumberDelta(newStage.getNumber()); itemDeltaList.add(stageNumberDelta); PropertyDelta<AccessCertificationCampaignStateType> stateDelta = createStateDelta(IN_REVIEW_STAGE); itemDeltaList.add(stateDelta); if (newStage.getNumber() == 1) { PropertyDelta<XMLGregorianCalendar> startDelta = createStartTimeDelta( XmlTypeConverter.createXMLGregorianCalendar(new Date())); itemDeltaList.add(startDelta); campaignJustCreated = true; } else { campaignJustCreated = false; } if (newStage.getEnd() != null) { XMLGregorianCalendar end = newStage.getEnd(); AccessCertificationStageDefinitionType stageDef = CertCampaignTypeUtil.findStageDefinition(campaign, newStage.getNumber()); List<TriggerType> triggers = new ArrayList<>(); // pseudo-random ID so this trigger will not be deleted by trigger task handler (if this code itself is executed as part of previous trigger firing) // TODO implement this more seriously! long lastId = (long) (Math.random() * 1000000000); TriggerType triggerClose = new TriggerType(prismContext); triggerClose.setHandlerUri(AccessCertificationCloseStageTriggerHandler.HANDLER_URI); triggerClose.setTimestamp(end); triggerClose.setId(lastId); triggers.add(triggerClose); for (Integer hoursBeforeDeadline : stageDef.getNotifyBeforeDeadline()) { XMLGregorianCalendar beforeEnd = null; beforeEnd = CloneUtil.clone(end); beforeEnd.add(XmlTypeConverter.createDuration(false, 0, 0, 0, hoursBeforeDeadline, 0, 0)); if (XmlTypeConverter.toMillis(beforeEnd) > System.currentTimeMillis()) { TriggerType triggerBeforeEnd = new TriggerType(prismContext); triggerBeforeEnd .setHandlerUri(AccessCertificationCloseStageApproachingTriggerHandler.HANDLER_URI); triggerBeforeEnd.setTimestamp(beforeEnd); triggerBeforeEnd.setId(++lastId); triggers.add(triggerBeforeEnd); } } ContainerDelta<TriggerType> triggerDelta = ContainerDelta.createModificationReplace( ObjectType.F_TRIGGER, AccessCertificationCampaignType.class, prismContext, triggers); itemDeltaList.add(triggerDelta); } repositoryService.modifyObject(AccessCertificationCampaignType.class, campaign.getOid(), itemDeltaList, result); // notifications campaign = refreshCampaign(campaign, task, result); if (campaign.getStageNumber() == 1) { eventHelper.onCampaignStart(campaign, task, result); } eventHelper.onCampaignStageStart(campaign, task, result); Collection<String> reviewers = eventHelper.getCurrentReviewers(campaign, caseList); for (String reviewerOid : reviewers) { List<AccessCertificationCaseType> cases = queryHelper.getCasesForReviewer(campaign, reviewerOid, task, result); ObjectReferenceType reviewerRef = ObjectTypeUtil.createObjectRef(reviewerOid, ObjectTypes.USER); eventHelper.onReviewRequested(reviewerRef, cases, campaign, task, result); } if (campaignJustCreated && campaign.getDefinitionRef() != null) { List<ItemDelta> deltas = DeltaBuilder.deltaFor(AccessCertificationDefinitionType.class, prismContext) .item(F_LAST_CAMPAIGN_STARTED_TIMESTAMP) .replace(XmlTypeConverter.createXMLGregorianCalendar(new Date())).asItemDeltas(); repositoryService.modifyObject(AccessCertificationDefinitionType.class, campaign.getDefinitionRef().getOid(), deltas, result); } }
From source file:com.evolveum.midpoint.model.common.mapping.Mapping.java
private XMLGregorianCalendar parseTime(MappingTimeDeclarationType timeType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException { if (timeType == null) { return null; }/*from w w w .j a va2 s.co m*/ XMLGregorianCalendar time = null; MappingSourceDeclarationType referenceTimeType = timeType.getReferenceTime(); if (referenceTimeType == null) { if (time == null) { throw new SchemaException( "No reference time specified (and there is also no default) in time specification in " + getMappingContextDescription()); } else { time = (XMLGregorianCalendar) defaultReferenceTime.clone(); } } else { time = parseTimeSource(referenceTimeType, task, result); if (time == null) { // Reference time is specified but the value is not present. return null; } time = (XMLGregorianCalendar) time.clone(); } Duration offset = timeType.getOffset(); if (offset != null) { time.add(offset); } return time; }