Search in sources :

Example 31 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory in project midpoint by Evolveum.

the class TestPlentyOfAssignments method test200DummyGroups.

/**
 * Create dummy groups that can be used for associationTargetSearch later on.
 * Create them from midPoint so they have shadows.
 * <p>
 * MID-3938 #8
 */
@Test
public void test200DummyGroups() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // WHEN
    when();
    PrismObjectDefinition<ShadowType> shadowDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
    PrismObjectDefinition<RoleType> roleDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(RoleType.class);
    ResourceSchema rSchema = ResourceSchemaFactory.getCompleteSchema(getDummyResourceObject());
    ResourceObjectClassDefinition rOcDef = rSchema.findObjectClassDefinition(getDummyResourceController().getGroupObjectClass());
    ObjectFactory objectFactory = new ObjectFactory();
    ItemPath nameAttributePath = ItemPath.create(ShadowType.F_ATTRIBUTES, SchemaConstants.ICFS_NAME);
    for (int i = 0; i < NUMBER_OF_GENERATED_DUMMY_GROUPS; i++) {
        PrismObject<ShadowType> shadow = shadowDef.instantiate();
        ShadowType shadowType = shadow.asObjectable();
        shadowType.resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).objectClass(rOcDef.getTypeName());
        ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, rOcDef);
        ResourceAttribute<String> nameAttribute = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME);
        String groupName = formatGroupName(i);
        nameAttribute.setRealValue(groupName);
        display("Group shadow " + i, shadow);
        addObject(shadow, task, result);
        PrismObject<RoleType> role = roleDef.instantiate();
        RoleType roleType = role.asObjectable();
        ItemPathType assPath = new ItemPathType(ItemPath.create(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME));
        SearchObjectExpressionEvaluatorType associationTargetSearchType = new SearchObjectExpressionEvaluatorType();
        EqualFilter<String> filter = prismContext.queryFactory().createEqual(nameAttributePath, null, null, prismContext, groupName);
        SearchFilterType filterType = prismContext.getQueryConverter().createSearchFilterType(filter);
        associationTargetSearchType.setFilter(filterType);
        associationTargetSearchType.setSearchStrategy(ObjectSearchStrategyType.IN_REPOSITORY);
        JAXBElement<SearchObjectExpressionEvaluatorType> evaluator = objectFactory.createAssociationTargetSearch(associationTargetSearchType);
        roleType.oid(generateRoleOid(GENERATED_DUMMY_GROUP_ROLE_OID_FORMAT, i)).name(String.format("Group role %04d", i)).beginInducement().beginConstruction().resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).kind(ShadowKindType.ACCOUNT).beginAssociation().ref(assPath).beginOutbound().beginExpression().expressionEvaluator(evaluator);
        try {
            IntegrationTestTools.displayXml("RRRRRRRRR group", role);
        } catch (SchemaException e) {
            throw new SystemException(e);
        }
        addObject(role, task, result);
    }
    // THEN
    then();
    assertSuccess(result);
    Collection<DummyGroup> dummyGroups = getDummyResource().listGroups();
    assertEquals("Wrong number of dummy groups", NUMBER_OF_GENERATED_DUMMY_GROUPS, dummyGroups.size());
    assertShadows(NUMBER_OF_GENERATED_DUMMY_GROUPS);
    assertObjects(RoleType.class, NUMBER_OF_GENERATED_EMPTY_ROLES + NUMBER_OF_GENERATED_DUMMY_ROLES + NUMBER_OF_ORDINARY_ROLES + NUMBER_OF_GENERATED_DUMMY_GROUPS);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 32 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory in project midpoint by Evolveum.

the class TestPlentyOfAssignments method initSystem.

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
    super.initSystem(initTask, initResult);
    initDummyResourcePirate(null, RESOURCE_DUMMY_FILE, RESOURCE_DUMMY_OID, initTask, initResult);
    importObjectFromFile(ROLE_BASIC_FILE, initResult);
    ObjectFactory objectFactory = new ObjectFactory();
    generateRoles(NUMBER_OF_GENERATED_EMPTY_ROLES, "Empty Role %04d", GENERATED_EMPTY_ROLE_OID_FORMAT, null, initResult);
    generateRoles(NUMBER_OF_GENERATED_DUMMY_ROLES, "Dummy Role %04d", GENERATED_DUMMY_ROLE_OID_FORMAT, (role, i) -> {
        ItemPathType attrPath = new ItemPathType(ItemPath.create(new QName(RESOURCE_DUMMY_NS, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME)));
        JAXBElement<Object> evaluator = objectFactory.createValue(formatRum(i));
        role.beginInducement().beginConstruction().resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).kind(ShadowKindType.ACCOUNT).beginAttribute().ref(attrPath).beginOutbound().beginExpression().expressionEvaluator(evaluator);
    }, initResult);
    inspector = new CountingInspector();
    InternalMonitor.setInspector(inspector);
}
Also used : ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 33 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.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 34 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.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 com.evolveum.midpoint.xml.ns._public.common.common_3.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 Marshaller (javax.xml.bind.Marshaller)10 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)10 StringWriter (java.io.StringWriter)9 BigInteger (java.math.BigInteger)9 JAXBContext (javax.xml.bind.JAXBContext)9 QName (javax.xml.namespace.QName)9 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)8 ArrayList (java.util.ArrayList)7 Holder (javax.xml.ws.Holder)7 ObjectFactory (org.apache.type_test.types3.ObjectFactory)7 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)6 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)6 Book (biblemulticonverter.data.Book)5 XStream (com.thoughtworks.xstream.XStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Ignore (jdk.nashorn.internal.ir.annotations.Ignore)5