Search in sources :

Example 61 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class ImportTest method test005ImportUsersWithOverwrite.

// Import the same thing again, this time with overwrite option. This should go well.
@Test
public void test005ImportUsersWithOverwrite() throws Exception {
    TestUtil.displayTestTile(this, "test005ImportUsersWithOverwrite");
    // GIVEN
    Task task = taskManager.createTaskInstance();
    OperationResult result = new OperationResult(ImportTest.class.getName() + "test005ImportUsersWithOverwrite");
    FileInputStream stream = new FileInputStream(IMPORT_USERS_OVERWRITE_FILE);
    ImportOptionsType options = getDefaultImportOptions();
    options.setOverwrite(true);
    dummyAuditService.clear();
    // WHEN
    modelService.importObjectsFromStream(stream, options, task, result);
    // THEN
    result.computeStatus();
    display("Result after import with overwrite", result);
    TestUtil.assertSuccess("Import failed (result)", result, 2);
    // list all users
    List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, new ObjectQuery(), null, task, result);
    // Three old users, one new
    assertEquals(5, users.size());
    for (PrismObject<UserType> user : users) {
        UserType userType = user.asObjectable();
        if (userType.getName().equals("jack")) {
            // OID and all the attributes should be the same
            assertEquals(USER_JACK_OID, userType.getOid());
            PrismAsserts.assertEqualsPolyString("wrong givenName", "Jack", userType.getGivenName());
            PrismAsserts.assertEqualsPolyString("wrong familyName", "Sparrow", userType.getFamilyName());
            PrismAsserts.assertEqualsPolyString("wrong fullName", "Cpt. Jack Sparrow", userType.getFullName());
        }
        if (userType.getName().equals("will")) {
            // OID should be the same, and there should be an employee type
            assertEquals(USER_WILL_OID, userType.getOid());
            assertTrue("Wrong Will's employee type", userType.getEmployeeType().contains("legendary"));
        }
        if (userType.getName().equals("guybrush")) {
            // OID may be different, there should be a locality attribute
            guybrushOid = userType.getOid();
            assertNotNull(guybrushOid);
            PrismAsserts.assertEqualsPolyString("Guybrush is not in the Caribbean", "Deep in the Caribbean", userType.getLocality());
        }
        if (userType.getName().equals("ht")) {
            // Herman should be here now
            hermanOid = userType.getOid();
            assertNotNull(hermanOid);
            PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman Toothrot", userType.getFullName());
            PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman", userType.getGivenName());
            PrismAsserts.assertEqualsPolyString("Herman is confused", "Toothrot", userType.getFamilyName());
        }
    }
    assertUsers(5);
    // Check audit
    display("Audit", dummyAuditService);
    // 1 failed, 7 succeeded
    dummyAuditService.assertRecords(8);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ImportOptionsType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 62 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method assertHasShadow.

protected void assertHasShadow(String username, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException {
    ObjectQuery query = createAccountShadowQuery(username, resource);
    List<PrismObject<ShadowType>> accounts = repositoryService.searchObjects(ShadowType.class, query, null, result);
    if (accounts.isEmpty()) {
        AssertJUnit.fail("No shadow for " + username + " on " + resource);
    } else if (accounts.size() > 1) {
        AssertJUnit.fail("Too many shadows for " + username + " on " + resource + " (" + accounts.size() + "): " + accounts);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 63 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class TestDummy method test110SeachIterative.

@Test
public void test110SeachIterative() throws Exception {
    final String TEST_NAME = "test110SeachIterative";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    // Make sure there is an account on resource that the provisioning has
    // never seen before, so there is no shadow
    // for it yet.
    DummyAccount newAccount = new DummyAccount("meathook");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Meathook");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Sea Monkey");
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    newAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 666L);
    newAccount.setEnabled(true);
    newAccount.setPassword("parrotMonster");
    dummyResource.addAccount(newAccount);
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_DUMMY_OID, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME), prismContext);
    final XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    final Holder<Boolean> seenMeathookHolder = new Holder<Boolean>(false);
    final List<PrismObject<ShadowType>> foundObjects = new ArrayList<PrismObject<ShadowType>>();
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            foundObjects.add(object);
            display("Found", object);
            XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
            assertTrue(object.canRepresent(ShadowType.class));
            try {
                checkAccountShadow(object, parentResult, true, startTs, endTs);
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            assertCachingMetadata(object, false, startTs, endTs);
            if (object.asObjectable().getName().getOrig().equals("meathook")) {
                meathookAccountOid = object.getOid();
                seenMeathookHolder.setValue(true);
                try {
                    Long loot = ShadowUtil.getAttributeValue(object, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME));
                    assertEquals("Wrong meathook's loot", (Long) 666L, loot);
                } catch (SchemaException e) {
                    throw new SystemException(e.getMessage(), e);
                }
            }
            return true;
        }
    };
    rememberShadowFetchOperationCount();
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
    // THEN
    XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
    result.computeStatus();
    display("searchObjectsIterative result", result);
    TestUtil.assertSuccess(result);
    assertShadowFetchOperationCountIncrement(1);
    assertEquals(4, foundObjects.size());
    checkConsistency(foundObjects);
    assertProtected(foundObjects, 1);
    PrismObject<ShadowType> shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    assertRepoShadowCachedAttributeValue(shadowWillRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Flying Dutchman");
    checkRepoAccountShadowWill(shadowWillRepo, startTs, endTs);
    PrismObject<ShadowType> shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
    display("Meathook shadow", shadowMeathook);
    assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    assertRepoCachingMetadata(shadowMeathook, startTs, endTs);
    // And again ...
    foundObjects.clear();
    rememberShadowFetchOperationCount();
    XMLGregorianCalendar startTs2 = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
    // THEN
    XMLGregorianCalendar endTs2 = clock.currentTimeXMLGregorianCalendar();
    assertShadowFetchOperationCountIncrement(1);
    display("Found shadows", foundObjects);
    assertEquals(4, foundObjects.size());
    checkConsistency(foundObjects);
    assertProtected(foundObjects, 1);
    shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWill(shadowWillRepo, startTs2, endTs2);
    shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
    assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
    assertRepoCachingMetadata(shadowMeathook, startTs2, endTs2);
    assertSteadyResource();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(com.evolveum.midpoint.util.Holder) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 64 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class TestRbac method test010SearchReuqestableRoles.

@Test
public void test010SearchReuqestableRoles() throws Exception {
    final String TEST_NAME = "test010SearchReuqestableRoles";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ObjectQuery query = QueryBuilder.queryFor(RoleType.class, prismContext).item(RoleType.F_REQUESTABLE).eq(true).build();
    // WHEN
    List<PrismObject<RoleType>> requestableRoles = modelService.searchObjects(RoleType.class, query, null, task, result);
    // THEN
    display("Requestable roles", requestableRoles);
    assertEquals("Unexpected number of requestable roles", 3, requestableRoles.size());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 65 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class ObjectAlreadyExistHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof ObjectAlreadyExistsException) {
            throw (ObjectAlreadyExistsException) ex;
        } else {
            throw new ObjectAlreadyExistsException(ex.getMessage(), ex);
        }
    }
    LOGGER.trace("Start to hanlde ObjectAlreadyExitsException.");
    OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectAlreadyExistHandler.handleError." + op.name());
    operationResult.addParam("shadow", shadow);
    operationResult.addParam("currentOperation", op);
    operationResult.addParam("exception", ex.getMessage());
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setResource(shadow.getResource().asPrismObject());
    change.setSourceChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_DISCOVERY));
    ObjectQuery query = createQueryByIcfName(shadow);
    final List<PrismObject<ShadowType>> foundAccount = getExistingAccount(query, task, operationResult);
    PrismObject<ShadowType> resourceAccount = null;
    if (!foundAccount.isEmpty() && foundAccount.size() == 1) {
        resourceAccount = foundAccount.get(0);
    }
    LOGGER.trace("Found conflicting resource object: {}", resourceAccount);
    try {
        if (resourceAccount != null) {
            // Original object and found object share the same object class, therefore they must
            // also share a kind. We can use this short-cut.
            resourceAccount.asObjectable().setKind(shadow.getKind());
            change.setCurrentShadow(resourceAccount);
            // TODO: task initialization
            //			Task task = taskManager.createTaskInstance();
            changeNotificationDispatcher.notifyChange(change, task, operationResult);
        }
    } finally {
        operationResult.computeStatus();
    }
    if (operationResult.isSuccess()) {
        parentResult.recordSuccess();
        parentResult.muteLastSubresultError();
    }
    if (compensate) {
        throw new ObjectAlreadyExistsException(ex.getMessage(), ex);
    }
    return shadow;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)697 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)453 Test (org.testng.annotations.Test)335 PrismObject (com.evolveum.midpoint.prism.PrismObject)284 Task (com.evolveum.midpoint.task.api.Task)268 QName (javax.xml.namespace.QName)111 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)78 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)76 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)64 ArrayList (java.util.ArrayList)61 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)58 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)53 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)41 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)41 SystemException (com.evolveum.midpoint.util.exception.SystemException)38 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)37 NotNull (org.jetbrains.annotations.NotNull)35 List (java.util.List)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)32 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)27