Search in sources :

Example 56 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class TestResources method test200GetResourceRawAfterSchema.

@Test
public void test200GetResourceRawAfterSchema() throws Exception {
    final String TEST_NAME = "test200GetResourceRawAfterSchema";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestResources.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    IntegrationTestTools.assertNoRepoCache();
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
    // WHEN
    PrismObject<ResourceType> resource = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, options, task, result);
    // THEN
    IntegrationTestTools.assertNoRepoCache();
    SqlRepoTestUtil.assertVersionProgress(null, resource.getVersion());
    lastVersion = resource.getVersion();
    display("Initial version", lastVersion);
    result.computeStatus();
    TestUtil.assertSuccess("getObject result", result);
    IntegrationTestTools.displayXml("Initialized dummy resource", resource);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Test(org.testng.annotations.Test)

Example 57 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class AbstractManualResourceTest method test102GetAccountWillFuture.

@Test
public void test102GetAccountWillFuture() throws Exception {
    final String TEST_NAME = "test102GetAccountWillFuture";
    displayTestTile(TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    syncServiceMock.reset();
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createPointInTimeType(PointInTimeType.FUTURE));
    // WHEN
    displayWhen(TEST_NAME);
    PrismObject<ShadowType> shadowProvisioning = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, task, result);
    // THEN
    displayThen(TEST_NAME);
    assertSuccess(result);
    display("Provisioning shadow", shadowProvisioning);
    ShadowType shadowTypeProvisioning = shadowProvisioning.asObjectable();
    assertShadowName(shadowProvisioning, ACCOUNT_WILL_USERNAME);
    assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, shadowTypeProvisioning.getKind());
    assertAttribute(shadowProvisioning, ATTR_USERNAME_QNAME, ACCOUNT_WILL_USERNAME);
    assertAttribute(shadowProvisioning, ATTR_FULLNAME_QNAME, ACCOUNT_WILL_FULLNAME);
    assertNoAttribute(shadowProvisioning, ATTR_DESCRIPTION_QNAME);
    assertShadowActivationAdministrativeStatus(shadowProvisioning, ActivationStatusType.ENABLED);
    assertShadowExists(shadowProvisioning, true);
// TODO 
//		assertShadowPassword(shadowProvisioning);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)

Example 58 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class ReportFunctions method searchCertificationDefinitions.

// TODO implement if needed
//    <O extends Containerable> RefFilter createReferenceEqualFilter(QName propertyName, Class<O> type, String... oids) {
//        return RefFilter.createReferenceEqual(propertyName, type, prismContext, oids);
//    }
//    <O extends Containerable> RefFilter createReferenceEqualFilter(ItemPath propertyPath, Class<O> type, String... oids) throws SchemaException {
//        return RefFilter.createReferenceEqual(propertyPath, type, prismContext, oids);
//    }
//    Object parseObjectFromXML (String xml) throws SchemaException {
//        return prismContext.parserFor(xml).xml().parseAnyData();
//    }
/**
     * Retrieves all definitions.
     * Augments them by count of campaigns (all + open ones).
     *
     * TODO query parameters, customizable sorting
     * definitions and campaigns counts are expected to be low, so we can afford to go through all of them here
     */
public Collection<PrismObject<AccessCertificationDefinitionForReportType>> searchCertificationDefinitions() throws ConfigurationException, SchemaException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    Task task = taskManager.createTaskInstance();
    OperationResult result = task.getResult();
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
    List<PrismObject<AccessCertificationDefinitionType>> definitions = model.searchObjects(AccessCertificationDefinitionType.class, null, options, task, result);
    final Map<String, PrismObject<AccessCertificationDefinitionForReportType>> definitionsForReportMap = new HashMap<>();
    for (PrismObject<AccessCertificationDefinitionType> definition : definitions) {
        // create subclass with the values copied from the superclass
        PrismObject<AccessCertificationDefinitionForReportType> definitionForReport = prismContext.createObjectable(AccessCertificationDefinitionForReportType.class).asPrismObject();
        for (Item<?, ?> item : definition.getValue().getItems()) {
            definitionForReport.getValue().add(item.clone());
        }
        definitionsForReportMap.put(definition.getOid(), definitionForReport);
    }
    ResultHandler<AccessCertificationCampaignType> handler = (campaignObject, parentResult) -> {
        AccessCertificationCampaignType campaign = campaignObject.asObjectable();
        if (campaign.getDefinitionRef() != null) {
            String definitionOid = campaign.getDefinitionRef().getOid();
            PrismObject<AccessCertificationDefinitionForReportType> definitionObject = definitionsForReportMap.get(definitionOid);
            if (definitionObject != null) {
                AccessCertificationDefinitionForReportType definition = definitionObject.asObjectable();
                int campaigns = definition.getCampaigns() != null ? definition.getCampaigns() : 0;
                definition.setCampaigns(campaigns + 1);
                AccessCertificationCampaignStateType state = campaign.getState();
                if (state != AccessCertificationCampaignStateType.CREATED && state != CLOSED) {
                    int openCampaigns = definition.getOpenCampaigns() != null ? definition.getOpenCampaigns() : 0;
                    definition.setOpenCampaigns(openCampaigns + 1);
                }
            }
        }
        return true;
    };
    model.searchObjectsIterative(AccessCertificationCampaignType.class, null, handler, null, task, result);
    List<PrismObject<AccessCertificationDefinitionForReportType>> rv = new ArrayList<>(definitionsForReportMap.values());
    Collections.sort(rv, (o1, o2) -> {
        String n1 = o1.asObjectable().getName().getOrig();
        String n2 = o2.asObjectable().getName().getOrig();
        if (n1 == null) {
            n1 = "";
        }
        return n1.compareTo(n2);
    });
    for (PrismObject<AccessCertificationDefinitionForReportType> defObject : rv) {
        AccessCertificationDefinitionForReportType def = defObject.asObjectable();
        if (def.getCampaigns() == null) {
            def.setCampaigns(0);
        }
        if (def.getOpenCampaigns() == null) {
            def.setOpenCampaigns(0);
        }
    }
    return rv;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) F_STATE(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_STATE) Trace(com.evolveum.midpoint.util.logging.Trace) F_NAME(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_NAME) TaskManager(com.evolveum.midpoint.task.api.TaskManager) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) RetrieveOption(com.evolveum.midpoint.schema.RetrieveOption) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) CLOSED(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.CLOSED) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) AuditService(com.evolveum.midpoint.audit.api.AuditService) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Task(com.evolveum.midpoint.task.api.Task) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AuditEventTypeType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventTypeType) ModelService(com.evolveum.midpoint.model.api.ModelService) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) AuditEventStageType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Entry(java.util.Map.Entry) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QName(javax.xml.namespace.QName) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Example 59 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class ReportFunctions method getCertificationCampaigns.

public List<PrismObject<AccessCertificationCampaignType>> getCertificationCampaigns(Boolean alsoClosedCampaigns) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    Task task = taskManager.createTaskInstance();
    ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCampaignType.class, prismContext).asc(F_NAME).build();
    if (!Boolean.TRUE.equals(alsoClosedCampaigns)) {
        query.addFilter(QueryBuilder.queryFor(AccessCertificationCampaignType.class, prismContext).not().item(F_STATE).eq(CLOSED).buildFilter());
    }
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
    options.add(SelectorOptions.create(AccessCertificationCampaignType.F_CASE, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE)));
    return model.searchObjects(AccessCertificationCampaignType.class, query, options, task, task.getResult());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 60 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class TestLdap method test202AssignLdapAccountToGuybrush.

/**
	 * Just a first step for the following test.
	 * Also, Guybrush has a photo. Check that binary property mapping works.
	 */
@Test
public void test202AssignLdapAccountToGuybrush() throws Exception {
    final String TEST_NAME = "test202AssignLdapAccountToGuybrush";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestLdap.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    byte[] photoIn = Files.readAllBytes(Paths.get(DOT_JPG_FILENAME));
    display("Photo in", MiscUtil.binaryToHex(photoIn));
    modifyUserReplace(USER_GUYBRUSH_OID, UserType.F_JPEG_PHOTO, task, result, photoIn);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
    PrismObject<UserType> userBefore = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, options, task, result);
    display("User before", userBefore);
    byte[] userJpegPhotoBefore = userBefore.asObjectable().getJpegPhoto();
    assertEquals("Photo byte length changed (user before)", photoIn.length, userJpegPhotoBefore.length);
    assertTrue("Photo bytes do not match (user before)", Arrays.equals(photoIn, userJpegPhotoBefore));
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    assignAccount(USER_GUYBRUSH_OID, RESOURCE_OPENDJ_OID, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    Entry entry = assertOpenDjAccount(USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, true);
    byte[] jpegPhotoLdap = OpenDJController.getAttributeValueBinary(entry, "jpegPhoto");
    assertNotNull("No jpegPhoto in LDAP entry", jpegPhotoLdap);
    assertEquals("Byte length changed (LDAP)", photoIn.length, jpegPhotoLdap.length);
    assertTrue("Bytes do not match (LDAP)", Arrays.equals(photoIn, jpegPhotoLdap));
    PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, options, task, result);
    display("User after", userAfter);
    String accountOid = getSingleLinkOid(userAfter);
    PrismObject<ShadowType> shadow = getShadowModel(accountOid);
    PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    QName jpegPhotoQName = new QName(RESOURCE_OPENDJ_NAMESPACE, "jpegPhoto");
    PrismProperty<byte[]> jpegPhotoAttr = attributesContainer.findProperty(jpegPhotoQName);
    byte[] photoBytesOut = jpegPhotoAttr.getValues().get(0).getValue();
    display("Photo bytes out", MiscUtil.binaryToHex(photoBytesOut));
    assertEquals("Photo byte length changed (shadow)", photoIn.length, photoBytesOut.length);
    assertTrue("Photo bytes do not match (shadow)", Arrays.equals(photoIn, photoBytesOut));
    assertUsers(NUM_INITIAL_USERS);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Entry(org.opends.server.types.Entry) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)127 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)106 Task (com.evolveum.midpoint.task.api.Task)82 Test (org.testng.annotations.Test)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)34 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)31 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)31 PrismObject (com.evolveum.midpoint.prism.PrismObject)28 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)28 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ArrayList (java.util.ArrayList)19 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 QName (javax.xml.namespace.QName)17 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)16 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)16 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)14 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)14 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12