use of javax.xml.datatype.XMLGregorianCalendar in project jena by apache.
the class NodeValueOps method additionNV.
public static NodeValue additionNV(NodeValue nv1, NodeValue nv2) {
ValueSpaceClassification vs1 = nv1.getValueSpace();
ValueSpaceClassification vs2 = nv2.getValueSpace();
if (vs1.equals(VSPACE_NUM) && vs2.equals(VSPACE_NUM))
return XSDFuncOp.numAdd(nv1, nv2);
if (vs1.equals(VSPACE_STRING) && vs2.equals(VSPACE_STRING))
return NodeValue.makeString(nv1.asString() + nv2.asString());
if (vs1.equals(VSPACE_DURATION) && vs2.equals(VSPACE_DURATION)) {
// A lot of testing to keep it as derived types.
boolean isDTDur = dtXSDdayTimeDuration.equals(nv1.getDatatypeURI()) && dtXSDdayTimeDuration.equals(nv2.getDatatypeURI());
boolean isYMDur = dtXSDyearMonthDuration.equals(nv1.getDatatypeURI()) && dtXSDyearMonthDuration.equals(nv2.getDatatypeURI());
Duration d3 = nv1.getDuration().add(nv2.getDuration());
String lex = d3.toString();
Node n;
if (isDTDur)
n = NodeFactoryExtra.createLiteralNode(lex, null, dtXSDdayTimeDuration);
else if (isYMDur)
n = NodeFactoryExtra.createLiteralNode(lex, null, dtXSDyearMonthDuration);
else
n = org.apache.jena.graph.NodeFactory.createLiteral(lex, XSDDatatype.XSDduration);
return NodeValue.makeNodeDuration(d3, n);
}
// Loose style. Add any duration to any date or time value.
if (vs1.equals(VSPACE_DATETIME) && vs2.equals(VSPACE_DURATION)) {
XMLGregorianCalendar cal = nv1.getDateTime();
XMLGregorianCalendar result = xsd_add(cal, nv2.getDuration());
NodeValue r = NodeValue.makeDateTime(result);
return r;
}
// Loose style. Add any duration to any date or time value.
if (vs1.equals(VSPACE_DATE) && vs2.equals(VSPACE_DURATION)) {
XMLGregorianCalendar cal = nv1.getDateTime();
XMLGregorianCalendar result = xsd_add(cal, nv2.getDuration());
NodeValue r = NodeValue.makeDate(result);
return r;
}
// Loose style. Add any duration to any date or time value.
if (vs1.equals(VSPACE_TIME) && vs2.equals(VSPACE_DURATION)) {
// ONLY dayTime.
XMLGregorianCalendar cal = nv1.getDateTime();
XMLGregorianCalendar result = xsd_add(cal, nv2.getDuration());
NodeValue r = NodeValue.makeNode(result.toXMLFormat(), XSDDatatype.XSDtime);
return r;
}
if (isDT(vs2) && vs1.equals(VSPACE_DURATION))
// Carefully ...
return additionNV(nv2, nv1);
throw new ExprEvalTypeException("Operator '+' : Undefined addition: " + nv1 + " and " + nv2);
}
use of javax.xml.datatype.XMLGregorianCalendar in project jena by apache.
the class NodeValueOps method xsd_substract.
private static Duration xsd_substract(XMLGregorianCalendar cal1, XMLGregorianCalendar cal2) {
GregorianCalendar gcal1 = cal1.toGregorianCalendar();
GregorianCalendar gcal2 = cal2.toGregorianCalendar();
long x1 = gcal1.getTimeInMillis();
long x2 = gcal2.getTimeInMillis();
return NodeValue.xmlDatatypeFactory.newDuration(x1 - x2);
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class TestActivation method test150ModifyUserJackAssignYellowAccount.
/**
* Assign yellow account.
*/
@Test
public void test150ModifyUserJackAssignYellowAccount() throws Exception {
final String TEST_NAME = "test150ModifyUserJackAssignYellowAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestActivation.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_YELLOW_OID, null, true);
deltas.add(accountAssignmentUserDelta);
XMLGregorianCalendar start = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
XMLGregorianCalendar end = clock.currentTimeXMLGregorianCalendar();
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
accountYellowOid = getLinkRefOid(userJack, RESOURCE_DUMMY_YELLOW_OID);
// Check account in dummy resource
assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, "jack", "Jack Sparrow", true);
// Check shadow
PrismObject<ShadowType> accountShadowYellow = getShadowModel(accountYellowOid);
assertAccountShadowModel(accountShadowYellow, accountYellowOid, ACCOUNT_JACK_DUMMY_USERNAME, getDummyResourceType(RESOURCE_DUMMY_YELLOW_NAME));
assertAdministrativeStatusEnabled(accountShadowYellow);
TestUtil.assertCreateTimestamp(accountShadowYellow, start, end);
assertEnableTimestampShadow(accountShadowYellow, start, end);
// Check user
TestUtil.assertModifyTimestamp(userJack, start, end);
assertAdministrativeStatusEnabled(userJack);
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class TestDeputy method test802AssignBarbossaDeputyOfJack.
/**
* Assign Barbossa as Jack's deputy. Barbossa should have all the privileges now.
* But they will expire soon ...
*/
@Test
public void test802AssignBarbossaDeputyOfJack() throws Exception {
final String TEST_NAME = "test802AssignBarbossaDeputyOfJack";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestDeputy.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userJackBefore = getUser(USER_JACK_OID);
display("User Jack before", userJackBefore);
assertAssignments(userJackBefore, 8);
assertLinks(userJackBefore, 3);
assertAuthorizations(userJackBefore, AUTZ_LOOT_URL, AUTZ_SAIL_URL, AUTZ_SAIL_URL, AUTZ_COMMAND_URL);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
ActivationType activationType = new ActivationType();
activationType.setValidTo(XmlTypeConverter.addDuration(startTs, "PT2H"));
// WHEN
TestUtil.displayWhen(TEST_NAME);
assignDeputy(USER_BARBOSSA_OID, USER_JACK_OID, assignment -> assignment.setActivation(activationType), task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
PrismObject<UserType> userBarbossaAfter = getUser(USER_BARBOSSA_OID);
display("User Barbossa after", userBarbossaAfter);
assertAssignedDeputy(userBarbossaAfter, USER_JACK_OID);
assertAssignedNoRole(userBarbossaAfter);
assertAssignments(userBarbossaAfter, 1);
assertAccount(userBarbossaAfter, RESOURCE_DUMMY_OID);
assertAccount(userBarbossaAfter, RESOURCE_DUMMY_RED_OID);
assertAccount(userBarbossaAfter, RESOURCE_DUMMY_CYAN_OID);
assertLinks(userBarbossaAfter, 3);
// Command autz should NOT be here, it is not delegable MID-3550
assertAuthorizations(userBarbossaAfter, AUTZ_LOOT_URL, AUTZ_SAIL_URL, AUTZ_SAIL_URL);
PrismObject<UserType> userJackAfter = getUser(USER_JACK_OID);
display("User Jack after", userJackAfter);
assertAssignments(userJackAfter, 8);
assertLinks(userJackAfter, 3);
assertAuthorizations(userJackAfter, AUTZ_LOOT_URL, AUTZ_SAIL_URL, AUTZ_SAIL_URL, AUTZ_COMMAND_URL);
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class AbstractInboundSyncTest method assertShadowOperationalData.
protected void assertShadowOperationalData(PrismObject<ShadowType> shadow, SynchronizationSituationType expectedSituation) {
ShadowType shadowType = shadow.asObjectable();
SynchronizationSituationType actualSituation = shadowType.getSynchronizationSituation();
assertEquals("Wrong situation in shadow " + shadow, expectedSituation, actualSituation);
XMLGregorianCalendar actualTimestampCal = shadowType.getSynchronizationTimestamp();
assert actualTimestampCal != null : "No synchronization timestamp in shadow " + shadow;
long actualTimestamp = XmlTypeConverter.toMillis(actualTimestampCal);
assert actualTimestamp >= timeBeforeSync : "Synchronization timestamp was not updated in shadow " + shadow;
// TODO: assert sync description
}
Aggregations