Search in sources :

Example 21 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class Main method listTasks.

private static Collection<TaskType> listTasks(ModelPortType modelPort) throws SAXException, IOException, FaultMessage {
    SelectorQualifiedGetOptionsType operationOptions = new SelectorQualifiedGetOptionsType();
    // Let's say we want to retrieve tasks' next scheduled time (because this may be a costly operation if
    // JDBC based quartz scheduler is used, the fetching of this attribute has to be explicitly requested)
    SelectorQualifiedGetOptionType getNextScheduledTimeOption = new SelectorQualifiedGetOptionType();
    // prepare a selector (described by path) + options (saying to retrieve that attribute)
    OptionObjectSelectorType selector = new OptionObjectSelectorType();
    selector.setPath(ModelClientUtil.createItemPathType("nextRunStartTimestamp"));
    getNextScheduledTimeOption.setSelector(selector);
    GetOperationOptionsType selectorOptions = new GetOperationOptionsType();
    selectorOptions.setRetrieve(RetrieveOptionType.INCLUDE);
    getNextScheduledTimeOption.setOptions(selectorOptions);
    // add newly created option to the list of operation options
    operationOptions.getOption().add(getNextScheduledTimeOption);
    Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    modelPort.searchObjects(ModelClientUtil.getTypeQName(TaskType.class), null, operationOptions, objectListHolder, resultHolder);
    ObjectListType objectList = objectListHolder.value;
    return (Collection) objectList.getObject();
}
Also used : GetOperationOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.GetOperationOptionsType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) OptionObjectSelectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.OptionObjectSelectorType) Holder(javax.xml.ws.Holder) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Collection(java.util.Collection) SelectorQualifiedGetOptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionType) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 22 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class Main method searchUserByName.

private static UserType searchUserByName(ModelPortType modelPort, String username) throws SAXException, IOException, FaultMessage, JAXBException {
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    modelPort.searchObjects(ModelClientUtil.getTypeQName(UserType.class), createUserQuery1(username), options, objectListHolder, resultHolder);
    ObjectListType objectList = objectListHolder.value;
    List<ObjectType> objects = objectList.getObject();
    if (objects.isEmpty()) {
        return null;
    }
    if (objects.size() == 1) {
        return (UserType) objects.get(0);
    }
    throw new IllegalStateException("Expected to find a single user with username '" + username + "' but found " + objects.size() + " users instead");
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 23 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class TestSanity method searchUserByName.

private UserType searchUserByName(String name) throws Exception {
    //        Document doc = DOMUtil.getDocument();
    //        Element nameElement = doc.createElementNS(SchemaConstants.C_NAME.getNamespaceURI(),
    //                SchemaConstants.C_NAME.getLocalPart());
    //        nameElement.setTextContent(name);
    //        Element filter = QueryUtil.createEqualFilter(doc, null, nameElement);
    //
    //        QueryType query = new QueryType();
    //        query.setFilter(filter);
    ObjectQuery q = ObjectQueryUtil.createNameQuery(UserType.class, prismContext, name);
    QueryType query = QueryJaxbConvertor.createQueryType(q, prismContext);
    OperationResultType resultType = new OperationResultType();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>(resultType);
    Holder<ObjectListType> listHolder = new Holder<ObjectListType>();
    assertNoRepoCache();
    modelWeb.searchObjects(ObjectTypes.USER.getTypeQName(), query, null, listHolder, resultHolder);
    assertNoRepoCache();
    ObjectListType objects = listHolder.value;
    TestUtil.assertSuccess("searchObjects has failed", resultHolder.value);
    AssertJUnit.assertEquals("User not found (or found too many)", 1, objects.getObject().size());
    UserType user = (UserType) objects.getObject().get(0);
    AssertJUnit.assertEquals(user.getName(), PrismTestUtil.createPolyStringType(name));
    return user;
}
Also used : OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 24 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class TestSanity method test400ImportFromResource.

@Test
public void test400ImportFromResource() throws Exception {
    final String TEST_NAME = "test400ImportFromResource";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    checkAllShadows();
    assertNoRepoCache();
    OperationResult result = new OperationResult(TestSanity.class.getName() + "." + TEST_NAME);
    // Make sure Mr. Gibbs has "l" attribute set to the same value as an outbound expression is setting
    ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_GIBBS_MODIFY_FILE);
    display("Entry from LDIF", entry);
    // Let's add an entry with multiple uids.
    Entry addEntry = openDJController.addEntryFromLdifFile(LDIF_HERMAN_FILENAME);
    display("Entry from LDIF", addEntry);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    TaskType taskType = modelWeb.importFromResource(RESOURCE_OPENDJ_OID, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertNoRepoCache();
    displayJaxb("importFromResource result", taskType.getResult(), SchemaConstants.C_RESULT);
    AssertJUnit.assertEquals("importFromResource has failed", OperationResultStatusType.IN_PROGRESS, taskType.getResult().getStatus());
    // Convert the returned TaskType to a more usable Task
    Task task = taskManager.createTaskInstance(taskType.asPrismObject(), result);
    AssertJUnit.assertNotNull(task);
    assertNotNull(task.getOid());
    AssertJUnit.assertTrue(task.isAsynchronous());
    AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());
    display("Import task after launch", task);
    PrismObject<TaskType> tObject = repositoryService.getObject(TaskType.class, task.getOid(), null, result);
    TaskType taskAfter = tObject.asObjectable();
    display("Import task in repo after launch", taskAfter);
    result.computeStatus();
    TestUtil.assertSuccess("getObject has failed", result);
    final String taskOid = task.getOid();
    waitFor("Waiting for import to complete", new Checker() {

        @Override
        public boolean check() throws CommonException {
            Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
            Holder<ObjectType> objectHolder = new Holder<ObjectType>();
            OperationResult opResult = new OperationResult("import check");
            assertNoRepoCache();
            SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
            try {
                modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), taskOid, options, objectHolder, resultHolder);
            } catch (FaultMessage faultMessage) {
                throw new SystemException(faultMessage);
            }
            assertNoRepoCache();
            //				display("getObject result (wait loop)",resultHolder.value);
            TestUtil.assertSuccess("getObject has failed", resultHolder.value);
            Task task = taskManager.createTaskInstance((PrismObject<TaskType>) objectHolder.value.asPrismObject(), opResult);
            System.out.println(new Date() + ": Import task status: " + task.getExecutionStatus() + ", progress: " + task.getProgress());
            if (task.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
                // Task closed, wait finished
                return true;
            }
            //				IntegrationTestTools.display("Task result while waiting: ", task.getResult());
            return false;
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 180000);
    // wait a second until the task will be definitely saved
    Thread.sleep(1000);
    //### Check task state after the task is finished ###
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();
    modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), task.getOid(), options, objectHolder, resultHolder);
    assertNoRepoCache();
    TestUtil.assertSuccess("getObject has failed", resultHolder.value);
    task = taskManager.createTaskInstance((PrismObject<TaskType>) objectHolder.value.asPrismObject(), result);
    display("Import task after finish (fetched from model)", task);
    AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());
    assertNotNull("Null lastRunStartTimestamp in " + task, task.getLastRunStartTimestamp());
    assertNotNull("Null lastRunFinishTimestamp in " + task, task.getLastRunFinishTimestamp());
    long importDuration = task.getLastRunFinishTimestamp() - task.getLastRunStartTimestamp();
    double usersPerSec = (task.getProgress() * 1000) / importDuration;
    display("Imported " + task.getProgress() + " users in " + importDuration + " milliseconds (" + usersPerSec + " users/sec)");
    OperationResult taskResult = task.getResult();
    AssertJUnit.assertNotNull("Task has no result", taskResult);
    TestUtil.assertSuccess("Import task result is not success", taskResult);
    AssertJUnit.assertTrue("Task failed", taskResult.isSuccess());
    AssertJUnit.assertTrue("No progress", task.getProgress() > 0);
    //### Check if the import created users and shadows ###
    // Listing of shadows is not supported by the provisioning. So we need
    // to look directly into repository
    List<PrismObject<ShadowType>> sobjects = repositoryService.searchObjects(ShadowType.class, null, null, result);
    result.computeStatus();
    TestUtil.assertSuccess("listObjects has failed", result);
    AssertJUnit.assertFalse("No shadows created", sobjects.isEmpty());
    for (PrismObject<ShadowType> aObject : sobjects) {
        ShadowType shadow = aObject.asObjectable();
        display("Shadow object after import (repo)", shadow);
        // This would be really strange ;-)
        assertNotEmpty("No OID in shadow", shadow.getOid());
        assertNotEmpty("No name in shadow", shadow.getName());
        AssertJUnit.assertNotNull("No objectclass in shadow", shadow.getObjectClass());
        AssertJUnit.assertNotNull("Null attributes in shadow", shadow.getAttributes());
        String resourceOid = shadow.getResourceRef().getOid();
        if (resourceOid.equals(RESOURCE_OPENDJ_OID)) {
            assertAttributeNotNull("No identifier in shadow", shadow, getOpenDjPrimaryIdentifierQName());
        } else {
            assertAttributeNotNull("No UID in shadow", shadow, SchemaConstants.ICFS_UID);
        }
    }
    Holder<ObjectListType> listHolder = new Holder<>();
    assertNoRepoCache();
    modelWeb.searchObjects(ObjectTypes.USER.getTypeQName(), null, null, listHolder, resultHolder);
    assertNoRepoCache();
    ObjectListType uobjects = listHolder.value;
    TestUtil.assertSuccess("listObjects has failed", resultHolder.value);
    AssertJUnit.assertFalse("No users created", uobjects.getObject().isEmpty());
    // TODO: use another account, not guybrush
    display("Users after import " + uobjects.getObject().size());
    for (ObjectType oo : uobjects.getObject()) {
        UserType user = (UserType) oo;
        if (SystemObjectsType.USER_ADMINISTRATOR.value().equals(user.getOid())) {
            //skip administrator check
            continue;
        }
        display("User after import (repo)", user);
        // This would be
        assertNotEmpty("No OID in user", user.getOid());
        // really
        // strange ;-)
        assertNotEmpty("No name in user", user.getName());
        assertNotNull("No fullName in user", user.getFullName());
        assertNotEmpty("No fullName in user", user.getFullName().getOrig());
        assertNotEmpty("No familyName in user", user.getFamilyName().getOrig());
        if (user.getName().getOrig().equals(USER_GUYBRUSH_USERNAME)) {
            // skip the rest of checks for guybrush, he does not have LDAP account now
            continue;
        }
        assertTrue("User " + user.getName() + " is disabled (" + user.getActivation().getAdministrativeStatus() + ")", user.getActivation() == null || user.getActivation().getAdministrativeStatus() == ActivationStatusType.ENABLED);
        List<ObjectReferenceType> accountRefs = user.getLinkRef();
        AssertJUnit.assertEquals("Wrong accountRef for user " + user.getName(), 1, accountRefs.size());
        ObjectReferenceType accountRef = accountRefs.get(0);
        boolean found = false;
        for (PrismObject<ShadowType> aObject : sobjects) {
            ShadowType acc = aObject.asObjectable();
            if (accountRef.getOid().equals(acc.getOid())) {
                found = true;
                break;
            }
        }
        if (!found) {
            AssertJUnit.fail("accountRef does not point to existing account " + accountRef.getOid());
        }
        PrismObject<ShadowType> aObject = modelService.getObject(ShadowType.class, accountRef.getOid(), null, task, result);
        ShadowType account = aObject.asObjectable();
        display("Account after import ", account);
        String attributeValueL = ShadowUtil.getMultiStringAttributeValueAsSingle(account, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "l"));
        //            assertEquals("Unexcpected value of l", "middle of nowhere", attributeValueL);
        assertEquals("Unexcpected value of l", getUserLocality(user), attributeValueL);
    }
    // This also includes "idm" user imported from LDAP. Later we need to ignore that one.
    assertEquals("Wrong number of users after import", 10, uobjects.getObject().size());
    checkAllShadows();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) Date(java.util.Date) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 25 with ObjectListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType in project midpoint by Evolveum.

the class TestSanity method test480ListResources.

@Test
public void test480ListResources() throws Exception {
    final String TEST_NAME = "test480ListResources";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResultType result = new OperationResultType();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>(result);
    Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    // WHEN
    modelWeb.searchObjects(ObjectTypes.RESOURCE.getTypeQName(), null, options, objectListHolder, resultHolder);
    // THEN
    display("Resources", objectListHolder.value);
    assertEquals("Unexpected number of resources", 4, objectListHolder.value.getObject().size());
    for (ObjectType object : objectListHolder.value.getObject()) {
        // Marshalling may fail even though the Java object is OK so test for it
        String xml = prismContext.serializeObjectToString(object.asPrismObject(), PrismContext.LANG_XML);
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)27 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)26 Holder (javax.xml.ws.Holder)24 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)18 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)14 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)12 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 Collection (java.util.Collection)9 FaultMessage (com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage)6 Test (org.testng.annotations.Test)6 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)5 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)5 QName (javax.xml.namespace.QName)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)4 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3