Search in sources :

Example 11 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class ResourceContentPanel method initColumns.

private List<IColumn<SelectableBean<ShadowType>, String>> initColumns() {
    List<ColumnTypeDto<String>> columnDefs = Arrays.asList(new ColumnTypeDto<String>("ShadowType.synchronizationSituation", SelectableBean.F_VALUE + ".synchronizationSituation", ShadowType.F_SYNCHRONIZATION_SITUATION.getLocalPart()), new ColumnTypeDto<String>("ShadowType.intent", SelectableBean.F_VALUE + ".intent", ShadowType.F_INTENT.getLocalPart()));
    List<IColumn<SelectableBean<ShadowType>, String>> columns = new ArrayList<>();
    IColumn<SelectableBean<ShadowType>, String> identifiersColumn = new AbstractColumn<SelectableBean<ShadowType>, String>(createStringResource("pageContentAccounts.identifiers")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ShadowType>>> cellItem, String componentId, IModel<SelectableBean<ShadowType>> rowModel) {
            SelectableBean<ShadowType> dto = rowModel.getObject();
            RepeatingView repeater = new RepeatingView(componentId);
            ShadowType value = dto.getValue();
            if (value != null) {
                for (ResourceAttribute<?> attr : ShadowUtil.getAllIdentifiers(value)) {
                    repeater.add(new Label(repeater.newChildId(), attr.getElementName().getLocalPart() + ": " + attr.getRealValue()));
                }
            }
            cellItem.add(repeater);
        }
    };
    columns.add(identifiersColumn);
    columns.addAll((Collection) ColumnUtils.createColumns(columnDefs));
    ObjectLinkColumn<SelectableBean<ShadowType>> ownerColumn = new ObjectLinkColumn<SelectableBean<ShadowType>>(createStringResource("pageContentAccounts.owner")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected IModel<FocusType> createLinkModel(final IModel<SelectableBean<ShadowType>> rowModel) {
            return new AbstractReadOnlyModel<FocusType>() {

                private static final long serialVersionUID = 1L;

                @Override
                public FocusType getObject() {
                    FocusType owner = loadShadowOwner(rowModel);
                    if (owner == null) {
                        return null;
                    }
                    return owner;
                }
            };
        }

        @Override
        public void onClick(AjaxRequestTarget target, IModel<SelectableBean<ShadowType>> rowModel, ObjectType targetObjectType) {
            ownerDetailsPerformed(target, (FocusType) targetObjectType);
        }
    };
    columns.add(ownerColumn);
    columns.add(new LinkColumn<SelectableBean<ShadowType>>(createStringResource("PageAccounts.accounts.result")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected IModel<String> createLinkModel(final IModel<SelectableBean<ShadowType>> rowModel) {
            return new AbstractReadOnlyModel<String>() {

                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return getResultLabel(rowModel);
                }
            };
        }

        @Override
        public void onClick(AjaxRequestTarget target, IModel<SelectableBean<ShadowType>> rowModel) {
            OperationResultType resultType = getResult(rowModel);
            OperationResult result = OperationResult.createOperationResult(resultType);
            OperationResultPanel body = new OperationResultPanel(ResourceContentPanel.this.getPageBase().getMainPopupBodyId(), new Model<OpResult>(OpResult.getOpResult(pageBase, result)), getPage());
            body.setOutputMarkupId(true);
            ResourceContentPanel.this.getPageBase().showMainPopup(body, target);
        }
    });
    return columns;
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) ArrayList(java.util.ArrayList) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) Label(org.apache.wicket.markup.html.basic.Label) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ColumnTypeDto(com.evolveum.midpoint.web.component.data.column.ColumnTypeDto) Item(org.apache.wicket.markup.repeater.Item) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) IModel(org.apache.wicket.model.IModel) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResultPanel(com.evolveum.midpoint.gui.api.component.result.OperationResultPanel) AbstractColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectLinkColumn(com.evolveum.midpoint.web.component.data.column.ObjectLinkColumn) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) IModel(org.apache.wicket.model.IModel) ListModel(org.apache.wicket.model.util.ListModel) Model(org.apache.wicket.model.Model) StringResourceModel(org.apache.wicket.model.StringResourceModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel)

Example 12 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class PageAccount method savePerformed.

private void savePerformed(AjaxRequestTarget target) {
    LOGGER.debug("Saving account changes.");
    OperationResult result = new OperationResult(OPERATION_SAVE_ACCOUNT);
    try {
        WebComponentUtil.revive(accountModel, getPrismContext());
        ObjectWrapper wrapper = accountModel.getObject();
        ObjectDelta<ShadowType> delta = wrapper.getObjectDelta();
        if (delta == null) {
            return;
        }
        if (delta.getPrismContext() == null) {
            getPrismContext().adopt(delta);
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Account delta computed from form:\n{}", new Object[] { delta.debugDump(3) });
        }
        if (delta.isEmpty()) {
            return;
        }
        WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
        Task task = createSimpleTask(OPERATION_SAVE_ACCOUNT);
        Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
        deltas.add(delta);
        getModelService().executeChanges(deltas, null, task, result);
        result.recomputeStatus();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't save account.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save account", ex);
    }
    if (!result.isSuccess()) {
        showResult(result);
        target.add(getFeedbackPanel());
    } else {
        showResult(result);
        redirectBack();
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ObjectWrapper(com.evolveum.midpoint.web.component.prism.ObjectWrapper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 13 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class LensProjectionContext method fromLensProjectionContextType.

public static LensProjectionContext fromLensProjectionContextType(LensProjectionContextType projectionContextType, LensContext lensContext, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    String objectTypeClassString = projectionContextType.getObjectTypeClass();
    if (StringUtils.isEmpty(objectTypeClassString)) {
        throw new SystemException("Object type class is undefined in LensProjectionContextType");
    }
    ResourceShadowDiscriminator resourceShadowDiscriminator = ResourceShadowDiscriminator.fromResourceShadowDiscriminatorType(projectionContextType.getResourceShadowDiscriminator());
    LensProjectionContext projectionContext = new LensProjectionContext(lensContext, resourceShadowDiscriminator);
    projectionContext.retrieveFromLensElementContextType(projectionContextType, task, result);
    if (projectionContextType.getSyncDelta() != null) {
        projectionContext.syncDelta = DeltaConvertor.createObjectDelta(projectionContextType.getSyncDelta(), lensContext.getPrismContext());
    } else {
        projectionContext.syncDelta = null;
    }
    ObjectDeltaType secondaryDeltaType = projectionContextType.getSecondaryDelta();
    projectionContext.secondaryDelta = secondaryDeltaType != null ? (ObjectDelta) DeltaConvertor.createObjectDelta(secondaryDeltaType, lensContext.getPrismContext()) : null;
    ObjectType object = projectionContextType.getObjectNew() != null ? projectionContextType.getObjectNew() : projectionContextType.getObjectOld();
    projectionContext.fixProvisioningTypeInDelta(projectionContext.secondaryDelta, object, task, result);
    projectionContext.wave = projectionContextType.getWave() != null ? projectionContextType.getWave() : 0;
    projectionContext.fullShadow = projectionContextType.isFullShadow() != null ? projectionContextType.isFullShadow() : false;
    projectionContext.isAssigned = projectionContextType.isIsAssigned() != null ? projectionContextType.isIsAssigned() : false;
    projectionContext.isAssignedOld = projectionContextType.isIsAssignedOld() != null ? projectionContextType.isIsAssignedOld() : false;
    projectionContext.isActive = projectionContextType.isIsActive() != null ? projectionContextType.isIsActive() : false;
    projectionContext.isLegal = projectionContextType.isIsLegal();
    projectionContext.isLegalOld = projectionContextType.isIsLegalOld();
    projectionContext.isExists = projectionContextType.isIsExists() != null ? projectionContextType.isIsExists() : false;
    projectionContext.synchronizationPolicyDecision = SynchronizationPolicyDecision.fromSynchronizationPolicyDecisionType(projectionContextType.getSynchronizationPolicyDecision());
    projectionContext.doReconciliation = projectionContextType.isDoReconciliation() != null ? projectionContextType.isDoReconciliation() : false;
    projectionContext.synchronizationSituationDetected = projectionContextType.getSynchronizationSituationDetected();
    projectionContext.synchronizationSituationResolved = projectionContextType.getSynchronizationSituationResolved();
    projectionContext.accountPasswordPolicy = projectionContextType.getAccountPasswordPolicy();
    projectionContext.syncAbsoluteTrigger = projectionContextType.isSyncAbsoluteTrigger();
    return projectionContext;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 14 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class LensUtil method checkObjectPolicy.

private static <F extends ObjectType> void checkObjectPolicy(LensFocusContext<F> focusContext, ObjectPolicyConfigurationType objectPolicyConfigurationType) throws SchemaException, PolicyViolationException {
    if (objectPolicyConfigurationType == null) {
        return;
    }
    PrismObject<F> focusObjectNew = focusContext.getObjectNew();
    ObjectDelta<F> focusDelta = focusContext.getDelta();
    for (PropertyConstraintType propertyConstraintType : objectPolicyConfigurationType.getPropertyConstraint()) {
        ItemPath itemPath = propertyConstraintType.getPath().getItemPath();
        if (BooleanUtils.isTrue(propertyConstraintType.isOidBound())) {
            if (focusDelta != null) {
                if (focusDelta.isAdd()) {
                    PrismProperty<Object> propNew = focusObjectNew.findProperty(itemPath);
                    if (propNew != null) {
                        // prop delta is OK, but it has to match
                        if (focusObjectNew.getOid() != null) {
                            if (!focusObjectNew.getOid().equals(propNew.getRealValue().toString())) {
                                throw new PolicyViolationException("Cannot set " + itemPath + " to a value different than OID in oid bound mode");
                            }
                        }
                    }
                } else {
                    PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(itemPath);
                    if (nameDelta != null) {
                        if (nameDelta.isReplace()) {
                            Collection<PrismPropertyValue<Object>> valuesToReplace = nameDelta.getValuesToReplace();
                            if (valuesToReplace.size() == 1) {
                                String stringValue = valuesToReplace.iterator().next().getValue().toString();
                                if (focusContext.getOid().equals(stringValue)) {
                                    // This is OK. It is most likely a correction made by a recompute.
                                    continue;
                                }
                            }
                        }
                        throw new PolicyViolationException("Cannot change " + itemPath + " in oid bound mode");
                    }
                }
            }
        }
    }
    // Deprecated
    if (BooleanUtils.isTrue(objectPolicyConfigurationType.isOidNameBoundMode())) {
        if (focusDelta != null) {
            if (focusDelta.isAdd()) {
                PolyStringType namePolyType = focusObjectNew.asObjectable().getName();
                if (namePolyType != null) {
                    // name delta is OK, but it has to match
                    if (focusObjectNew.getOid() != null) {
                        if (!focusObjectNew.getOid().equals(namePolyType.getOrig())) {
                            throw new PolicyViolationException("Cannot set name to a value different than OID in name-oid bound mode");
                        }
                    }
                }
            } else {
                PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(FocusType.F_NAME);
                if (nameDelta != null) {
                    throw new PolicyViolationException("Cannot change name in name-oid bound mode");
                }
            }
        }
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with ObjectType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectType in project midpoint by Evolveum.

the class Clockwork method triggerReconcileAffected.

private <F extends ObjectType> HookOperationMode triggerReconcileAffected(LensContext<F> context, Task task, OperationResult result) throws SchemaException {
    // check applicability
    if (!ModelExecuteOptions.isReconcileAffected(context.getOptions())) {
        return HookOperationMode.FOREGROUND;
    }
    if (context.getFocusClass() == null || !RoleType.class.isAssignableFrom(context.getFocusClass())) {
        LOGGER.warn("ReconcileAffected requested but not available for {}. Doing nothing.", context.getFocusClass());
        return HookOperationMode.FOREGROUND;
    }
    // check preconditions
    if (context.getFocusContext() == null) {
        throw new IllegalStateException("No focus context when expected it");
    }
    PrismObject<RoleType> role = (PrismObject) context.getFocusContext().getObjectAny();
    if (role == null) {
        throw new IllegalStateException("No role when expected it");
    }
    // preparing the recompute/reconciliation task
    Task reconTask;
    if (task.isPersistent()) {
        reconTask = task.createSubtask();
    } else {
        reconTask = task;
    }
    assert !reconTask.isPersistent();
    // creating object query
    PrismPropertyDefinition propertyDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    PrismReferenceValue referenceValue = new PrismReferenceValue(context.getFocusContext().getOid(), RoleType.COMPLEX_TYPE);
    ObjectFilter refFilter = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(referenceValue).buildFilter();
    SearchFilterType filterType = QueryConvertor.createSearchFilterType(refFilter, prismContext);
    QueryType queryType = new QueryType();
    queryType.setFilter(filterType);
    PrismProperty<QueryType> property = propertyDef.instantiate();
    property.setRealValue(queryType);
    reconTask.addExtensionProperty(property);
    // other parameters
    reconTask.setName("Recomputing users after changing role " + role.asObjectable().getName());
    reconTask.setBinding(TaskBinding.LOOSE);
    reconTask.setInitialExecutionStatus(TaskExecutionStatus.RUNNABLE);
    reconTask.setHandlerUri(RecomputeTaskHandler.HANDLER_URI);
    reconTask.setCategory(TaskCategory.RECOMPUTATION);
    taskManager.switchToBackground(reconTask, result);
    result.setBackgroundTaskOid(reconTask.getOid());
    result.recordStatus(OperationResultStatus.IN_PROGRESS, "Reconciliation task switched to background");
    return HookOperationMode.BACKGROUND;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)371 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)297 Test (org.testng.annotations.Test)264 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)253 Task (com.evolveum.midpoint.task.api.Task)252 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)223 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)155 ArrayList (java.util.ArrayList)123 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)100 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)58 Holder (javax.xml.ws.Holder)49 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)46 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)46 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)38 QName (javax.xml.namespace.QName)38 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)37 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)33 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)33 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32