use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class RepositoryObjectDataProvider method createItem.
private DebugObjectItem createItem(PrismObject<? extends ObjectType> object, OperationResult result) {
DebugObjectItem item = DebugObjectItem.createDebugObjectItem(object);
if (ShadowType.class.isAssignableFrom(object.getCompileTimeClass())) {
PrismReference ref = object.findReference(new ItemPath(ShadowType.F_RESOURCE_REF));
if (ref == null || ref.getValue() == null) {
return item;
}
PrismReferenceValue refValue = ref.getValue();
String resourceOid = refValue.getOid();
ResourceDescription desc = resourceCache.get(resourceOid);
if (desc == null) {
desc = loadDescription(resourceOid, result);
resourceCache.put(resourceOid, desc);
}
item.setResourceName(desc.getName());
item.setResourceType(desc.getType());
}
return item;
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class RepositoryObjectDataProvider method loadDescription.
private ResourceDescription loadDescription(String oid, OperationResult result) {
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ResourceType.F_CONNECTOR, GetOperationOptions.createResolve());
OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESOURCE);
subResult.addParam("oid", oid);
PrismObject<ResourceType> resource = null;
String type = null;
try {
resource = getModel().getObject(ResourceType.class, oid, options, getPage().createSimpleTask(OPERATION_LOAD_RESOURCE), subResult);
PrismReference ref = resource.findReference(ResourceType.F_CONNECTOR_REF);
if (ref != null && ref.getValue() != null) {
PrismReferenceValue refValue = ref.getValue();
if (refValue.getObject() != null) {
PrismObject connector = refValue.getObject();
PrismProperty<String> pType = connector.findProperty(ConnectorType.F_CONNECTOR_TYPE);
if (pType != null && pType.getRealValue() != null) {
type = pType.getRealValue(String.class);
}
}
}
subResult.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource for account", ex);
subResult.recordFatalError("Couldn't load resource for account.");
} finally {
subResult.recomputeStatus();
}
return new ResourceDescription(oid, WebComponentUtil.getName(resource), type);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class NameStep method isConnectorOnHost.
private boolean isConnectorOnHost(PrismObject<ConnectorType> connector, @Nullable PrismObject<ConnectorHostType> host) {
PrismReference connHostRef = connector.findReference(ConnectorType.F_CONNECTOR_HOST_REF);
String connHostOid = connHostRef != null ? connHostRef.getOid() : null;
String hostOid = host != null ? host.getOid() : null;
return ObjectUtils.equals(connHostOid, hostOid);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class RawTypeUtil method getParsedItem.
public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
Item<IV, ID> subItem = null;
List<IV> parsedValues = new ArrayList<IV>();
for (RawType rawValue : values) {
if (itemDefinition == null && containerDef != null) {
itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
}
IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
if (parsed != null) {
parsedValues.add(parsed);
}
}
PrismContext prismContext = null;
if (containerDef != null) {
prismContext = containerDef.getPrismContext();
}
if (prismContext == null && itemDefinition != null) {
prismContext = itemDefinition.getPrismContext();
}
if (itemDefinition == null) {
PrismProperty property = new PrismProperty(elementQName, prismContext);
property.addAll(PrismValue.cloneCollection(parsedValues));
return property;
}
if (itemDefinition instanceof PrismPropertyDefinition<?>) {
// property
PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
property.add((PrismPropertyValue) val.clone());
}
subItem = (Item<IV, ID>) property;
} else if (itemDefinition instanceof PrismContainerDefinition<?>) {
PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
container.add((PrismContainerValue) val.clone());
}
subItem = (Item<IV, ID>) container;
} else if (itemDefinition instanceof PrismReferenceDefinition) {
// TODO
PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
for (IV val : parsedValues) {
PrismReferenceValue ref;
if (val instanceof PrismReferenceValue) {
ref = (PrismReferenceValue) val.clone();
} else if (val instanceof PrismContainerValue) {
// this is embedded (full) object
Containerable c = ((PrismContainerValue) val).asContainerable();
if (!(c instanceof Objectable)) {
throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
}
Objectable o = (Objectable) c;
ref = new PrismReferenceValue();
ref.setObject(o.asPrismObject());
} else {
throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
}
reference.merge(ref);
}
subItem = (Item<IV, ID>) reference;
} else {
throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
}
return subItem;
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TestMultiResource method test440DavidAndGoliathAssignRoleAndCreateUserInOneStep.
@Test
public void test440DavidAndGoliathAssignRoleAndCreateUserInOneStep() throws Exception {
final String TEST_NAME = "test440DavidAndGoliathAssignRoleAndCreateUserInOneStep";
TestUtil.displayTestTile(TEST_NAME);
dummyResourceGoliath.setBreakMode(BreakMode.NONE);
dummyResourceDavid.setBreakMode(BreakMode.NONE);
try {
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// delete user and his roles which were added before
PrismObject<UserType> userWorld = findUserByUsername(USER_FIELD_NAME);
AssertJUnit.assertNotNull("User must not be null.", userWorld);
ObjectDelta<UserType> delta = ObjectDelta.createDeleteDelta(UserType.class, userWorld.getOid(), prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
deltas.add(delta);
modelService.executeChanges(deltas, null, task, result);
OperationResult deleteResult = new OperationResult("Check if user was deleted properly.");
try {
repositoryService.getObject(UserType.class, userWorld.getOid(), null, deleteResult);
} catch (ObjectNotFoundException ex) {
//this is OK, we deleted user before
}
// GIVEN
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
PrismObject<UserType> userBefore = createUser(USER_WORLD_NAME, USER_WORLD_FULL_NAME, true);
userBefore.asObjectable().getOrganizationalUnit().add(PrismTestUtil.createPolyStringType("stone"));
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
targetRef.getValue().setOid(ROLE_FIGHT_OID);
targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);
userBefore.findOrCreateContainer(UserType.F_ASSIGNMENT).add((PrismContainerValue) cval);
// userBefore.asObjectable().getAssignment().add(cval.asContainerable());
// this should add user and at the sate time assign the role fight..->
// the result of the operation have to be the same as in test 400
addObject(userBefore);
dummyAuditService.clear();
// WHEN
TestUtil.displayWhen(TEST_NAME);
// assignRole(userBefore.getOid(), ROLE_FIGHT_OID, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertDavidGoliath(userBefore.getOid(), "stone", USER_WORLD_NAME, true, true, true);
// Check audit
display("Audit", dummyAuditService);
// dummyAuditService.assertRecords(4);
// dummyAuditService.assertSimpleRecordSanity();
// dummyAuditService.assertAnyRequestDeltas();
// dummyAuditService.assertExecutionDeltas(0,3);
// dummyAuditService.asserHasDelta(0,ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(0,ChangeType.ADD, ShadowType.class);
// dummyAuditService.assertExecutionDeltas(1,3);
// dummyAuditService.asserHasDelta(1,ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(1,ChangeType.ADD, ShadowType.class);
// dummyAuditService.assertExecutionDeltas(2,2);
// dummyAuditService.asserHasDelta(2,ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(2,ChangeType.MODIFY, ShadowType.class);
// dummyAuditService.assertExecutionSuccess();
//
// // Have a closer look at the last shadow modify delta. Make sure there are no phantom changes.
// ObjectDeltaOperation<?> executionDeltaOp = dummyAuditService.getExecutionDelta(2, ChangeType.MODIFY, ShadowType.class);
// ObjectDelta<?> executionDelta = executionDeltaOp.getObjectDelta();
// display("Last execution delta", executionDelta);
// PrismAsserts.assertModifications("Phantom changes in last delta:", executionDelta, 2);
} catch (Exception ex) {
LOGGER.info("ex: {}", ex);
throw ex;
}
}
Aggregations