Search in sources :

Example 6 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class AssociationFromLinkExpressionEvaluator method evaluate.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java.util.Collection, java.util.Map, boolean, java.lang.String, com.evolveum.midpoint.schema.result.OperationResult)
	 */
@Override
public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    String desc = context.getContextDescription();
    Object orderOneObject = context.getVariables().get(ExpressionConstants.VAR_ORDER_ONE_OBJECT);
    if (orderOneObject == null) {
        throw new ExpressionEvaluationException("No order one object variable in " + desc + "; the expression may be used in a wrong place. It is only supposed to work in a role.");
    }
    if (!(orderOneObject instanceof AbstractRoleType)) {
        throw new ExpressionEvaluationException("Order one object variable in " + desc + " is not a role, it is " + orderOneObject.getClass().getName() + "; the expression may be used in a wrong place. It is only supposed to work in a role.");
    }
    AbstractRoleType thisRole = (AbstractRoleType) orderOneObject;
    LOGGER.trace("Evaluating association from link on: {}", thisRole);
    RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) context.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
    if (rAssocTargetDef == null) {
        throw new ExpressionEvaluationException("No association target object class definition variable in " + desc + "; the expression may be used in a wrong place. It is only supposed to create an association.");
    }
    ShadowDiscriminatorType projectionDiscriminator = evaluatorType.getProjectionDiscriminator();
    if (projectionDiscriminator == null) {
        throw new ExpressionEvaluationException("No projectionDiscriminator in " + desc);
    }
    ShadowKindType kind = projectionDiscriminator.getKind();
    if (kind == null) {
        throw new ExpressionEvaluationException("No kind in projectionDiscriminator in " + desc);
    }
    String intent = projectionDiscriminator.getIntent();
    PrismContainer<ShadowAssociationType> output = outputDefinition.instantiate();
    QName assocName = context.getMappingQName();
    String resourceOid = rAssocTargetDef.getResourceType().getOid();
    Collection<SelectorOptions<GetOperationOptions>> options = null;
    // Always process the first role (myself) regardless of recursion setting
    gatherAssociationsFromAbstractRole(thisRole, output, resourceOid, kind, intent, assocName, options, desc, context);
    if (thisRole instanceof OrgType && matchesForRecursion((OrgType) thisRole)) {
        gatherAssociationsFromAbstractRoleRecurse((OrgType) thisRole, output, resourceOid, kind, intent, assocName, options, desc, context);
    }
    return ItemDelta.toDeltaSetTriple(output, null);
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) QName(javax.xml.namespace.QName) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) ShadowDiscriminatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType)

Example 7 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class AssociationFromLinkExpressionEvaluator method gatherAssociationsFromAbstractRole.

private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options, String desc, ExpressionEvaluationContext params) throws SchemaException {
    for (ObjectReferenceType linkRef : thisRole.getLinkRef()) {
        ShadowType shadowType;
        try {
            shadowType = objectResolver.resolve(linkRef, ShadowType.class, options, desc, params.getTask(), params.getResult());
        } catch (ObjectNotFoundException e) {
            // Linked shadow not found. This may happen e.g. if the account is deleted and model haven't got
            // the chance to react yet. Just ignore such shadow.
            LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + thisRole + " because it no longer exists");
            continue;
        }
        if (ShadowUtil.matches(shadowType, resourceOid, kind, intent)) {
            PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
            ShadowAssociationType shadowAssociationType = newValue.asContainerable();
            shadowAssociationType.setName(assocName);
            ObjectReferenceType shadowRef = new ObjectReferenceType();
            shadowRef.setOid(linkRef.getOid());
            shadowAssociationType.setShadowRef(shadowRef);
        }
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 8 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class ResourceRelatedHandlerPanel method initLayout.

private void initLayout() {
    final VisibleEnableBehaviour visibleIfEdit = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return parentPage.isEdit();
        }
    };
    final VisibleEnableBehaviour visibleIfView = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !parentPage.isEdit();
        }
    };
    enabledIfEdit = new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            return parentPage.isEdit();
        }
    };
    final VisibleEnableBehaviour visibleForResourceCoordinates = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getTaskDto().configuresResourceCoordinates();
        }
    };
    final WebMarkupContainer resourceRefContainer = new WebMarkupContainer(ID_RESOURCE_REF_CONTAINER);
    resourceRefContainer.add(visibleForResourceCoordinates);
    resourceRefContainer.setOutputMarkupId(true);
    add(resourceRefContainer);
    final DropDownChoice<TaskAddResourcesDto> resourceRef = new DropDownChoice<>(ID_RESOURCE_REF, new PropertyModel<TaskAddResourcesDto>(getModel(), ResourceRelatedHandlerDto.F_RESOURCE_REFERENCE), new AbstractReadOnlyModel<List<TaskAddResourcesDto>>() {

        @Override
        public List<TaskAddResourcesDto> getObject() {
            return createResourceList();
        }
    }, new ChoiceableChoiceRenderer<TaskAddResourcesDto>());
    resourceRef.setOutputMarkupId(true);
    resourceRef.add(enabledIfEdit);
    resourceRef.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            Task task = parentPage.createSimpleTask(OPERATION_LOAD_RESOURCE);
            OperationResult result = task.getResult();
            List<QName> objectClassList = new ArrayList<>();
            TaskAddResourcesDto resourcesDto = getModelObject().getResourceRef();
            if (resourcesDto != null) {
                PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(ResourceType.class, resourcesDto.getOid(), parentPage, task, result);
                try {
                    ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, parentPage.getPrismContext());
                    schema.getObjectClassDefinitions();
                    for (Definition def : schema.getDefinitions()) {
                        objectClassList.add(def.getTypeName());
                    }
                    getModelObject().setObjectClassList(objectClassList);
                } catch (Exception e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object class list from resource.", e);
                    error("Couldn't load object class list from resource.");
                }
            }
            target.add(resourceRefContainer);
        }
    });
    resourceRefContainer.add(resourceRef);
    WebMarkupContainer kindContainer = new WebMarkupContainer(ID_KIND_CONTAINER);
    kindContainer.add(visibleForResourceCoordinates);
    add(kindContainer);
    final DropDownChoice kind = new DropDownChoice<>(ID_KIND, new PropertyModel<ShadowKindType>(getModel(), ResourceRelatedHandlerDto.F_KIND), WebComponentUtil.createReadonlyModelFromEnum(ShadowKindType.class), new EnumChoiceRenderer<ShadowKindType>());
    kind.setOutputMarkupId(true);
    kind.setNullValid(true);
    kindContainer.add(kind);
    WebMarkupContainer intentContainer = new WebMarkupContainer(ID_INTENT_CONTAINER);
    intentContainer.add(visibleForResourceCoordinates);
    add(intentContainer);
    final TextField<String> intent = new TextField<>(ID_INTENT, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_INTENT));
    intentContainer.add(intent);
    intent.setOutputMarkupId(true);
    intent.add(enabledIfEdit);
    WebMarkupContainer objectClassContainer = new WebMarkupContainer(ID_OBJECT_CLASS_CONTAINER);
    objectClassContainer.add(visibleForResourceCoordinates);
    add(objectClassContainer);
    AutoCompleteSettings autoCompleteSettings = new AutoCompleteSettings();
    autoCompleteSettings.setShowListOnEmptyInput(true);
    final AutoCompleteTextField<String> objectClass = new AutoCompleteTextField<String>(ID_OBJECT_CLASS, new PropertyModel<String>(getModel(), ResourceRelatedHandlerDto.F_OBJECT_CLASS), autoCompleteSettings) {

        @Override
        protected Iterator<String> getChoices(String input) {
            return prepareObjectClassChoiceList(input);
        }
    };
    objectClass.add(enabledIfEdit);
    objectClassContainer.add(objectClass);
    WebMarkupContainer optionsContainer = new WebMarkupContainer(ID_OPTIONS_CONTAINER);
    optionsContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getTaskDto().configuresDryRun();
        }
    });
    add(optionsContainer);
    WebMarkupContainer dryRunContainer = new WebMarkupContainer(ID_DRY_RUN_CONTAINER);
    dryRunContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getTaskDto().configuresDryRun();
        }
    });
    optionsContainer.add(dryRunContainer);
    CheckBox dryRun = new CheckBox(ID_DRY_RUN, new PropertyModel<Boolean>(getModel(), ResourceRelatedHandlerDto.F_DRY_RUN));
    dryRun.add(enabledIfEdit);
    dryRunContainer.add(dryRun);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) TextField(org.apache.wicket.markup.html.form.TextField) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Definition(com.evolveum.midpoint.prism.Definition) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AutoCompleteSettings(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) CheckBox(org.apache.wicket.markup.html.form.CheckBox) TaskAddResourcesDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskAddResourcesDto) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 9 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class EntitlementConverter method postProcessEntitlementsRead.

//////////
// GET
/////////
public void postProcessEntitlementsRead(ProvisioningContext subjectCtx, PrismObject<ShadowType> resourceObject, OperationResult parentResult) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ResourceType resourceType = subjectCtx.getResource();
    LOGGER.trace("Starting postProcessEntitlementRead");
    RefinedObjectClassDefinition objectClassDefinition = subjectCtx.getObjectClassDefinition();
    Collection<RefinedAssociationDefinition> entitlementAssociationDefs = objectClassDefinition.getAssociationDefinitions();
    if (entitlementAssociationDefs != null) {
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(resourceObject);
        PrismContainerDefinition<ShadowAssociationType> associationDef = resourceObject.getDefinition().findContainerDefinition(ShadowType.F_ASSOCIATION);
        PrismContainer<ShadowAssociationType> associationContainer = associationDef.instantiate();
        for (RefinedAssociationDefinition assocDefType : entitlementAssociationDefs) {
            ShadowKindType entitlementKind = assocDefType.getKind();
            if (entitlementKind == null) {
                entitlementKind = ShadowKindType.ENTITLEMENT;
            }
            for (String entitlementIntent : assocDefType.getIntents()) {
                LOGGER.trace("Resolving association {} for kind {} and intent {}", assocDefType.getName(), entitlementKind, entitlementIntent);
                ProvisioningContext entitlementCtx = subjectCtx.spawn(entitlementKind, entitlementIntent);
                RefinedObjectClassDefinition entitlementDef = entitlementCtx.getObjectClassDefinition();
                if (entitlementDef == null) {
                    throw new SchemaException("No definition for entitlement intent(s) '" + assocDefType.getIntents() + "' in " + resourceType);
                }
                ResourceObjectAssociationDirectionType direction = assocDefType.getResourceObjectAssociationType().getDirection();
                if (direction == ResourceObjectAssociationDirectionType.SUBJECT_TO_OBJECT) {
                    postProcessEntitlementSubjectToEntitlement(resourceType, resourceObject, objectClassDefinition, assocDefType, entitlementDef, attributesContainer, associationContainer, parentResult);
                } else if (direction == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
                    if (assocDefType.getResourceObjectAssociationType().getShortcutAssociationAttribute() != null) {
                        postProcessEntitlementSubjectToEntitlement(resourceType, resourceObject, objectClassDefinition, assocDefType, entitlementDef, attributesContainer, associationContainer, assocDefType.getResourceObjectAssociationType().getShortcutAssociationAttribute(), assocDefType.getResourceObjectAssociationType().getShortcutValueAttribute(), parentResult);
                    } else {
                        postProcessEntitlementEntitlementToSubject(subjectCtx, resourceObject, assocDefType, entitlementCtx, attributesContainer, associationContainer, parentResult);
                    }
                } else {
                    throw new IllegalArgumentException("Unknown entitlement direction " + direction + " in association " + assocDefType + " in " + resourceType);
                }
            }
        }
        if (!associationContainer.isEmpty()) {
            resourceObject.add(associationContainer);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceObjectAssociationDirectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectAssociationDirectionType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 10 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class SynchronizationServiceUtils method isPolicyApplicable.

private static boolean isPolicyApplicable(ObjectSynchronizationDiscriminatorType synchronizationDiscriminator, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
    ShadowKindType kind = synchronizationDiscriminator.getKind();
    String intent = synchronizationDiscriminator.getIntent();
    if (kind == null && intent == null) {
        throw new SchemaException("Illegal state, object synchronization discriminator type must have kind/intent specified. Current values are: kind=" + kind + ", intent=" + intent);
    }
    return SynchronizationUtils.isPolicyApplicable(null, kind, intent, synchronizationPolicy, resource);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Aggregations

ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)33 QName (javax.xml.namespace.QName)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 ArrayList (java.util.ArrayList)7 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 List (java.util.List)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 NotNull (org.jetbrains.annotations.NotNull)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)3