use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageRegistrationFinish method removeNonceAndSetLifecycleState.
private void removeNonceAndSetLifecycleState(String userOid, NonceType nonce, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
OperationResult result = parentResult.createSubresult(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
try {
runAsChecked(() -> {
Task task = createSimpleTask(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
ObjectDelta<UserType> delta = getPrismContext().deltaFactory().object().createModificationDeleteContainer(UserType.class, userOid, ItemPath.create(UserType.F_CREDENTIALS, CredentialsType.F_NONCE), nonce);
delta.addModificationReplaceProperty(UserType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_ACTIVE);
WebModelServiceUtils.save(delta, result, task, PageRegistrationFinish.this);
return null;
}, administrator);
} catch (CommonException | RuntimeException e) {
result.recordFatalError(getString("PageRegistrationConfirmation.message.removeNonceAndSetLifecycleState.fatalError"), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't remove nonce and set lifecycle state", e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageRegistrationConfirmation method assignDefaultRoles.
private void assignDefaultRoles(String userOid, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
List<ObjectReferenceType> rolesToAssign = getSelfRegistrationConfiguration().getDefaultRoles();
if (CollectionUtils.isEmpty(rolesToAssign)) {
return;
}
OperationResult result = parentResult.createSubresult(OPERATION_ASSIGN_DEFAULT_ROLES);
try {
PrismContext prismContext = getPrismContext();
List<AssignmentType> assignmentsToCreate = rolesToAssign.stream().map(ref -> ObjectTypeUtil.createAssignmentTo(ref, prismContext)).collect(Collectors.toList());
ObjectDelta<Objectable> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).addRealValues(assignmentsToCreate).asObjectDelta(userOid);
runAsChecked(() -> {
Task task = createSimpleTask(OPERATION_ASSIGN_DEFAULT_ROLES);
WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
return null;
}, administrator);
} catch (CommonException | RuntimeException e) {
result.recordFatalError(getString("PageRegistrationConfirmation.message.assignDefaultRoles.fatalError"), e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageRegistrationConfirmation method removeNonceAndSetLifecycleState.
private void removeNonceAndSetLifecycleState(String userOid, NonceType nonce, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
OperationResult result = parentResult.createSubresult(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
try {
runAsChecked(() -> {
Task task = createSimpleTask(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
ObjectDelta<UserType> delta = getPrismContext().deltaFactory().object().createModificationDeleteContainer(UserType.class, userOid, ItemPath.create(UserType.F_CREDENTIALS, CredentialsType.F_NONCE), nonce);
delta.addModificationReplaceProperty(UserType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_ACTIVE);
WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
return null;
}, administrator);
} catch (CommonException | RuntimeException e) {
result.recordFatalError(getString("PageRegistrationConfirmation.message.removeNonceAndSetLifecycleState.fatalError"), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't remove nonce and set lifecycle state", e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class OrgTreeProvider method size.
public long size(TreeSelectableBean<OrgType> node) {
Task task = getPageBase().createSimpleTask(LOAD_ORG_UNITS);
OperationResult result = task.getResult();
String nodeOid = null;
if (node != null) {
nodeOid = node.getValue().getOid();
} else {
nodeOid = rootOid.getObject();
}
Integer orgs = null;
try {
ObjectQuery query = getPageBase().getPrismContext().queryFor(OrgType.class).isDirectChildOf(nodeOid).build();
orgs = getModelService().countObjects(OrgType.class, query, null, task, result);
LOGGER.debug("Found {} sub-orgs.", orgs);
} catch (CommonException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load children", ex);
result.recordFatalError(getPageBase().createStringResource("OrgTreeProvider.message.getChildren.fatalError").getString(), ex);
} finally {
result.computeStatus();
}
if (WebComponentUtil.showResultInPage(result)) {
getPageBase().showResult(result);
throw new RestartResponseException(PageOrgTree.class);
}
return orgs == null ? 0 : orgs.longValue();
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class OrgTreeProvider method getChildren.
@Override
public Iterator<? extends TreeSelectableBean<OrgType>> getChildren(TreeSelectableBean<OrgType> node) {
LOGGER.debug("Getting children for {}", node.getValue());
String nodeOid = node.getValue().getOid();
List<TreeSelectableBean<OrgType>> children;
long currentTime = System.currentTimeMillis();
if (currentTime > lastFetchOperation + EXPIRATION_AFTER_LAST_FETCH_OPERATION) {
childrenCache.clear();
}
if (childrenCache.containsKey(nodeOid)) {
LOGGER.debug("Using cached children for {}", node.getValue());
children = childrenCache.get(nodeOid);
} else {
LOGGER.debug("Loading fresh children for {}", node.getValue());
OperationResult result = new OperationResult(LOAD_ORG_UNITS);
try {
ObjectQuery query = getPageBase().getPrismContext().queryFor(OrgType.class).isDirectChildOf(nodeOid).build();
ObjectFilter customFilter = getCustomFilter();
if (customFilter != null) {
query.addFilter(customFilter);
}
Task task = getPageBase().createSimpleTask(LOAD_ORG_UNITS);
ObjectPaging paging = createPaging(node);
query.setPaging(paging);
List<PrismObject<OrgType>> orgs = getModelService().searchObjects(OrgType.class, query, null, task, result);
LOGGER.debug("Found {} sub-orgs.", orgs.size());
children = new ArrayList<>();
for (PrismObject<OrgType> org : orgs) {
children.add(createObjectWrapper(node, org));
}
childrenCache.put(nodeOid, children);
} catch (CommonException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load children", ex);
result.recordFatalError(getPageBase().createStringResource("OrgTreeProvider.message.getChildren.fatalError").getString(), ex);
children = new ArrayList<>();
} finally {
result.computeStatus();
}
if (WebComponentUtil.showResultInPage(result)) {
getPageBase().showResult(result);
throw new RestartResponseException(PageOrgTree.class);
}
children.forEach(orgUnit -> {
getAvailableData().putIfAbsent(orgUnit.getValue().getOid(), orgUnit);
});
}
LOGGER.debug("Finished getting children.");
lastFetchOperation = System.currentTimeMillis();
return children.iterator();
}
Aggregations