use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class FocusListInlineMenuHelper method updateActivationPerformed.
/**
* This method updates object activation. If selectedObject parameter is not null,
* than it updates only that objects, otherwise it checks table for selected
* objects.
*/
private void updateActivationPerformed(AjaxRequestTarget target, boolean enabling, F selectedObject) {
List<F> objects = getObjectsToActOn(target, selectedObject);
if (objects.isEmpty()) {
return;
}
OperationResult result = new OperationResult(getOperationName(enabling ? OPERATION_ENABLE_OBJECTS : OPERATION_DISABLE_OBJECTS));
for (F object : objects) {
String operationName = getOperationName(enabling ? OPERATION_ENABLE_OBJECT : OPERATION_DISABLE_OBJECT);
OperationResult subResult = result.createSubresult(operationName);
try {
Task task = parentPage.createSimpleTask(operationName);
ObjectDelta objectDelta = WebModelServiceUtils.createActivationAdminStatusDelta(objectClass, object.getOid(), enabling, parentPage.getPrismContext());
parentPage.getModelService().executeChanges(MiscUtil.createCollection(objectDelta), null, task, subResult);
subResult.recordSuccess();
} catch (CommonException | RuntimeException ex) {
subResult.recomputeStatus();
if (enabling) {
subResult.recordFatalError("FocusListInlineMenuHelper.message.enable.fatalError", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't enable object", ex);
} else {
subResult.recordFatalError("FocusListInlineMenuHelper.message.disable.fatalError", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't disable object", ex);
}
}
}
result.recomputeStatus();
parentPage.showResult(result);
target.add(parentPage.getFeedbackPanel());
focusListComponent.clearCache();
focusListComponent.refreshTable(target);
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class FocusListInlineMenuHelper method reconcilePerformed.
private void reconcilePerformed(AjaxRequestTarget target, F selectedObject) {
List<F> objects = getObjectsToActOn(target, selectedObject);
if (objects.isEmpty()) {
return;
}
OperationResult result = new OperationResult(getOperationName(OPERATION_RECONCILE_OBJECTS));
for (F object : objects) {
OperationResult opResult = result.createSubresult(getOperationName(OPERATION_RECONCILE_OBJECT));
try {
Task task = parentPage.createSimpleTask(OPERATION_RECONCILE_OBJECT);
ObjectDelta delta = parentPage.getPrismContext().deltaFactory().object().createEmptyModifyDelta(objectClass, object.getOid());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
parentPage.getModelService().executeChanges(deltas, parentPage.executeOptions().reconcile(), task, opResult);
opResult.computeStatusIfUnknown();
} catch (CommonException | RuntimeException ex) {
opResult.recomputeStatus();
opResult.recordFatalError(parentPage.createStringResource("FocusListInlineMenuHelper.message.reconcile.fatalError", object).getString(), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reconcile object " + object + ".", ex);
}
}
result.recomputeStatus();
parentPage.showResult(result);
target.add(parentPage.getFeedbackPanel());
focusListComponent.refreshTable(target);
focusListComponent.clearCache();
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PagePostAuthentication method submitRegistration.
@Override
protected void submitRegistration(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_SAVE_USER);
ObjectDelta<UserType> userDelta = null;
try {
userDelta = getUserDelta();
getPrismContext().adopt(userDelta);
WebModelServiceUtils.save(userDelta, result, this);
result.recordSuccessIfUnknown();
} catch (SchemaException e) {
LoggingUtils.logException(LOGGER, "Error during saving user.", e);
result.recordFatalError(getString("PagePostAuthentication.message.submitRegistration.fatalError"), e);
}
result.computeStatus();
if (result.isAcceptable()) {
runPrivileged(() -> {
ObjectDelta<UserType> lifecycleDelta = getPrismContext().deltaFactory().object().createModificationDeleteProperty(UserType.class, userModel.getObject().getOid(), UserType.F_LIFECYCLE_STATE, getPostAuthenticationConfiguration().getRequiredLifecycleState());
OperationResult opResult = new OperationResult(OPERATION_SAVE_USER);
Task task = createAnonymousTask(OPERATION_SAVE_USER);
WebModelServiceUtils.save(lifecycleDelta, opResult, task, PagePostAuthentication.this);
opResult.recordSuccessIfUnknown();
return opResult;
});
}
result.computeStatus();
showResult(result, true);
if (!result.isAcceptable()) {
target.add(PagePostAuthentication.this);
} else {
MidPointPrincipal principal = AuthUtil.getPrincipalUser();
try {
getModelInteractionService().refreshPrincipal(principal.getOid(), principal.getFocus().getClass());
navigateToNext(getMidpointApplication().getHomePage());
} catch (CommonException e) {
LOGGER.error("Error while refreshing user: ", e);
target.add(PagePostAuthentication.this);
}
}
target.add(getFeedbackPanel());
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class CapabilityStep method savePerformed.
private void savePerformed() {
Task task = getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES);
OperationResult result = task.getResult();
ModelService modelService = getPageBase().getModelService();
boolean saved = false;
try {
PrismObject<ResourceType> oldResource;
final PrismObject<ResourceType> resourceObject = resourceModel.getObject();
ResourceType resource = resourceObject.asObjectable();
List<Object> unsupportedCapabilities = new ArrayList<>();
if (resource.getCapabilities().getConfigured() != null) {
for (Object o : resource.getCapabilities().getConfigured().getAny()) {
CapabilityType capabilityType = CapabilityUtil.asCapabilityType(o);
if (!Capability.supports(capabilityType.getClass())) {
unsupportedCapabilities.add(o);
}
}
}
// AnyArrayList that is used to implement getAny() is really strange (e.g. doesn't support iterator.remove();
// and its support for clear() is questionable) -- so let's recreate it altogether
resource.getCapabilities().setConfigured(new CapabilityCollectionType());
resource.getCapabilities().getConfigured().getAny().addAll(unsupportedCapabilities);
ObjectFactory capabilityFactory = new ObjectFactory();
for (CapabilityDto dto : dtoModel.getObject().getCapabilities()) {
JAXBElement<? extends CapabilityType> jaxbCapability = createJAXBCapability(dto.getCapability(), capabilityFactory);
if (jaxbCapability != null) {
resource.getCapabilities().getConfigured().getAny().add(jaxbCapability);
}
}
oldResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
if (oldResource != null) {
ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, resourceObject);
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
@SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES), result);
parentPage.resetModels();
saved = true;
}
}
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save capabilities", e);
result.recordFatalError(getString("CapabilityStep.message.cantSaveCaps"), e);
} finally {
result.computeStatusIfUnknown();
setResult(result);
}
if (parentPage.showSaveResultInPage(saved, result)) {
getPageBase().showResult(result);
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class SchemaHandlingStep method savePerformed.
private void savePerformed() {
PrismObject<ResourceType> oldResource;
@NotNull PrismObject<ResourceType> newResource = resourceModel.getObject();
Task task = parentPage.createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING);
OperationResult result = task.getResult();
ModelService modelService = parentPage.getModelService();
ObjectDelta delta;
boolean saved = false;
removeEmptyContainers(newResource);
try {
oldResource = WebModelServiceUtils.loadObject(ResourceType.class, newResource.getOid(), parentPage, task, result);
if (oldResource == null) {
throw new IllegalStateException("No resource to apply schema handling to");
}
delta = parentPage.computeDiff(oldResource, newResource);
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
@SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
modelService.executeChanges(deltas, null, parentPage.createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING), result);
parentPage.resetModels();
saved = true;
}
} catch (RuntimeException | CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save schema handling", e);
result.recordFatalError(getString("SchemaHandlingStep.message.saveError", e));
} finally {
result.computeStatusIfUnknown();
}
setResult(result);
if (parentPage.showSaveResultInPage(saved, result)) {
parentPage.showResult(result);
}
}
Aggregations