Search in sources :

Example 61 with AssignmentType

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

the class QAssignmentMapping method insert.

// about duplication see the comment in QObjectMapping.toRowObjectWithoutFullObject
@SuppressWarnings("DuplicatedCode")
@Override
public MAssignment insert(AssignmentType assignment, OR ownerRow, JdbcSession jdbcSession) {
    MAssignment row = initRowObject(assignment, ownerRow);
    row.lifecycleState = assignment.getLifecycleState();
    row.orderValue = assignment.getOrder();
    setReference(assignment.getOrgRef(), o -> row.orgRefTargetOid = o, t -> row.orgRefTargetType = t, r -> row.orgRefRelationId = r);
    setReference(assignment.getTargetRef(), o -> row.targetRefTargetOid = o, t -> row.targetRefTargetType = t, r -> row.targetRefRelationId = r);
    setReference(assignment.getTenantRef(), o -> row.tenantRefTargetOid = o, t -> row.tenantRefTargetType = t, r -> row.tenantRefRelationId = r);
    row.policySituations = processCacheableUris(assignment.getPolicySituation());
    row.subtypes = stringsToArray(assignment.getSubtype());
    row.ext = processExtensions(assignment.getExtension(), MExtItemHolderType.EXTENSION);
    ConstructionType construction = assignment.getConstruction();
    if (construction != null) {
        setReference(construction.getResourceRef(), o -> row.resourceRefTargetOid = o, t -> row.resourceRefTargetType = t, r -> row.resourceRefRelationId = r);
    }
    ActivationType activation = assignment.getActivation();
    if (activation != null) {
        row.administrativeStatus = activation.getAdministrativeStatus();
        row.effectiveStatus = activation.getEffectiveStatus();
        row.enableTimestamp = MiscUtil.asInstant(activation.getEnableTimestamp());
        row.disableTimestamp = MiscUtil.asInstant(activation.getDisableTimestamp());
        row.disableReason = activation.getDisableReason();
        row.validityStatus = activation.getValidityStatus();
        row.validFrom = MiscUtil.asInstant(activation.getValidFrom());
        row.validTo = MiscUtil.asInstant(activation.getValidTo());
        row.validityChangeTimestamp = MiscUtil.asInstant(activation.getValidityChangeTimestamp());
        row.archiveTimestamp = MiscUtil.asInstant(activation.getArchiveTimestamp());
    }
    MetadataType metadata = assignment.getMetadata();
    if (metadata != null) {
        setReference(metadata.getCreatorRef(), o -> row.creatorRefTargetOid = o, t -> row.creatorRefTargetType = t, r -> row.creatorRefRelationId = r);
        row.createChannelId = processCacheableUri(metadata.getCreateChannel());
        row.createTimestamp = MiscUtil.asInstant(metadata.getCreateTimestamp());
        setReference(metadata.getModifierRef(), o -> row.modifierRefTargetOid = o, t -> row.modifierRefTargetType = t, r -> row.modifierRefRelationId = r);
        row.modifyChannelId = processCacheableUri(metadata.getModifyChannel());
        row.modifyTimestamp = MiscUtil.asInstant(metadata.getModifyTimestamp());
    }
    // insert before treating sub-entities
    insert(row, jdbcSession);
    if (metadata != null) {
        storeRefs(row, metadata.getCreateApproverRef(), QAssignmentReferenceMapping.getForAssignmentCreateApprover(), jdbcSession);
        storeRefs(row, metadata.getModifyApproverRef(), QAssignmentReferenceMapping.getForAssignmentModifyApprover(), jdbcSession);
    }
    return row;
}
Also used : ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType)

Example 62 with AssignmentType

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

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

the class AssignmentCounter method count.

@Override
public int count(AssignmentHolderDetailsModel<AH> objectDetailsModels, PageBase pageBase) {
    PrismObjectWrapper<AH> assignmentHolderWrapper = objectDetailsModels.getObjectWrapperModel().getObject();
    AH object = assignmentHolderWrapper.getObject().asObjectable();
    List<AssignmentType> assignments = object.getAssignment();
    int count = 0;
    for (AssignmentType assignment : assignments) {
        if (WebComponentUtil.isArchetypeAssignment(assignment) || WebComponentUtil.isDelegationAssignment(assignment)) {
            continue;
        }
        count++;
    }
    return count;
}
Also used : AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Example 64 with AssignmentType

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

the class TaskBasicTabPanel method initLayout.

private void initLayout() {
    ItemPanelSettings settings = new ItemPanelSettingsBuilder().editabilityHandler(wrapper -> getTask().getHandlerUri() == null).build();
    TaskHandlerSelectorPanel handlerSelectorPanel = new TaskHandlerSelectorPanel(ID_HANDLER, PrismPropertyWrapperModel.fromContainerWrapper(getModel(), TaskType.F_HANDLER_URI), settings) {

        @Override
        protected void onUpdatePerformed(AjaxRequestTarget target) {
            String newHandlerUri = getTask().getHandlerUri();
            if (StringUtils.isBlank(newHandlerUri) || !newHandlerUri.startsWith("http://")) {
                LOGGER.trace("Nothing to do, handler still not set");
                return;
            }
            TaskHandler taskHandler = getPageBase().getTaskManager().getHandler(newHandlerUri);
            if (taskHandler == null) {
                LOGGER.trace("Nothing to do, cannot find TaskHandler for {}", newHandlerUri);
                return;
            }
            if (!WebComponentUtil.hasAnyArchetypeAssignment(getTask())) {
                String archetypeOid = taskHandler.getArchetypeOid(newHandlerUri);
                WebComponentUtil.addNewArchetype(TaskBasicTabPanel.this.getModelObject(), archetypeOid, target, getPageBase());
            }
            PrismObjectWrapperFactory<TaskType> wrapperFactory = TaskBasicTabPanel.this.getPageBase().findObjectWrapperFactory(getTask().asPrismObject().getDefinition());
            Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_WRAPPER);
            OperationResult result = task.getResult();
            WrapperContext ctx = new WrapperContext(task, result);
            ctx.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(getTask().asPrismObject()));
            try {
                wrapperFactory.updateWrapper(TaskBasicTabPanel.this.getModelObject(), ctx);
                // TODO ugly hack: after updateWrapper method is called, both previously set items (handlerUri and assignments)
                // are marked as NOT_CHANGED with the same value. We need to find a way how to force the ValueStatus
                // or change the mechanism for computing deltas. Probably only the first will work
                PrismPropertyWrapper<String> handlerWrapper = TaskBasicTabPanel.this.getModelObject().findProperty(ItemPath.create(TaskType.F_HANDLER_URI));
                handlerWrapper.getValue().setStatus(ValueStatus.ADDED);
                PrismContainerWrapper<AssignmentType> assignmentWrapper = TaskBasicTabPanel.this.getModelObject().findContainer(ItemPath.create(TaskType.F_ASSIGNMENT));
                for (PrismContainerValueWrapper<AssignmentType> assignmentWrapperValue : assignmentWrapper.getValues()) {
                    if (WebComponentUtil.isArchetypeAssignment(assignmentWrapperValue.getRealValue())) {
                        assignmentWrapperValue.setStatus(ValueStatus.ADDED);
                    }
                }
            } catch (SchemaException | IllegalArgumentException e) {
                LOGGER.error("Unexpected problem occurs during updating wrapper. Reason: {}", e.getMessage(), e);
            }
            updateHandlerPerformed(target);
        }
    };
    handlerSelectorPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return satisfyArchetypeAssignment();
        }
    });
    add(handlerSelectorPanel);
    ItemVisibilityHandler visibilityHandler = wrapper -> getBasicTabVisibility(wrapper.getPath());
    ItemEditabilityHandler editabilityHandler = wrapper -> getBasicTabEditability(wrapper.getPath());
    try {
        ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder().visibilityHandler(visibilityHandler).editabilityHandler(editabilityHandler).mandatoryHandler(getItemMandatoryHandler());
        Panel panel = getPageBase().initItemPanel(ID_MAIN_PANEL, TaskType.COMPLEX_TYPE, getModel(), builder.build());
        add(panel);
    } catch (SchemaException e) {
        LOGGER.error("Cannot create task basic panel: {}", e.getMessage(), e);
        // TODO opertion result? localization?
        getSession().error("Cannot create task basic panel");
        throw new RestartResponseException(PageTasks.class);
    }
}
Also used : java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ItemVisibility(com.evolveum.midpoint.web.component.prism.ItemVisibility) StringUtils(org.apache.commons.lang3.StringUtils) RestartResponseException(org.apache.wicket.RestartResponseException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) PrismPropertyWrapperModel(com.evolveum.midpoint.web.model.PrismPropertyWrapperModel) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) Component(org.apache.wicket.Component) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Panel(org.apache.wicket.markup.html.panel.Panel) TaskHandler(com.evolveum.midpoint.task.api.TaskHandler) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) PrismObjectWrapperFactory(com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory) com.evolveum.midpoint.gui.api.prism.wrapper(com.evolveum.midpoint.gui.api.prism.wrapper) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) TaskHandler(com.evolveum.midpoint.task.api.TaskHandler) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Panel(org.apache.wicket.markup.html.panel.Panel) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 65 with AssignmentType

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

the class TestParseMetarole method assertMetaroleJaxb.

private void assertMetaroleJaxb(RoleType roleType, boolean isObject) throws SchemaException {
    assertEquals("Wrong name", PrismTestUtil.createPolyStringType("Generic Metarole"), roleType.getName());
    boolean found = false;
    for (AssignmentType inducement : roleType.getInducement()) {
        if (inducement.getId() == 2L) {
            found = true;
            PolicyRuleType rule = inducement.getPolicyRule();
            assertNotNull("No constraints", rule.getPolicyConstraints());
            assertEquals("Wrong # of assignment constraints", 1, rule.getPolicyConstraints().getAssignment().size());
            assertTrue("Wrong (not empty) assignment constraints", rule.getPolicyConstraints().getAssignment().get(0).asPrismContainerValue().isEmpty());
            break;
        }
    }
    assertTrue("Assignment number 2 was not found", found);
}
Also used : PolicyRuleType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Aggregations

AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)121 Test (org.testng.annotations.Test)61 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)55 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)42 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)41 Task (com.evolveum.midpoint.task.api.Task)39 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)25 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)21 QName (javax.xml.namespace.QName)20 PrismObject (com.evolveum.midpoint.prism.PrismObject)19 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)17 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)17 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)17 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)17 ArrayList (java.util.ArrayList)17 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)15 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)14