Search in sources :

Example 1 with S_ItemEntry

use of com.evolveum.midpoint.prism.delta.builder.S_ItemEntry in project midpoint by Evolveum.

the class NameStep method applyState.

@Override
public void applyState() {
    parentPage.refreshIssues(null);
    if (parentPage.isReadOnly() || !isComplete()) {
        return;
    }
    PrismContext prismContext = parentPage.getPrismContext();
    Task task = parentPage.createSimpleTask(OPERATION_SAVE_RESOURCE);
    OperationResult result = task.getResult();
    boolean saved = false;
    try {
        PrismObject<ResourceType> resource = resourceModelRaw.getObject();
        PrismObject<ConnectorType> connector = getSelectedConnector();
        if (connector == null) {
            // should be treated by form validation
            throw new IllegalStateException("No connector selected");
        }
        ObjectDelta delta;
        final String oid = resource.getOid();
        boolean isNew = oid == null;
        if (isNew) {
            resource = prismContext.createObject(ResourceType.class);
            ResourceType resourceType = resource.asObjectable();
            resourceType.setName(PolyStringType.fromOrig(resourceNameModel.getObject()));
            resourceType.setDescription(resourceDescriptionModel.getObject());
            resourceType.setConnectorRef(ObjectTypeUtil.createObjectRef(connector));
            delta = ObjectDelta.createAddDelta(resource);
        } else {
            PrismObject<ResourceType> oldResourceObject = WebModelServiceUtils.loadObject(ResourceType.class, oid, GetOperationOptions.createRawCollection(), parentPage, parentPage.createSimpleTask("loadResource"), result);
            if (oldResourceObject == null) {
                throw new SystemException("Resource being edited (" + oid + ") couldn't be retrieved");
            }
            ResourceType oldResource = oldResourceObject.asObjectable();
            S_ItemEntry i = DeltaBuilder.deltaFor(ResourceType.class, prismContext);
            if (!StringUtils.equals(PolyString.getOrig(oldResource.getName()), resourceNameModel.getObject())) {
                i = i.item(ResourceType.F_NAME).replace(PolyString.fromOrig(resourceNameModel.getObject()));
            }
            if (!StringUtils.equals(oldResource.getDescription(), resourceDescriptionModel.getObject())) {
                i = i.item(ResourceType.F_DESCRIPTION).replace(resourceDescriptionModel.getObject());
            }
            String oldConnectorOid = oldResource.getConnectorRef() != null ? oldResource.getConnectorRef().getOid() : null;
            String newConnectorOid = connector.getOid();
            if (!StringUtils.equals(oldConnectorOid, newConnectorOid)) {
                i = i.item(ResourceType.F_CONNECTOR_REF).replace(ObjectTypeUtil.createObjectRef(connector).asReferenceValue());
            }
            if (!isConfigurationSchemaCompatible(connector)) {
                i = i.item(ResourceType.F_CONNECTOR_CONFIGURATION).replace();
            }
            delta = i.asObjectDelta(oid);
        }
        if (!delta.isEmpty()) {
            parentPage.logDelta(delta);
            WebModelServiceUtils.save(delta, ModelExecuteOptions.createRaw(), result, null, parentPage);
            parentPage.resetModels();
            saved = true;
        }
        if (isNew) {
            parentPage.setEditedResourceOid(delta.getOid());
        }
    } catch (RuntimeException | SchemaException ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save resource", ex);
        result.recordFatalError("Couldn't save resource, reason: " + ex.getMessage(), ex);
    } finally {
        result.computeStatusIfUnknown();
        setResult(result);
    }
    if (parentPage.showSaveResultInPage(saved, result)) {
        parentPage.showResult(result);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SystemException(com.evolveum.midpoint.util.exception.SystemException) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 2 with S_ItemEntry

use of com.evolveum.midpoint.prism.delta.builder.S_ItemEntry in project midpoint by Evolveum.

the class PolicyRuleBasedAspect method assignmentToDelta.

// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(Class<? extends Objectable> focusClass, AssignmentType assignmentType, boolean assignmentRemoved, String objectOid) throws SchemaException {
    PrismContainerValue value = assignmentType.clone().asPrismContainerValue();
    S_ValuesEntry item = DeltaBuilder.deltaFor(focusClass, prismContext).item(FocusType.F_ASSIGNMENT);
    S_ItemEntry op = assignmentRemoved ? item.delete(value) : item.add(value);
    return (ObjectDelta<? extends FocusType>) op.asObjectDelta(objectOid);
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) S_ValuesEntry(com.evolveum.midpoint.prism.delta.builder.S_ValuesEntry)

Example 3 with S_ItemEntry

use of com.evolveum.midpoint.prism.delta.builder.S_ItemEntry in project midpoint by Evolveum.

the class MidpointUtil method recordEventInTask.

// additional delta is a bit hack ... TODO refactor (but without splitting the modify operation!)
public static void recordEventInTask(CaseEventType event, ObjectDeltaType additionalDelta, String taskOid, OperationResult result) {
    RepositoryService cacheRepositoryService = getCacheRepositoryService();
    PrismContext prismContext = getPrismContext();
    try {
        S_ItemEntry deltaBuilder = DeltaBuilder.deltaFor(TaskType.class, getPrismContext()).item(F_WORKFLOW_CONTEXT, F_EVENT).add(event);
        if (additionalDelta != null) {
            PrismObject<TaskType> task = cacheRepositoryService.getObject(TaskType.class, taskOid, null, result);
            WfPrimaryChangeProcessorStateType state = WfContextUtil.getPrimaryChangeProcessorState(task.asObjectable().getWorkflowContext());
            ObjectTreeDeltasType updatedDelta = ObjectTreeDeltas.mergeDeltas(state.getDeltasToProcess(), additionalDelta, prismContext);
            // assuming it already exists!
            ItemPath deltasToProcessPath = new ItemPath(F_WORKFLOW_CONTEXT, F_PROCESSOR_SPECIFIC_STATE, WfPrimaryChangeProcessorStateType.F_DELTAS_TO_PROCESS);
            ItemDefinition<?> deltasToProcessDefinition = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(WfPrimaryChangeProcessorStateType.class).findItemDefinition(WfPrimaryChangeProcessorStateType.F_DELTAS_TO_PROCESS);
            deltaBuilder = deltaBuilder.item(deltasToProcessPath, deltasToProcessDefinition).replace(updatedDelta);
        }
        cacheRepositoryService.modifyObject(TaskType.class, taskOid, deltaBuilder.asItemDeltas(), result);
    } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException e) {
        throw new SystemException("Couldn't record decision to the task " + taskOid + ": " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SpringApplicationContextHolder.getPrismContext(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SpringApplicationContextHolder.getCacheRepositoryService(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getCacheRepositoryService) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 S_ValuesEntry (com.evolveum.midpoint.prism.delta.builder.S_ValuesEntry)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SpringApplicationContextHolder.getCacheRepositoryService (com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getCacheRepositoryService)1 SpringApplicationContextHolder.getPrismContext (com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext)1 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1