Search in sources :

Example 61 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class SearchIterativeTest method test130AddOneForOne.

@Test
public void test130AddOneForOne() throws Exception {
    OperationResult result = new OperationResult("test130AddOneForOne");
    final List<PrismObject<UserType>> objects = new ArrayList<>();
    ResultHandler handler = new ResultHandler() {

        @Override
        public boolean handle(PrismObject object, OperationResult parentResult) {
            objects.add(object);
            System.out.print("Got object " + object.getOid());
            try {
                int number = Integer.parseInt(((UserType) object.asObjectable()).getCostCenter());
                if (number >= 0) {
                    UserType user = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).instantiate().asObjectable();
                    user.setOid("user-" + (2 * BASE + COUNT - number) + "-FF");
                    user.setName(new PolyStringType(new PolyString("user-new-" + number)));
                    user.setCostCenter(String.valueOf(-number));
                    repositoryService.addObject(user.asPrismObject(), null, parentResult);
                    System.out.print(" ... creating object " + user.getOid());
                }
            } catch (ObjectAlreadyExistsException | SchemaException e) {
                throw new SystemException(e);
            }
            System.out.println();
            return true;
        }
    };
    repositoryService.searchObjectsIterative(UserType.class, null, handler, null, true, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    boolean[] map = assertObjects(objects, null);
    for (int i = 0; i < COUNT; i++) {
        if (i % 2 == 0) {
            assertFalse("Object " + (BASE + i) + " does exist but it should not", map[i]);
        } else {
            assertTrue("Object " + (BASE + i) + " does not exist but it should", map[i]);
        }
    }
    System.out.println("Object processed: " + objects.size());
    int count = repositoryService.countObjects(UserType.class, null, result);
    assertEquals("Wrong # of objects after operation", COUNT, count);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Test(org.testng.annotations.Test)

Example 62 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class NodeRegistrar method verifyNodeObject.

/**
     * Checks whether this Node object was not overwritten by another node (implying there is duplicate node ID in cluster).
     *
     * @param result
     */
void verifyNodeObject(OperationResult result) {
    PrismObject<NodeType> nodeInRepo;
    String oid = nodePrism.getOid();
    PolyStringType myName = nodePrism.asObjectable().getName();
    LOGGER.trace("Verifying node record with OID = " + oid);
    // first, let us check the record of this node - whether it exists and whether the internalNodeIdentifier is OK
    try {
        nodeInRepo = getRepositoryService().getObject(NodeType.class, oid, null, result);
    } catch (ObjectNotFoundException e) {
        if (doesNodeExist(result, myName)) {
            LoggingUtils.logException(LOGGER, "The record of this node cannot be read (OID {} not found), but " + "another node record with the name '{}' exists. It seems that in this cluster " + "there are two or more nodes with the same name '{}'. Stopping the scheduler " + "to minimize the damage.", e, oid, myName, myName);
            registerNodeError(NodeErrorStatusType.DUPLICATE_NODE_ID_OR_NAME);
            return;
        } else {
            LoggingUtils.logException(LOGGER, "The record of this node cannot be read (OID {} not found). It  " + "seems it was deleted in the meantime. Please check the reason. Stopping the scheduler " + "to minimize the damage.", e, oid, myName, myName);
            // actually we could re-register the node, but it is safer (and easier for now :) to stop the node instead
            registerNodeError(NodeErrorStatusType.NODE_REGISTRATION_FAILED);
            return;
        }
    } catch (SchemaException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Cannot check the record of this node (OID = {}) because of schema exception. Stopping the scheduler.", e, oid);
        registerNodeError(NodeErrorStatusType.NODE_REGISTRATION_FAILED);
        return;
    }
    // check the internalNodeIdentifier
    String existingId = nodePrism.asObjectable().getInternalNodeIdentifier();
    String idInRepo = nodeInRepo.asObjectable().getInternalNodeIdentifier();
    if (!existingId.equals(idInRepo)) {
        LOGGER.error("Internal node identifier has been overwritten in the repository. " + "Probably somebody has overwritten it in the meantime, i.e. another node with the name of '" + nodePrism.asObjectable().getName() + "' is running. Stopping the scheduler.");
        registerNodeError(NodeErrorStatusType.DUPLICATE_NODE_ID_OR_NAME);
        return;
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 63 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class AbstractEDirTest method test500AddOrgMeleeIsland.

// TODO: create account with a group membership
@Test
public void test500AddOrgMeleeIsland() throws Exception {
    final String TEST_NAME = "test500AddOrgMeleeIsland";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<OrgType> org = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(OrgType.class).instantiate();
    OrgType orgType = org.asObjectable();
    orgType.setName(new PolyStringType(GROUP_MELEE_ISLAND_NAME));
    AssignmentType metaroleAssignment = new AssignmentType();
    ObjectReferenceType metaroleRef = new ObjectReferenceType();
    metaroleRef.setOid(ROLE_META_ORG_OID);
    metaroleRef.setType(RoleType.COMPLEX_TYPE);
    metaroleAssignment.setTargetRef(metaroleRef);
    orgType.getAssignment().add(metaroleAssignment);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    addObject(org, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    orgMeleeIslandOid = org.getOid();
    Entry entry = assertLdapGroup(GROUP_MELEE_ISLAND_NAME);
    org = getObject(OrgType.class, orgMeleeIslandOid);
    groupMeleeOid = getSingleLinkOid(org);
    PrismObject<ShadowType> shadow = getShadowModel(groupMeleeOid);
    display("Shadow (model)", shadow);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) Entry(org.apache.directory.api.ldap.model.entry.Entry) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 64 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class AbstractAdLdapTest method test500AddOrgMeleeIsland.

@Test
public void test500AddOrgMeleeIsland() throws Exception {
    final String TEST_NAME = "test500AddOrgMeleeIsland";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<OrgType> org = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(OrgType.class).instantiate();
    OrgType orgType = org.asObjectable();
    orgType.setName(new PolyStringType(GROUP_MELEE_ISLAND_NAME));
    AssignmentType metaroleAssignment = new AssignmentType();
    ObjectReferenceType metaroleRef = new ObjectReferenceType();
    metaroleRef.setOid(ROLE_META_ORG_OID);
    metaroleRef.setType(RoleType.COMPLEX_TYPE);
    metaroleAssignment.setTargetRef(metaroleRef);
    orgType.getAssignment().add(metaroleAssignment);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    addObject(org, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    orgMeleeIslandOid = org.getOid();
    Entry entry = assertLdapGroup(GROUP_MELEE_ISLAND_NAME);
    org = getObject(OrgType.class, orgMeleeIslandOid);
    groupMeleeOid = getSingleLinkOid(org);
    PrismObject<ShadowType> shadow = getShadowModel(groupMeleeOid);
    display("Shadow (model)", shadow);
    assertLdapConnectorInstances(2);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest)

Example 65 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class ModelClientUtil method createPolyStringType.

//    public static SearchFilterType parseSearchFilterType(String filterClauseAsXml) throws IOException, SAXException {
//        Element filterClauseAsElement = parseElement(filterClauseAsXml);
//        SearchFilterType searchFilterType = new SearchFilterType();
//        searchFilterType.setFilterClause(filterClauseAsElement);
//        return searchFilterType;
//    }
public static PolyStringType createPolyStringType(String string, Document doc) {
    PolyStringType polyStringType = new PolyStringType();
    polyStringType.setOrig(string);
    return polyStringType;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType)

Aggregations

PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)94 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 Test (org.testng.annotations.Test)23 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)20 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 QName (javax.xml.namespace.QName)11 Task (com.evolveum.midpoint.task.api.Task)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 File (java.io.File)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ArrayList (java.util.ArrayList)7 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4