use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TaskQuartzImpl method resolveOwnerRef.
PrismObject<UserType> resolveOwnerRef(OperationResult result) throws SchemaException {
PrismReference ownerRef = taskPrism.findReference(TaskType.F_OWNER_REF);
if (ownerRef == null) {
throw new SchemaException("Task " + getOid() + " does not have an owner (missing ownerRef)");
}
try {
PrismObject<UserType> owner = repositoryService.getObject(UserType.class, ownerRef.getOid(), null, result);
ownerRef.getValue().setObject(owner);
return owner;
} catch (ObjectNotFoundException e) {
LoggingUtils.logExceptionAsWarning(LOGGER, "The owner of task {} cannot be found (owner OID: {})", e, getOid(), ownerRef.getOid());
return null;
}
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TaskQuartzImpl method getObjectRef.
// @Override
// public String getChannel() {
// PrismProperty<String> channelProperty = taskPrism.findProperty(TaskType.F_CHANNEL);
// if (channelProperty == null) {
// return null;
// }
// return channelProperty.getRealValue();
// }
// @Override
// public void setChannel(String channelUri) {
// // TODO: Is this OK?
// PrismProperty<String> channelProperty;
// try {
// channelProperty = taskPrism.findOrCreateProperty(TaskType.F_CHANNEL);
// } catch (SchemaException e) {
// // This should not happen
// throw new IllegalStateException("Internal schema error: "+e.getMessage(),e);
// }
// channelProperty.setRealValue(channelUri);
// }
/*
* Object
*/
@Override
public ObjectReferenceType getObjectRef() {
PrismReference objectRef = taskPrism.findReference(TaskType.F_OBJECT_REF);
if (objectRef == null) {
return null;
}
ObjectReferenceType objRefType = new ObjectReferenceType();
objRefType.setOid(objectRef.getOid());
objRefType.setType(objectRef.getValue().getTargetType());
return objRefType;
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TaskQuartzImpl method getObject.
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
// Shortcut
PrismReference objectRef = taskPrism.findReference(TaskType.F_OBJECT_REF);
if (objectRef == null) {
return null;
}
if (objectRef.getValue().getObject() != null) {
PrismObject object = objectRef.getValue().getObject();
if (object.canRepresent(type)) {
return (PrismObject<T>) object;
} else {
throw new IllegalArgumentException("Requested object type " + type + ", but the type of object in the task is " + object.getClass());
}
}
OperationResult result = parentResult.createSubresult(DOT_INTERFACE + "getObject");
result.addContext(OperationResult.CONTEXT_OID, getOid());
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, TaskQuartzImpl.class);
try {
PrismObject<T> object = repositoryService.getObject(type, objectRef.getOid(), null, result);
objectRef.getValue().setObject(object);
result.recordSuccess();
return object;
} catch (ObjectNotFoundException ex) {
result.recordFatalError("Object not found", ex);
throw ex;
} catch (SchemaException ex) {
result.recordFatalError("Schema error", ex);
throw ex;
}
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class ConsistencyTest method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
* @throws Exception
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
final String TEST_NAME = "test511AssignAccountMorgan";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
openDJController.assumeRunning();
Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
//prepare new OU in opendj
Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
JAXBElement val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class PageSelfDashboard method createAssignmentItem.
private AssignmentItemDto createAssignmentItem(PrismObject<UserType> user, PrismContainerValue<AssignmentType> assignment, Task task, OperationResult result) {
ActivationType activation = assignment.asContainerable().getActivation();
if (activation != null && activation.getAdministrativeStatus() != null && !activation.getAdministrativeStatus().equals(ActivationStatusType.ENABLED)) {
return null;
}
PrismReference targetRef = assignment.findReference(AssignmentType.F_TARGET_REF);
if (targetRef == null || targetRef.isEmpty()) {
// account construction
PrismContainer construction = assignment.findContainer(AssignmentType.F_CONSTRUCTION);
String name = null;
String description = "";
if (construction.getValue().asContainerable() != null && !construction.isEmpty()) {
ConstructionType constr = (ConstructionType) construction.getValue().asContainerable();
if (constr.getResourceRef() != null) {
ObjectReferenceType resourceRef = constr.getResourceRef();
PrismObject resource = WebModelServiceUtils.loadObject(ResourceType.class, resourceRef.getOid(), this, task, result);
name = WebComponentUtil.getName(resource);
description = constr.getDescription();
}
}
return new AssignmentItemDto(AssignmentEditorDtoType.CONSTRUCTION, name, description, null);
}
PrismReferenceValue refValue = targetRef.getValue();
PrismObject value = refValue.getObject();
if (value == null) {
// resolve reference
value = WebModelServiceUtils.loadObject(ObjectType.class, refValue.getOid(), this, task, result);
}
if (value == null) {
// we couldn't resolve assignment details
return new AssignmentItemDto(null, null, null, null);
}
String name = WebComponentUtil.getDisplayNameOrName(value);
AssignmentEditorDtoType type = AssignmentEditorDtoType.getType(value.getCompileTimeClass());
String relation = refValue.getRelation() != null ? refValue.getRelation().getLocalPart() : null;
return new AssignmentItemDto(type, name, getAssignmentDescription(value), relation);
}
Aggregations