use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method searchOwners.
private List<PrismObject<FocusType>> searchOwners(PrismObject<ShadowType> shadow, OperationResult result) {
try {
ObjectQuery ownerQuery = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_LINK_REF).ref(shadow.getOid()).build();
List<PrismObject<FocusType>> owners = repositoryService.searchObjects(FocusType.class, ownerQuery, null, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Owners for {}: {}", ObjectTypeUtil.toShortString(shadow), owners);
}
return owners;
} catch (SchemaException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create/execute owners query for shadow {}", e, ObjectTypeUtil.toShortString(shadow));
return null;
}
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method addIdentifierValue.
private void addIdentifierValue(ShadowCheckResult checkResult, ObjectTypeContext context, QName identifierName, String identifierValue, PrismObject<ShadowType> shadow) {
Map<String, List<PrismObject<ShadowType>>> valueMap = context.getIdentifierValueMap().get(identifierName);
if (valueMap == null) {
valueMap = new HashMap<>();
context.getIdentifierValueMap().put(identifierName, valueMap);
}
List<PrismObject<ShadowType>> existingShadows = valueMap.get(identifierValue);
if (existingShadows == null) {
// all is well
existingShadows = new ArrayList();
existingShadows.add(shadow);
valueMap.put(identifierValue, existingShadows);
} else {
// duplicate shadows statistics are collected in a special way
duplicateShadowsDetected.add(shadow.getOid());
LOGGER.error("Multiple shadows with the value of identifier attribute {} = {}: existing one(s): {}, duplicate: {}", identifierName, identifierValue, shortDumpList(existingShadows), ObjectTypeUtil.toShortString(shadow.asObjectable()));
existingShadows.add(shadow);
}
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class ModelDiagController method repositorySelfTestUser.
private void repositorySelfTestUser(Task task, OperationResult testResult) {
OperationResult result = testResult.createSubresult(REPOSITORY_SELF_TEST_USER);
PrismObject<UserType> user;
try {
user = getObjectDefinition(UserType.class).instantiate();
} catch (SchemaException e) {
result.recordFatalError(e);
return;
}
UserType userType = user.asObjectable();
String name = generateRandomName();
PolyStringType namePolyStringType = toPolyStringType(name);
userType.setName(namePolyStringType);
result.addContext("name", name);
userType.setDescription(SelfTestData.POLICIJA);
userType.setFullName(toPolyStringType(USER_FULL_NAME));
userType.setGivenName(toPolyStringType(USER_GIVEN_NAME));
userType.setFamilyName(toPolyStringType(USER_FAMILY_NAME));
userType.setTitle(toPolyStringType(INSANE_NATIONAL_STRING));
userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[0]);
userType.getEmployeeType().add(USER_EMPLOYEE_TYPE[1]);
userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[0]));
userType.getOrganization().add(toPolyStringType(USER_ORGANIZATION[1]));
String oid;
try {
oid = repositoryService.addObject(user, null, result);
} catch (ObjectAlreadyExistsException | SchemaException | RuntimeException e) {
result.recordFatalError(e);
return;
}
try {
{
OperationResult subresult = result.createSubresult(result.getOperation() + ".getObject");
PrismObject<UserType> userRetrieved;
try {
userRetrieved = repositoryService.getObject(UserType.class, oid, null, subresult);
} catch (ObjectNotFoundException | SchemaException | RuntimeException e) {
result.recordFatalError(e);
return;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Self-test:user getObject:\n{}", userRetrieved.debugDump());
}
checkUser(userRetrieved, name, subresult);
subresult.recordSuccessIfUnknown();
}
{
OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.fullName");
try {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_FULL_NAME).eq(toPolyString(USER_FULL_NAME)).build();
subresult.addParam("query", query);
List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
}
assertSingleSearchResult("user", foundObjects, subresult);
PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
checkUser(userRetrieved, name, subresult);
subresult.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException e) {
subresult.recordFatalError(e);
return;
}
}
// MID-1116
{
OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.employeeType");
try {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_EMPLOYEE_TYPE).eq(USER_EMPLOYEE_TYPE[0]).build();
subresult.addParam("query", query);
List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
}
assertSingleSearchResult("user", foundObjects, subresult);
PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
checkUser(userRetrieved, name, subresult);
subresult.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException e) {
subresult.recordFatalError(e);
return;
}
}
// MID-1116
{
OperationResult subresult = result.createSubresult(result.getOperation() + ".searchObjects.organization");
try {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_ORGANIZATION).eq(toPolyString(USER_ORGANIZATION[1])).build();
subresult.addParam("query", query);
List<PrismObject<UserType>> foundObjects = repositoryService.searchObjects(UserType.class, query, null, subresult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Self-test:user searchObjects:\n{}", DebugUtil.debugDump(foundObjects));
}
assertSingleSearchResult("user", foundObjects, subresult);
PrismObject<UserType> userRetrieved = foundObjects.iterator().next();
checkUser(userRetrieved, name, subresult);
subresult.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException e) {
subresult.recordFatalError(e);
return;
}
}
} finally {
try {
repositoryService.deleteObject(UserType.class, oid, testResult);
} catch (ObjectNotFoundException | RuntimeException e) {
result.recordFatalError(e);
return;
}
result.computeStatus();
}
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class OrgStructFunctionsImpl method getManagersOfOrg.
@Override
public Collection<UserType> getManagersOfOrg(String orgOid, boolean preAuthorized) throws SchemaException, SecurityViolationException {
Set<UserType> retval = new HashSet<UserType>();
OperationResult result = new OperationResult("getManagerOfOrg");
PrismReferenceValue parentOrgRefVal = new PrismReferenceValue(orgOid, OrgType.COMPLEX_TYPE);
parentOrgRefVal.setRelation(SchemaConstants.ORG_MANAGER);
ObjectQuery objectQuery = QueryBuilder.queryFor(ObjectType.class, prismContext).item(ObjectType.F_PARENT_ORG_REF).ref(parentOrgRefVal).build();
List<PrismObject<ObjectType>> members = searchObjects(ObjectType.class, objectQuery, result, preAuthorized);
for (PrismObject<ObjectType> member : members) {
if (member.asObjectable() instanceof UserType) {
UserType user = (UserType) member.asObjectable();
retval.add(user);
}
}
return retval;
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class PageDebugView method savePerformed.
public void savePerformed(AjaxRequestTarget target) {
ObjectViewDto dto = model.getObject();
if (StringUtils.isEmpty(dto.getXml())) {
error(getString("pageDebugView.message.cantSaveEmpty"));
target.add(getFeedbackPanel());
return;
}
Task task = createSimpleTask(OPERATION_SAVE_OBJECT);
OperationResult result = task.getResult();
try {
PrismObject<ObjectType> oldObject = dto.getObject();
oldObject.revive(getPrismContext());
Holder<PrismObject<ObjectType>> objectHolder = new Holder<>(null);
validateObject(result, objectHolder);
if (result.isAcceptable()) {
PrismObject<ObjectType> newObject = objectHolder.getValue();
ObjectDelta<ObjectType> delta = oldObject.diff(newObject, true, true);
if (delta.getPrismContext() == null) {
LOGGER.warn("No prism context in delta {} after diff, adding it", delta);
delta.revive(getPrismContext());
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta to be applied:\n{}", delta.debugDump());
}
//quick fix for now (MID-1910), maybe it should be somewhere in model..
// if (isReport(oldObject)){
// ReportTypeUtil.applyConfigurationDefinition((PrismObject)newObject, delta, getPrismContext());
// }
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(delta);
ModelExecuteOptions options = new ModelExecuteOptions();
if (saveAsRaw.getObject()) {
options.setRaw(true);
}
if (reevaluateSearchFilters.getObject()) {
options.setReevaluateSearchFilters(true);
}
if (!encrypt.getObject()) {
options.setNoCrypt(true);
}
getModelService().executeChanges(deltas, options, task, result);
result.computeStatus();
}
} catch (Exception ex) {
result.recordFatalError("Couldn't save object.", ex);
}
if (result.isError()) {
showResult(result);
target.add(getFeedbackPanel());
} else {
showResult(result);
redirectBack();
}
}
Aggregations