Search in sources :

Example 56 with XMLGregorianCalendar

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);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) NodeValue(org.apache.jena.sparql.expr.NodeValue) ExprEvalTypeException(org.apache.jena.sparql.expr.ExprEvalTypeException) Node(org.apache.jena.graph.Node) Duration(javax.xml.datatype.Duration) ValueSpaceClassification(org.apache.jena.sparql.expr.ValueSpaceClassification)

Example 57 with XMLGregorianCalendar

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);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 58 with XMLGregorianCalendar

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestValidityRecomputeTask(com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractSynchronizationStoryTest(com.evolveum.midpoint.model.intest.sync.AbstractSynchronizationStoryTest)

Example 59 with XMLGregorianCalendar

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);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) TestValidityRecomputeTask(com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 60 with XMLGregorianCalendar

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
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)

Aggregations

XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)336 Test (org.testng.annotations.Test)159 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)130 Task (com.evolveum.midpoint.task.api.Task)104 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)72 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)52 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)44 Date (java.util.Date)36 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)32 ArrayList (java.util.ArrayList)32 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)31 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)30 AbstractSynchronizationStoryTest (com.evolveum.midpoint.model.intest.sync.AbstractSynchronizationStoryTest)23 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)21 GregorianCalendar (java.util.GregorianCalendar)18 QName (javax.xml.namespace.QName)18 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)15 Duration (javax.xml.datatype.Duration)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14