use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class JaxbTestUtil method determineElementQName.
private QName determineElementQName(Containerable containerable) {
PrismContainerValue prismContainerValue = containerable.asPrismContainerValue();
PrismContainerDefinition<?> definition = prismContainerValue.getParent() != null ? prismContainerValue.getParent().getDefinition() : null;
if (definition != null) {
if (definition.getName() != null) {
return definition.getName();
}
}
throw new IllegalStateException("Cannot determine element name of " + containerable + " (parent = " + prismContainerValue.getParent() + ", definition = " + definition + ")");
}
use of com.evolveum.midpoint.prism.PrismContainerValue 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.PrismContainerValue in project midpoint by Evolveum.
the class Construction method evaluateAssociation.
private Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluateAssociation(ResourceObjectAssociationType associationDefinitionType, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
QName assocName = ItemPathUtil.getOnlySegmentQName(associationDefinitionType.getRef());
if (assocName == null) {
throw new SchemaException("Missing 'ref' in association in construction in " + getSource());
}
MappingType outboundMappingType = associationDefinitionType.getOutbound();
if (outboundMappingType == null) {
throw new SchemaException("No outbound section in definition of association " + assocName + " in construction in " + getSource());
}
PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>createMappingBuilder().mappingType(outboundMappingType).contextDescription("for association " + PrettyPrinter.prettyPrint(assocName) + " in " + getSource()).originType(OriginType.ASSIGNMENTS).originObject(getSource());
RefinedAssociationDefinition rAssocDef = refinedObjectClassDefinition.findAssociationDefinition(assocName);
if (rAssocDef == null) {
throw new SchemaException("No association " + assocName + " in object class " + refinedObjectClassDefinition.getHumanReadableName() + " in construction in " + getSource());
}
Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = evaluateMapping(mappingBuilder, assocName, outputDefinition, rAssocDef.getAssociationTarget(), task, result);
LOGGER.trace("Evaluated mapping for association " + assocName + ": " + evaluatedMapping);
return evaluatedMapping;
}
use of com.evolveum.midpoint.prism.PrismContainerValue 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;
}
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class PolicyRuleBasedAspect method assignmentToDelta.
// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(Class<? extends Objectable> focusClass, AssignmentType assignmentType, boolean assignmentRemoved, String objectOid) throws SchemaException {
PrismContainerValue value = assignmentType.clone().asPrismContainerValue();
S_ValuesEntry item = DeltaBuilder.deltaFor(focusClass, prismContext).item(FocusType.F_ASSIGNMENT);
S_ItemEntry op = assignmentRemoved ? item.delete(value) : item.add(value);
return (ObjectDelta<? extends FocusType>) op.asObjectDelta(objectOid);
}
Aggregations