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);
}
}
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);
}
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);
}
}
Aggregations