Search in sources :

Example 51 with ObjectFilter

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

the class TestParseResource method assertResourcePrism.

private void assertResourcePrism(PrismObject<ResourceType> resource, boolean isSimple) throws SchemaException {
    PrismContext prismContext = getPrismContext();
    AssertJUnit.assertEquals("Wrong oid (prism)", TestConstants.RESOURCE_OID, resource.getOid());
    //		assertEquals("Wrong version", "42", resource.getVersion());
    PrismObjectDefinition<ResourceType> resourceDefinition = resource.getDefinition();
    assertNotNull("No resource definition", resourceDefinition);
    PrismAsserts.assertObjectDefinition(resourceDefinition, new QName(SchemaConstantsGenerated.NS_COMMON, "resource"), ResourceType.COMPLEX_TYPE, ResourceType.class);
    assertEquals("Wrong class in resource", ResourceType.class, resource.getCompileTimeClass());
    ResourceType resourceType = resource.asObjectable();
    assertNotNull("asObjectable resulted in null", resourceType);
    assertPropertyValue(resource, "name", PrismTestUtil.createPolyString("Embedded Test OpenDJ"));
    assertPropertyDefinition(resource, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
    if (!isSimple) {
        assertPropertyValue(resource, "namespace", TestConstants.RESOURCE_NAMESPACE);
        assertPropertyDefinition(resource, "namespace", DOMUtil.XSD_ANYURI, 0, 1);
    }
    PrismReference connectorRef = resource.findReference(ResourceType.F_CONNECTOR_REF);
    assertNotNull("No connectorRef", connectorRef);
    PrismReferenceValue connectorRefVal = connectorRef.getValue();
    assertNotNull("No connectorRef value", connectorRefVal);
    assertEquals("Wrong type in connectorRef value", ConnectorType.COMPLEX_TYPE, connectorRefVal.getTargetType());
    SearchFilterType filter = connectorRefVal.getFilter();
    assertNotNull("No filter in connectorRef value", filter);
    if (!isSimple) {
        ObjectFilter objectFilter = QueryConvertor.parseFilter(filter, ConnectorType.class, prismContext);
        assertTrue("Wrong kind of filter: " + objectFilter, objectFilter instanceof EqualFilter);
        EqualFilter equalFilter = (EqualFilter) objectFilter;
        // should be extension/x:extConnType
        ItemPath path = equalFilter.getPath();
        PrismAsserts.assertPathEqualsExceptForPrefixes("Wrong filter path", namespaces ? new ItemPath(new QName("extension"), new QName("http://x/", "extConnType")) : new ItemPath(new QName("extension"), new QName("extConnType")), path);
        PrismPropertyValue filterValue = (PrismPropertyValue) equalFilter.getValues().get(0);
        assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((RawType) filterValue.getValue()).getParsedRealValue(String.class).trim());
    //assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((String) filterValue.getValue()).trim());
    }
    EvaluationTimeType resolutionTime = connectorRefVal.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.IMPORT, resolutionTime);
    }
    PrismContainer<?> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertContainerDefinition(configurationContainer, "configuration", ConnectorConfigurationType.COMPLEX_TYPE, 1, 1);
    PrismContainerValue<?> configContainerValue = configurationContainer.getValue();
    List<Item<?, ?>> configItems = configContainerValue.getItems();
    assertEquals("Wrong number of config items", isSimple ? 1 : 4, configItems.size());
    PrismContainer<?> ldapConfigPropertiesContainer = configurationContainer.findContainer(ICFC_CONFIGURATION_PROPERTIES);
    assertNotNull("No icfcldap:configurationProperties container", ldapConfigPropertiesContainer);
    PrismContainerDefinition<?> ldapConfigPropertiesContainerDef = ldapConfigPropertiesContainer.getDefinition();
    assertNotNull("No icfcldap:configurationProperties container definition", ldapConfigPropertiesContainerDef);
    assertEquals("icfcldap:configurationProperties container definition maxOccurs", 1, ldapConfigPropertiesContainerDef.getMaxOccurs());
    List<Item<?, ?>> ldapConfigPropItems = ldapConfigPropertiesContainer.getValue().getItems();
    assertEquals("Wrong number of ldapConfigPropItems items", 7, ldapConfigPropItems.size());
    PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    if (isSimple) {
        assertNull("Schema sneaked in", schemaContainer);
    } else {
        assertNotNull("No schema container", schemaContainer);
    }
    PrismContainer<?> schemaHandlingContainer = resource.findContainer(ResourceType.F_SCHEMA_HANDLING);
    if (isSimple) {
        assertNull("SchemaHandling sneaked in", schemaHandlingContainer);
    } else {
        assertNotNull("No schemaHandling container", schemaHandlingContainer);
    }
    if (!isSimple) {
        PrismProperty<SynchronizationType> synchronizationProp = resource.findProperty(ResourceType.F_SYNCHRONIZATION);
        SynchronizationType synchronizationType = synchronizationProp.getRealValue();
        ObjectSynchronizationType objectSynchronizationType = synchronizationType.getObjectSynchronization().get(0);
        List<ConditionalSearchFilterType> correlations = objectSynchronizationType.getCorrelation();
        assertEquals("Wrong number of correlation expressions", 1, correlations.size());
        ConditionalSearchFilterType correlationFilterType = correlations.get(0);
        System.out.println("\nCorrelation filter");
        System.out.println(correlationFilterType.debugDump());
        ObjectFilter objectFilter = QueryConvertor.parseFilter(correlationFilterType.serializeToXNode(), prismContext);
        PrismAsserts.assertAssignableFrom(EqualFilter.class, objectFilter);
        EqualFilter equalsFilter = (EqualFilter) objectFilter;
        equalsFilter.getFullPath();
        assertNull("Unexpected values in correlation expression", equalsFilter.getValues());
        ExpressionWrapper expression = equalsFilter.getExpression();
        assertNotNull("No expressions in correlation expression", expression);
        ExpressionType expressionType = (ExpressionType) expression.getExpression();
        assertEquals("Wrong number of expression evaluators in correlation expression", 1, expressionType.getExpressionEvaluator().size());
        ItemPathType itemPathType = (ItemPathType) expressionType.getExpressionEvaluator().get(0).getValue();
        // $account/c:attributes/my:yyy
        PrismAsserts.assertPathEqualsExceptForPrefixes("path in correlation expression", namespaces ? new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName(SchemaConstantsGenerated.NS_COMMON, "attributes")), new NameItemPathSegment(new QName("http://myself.me/schemas/whatever", "yyy"))) : new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName("attributes")), new NameItemPathSegment(new QName("yyy"))), itemPathType.getItemPath());
    //PrismAsserts.assertAllParsedNodes(expression);
    // TODO
    }
}
Also used : NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 52 with ObjectFilter

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

the class AccCertUpdateHelper method createAdHocCampaignObject.

<O extends ObjectType> AccessCertificationCampaignType createAdHocCampaignObject(AccessCertificationDefinitionType definition, PrismObject<O> focus, Task task, OperationResult result) throws SecurityViolationException, ObjectNotFoundException, SchemaException {
    definition.setName(PolyStringType.fromOrig(PolyString.getOrig(definition.getName()) + " " + PolyString.getOrig(focus.getName())));
    definition.setLastCampaignIdUsed(null);
    AccessCertificationCampaignType campaign = createCampaignObject(definition, task, result);
    AccessCertificationObjectBasedScopeType scope;
    if ((campaign.getScopeDefinition() instanceof AccessCertificationObjectBasedScopeType)) {
        scope = (AccessCertificationObjectBasedScopeType) campaign.getScopeDefinition();
    } else {
        // TODO!
        scope = new AccessCertificationAssignmentReviewScopeType(prismContext);
        campaign.setScopeDefinition(scope);
    }
    Class<? extends ObjectType> focusClass = focus.asObjectable().getClass();
    scope.setObjectType(ObjectTypes.getObjectType(focusClass).getTypeQName());
    ObjectFilter objectFilter = QueryBuilder.queryFor(focusClass, prismContext).id(focus.getOid()).buildFilter();
    scope.setSearchFilter(QueryConvertor.createSearchFilterType(objectFilter, prismContext));
    return campaign;
}
Also used : ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 53 with ObjectFilter

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

the class AccCertCaseOperationsHelper method getDeltasToCreateCases.

<F extends FocusType> List<ItemDelta<?, ?>> getDeltasToCreateCases(final AccessCertificationCampaignType campaign, AccessCertificationStageType stage, final CertificationHandler handler, final Task task, final OperationResult result) throws SchemaException, ObjectNotFoundException {
    final List<ItemDelta<?, ?>> rv = new ArrayList<>();
    final String campaignShortName = toShortString(campaign);
    final AccessCertificationScopeType scope = campaign.getScopeDefinition();
    LOGGER.trace("Creating cases for scope {} in campaign {}", scope, campaignShortName);
    if (scope != null && !(scope instanceof AccessCertificationObjectBasedScopeType)) {
        throw new IllegalStateException("Unsupported access certification scope type: " + scope.getClass() + " for campaign " + campaignShortName);
    }
    final AccessCertificationObjectBasedScopeType objectBasedScope = (AccessCertificationObjectBasedScopeType) scope;
    final List<AccessCertificationCaseType> existingCases = queryHelper.searchCases(campaign.getOid(), null, null, result);
    if (!existingCases.isEmpty()) {
        throw new IllegalStateException("Unexpected " + existingCases.size() + " certification case(s) in campaign object " + campaignShortName + ". At this time there should be none.");
    }
    // create a query to find target objects from which certification cases will be created
    final ObjectQuery query = new ObjectQuery();
    final QName scopeDeclaredObjectType;
    if (objectBasedScope != null) {
        scopeDeclaredObjectType = objectBasedScope.getObjectType();
    } else {
        scopeDeclaredObjectType = null;
    }
    final QName objectType;
    if (scopeDeclaredObjectType != null) {
        objectType = scopeDeclaredObjectType;
    } else {
        objectType = handler.getDefaultObjectType();
    }
    if (objectType == null) {
        throw new IllegalStateException("Unspecified object type (and no default one provided) for campaign " + campaignShortName);
    }
    @SuppressWarnings({ "unchecked", "raw" }) final Class<F> objectClass = (Class<F>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
    if (objectClass == null) {
        throw new IllegalStateException("Object class not found for object type " + objectType + " in campaign " + campaignShortName);
    }
    final SearchFilterType searchFilter = objectBasedScope != null ? objectBasedScope.getSearchFilter() : null;
    if (searchFilter != null) {
        ObjectFilter filter = QueryConvertor.parseFilter(searchFilter, objectClass, prismContext);
        query.setFilter(filter);
    }
    final List<AccessCertificationCaseType> caseList = new ArrayList<>();
    // create certification cases by executing the query and caseExpression on its results
    // here the subclasses of this class come into play
    ResultHandler<F> resultHandler = (object, parentResult) -> {
        try {
            caseList.addAll(handler.createCasesForObject(object, campaign, task, parentResult));
        } catch (ExpressionEvaluationException | ObjectNotFoundException | SchemaException e) {
            // TODO process the exception more intelligently
            throw new SystemException("Cannot create certification case for object " + toShortString(object.asObjectable()) + ": " + e.getMessage(), e);
        }
        return true;
    };
    repositoryService.searchObjectsIterative(objectClass, query, resultHandler, null, false, result);
    AccessCertificationReviewerSpecificationType reviewerSpec = reviewersHelper.findReviewersSpecification(campaign, 1, task, result);
    ContainerDelta<AccessCertificationCaseType> caseDelta = ContainerDelta.createDelta(F_CASE, AccessCertificationCampaignType.class, prismContext);
    for (AccessCertificationCaseType _case : caseList) {
        _case.setStageNumber(1);
        _case.setCurrentStageCreateTimestamp(stage.getStartTimestamp());
        _case.setCurrentStageDeadline(stage.getDeadline());
        List<ObjectReferenceType> reviewers = reviewersHelper.getReviewersForCase(_case, campaign, reviewerSpec, task, result);
        _case.getWorkItem().addAll(createWorkItems(reviewers, 1));
        String currentStageOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, 1));
        _case.setCurrentStageOutcome(currentStageOutcome);
        _case.setOutcome(OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, currentStageOutcome)));
        @SuppressWarnings({ "raw", "unchecked" }) PrismContainerValue<AccessCertificationCaseType> caseCVal = _case.asPrismContainerValue();
        caseDelta.addValueToAdd(caseCVal);
        LOGGER.trace("Adding certification case:\n{}", caseCVal.debugDumpLazily());
    }
    rv.add(caseDelta);
    LOGGER.trace("Created {} deltas to create {} cases for campaign {}", rv.size(), caseList.size(), campaignShortName);
    return rv;
}
Also used : 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) SecurityEnforcer(com.evolveum.midpoint.security.api.SecurityEnforcer) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) F_CASE(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_CASE) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) DeltaBuilder(com.evolveum.midpoint.prism.delta.builder.DeltaBuilder) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) Task(com.evolveum.midpoint.task.api.Task) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) CertCampaignTypeUtil(com.evolveum.midpoint.schema.util.CertCampaignTypeUtil) ObjectUtils(org.apache.commons.lang.ObjectUtils) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) QueryConvertor(com.evolveum.midpoint.prism.marshaller.QueryConvertor) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) CertificationHandler(com.evolveum.midpoint.certification.impl.handlers.CertificationHandler) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Clock(com.evolveum.midpoint.common.Clock) AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) OutcomeUtils(com.evolveum.midpoint.certification.api.OutcomeUtils) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ObjectTypeUtil.toShortString(com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString) AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectTypeUtil.toShortString(com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 54 with ObjectFilter

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

the class ShadowRefreshTaskHandler method createQuery.

@Override
protected ObjectQuery createQuery(AbstractScannerResultHandler<ShadowType> handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException {
    ObjectQuery query = new ObjectQuery();
    ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, prismContext).exists(ShadowType.F_PENDING_OPERATION).buildFilter();
    query.setFilter(filter);
    return query;
}
Also used : ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 55 with ObjectFilter

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

the class TestFilterExpression method test152EvaluateExpressionEmployeeTypeDefaultsCaptain.

@Test
public void test152EvaluateExpressionEmployeeTypeDefaultsCaptain() throws Exception {
    final String TEST_NAME = "test152EvaluateExpressionEmployeeTypeDefaultsCaptain";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestFilterExpression.class.getName() + "." + TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    ObjectFilter filter = evaluateExpressionAssertFilter("expression-employeeType-filter-defaults.xml", "CAPTAIN", EqualFilter.class, task, result);
    EqualFilter equalFilter = (EqualFilter) filter;
    PrismAsserts.assertValues("Wrong values in filter", equalFilter.getValues(), "CAPTAIN");
    executeFilter(filter, 1, task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)64 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)30 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)25 Task (com.evolveum.midpoint.task.api.Task)21 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 QName (javax.xml.namespace.QName)12 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)8 NoneFilter (com.evolveum.midpoint.prism.query.NoneFilter)7 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)7 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5