Search in sources :

Example 31 with ObjectFactory

use of biblemulticonverter.schema.zef2005.ObjectFactory in project midpoint by Evolveum.

the class OpResult method getOpResult.

public static OpResult getOpResult(PageBase page, OperationResult result) {
    OpResult opResult = new OpResult();
    Validate.notNull(result, "Operation result must not be null.");
    Validate.notNull(result.getStatus(), "Operation result status must not be null.");
    opResult.message = result.getMessage();
    opResult.operation = result.getOperation();
    opResult.status = result.getStatus();
    opResult.count = result.getCount();
    if (result.getCause() != null) {
        Throwable cause = result.getCause();
        opResult.exceptionMessage = cause.getMessage();
        Writer writer = new StringWriter();
        cause.printStackTrace(new PrintWriter(writer));
        opResult.exceptionsStackTrace = writer.toString();
    }
    if (result.getParams() != null) {
        for (Map.Entry<String, Serializable> entry : result.getParams().entrySet()) {
            String paramValue = null;
            Object value = entry.getValue();
            if (value != null) {
                paramValue = value.toString();
            }
            opResult.getParams().add(new Param(entry.getKey(), paramValue));
        }
    }
    if (result.getContext() != null) {
        for (Map.Entry<String, Serializable> entry : result.getContext().entrySet()) {
            String contextValue = null;
            Object value = entry.getValue();
            if (value != null) {
                contextValue = value.toString();
            }
            opResult.getContexts().add(new Context(entry.getKey(), contextValue));
        }
    }
    if (result.getSubresults() != null) {
        for (OperationResult subresult : result.getSubresults()) {
            OpResult subOpResult = OpResult.getOpResult(page, subresult);
            opResult.getSubresults().add(subOpResult);
            subOpResult.parent = opResult;
            if (subOpResult.getBackgroundTaskOid() != null) {
                opResult.backgroundTaskOid = subOpResult.getBackgroundTaskOid();
            }
        }
    }
    if (result.getBackgroundTaskOid() != null) {
        opResult.backgroundTaskOid = result.getBackgroundTaskOid();
    }
    try {
        OperationResultType resultType = result.createOperationResultType();
        ObjectFactory of = new ObjectFactory();
        opResult.xml = page.getPrismContext().xmlSerializer().serialize(of.createOperationResult(resultType));
    } catch (SchemaException | RuntimeException ex) {
        String m = "Can't create xml: " + ex;
        //			error(m);
        opResult.xml = "<?xml version='1.0'?><message>" + StringEscapeUtils.escapeXml(m) + "</message>";
    //            throw ex;
    }
    return opResult;
}
Also used : Serializable(java.io.Serializable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) StringWriter(java.io.StringWriter) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Map(java.util.Map) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 32 with ObjectFactory

use of biblemulticonverter.schema.zef2005.ObjectFactory in project midpoint by Evolveum.

the class ConsistencyTest method test511AssignAccountMorgan.

/**
	 * assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
	 * account should be linked to the user.
	 * @throws Exception
	 */
@Test
public void test511AssignAccountMorgan() throws Exception {
    final String TEST_NAME = "test511AssignAccountMorgan";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    openDJController.assumeRunning();
    Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    //prepare new OU in opendj
    Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
    ExpressionType expression = new ExpressionType();
    ObjectFactory of = new ObjectFactory();
    RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
    JAXBElement val = of.createValue(raw);
    expression.getExpressionEvaluator().add(val);
    MappingType mapping = new MappingType();
    mapping.setExpression(expression);
    ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
    attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
    attrDefType.setOutbound(mapping);
    ConstructionType construction = new ConstructionType();
    construction.getAttribute().add(attrDefType);
    construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
    AssignmentType assignment = new AssignmentType();
    assignment.setConstruction(construction);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    //		assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
    PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
    display("User morgan after", userMorgan);
    UserType userMorganType = userMorgan.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
    String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
    assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account        
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) 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) Entry(org.opends.server.types.Entry) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 33 with ObjectFactory

use of biblemulticonverter.schema.zef2005.ObjectFactory in project midpoint by Evolveum.

the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.

/**
     * We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
     *
     */
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
    final String TEST_NAME = "test191ModifyUserJackModifyAssignment";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    //PrismPropertyDefinition definition = getAssignmentDefinition().findPropertyDefinition(new QName(SchemaConstantsGenerated.NS_COMMON, "accountConstruction"));
    PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(dummyResource, prismContext);
    // This explicitly parses the schema, therefore ...
    assertResourceSchemaParseCountIncrement(1);
    RefinedObjectClassDefinition accountDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
    PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new QName("http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
    assertNotNull("gossip attribute definition not found", gossipDefinition);
    ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
    ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
    radt.setRef(new ItemPathType(new ItemPath(gossipDefinition.getName())));
    MappingType outbound = new MappingType();
    radt.setOutbound(outbound);
    ExpressionType expression = new ExpressionType();
    outbound.setExpression(expression);
    MappingType value = new MappingType();
    PrismProperty<String> property = gossipDefinition.instantiate();
    property.add(new PrismPropertyValue<String>("q"));
    List evaluators = expression.getExpressionEvaluator();
    Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property, null);
    ObjectFactory of = new ObjectFactory();
    for (JAXBElement<RawType> obj : collection) {
        evaluators.add(of.createValue(obj.getValue()));
    }
    value.setExpression(expression);
    radt.setOutbound(value);
    accountConstruction.getAttribute().add(radt);
    PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
    assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
    Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
    ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
    deltas.add(accountAssignmentUserDelta);
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
    display("User before change execution", userJackOld);
    display("Deltas to execute execution", deltas);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    // First fetch: initial account read
    // Second fetch: fetchback after modification to correctly process inbound
    assertShadowFetchOperationCountIncrement(2);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack, "Jack Sparrow");
    accountJackOid = getSingleLinkOid(userJack);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
    // Check account in dummy resource
    assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
    DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
    display(dummyAccount.debugDump());
    assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
    //assertEquals("Missing or incorrect attribute value", "soda", dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, String.class));
    assertDummyScriptsModify(userJack, true);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
    assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    assertScriptCompileIncrement(0);
    assertSteadyResources();
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) 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) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) List(java.util.List) ArrayList(java.util.ArrayList) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) QName(javax.xml.namespace.QName) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) JAXBElement(javax.xml.bind.JAXBElement) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 34 with ObjectFactory

use of biblemulticonverter.schema.zef2005.ObjectFactory in project midpoint by Evolveum.

the class ParamsTypeUtil method setUnknownJavaObjectEntry.

private static void setUnknownJavaObjectEntry(EntryType entryType, Serializable value) {
    UnknownJavaObjectType ujo = new UnknownJavaObjectType();
    ujo.setClazz(value.getClass().getName());
    ujo.setToString(value.toString());
    entryType.setEntryValue(new ObjectFactory().createUnknownJavaObject(ujo));
}
Also used : ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) UnknownJavaObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.UnknownJavaObjectType)

Example 35 with ObjectFactory

use of biblemulticonverter.schema.zef2005.ObjectFactory in project midpoint by Evolveum.

the class OperationResultFactory method createOperationResult.

public static OperationResultType createOperationResult(String operation, OperationResultStatusType status, Map<String, Element> params, String message, String messageCode, String localizedMessage, Object[] localizedArguments) {
    OperationResultType result = createOperationResult(operation, status, params, message, messageCode);
    if (StringUtils.isEmpty(localizedMessage)) {
        return result;
    }
    ObjectFactory factory = new ObjectFactory();
    LocalizedMessageType localizedMessageType = factory.createLocalizedMessageType();
    result.setLocalizedMessage(localizedMessageType);
    localizedMessageType.setKey(localizedMessage);
    if (localizedArguments == null || localizedArguments.length == 0) {
        return result;
    }
    for (Object object : localizedArguments) {
        localizedMessageType.getArgument().add(object);
    }
    return result;
}
Also used : ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) LocalizedMessageType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Aggregations

Test (org.junit.Test)15 JAXBElement (javax.xml.bind.JAXBElement)13 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)13 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 StringWriter (java.io.StringWriter)10 Marshaller (javax.xml.bind.Marshaller)10 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)10 BigInteger (java.math.BigInteger)9 JAXBContext (javax.xml.bind.JAXBContext)9 ArrayList (java.util.ArrayList)8 QName (javax.xml.namespace.QName)8 Holder (javax.xml.ws.Holder)7 ObjectFactory (org.apache.type_test.types3.ObjectFactory)7 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)6 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)5 XStream (com.thoughtworks.xstream.XStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Writer (java.io.Writer)5 Ignore (jdk.nashorn.internal.ir.annotations.Ignore)5 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)5