use of com.evolveum.midpoint.web.util.validation.SimpleValidationError in project midpoint by Evolveum.
the class PageAdminObjectDetails method saveOrPreviewPerformed.
public void saveOrPreviewPerformed(AjaxRequestTarget target, OperationResult result, boolean previewOnly) {
boolean isAnythingChanged = processDeputyAssignments();
ObjectWrapper<O> objectWrapper = getObjectWrapper();
LOGGER.debug("Saving object {}", objectWrapper);
// todo: improve, delta variable is quickfix for MID-1006
// redirecting to user list page everytime user is created in repository
// during user add in gui,
// and we're not taking care about account/assignment create errors
// (error message is still displayed)
delta = null;
Task task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
ModelExecuteOptions options = getExecuteChangesOptions();
LOGGER.debug("Using execute options {}.", new Object[] { options });
try {
reviveModels();
delta = objectWrapper.getObjectDelta();
if (objectWrapper.getOldDelta() != null) {
delta = ObjectDelta.summarize(objectWrapper.getOldDelta(), delta);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("User delta computed from form:\n{}", new Object[] { delta.debugDump(3) });
}
} catch (Exception ex) {
result.recordFatalError(getString("pageUser.message.cantCreateUser"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
showResult(result);
return;
}
switch(objectWrapper.getStatus()) {
case ADDING:
try {
PrismObject<O> objectToAdd = delta.getObjectToAdd();
WebComponentUtil.encryptCredentials(objectToAdd, true, getMidpointApplication());
prepareObjectForAdd(objectToAdd);
getPrismContext().adopt(objectToAdd, getCompileTimeClass());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta before add user:\n{}", new Object[] { delta.debugDump(3) });
}
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
final Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
final Collection<SimpleValidationError> validationErrors = performCustomValidation(objectToAdd, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
} else {
result.recordSuccess();
}
} catch (Exception ex) {
result.recordFatalError(getString("pageFocus.message.cantCreateFocus"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
showResult(result);
}
break;
case MODIFYING:
try {
WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
prepareObjectDeltaForModify(delta);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta before modify user:\n{}", new Object[] { delta.debugDump(3) });
}
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
deltas.add(delta);
}
List<ObjectDelta<? extends ObjectType>> additionalDeltas = getAdditionalModifyDeltas(result);
if (additionalDeltas != null) {
for (ObjectDelta additionalDelta : additionalDeltas) {
if (!additionalDelta.isEmpty()) {
additionalDelta.revive(getPrismContext());
deltas.add(additionalDelta);
}
}
}
if (delta.isEmpty() && ModelExecuteOptions.isReconcile(options)) {
ObjectDelta emptyDelta = ObjectDelta.createEmptyModifyDelta(getCompileTimeClass(), objectWrapper.getObject().getOid(), getPrismContext());
deltas.add(emptyDelta);
Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
} else if (!deltas.isEmpty()) {
Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
} else {
// from previous attempts (useful only if we would call finishProcessing at the end, but that's not the case now)
progressReporter.clearProgressPanel();
if (!previewOnly) {
if (!isAnythingChanged) {
result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
showResult(result);
}
redirectBack();
} else {
warn(getString("PageAdminObjectDetails.noChangesPreview"));
target.add(getFeedbackPanel());
}
}
} catch (Exception ex) {
if (!executeForceDelete(objectWrapper, task, options, result)) {
result.recordFatalError(getString("pageUser.message.cantUpdateUser"), ex);
LoggingUtils.logUnexpectedException(LOGGER, getString("pageUser.message.cantUpdateUser"), ex);
} else {
result.recomputeStatus();
}
showResult(result);
}
break;
// support for add/delete containers (e.g. delete credentials)
default:
error(getString("pageAdminFocus.message.unsupportedState", objectWrapper.getStatus()));
}
// result.recomputeStatus();
//
// if (!result.isInProgress()) {
// LOGGER.trace("Result NOT in progress, calling finishProcessing");
// finishProcessing(target, result, false);
// }
LOGGER.trace("returning from saveOrPreviewPerformed");
}
use of com.evolveum.midpoint.web.util.validation.SimpleValidationError in project midpoint by Evolveum.
the class PageAdminObjectDetails method saveOrPreviewPerformed.
public void saveOrPreviewPerformed(AjaxRequestTarget target, OperationResult result, boolean previewOnly, Task task) {
boolean delegationChangesExist = processDeputyAssignments(previewOnly);
PrismObjectWrapper<O> objectWrapper = getObjectWrapper();
LOGGER.debug("Saving object {}", objectWrapper);
// todo: improve, delta variable is quickfix for MID-1006
// redirecting to user list page everytime user is created in repository
// during user add in gui,
// and we're not taking care about account/assignment create errors
// (error message is still displayed)
delta = null;
if (task == null) {
task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
}
ModelExecuteOptions options = getOptions(previewOnly);
LOGGER.debug("Using execute options {}.", options);
try {
reviveModels();
delta = objectWrapper.getObjectDelta();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("User delta computed from form:\n{}", delta.debugDump(3));
}
} catch (Exception ex) {
result.recordFatalError(getString("pageAdminObjectDetails.message.cantCreateObject"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Create Object failed", ex);
showResult(result);
target.add(getFeedbackPanel());
return;
}
switch(objectWrapper.getStatus()) {
case ADDED:
try {
PrismObject<O> objectToAdd = delta.getObjectToAdd();
WebComponentUtil.encryptCredentials(objectToAdd, true, getMidpointApplication());
prepareObjectForAdd(objectToAdd);
getPrismContext().adopt(objectToAdd, getCompileTimeClass());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta before add user:\n{}", delta.debugDump(3));
}
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
final Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
final Collection<SimpleValidationError> validationErrors = performCustomValidation(objectToAdd, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
if (isSaveInBackground() && !previewOnly) {
progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
} else {
progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
}
} else {
result.recordSuccess();
}
} catch (Exception ex) {
result.recordFatalError(getString("pageFocus.message.cantCreateFocus"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
showResult(result);
}
break;
case NOT_CHANGED:
try {
WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
// preparing of deltas for projections (ADD, DELETE, UNLINK)
prepareObjectDeltaForModify(delta);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta before modify user:\n{}", delta.debugDump(3));
}
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
deltas.add(delta);
}
List<ObjectDelta<? extends ObjectType>> additionalDeltas = getAdditionalModifyDeltas(result);
if (additionalDeltas != null) {
for (ObjectDelta additionalDelta : additionalDeltas) {
if (!additionalDelta.isEmpty()) {
additionalDelta.revive(getPrismContext());
deltas.add(additionalDelta);
}
}
}
if (delta.isEmpty() && ModelExecuteOptions.isReconcile(options)) {
ObjectDelta emptyDelta = getPrismContext().deltaFactory().object().createEmptyModifyDelta(getCompileTimeClass(), objectWrapper.getObject().getOid());
deltas.add(emptyDelta);
Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
if (isSaveInBackground() && !previewOnly) {
progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
} else {
progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
}
} else if (!deltas.isEmpty()) {
Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
if (checkValidationErrors(target, validationErrors)) {
return;
}
if (isSaveInBackground() && !previewOnly) {
progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
} else {
progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
}
} else if (previewOnly && delta.isEmpty() && delegationChangesExist) {
if (isSaveInBackground() && !previewOnly) {
progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
} else {
progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
}
} else {
// from previous attempts (useful only if we would call finishProcessing at the end, but that's not the case now)
progressPanel.clearProgressPanel();
if (!previewOnly) {
if (!delegationChangesExist) {
result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
showResult(result);
}
redirectBack();
} else {
if (!delegationChangesExist) {
warn(getString("PageAdminObjectDetails.noChangesPreview"));
target.add(getFeedbackPanel());
}
}
}
} catch (Exception ex) {
if (!executeForceDelete(objectWrapper, task, options, result)) {
result.recordFatalError(getString("pageUser.message.cantUpdateUser"), ex);
LoggingUtils.logUnexpectedException(LOGGER, getString("pageUser.message.cantUpdateUser"), ex);
} else {
result.recomputeStatus();
}
showResult(result);
}
break;
// support for add/delete containers (e.g. delete credentials)
default:
error(getString("pageAdminFocus.message.unsupportedState", objectWrapper.getStatus()));
}
LOGGER.trace("returning from saveOrPreviewPerformed");
}
use of com.evolveum.midpoint.web.util.validation.SimpleValidationError in project midpoint by Evolveum.
the class PageAdminObjectDetails method performCustomValidation.
protected Collection<SimpleValidationError> performCustomValidation(PrismObject<O> object, Collection<ObjectDelta<? extends ObjectType>> deltas) throws SchemaException {
Collection<SimpleValidationError> errors = null;
if (object == null) {
if (getObjectWrapper() != null && getObjectWrapper().getObjectOld() != null) {
// otherwise original object could get corrupted e.g. by applying the delta below
object = getObjectWrapper().getObjectOld().clone();
for (ObjectDelta delta : deltas) {
// because among deltas there can be also ShadowType deltas
if (UserType.class.isAssignableFrom(delta.getObjectTypeClass())) {
delta.applyTo(object);
}
}
}
} else {
object = object.clone();
}
performAdditionalValidation(object, deltas, errors);
for (MidpointFormValidator validator : getFormValidatorRegistry().getValidators()) {
if (errors == null) {
errors = validator.validateObject(object, deltas);
} else {
errors.addAll(validator.validateObject(object, deltas));
}
}
return errors;
}
use of com.evolveum.midpoint.web.util.validation.SimpleValidationError in project midpoint by Evolveum.
the class AbstractPageObjectDetails method checkValidationErrors.
private void checkValidationErrors(AjaxRequestTarget target, Collection<SimpleValidationError> validationErrors) {
if (validationErrors != null && !validationErrors.isEmpty()) {
for (SimpleValidationError error : validationErrors) {
LOGGER.error("Validation error, attribute: '" + error.printAttribute() + "', message: '" + error.getMessage() + "'.");
error("Validation error, attribute: '" + error.printAttribute() + "', message: '" + error.getMessage() + "'.");
}
target.add(getFeedbackPanel());
throw new IllegalStateException("Validation errors found");
}
}
use of com.evolveum.midpoint.web.util.validation.SimpleValidationError in project midpoint by Evolveum.
the class InducedEntitlementsValidator method validateInducement.
private Collection<SimpleValidationError> validateInducement(AssignmentType assignment) {
List<SimpleValidationError> errors = new ArrayList<>();
// TODO impelemnt findContainer(ItemPath)
com.evolveum.midpoint.prism.Item<PrismContainerValue<ResourceObjectAssociationType>, PrismContainerDefinition<ResourceObjectAssociationType>> association = assignment.asPrismContainerValue().findItem(ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_ASSOCIATION));
if (association != null && !association.getValues().isEmpty()) {
for (PrismContainerValue<ResourceObjectAssociationType> associationValue : association.getValues()) {
PrismContainer<MappingType> outbound = associationValue.findContainer(ResourceObjectAssociationType.F_OUTBOUND);
if (outbound == null || outbound.getValues().isEmpty()) {
SimpleValidationError error = new SimpleValidationError();
error.setMessage(PageBase.createStringResourceStatic(null, "InducedEntitlementsPanel.validator.message").getString());
ItemPathType path = new ItemPathType();
path.setItemPath(ItemPath.create(AbstractRoleType.F_INDUCEMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ASSOCIATION, ResourceObjectAssociationType.F_OUTBOUND));
error.setAttribute(path);
errors.add(error);
}
}
}
return errors;
}
Aggregations