Search in sources :

Example 1 with AbstractRoleType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType 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 2 with AbstractRoleType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType 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 3 with AbstractRoleType

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

the class RAbstractRole method copyFromJAXB.

// dynamically called
public static void copyFromJAXB(AbstractRoleType jaxb, RAbstractRole repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
    copyFocusInformationFromJAXB(jaxb, repo, repositoryContext, generatorResult);
    repo.setRequestable(jaxb.isRequestable());
    repo.setDisplayName(RPolyString.copyFromJAXB(jaxb.getDisplayName()));
    repo.setIdentifier(jaxb.getIdentifier());
    repo.setRiskLevel(jaxb.getRiskLevel());
    if (jaxb.getAutoassign() != null) {
        RAutoassignSpecification aa = new RAutoassignSpecification();
        RAutoassignSpecification.formJaxb(jaxb.getAutoassign(), aa);
        repo.setAutoassign(aa);
    }
    for (AssignmentType inducement : jaxb.getInducement()) {
        RAssignment rInducement = new RAssignment(repo, RAssignmentOwner.ABSTRACT_ROLE);
        RAssignment.fromJaxb(inducement, rInducement, jaxb, repositoryContext, generatorResult);
        repo.getAssignments().add(rInducement);
    }
}
Also used : RAssignment(com.evolveum.midpoint.repo.sql.data.common.container.RAssignment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) RAutoassignSpecification(com.evolveum.midpoint.repo.sql.data.common.embedded.RAutoassignSpecification)

Example 4 with AbstractRoleType

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

the class ApplicablePolicyGroupPanel method onPolicyAddedOrRemoved.

private void onPolicyAddedOrRemoved(PrismObject<AbstractRoleType> assignmentTargetObject, boolean added) {
    if (isAssignmentAlreadyInList(assignmentTargetObject.getOid())) {
        PrismContainerValueWrapper<AssignmentType> assignmentToRemove = null;
        for (PrismContainerValueWrapper<AssignmentType> assignment : assignmentsModel.getObject().getValues()) {
            ObjectReferenceType targetRef = assignment.getRealValue().getTargetRef();
            if (targetRef != null && targetRef.getOid().equals(assignmentTargetObject.getOid())) {
                if (added && assignment.getStatus() == ValueStatus.DELETED) {
                    assignment.setStatus(ValueStatus.NOT_CHANGED);
                } else if (!added && assignment.getStatus() == ValueStatus.ADDED) {
                    assignmentToRemove = assignment;
                } else if (!added) {
                    assignment.setStatus(ValueStatus.DELETED);
                }
            }
        }
        assignmentsModel.getObject().getValues().remove(assignmentToRemove);
    } else {
        if (added) {
            // TODO: not sure if this is correct way of creating new value.. this value is added directly to the origin object... what about deltas??
            PrismContainerValue<AssignmentType> newAssignment = assignmentsModel.getObject().getItem().createNewValue();
            ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(assignmentTargetObject, getPageBase().getPrismContext());
            AssignmentType assignmentType = newAssignment.asContainerable();
            assignmentType.setTargetRef(ref);
            Task task = getPageBase().createSimpleTask("Creating new applicable policy");
            WrapperContext context = new WrapperContext(task, null);
            PrismContainerValueWrapper<AssignmentType> valueWrapper;
            try {
                valueWrapper = (PrismContainerValueWrapper<AssignmentType>) getPageBase().createValueWrapper(assignmentsModel.getObject(), newAssignment, ValueStatus.ADDED, context);
                assignmentsModel.getObject().getValues().add(valueWrapper);
            } catch (SchemaException e) {
            // TOTO error handling
            }
        // 
        // valueWrapper.setShowEmpty(true, false);
        }
    }
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) Task(com.evolveum.midpoint.task.api.Task) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Example 5 with AbstractRoleType

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

the class ApplicablePolicyGroupPanel method initLayout.

private void initLayout() {
    Label policyGroupName = new Label(ID_POLICY_GROUP_NAME, Model.of(WebComponentUtil.getDisplayNameOrName(getModelObject(), getPageBase(), OPERATION_LOAD_POLICY_GROUP_NAME)));
    policyGroupName.setOutputMarkupId(true);
    add(policyGroupName);
    ListView<PrismObject<AbstractRoleType>> policiesPanel = new ListView<PrismObject<AbstractRoleType>>(ID_POLICIES_CONTAINER, policiesListModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<PrismObject<AbstractRoleType>> listItem) {
            PrismObject<AbstractRoleType> abstractRole = listItem.getModelObject();
            CheckBoxPanel policyCheckBox = new CheckBoxPanel(ID_POLICY_CHECK_BOX, getCheckboxModel(abstractRole), // label
            Model.of(WebComponentUtil.getDisplayNameOrName(abstractRole)), // tooltip
            null) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onUpdate(AjaxRequestTarget target) {
                    onPolicyAddedOrRemoved(listItem.getModelObject(), getValue());
                }
            };
            policyCheckBox.setOutputMarkupId(true);
            listItem.add(policyCheckBox);
        }
    };
    policiesPanel.setOutputMarkupId(true);
    add(policiesPanel);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) ListView(org.apache.wicket.markup.html.list.ListView) Label(org.apache.wicket.markup.html.basic.Label) AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) ListItem(org.apache.wicket.markup.html.list.ListItem) CheckBoxPanel(com.evolveum.midpoint.gui.api.component.form.CheckBoxPanel)

Aggregations

AbstractRoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)3 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)3 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)3 QName (javax.xml.namespace.QName)3 RAssignment (com.evolveum.midpoint.repo.sql.data.common.container.RAssignment)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)2 ShadowDiscriminatorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType)2 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)2 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)1 CheckBoxPanel (com.evolveum.midpoint.gui.api.component.form.CheckBoxPanel)1 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)1 AssignmentPathSegment (com.evolveum.midpoint.model.api.context.AssignmentPathSegment)1 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)1 LensUtil (com.evolveum.midpoint.model.impl.lens.LensUtil)1 AutoassignRoleMappingEvaluationRequest (com.evolveum.midpoint.model.impl.lens.projector.mappings.AutoassignRoleMappingEvaluationRequest)1 FocalMappingEvaluationRequest (com.evolveum.midpoint.model.impl.lens.projector.mappings.FocalMappingEvaluationRequest)1