Search in sources :

Example 66 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class AssociationTargetSearchExpressionEvaluator method extendQuery.

@Override
protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext params) throws SchemaException, ExpressionEvaluationException {
    RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) params.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
    if (rAssocTargetDef == null) {
        throw new ExpressionEvaluationException("No association target object class definition variable in " + params.getContextDescription() + "; the expression may be used in a wrong place. It is only supposed to create an association.");
    }
    ObjectFilter resourceFilter = ObjectQueryUtil.createResourceFilter(rAssocTargetDef.getResourceType().getOid(), getPrismContext());
    ObjectFilter objectClassFilter = ObjectQueryUtil.createObjectClassFilter(rAssocTargetDef.getObjectClassDefinition().getTypeName(), getPrismContext());
    ObjectFilter extendedFilter = AndFilter.createAnd(resourceFilter, objectClassFilter, query.getFilter());
    query.setFilter(extendedFilter);
    return query;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 67 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class DotModel method exportDot.

public String exportDot() {
    StringBuilder sb = new StringBuilder();
    sb.append("digraph G {\n");
    Set<DataItem> itemsShown = new HashSet<>();
    int clusterNumber = 1;
    int indent = 1;
    for (PrismObject<ResourceType> resource : dataModel.getResources().values()) {
        if (subgraphsForResources) {
            sb.append(indent(indent)).append("subgraph cluster_").append(clusterNumber++).append(" {\n");
            sb.append(indent(indent + 1)).append("label=\"").append(resource.getName()).append("\";\n");
            // TODO style for resource label
            indent++;
        }
        RefinedResourceSchema schema = dataModel.getRefinedResourceSchema(resource.getOid());
        for (RefinedObjectClassDefinition def : schema.getRefinedDefinitions()) {
            StringBuilder sb1 = new StringBuilder();
            sb1.append(indent(indent)).append("subgraph cluster_").append(clusterNumber++).append(" {\n");
            String typeName = "";
            if (!subgraphsForResources && dataModel.getResources().size() > 1) {
                typeName = PolyString.getOrig(resource.getName()) + LF;
            }
            typeName += getObjectTypeName(def, true);
            sb1.append(indent(indent + 1)).append("label=\"").append(typeName).append("\";\n");
            sb1.append(indent(indent + 1)).append("fontname=\"times-bold\";\n\n");
            String previousNodeName = null;
            indent++;
            for (ResourceAttributeDefinition attrDef : def.getAttributeDefinitions()) {
                if (attrDef.isIgnored()) {
                    continue;
                }
                ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(attrDef.getName()));
                previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, item);
            }
            for (RefinedAssociationDefinition assocDef : def.getAssociationDefinitions()) {
                if (assocDef.isIgnored()) {
                    continue;
                }
                ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(assocDef.getName()));
                previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, item);
            }
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, DataModelVisualizerImpl.ACTIVATION_EXISTENCE)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));
            indent--;
            sb1.append(indent(indent)).append("}\n");
            if (previousNodeName != null) {
                sb.append(sb1.toString());
            }
        }
        if (subgraphsForResources) {
            sb.append(indent(indent)).append("}\n");
            indent--;
        }
    }
    sb.append("\n");
    int mappingNode = 1;
    for (Relation relation : dataModel.getRelations()) {
        showNodesIfNeeded(sb, indent, itemsShown, relation.getSources());
        showNodeIfNeeded(sb, indent, itemsShown, relation.getTarget());
        DotRelation dotRelation = getDotRelation(relation);
        if (relation.getSources().size() == 1 && relation.getTarget() != null) {
            DataItem sourceItem = relation.getSources().get(0);
            DataItem targetItem = relation.getTarget();
            DotDataItem dotSourceItem = getDotDataItem(sourceItem);
            DotDataItem dotTargetItem = getDotDataItem(targetItem);
            sb.append(indent(indent)).append(dotSourceItem.getNodeName());
            sb.append(" -> ").append(dotTargetItem.getNodeName());
            sb.append(" [label=\"").append(dotRelation.getEdgeLabel()).append("\"");
            sb.append(", style=").append(dotRelation.getEdgeStyle());
            sb.append(", tooltip=\"").append(dotRelation.getEdgeTooltip()).append("\"");
            sb.append(", labeltooltip=\"").append(dotRelation.getEdgeTooltip()).append("\"");
            sb.append("];").append("\n");
        } else {
            String mappingName = "m" + (mappingNode++);
            String nodeLabel = dotRelation.getNodeLabel(mappingName);
            if (nodeLabel != null) {
                sb.append(indent(indent)).append(mappingName).append(" [label=\"").append(nodeLabel).append("\"");
                String styles = dotRelation.getNodeStyleAttributes();
                if (StringUtils.isNotEmpty(styles)) {
                    sb.append(", ").append(styles);
                }
                sb.append(", tooltip=\"").append(dotRelation.getNodeTooltip()).append("\"");
                sb.append("];\n");
            }
            for (DataItem src : relation.getSources()) {
                DotDataItem dotSrc = getDotDataItem(src);
                sb.append(indent(indent)).append(dotSrc.getNodeName()).append(" -> ").append(mappingName).append(" [style=").append(dotRelation.getEdgeStyle()).append("]\n");
            }
            if (relation.getTarget() != null) {
                DotDataItem dotTarget = getDotDataItem(relation.getTarget());
                sb.append(indent(indent)).append(mappingName).append(" -> ").append(dotTarget.getNodeName()).append(" [style=").append(dotRelation.getEdgeStyle()).append("]\n");
            }
        }
    }
    sb.append("}");
    String dot = sb.toString();
    LOGGER.debug("Resulting DOT:\n{}", dot);
    return dot;
}
Also used : ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 68 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class MidpointFunctionsImpl method countAccounts.

private <T> Integer countAccounts(ResourceType resourceType, QName attributeName, T attributeValue, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
    RefinedObjectClassDefinition rAccountDef = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    RefinedAttributeDefinition attrDef = rAccountDef.findAttributeDefinition(attributeName);
    ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq(attributeValue).and().item(ShadowType.F_OBJECT_CLASS).eq(rAccountDef.getObjectClassDefinition().getTypeName()).and().item(ShadowType.F_RESOURCE_REF).ref(resourceType.getOid()).build();
    return modelObjectResolver.countObjects(ShadowType.class, query, null, task, result);
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 69 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class ShadowConstraintsChecker method check.

public void check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    RefinedObjectClassDefinition projOcDef = projectionContext.getCompositeObjectClassDefinition();
    PrismObject<ShadowType> projectionNew = projectionContext.getObjectNew();
    if (projectionNew == null) {
        // This must be delete
        LOGGER.trace("No new object in projection context. Current shadow satisfy constraints");
        satisfiesConstraints = true;
        return;
    }
    PrismContainer<?> attributesContainer = projectionNew.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // No attributes no constraint violations
        LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
        satisfiesConstraints = true;
        return;
    }
    ConstraintViolationConfirmer confirmer = new ConstraintViolationConfirmer() {

        @Override
        public boolean confirmViolation(String oid) {
            boolean violation = true;
            LensProjectionContext foundContext = context.findProjectionContextByOid(oid);
            if (foundContext != null) {
                if (foundContext.getResourceShadowDiscriminator() != null) {
                    if (foundContext.getResourceShadowDiscriminator().isThombstone()) {
                        violation = false;
                    }
                    LOGGER.trace("Comparing with account in other context resulted to violation confirmation of {}", violation);
                }
            }
            return violation;
        }
    };
    constraintsCheckingResult = provisioningService.checkConstraints(projOcDef, projectionNew, projectionContext.getResource(), projectionContext.getOid(), projectionContext.getResourceShadowDiscriminator(), confirmer, task, result);
    if (constraintsCheckingResult.isSatisfiesConstraints()) {
        satisfiesConstraints = true;
        return;
    }
    for (QName checkedAttributeName : constraintsCheckingResult.getCheckedAttributes()) {
        if (constraintsCheckingResult.getConflictingAttributes().contains(checkedAttributeName)) {
            if (isInDelta(checkedAttributeName, projectionContext.getPrimaryDelta())) {
                throw new ObjectAlreadyExistsException("Attribute " + checkedAttributeName + " conflicts with existing object (and it is present in primary " + "account delta therefore no iteration is performed)");
            }
        }
    }
    if (projectionContext.getResourceShadowDiscriminator() != null && projectionContext.getResourceShadowDiscriminator().isThombstone()) {
        satisfiesConstraints = true;
    } else {
        satisfiesConstraints = false;
    }
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ConstraintViolationConfirmer(com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 70 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class TestPreviewChanges method test150GetGuybrushRefinedObjectClassDef.

@Test
public void test150GetGuybrushRefinedObjectClassDef() throws Exception {
    final String TEST_NAME = "test150GetGuybrushRefinedObjectClassDef";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<ShadowType> shadow = getShadowModel(ACCOUNT_SHADOW_GUYBRUSH_OID);
    // WHEN
    RefinedObjectClassDefinition rOCDef = modelInteractionService.getEditObjectClassDefinition(shadow, getDummyResourceObject(), AuthorizationPhaseType.REQUEST);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess(result);
    display("Refined object class", rOCDef);
    assertNotNull("Null config", rOCDef);
    display("Password credentials outbound", rOCDef.getPasswordOutbound());
    assertNotNull("Assert not null", rOCDef.getPasswordOutbound());
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)72 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)33 QName (javax.xml.namespace.QName)28 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)20 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)17 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 ArrayList (java.util.ArrayList)13 Test (org.testng.annotations.Test)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 Task (com.evolveum.midpoint.task.api.Task)8 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 SystemException (com.evolveum.midpoint.util.exception.SystemException)7 Collection (java.util.Collection)7 RefinedAssociationDefinition (com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)6