use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class PageCertDefinition method savePerformed.
// endregion
// region Actions
public void savePerformed(AjaxRequestTarget target) {
CertDefinitionDto dto = definitionModel.getObject();
if (StringUtils.isEmpty(dto.getName())) {
error(getString("CertDefinitionPage.message.cantSaveEmptyName"));
target.add(getFeedbackPanel());
return;
}
Task task = createSimpleTask(OPERATION_SAVE_DEFINITION);
OperationResult result = task.getResult();
try {
AccessCertificationDefinitionType oldObject = dto.getOldDefinition();
oldObject.asPrismObject().revive(getPrismContext());
AccessCertificationDefinitionType newObject = dto.getUpdatedDefinition(getPrismContext());
newObject.asPrismObject().revive(getPrismContext());
ObjectDelta<AccessCertificationDefinitionType> delta;
if (oldObject.getOid() != null) {
delta = DiffUtil.diff(oldObject, newObject);
} else {
delta = DeltaFactory.Object.createAddDelta(newObject.asPrismObject());
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Access definition delta:\n{}", delta.debugDump());
}
delta.normalize();
if (!delta.isEmpty()) {
getPrismContext().adopt(delta);
ModelExecuteOptions options = new ModelExecuteOptions(getPrismContext());
options.raw(true);
getModelService().executeChanges(MiscUtil.createCollection(delta), options, task, result);
}
result.computeStatus();
} catch (Exception ex) {
result.recordFatalError(getString("PageCertDefinition.message.savePerformed.fatalError", ex.getMessage()), ex);
}
showResult(result);
if (result.isError()) {
target.add(getFeedbackPanel());
} else {
redirectBack();
}
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class TreeTablePanel method recomputePerformed.
private void recomputePerformed(SelectableBeanImpl<OrgType> orgToRecompute, AjaxRequestTarget target) {
Task task = getPageBase().createSimpleTask(OPERATION_RECOMPUTE);
OperationResult result = new OperationResult(OPERATION_RECOMPUTE);
if (orgToRecompute.getValue() == null) {
return;
}
try {
ObjectDelta emptyDelta = getPageBase().getPrismContext().deltaFactory().object().createEmptyModifyDelta(OrgType.class, orgToRecompute.getValue().getOid());
ModelExecuteOptions options = new ModelExecuteOptions(getPrismContext());
options.reconcile(true);
getPageBase().getModelService().executeChanges(MiscUtil.createCollection(emptyDelta), options, task, result);
result.recordSuccess();
} catch (Exception e) {
result.recordFatalError(getString("TreeTablePanel.message.recomputeError"), e);
LoggingUtils.logUnexpectedException(LOGGER, getString("TreeTablePanel.message.recomputeError"), e);
}
getPageBase().showResult(result);
target.add(getPageBase().getFeedbackPanel());
getTreePanel().refreshTabbedPanel(target);
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class PageAdminFocus method showAllAssignmentsPerformed.
public List<AssignmentValueWrapper> showAllAssignmentsPerformed(IModel<PrismContainerWrapper<AssignmentType>> parent) {
LOGGER.debug("Recompute user assignments");
Task task = createSimpleTask(OPERATION_RECOMPUTE_ASSIGNMENTS);
OperationResult result = new OperationResult(OPERATION_RECOMPUTE_ASSIGNMENTS);
ObjectDelta<F> delta;
Set<AssignmentValueWrapper> assignmentValueWrapperSet = new TreeSet<>();
try {
reviveModels();
PrismObjectWrapper<F> focusWrapper = getObjectWrapper();
delta = focusWrapper.getObjectDelta();
switch(focusWrapper.getStatus()) {
case ADDED:
PrismObject<F> focus = delta.getObjectToAdd();
prepareObjectForAdd(focus);
getPrismContext().adopt(focus, getCompileTimeClass());
LOGGER.trace("Delta before add focus:\n{}", delta.debugDumpLazily(3));
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
} else {
result.recordSuccess();
}
break;
case NOT_CHANGED:
prepareObjectDeltaForModify(delta);
LOGGER.trace("Delta before modify user:\n{}", delta.debugDumpLazily(3));
List<ObjectDelta<? extends ObjectType>> accountDeltas = getShadowModifyDeltas(result);
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
}
for (ObjectDelta accDelta : accountDeltas) {
if (!accDelta.isEmpty()) {
accDelta.revive(getPrismContext());
}
}
break;
default:
error(getString("pageAdminFocus.message.unsupportedState", focusWrapper.getStatus()));
}
ModelContext<UserType> modelContext;
try {
ModelExecuteOptions options = executeOptions().evaluateAllAssignmentRelationsOnRecompute();
modelContext = getModelInteractionService().previewChanges(Collections.singleton(delta), options, task, result);
} catch (NoFocusNameSchemaException e) {
info(getString("pageAdminFocus.message.noUserName"));
return null;
}
Collection<? extends EvaluatedAssignment<?>> evaluatedAssignments = modelContext.getNonNegativeEvaluatedAssignments();
if (evaluatedAssignments.isEmpty()) {
info(getString("pageAdminFocus.message.noAssignmentsAvailable"));
return null;
}
for (EvaluatedAssignment<?> evaluatedAssignment : evaluatedAssignments) {
if (!evaluatedAssignment.isValid()) {
continue;
}
// roles and orgs
DeltaSetTriple<? extends EvaluatedAssignmentTarget> targetsTriple = evaluatedAssignment.getRoles();
Collection<? extends EvaluatedAssignmentTarget> targets = targetsTriple.getNonNegativeValues();
for (EvaluatedAssignmentTarget target : targets) {
target.getTarget();
if (ArchetypeType.class.equals(target.getTarget().getCompileTimeClass())) {
continue;
}
if (target.appliesToFocusWithAnyRelation(getRelationRegistry())) {
AssignmentType assignmentType = target.getAssignment().clone();
assignmentType.setDescription(target.getTarget().asObjectable().getDescription());
assignmentType.getTargetRef().setTargetName(new PolyStringType(target.getTarget().getName()));
assignmentType.getTargetRef().setType(target.getTarget().getComplexTypeDefinition().getTypeName());
ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, this);
assignmentValueWrapper.setDirectAssignment(target.isDirectlyAssigned());
assignmentValueWrapper.setAssignmentParent(target.getAssignmentPath());
assignmentValueWrapperSet.add(assignmentValueWrapper);
}
}
// all resources
DeltaSetTriple<EvaluatedResourceObjectConstruction> evaluatedConstructionsTriple = evaluatedAssignment.getEvaluatedConstructions(task, result);
Collection<EvaluatedResourceObjectConstruction> evaluatedConstructions = evaluatedConstructionsTriple.getNonNegativeValues();
for (EvaluatedResourceObjectConstruction construction : evaluatedConstructions) {
if (!construction.isWeak()) {
PrismContainerDefinition<AssignmentType> assignmentDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class);
AssignmentType assignmentType = assignmentDef.instantiate().createNewValue().asContainerable();
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.setOid(construction.getResource().getOid());
targetRef.setType(ResourceType.COMPLEX_TYPE);
targetRef.setTargetName(new PolyStringType(construction.getResource().getName()));
assignmentType.setTargetRef(targetRef);
ConstructionType constructionType = new ConstructionType();
constructionType.setResourceRef(targetRef);
constructionType.setKind(construction.getKind());
constructionType.setIntent(construction.getIntent());
assignmentType.setConstruction(constructionType);
assignmentType.setDescription(construction.getResource().asObjectable().getDescription());
ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, this);
assignmentValueWrapper.setDirectAssignment(construction.isDirectlyAssigned());
assignmentValueWrapper.setAssignmentParent(construction.getAssignmentPath());
assignmentValueWrapperSet.add(assignmentValueWrapper);
}
}
}
return new ArrayList<>(assignmentValueWrapperSet);
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Could not create assignments preview.", e);
error("Could not create assignments preview. Reason: " + e);
}
return null;
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class PageAssignmentsList method onSingleUserRequestPerformed.
private void onSingleUserRequestPerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_REQUEST_ASSIGNMENTS);
ObjectDelta<UserType> delta;
try {
PrismObject<UserType> user = getTargetUser();
delta = prepareDelta(user, result);
ModelExecuteOptions options = createOptions();
// TODO make this configurable?
options.initialPartialProcessing(new PartialProcessingOptionsType().inbound(SKIP).projection(SKIP));
getModelService().executeChanges(Collections.singletonList(delta), options, createSimpleTask(OPERATION_REQUEST_ASSIGNMENTS), result);
result.recordSuccess();
SessionStorage storage = getSessionStorage();
storage.getRoleCatalog().getAssignmentShoppingCart().clear();
} catch (Exception e) {
result.recordFatalError(e);
result.setMessage(createStringResource("PageAssignmentsList.requestError").getString());
LoggingUtils.logUnexpectedException(LOGGER, "Could not save assignments ", e);
} finally {
result.recomputeStatus();
}
if (hasBackgroundTaskOperation(result)) {
result.setMessage(createStringResource("PageAssignmentsList.requestInProgress").getString());
showResult(result);
clearStorage();
setResponsePage(PageAssignmentShoppingCart.class);
return;
}
if (WebComponentUtil.isSuccessOrHandledError(result) || OperationResultStatus.IN_PROGRESS.equals(result.getStatus())) {
clearStorage();
result.setMessage(createStringResource("PageAssignmentsList.requestSuccess").getString());
setResponsePage(PageAssignmentShoppingCart.class);
} else {
result.setMessage(createStringResource("PageAssignmentsList.requestError").getString());
target.add(getFeedbackPanel());
target.add(PageAssignmentsList.this.get(ID_FORM));
}
showResult(result);
}
use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.
the class PageAssignmentsList method createOptions.
@NotNull
private ModelExecuteOptions createOptions() {
OperationBusinessContextType businessContextType;
if (descriptionModel.getObject() != null) {
businessContextType = new OperationBusinessContextType();
businessContextType.setComment(descriptionModel.getObject());
} else {
businessContextType = null;
}
ModelExecuteOptions options = ExecuteChangeOptionsDto.createFromSystemConfiguration().createOptions(getPrismContext());
options.requestBusinessContext(businessContextType);
return options;
}
Aggregations