public static PrismReference getReference(PrismContainerValue parent, QName fieldName) { try { PrismReference reference = parent.findReference(fieldName); if (reference != null) { return reference; } else { return (PrismReference) parent.createDetachedSubItem(fieldName, PrismReferenceImpl.class, null, parent.isImmutable()); } } catch (SchemaException e) { // This should not happen. Code generator and compiler should take care of that. throw new IllegalStateException("Internal schema error: "+e.getMessage(),e); } }
PrismReference reference = containerValue.findReferenceByCompositeObjectElementName(firstName); if (reference == null) { reference = containerValue.findReference(firstName); // alternatively look up by reference name (e.g. linkRef)
public <T> PrismContainerValueAsserter<C,RA> assertRefEquals(QName refName, String expectedOid) { PrismReference ref = getPrismValue().findReference(refName); if (ref == null && expectedOid == null) { return this; } assertNotNull("No reference "+refName.getLocalPart()+" in "+desc(), ref); List<PrismReferenceValue> refVals = ref.getValues(); if (refVals == null || refVals.isEmpty()) { fail("No values in reference "+refName.getLocalPart()+" in "+desc()); } if (refVals.size() > 1) { fail("Too many values in reference "+refName.getLocalPart()+" in "+desc()); } PrismReferenceValue refVal = refVals.get(0); assertNotNull("null value in "+refName.getLocalPart()+" in "+desc(), refVal); assertEquals("Wrong "+refName.getLocalPart()+" in "+desc(), expectedOid, refVal.getOid()); return this; }
private void resolveEntitlement(PrismContainerValue<ShadowAssociationType> value, LensProjectionContext projContext, ExpressionVariables variables) { LOGGER.trace("Producing value {} ", value); PrismObject<ShadowType> entitlement = projContext.getEntitlementMap().get(value.findReference(ShadowAssociationType.F_SHADOW_REF).getOid()); LOGGER.trace("Resolved entitlement {}", entitlement); if (variables.containsKey(ExpressionConstants.VAR_ENTITLEMENT)) { variables.replaceVariableDefinition(ExpressionConstants.VAR_ENTITLEMENT, entitlement); } else { variables.addVariableDefinition(ExpressionConstants.VAR_ENTITLEMENT, entitlement); } }
@Override public int compare(PrismContainerValue<ShadowAssociationType> o1, PrismContainerValue<ShadowAssociationType> o2) { if (o1 == null && o2 == null){ LOGGER.trace("Comparing {} and {}: 0 (A)", o1, o2); return 0; } if (o1 == null || o2 == null){ LOGGER.trace("Comparing {} and {}: 2 (B)", o1, o2); return 1; } PrismReference ref1 = o1.findReference(ShadowAssociationType.F_SHADOW_REF); PrismReference ref2 = o2.findReference(ShadowAssociationType.F_SHADOW_REF); // We do not want to compare references in details. Comparing OIDs suffices. // Otherwise we get into problems, as one of the references might be e.g. without type, // causing unpredictable behavior (MID-2368) String oid1 = ref1 != null ? ref1.getOid() : null; String oid2 = ref2 != null ? ref2.getOid() : null; if (ObjectUtils.equals(oid1, oid2)) { LOGGER.trace("Comparing {} and {}: 0 (C)", o1, o2); return 0; } LOGGER.trace("Comparing {} and {}: 1 (D)", o1, o2); return 1; } };
PrismReference shadowRef = value.findReference(ShadowAssociationType.F_SHADOW_REF); if (shadowRef == null) { continue;
assertNotNull("Null value in protectedStringDelta", assignmentVal); PrismReference targetRef = assignmentVal.findReference(AssignmentType.F_TARGET_REF); assertNotNull("No targetRef in assignment", targetRef); PrismReferenceValue targetRefVal = targetRef.getValue();
PrismReference targetRef = value4.findReference(AssignmentType.F_TARGET_REF); assertNotNull(targetRef); assertEquals(1, targetRef.getValues().size());
@Test public void test020ModifyAssignment() throws Exception { //given ObjectDelta<RoleType> delta = deltaFor(RoleType.class) .item(RoleType.F_ASSIGNMENT, 4L, AssignmentType.F_TARGET_REF) .replace(new ObjectReferenceType().oid(NEW_ASSIGNMENT_4_TARGET_OID).type(RoleType.COMPLEX_TYPE)) .asObjectDeltaCast(ROLE_OID); OperationResult result = new OperationResult("modify assignment"); // WHEN repositoryService.modifyObject(RoleType.class, delta.getOid(), delta.getModifications(), result); // THEN assertSuccess(result); PrismObject<RoleType> repoRole = getObject(RoleType.class, ROLE_OID); PrismContainer<AssignmentType> inducement = repoRole.findContainer(RoleType.F_INDUCEMENT); assertNotNull(inducement); assertEquals(3, inducement.getValues().size()); PrismContainer<AssignmentType> assignment = repoRole.findContainer(AbstractRoleType.F_ASSIGNMENT); assertNotNull(assignment); assertEquals(2, assignment.getValues().size()); PrismContainerValue<AssignmentType> value4 = assignment.getValue(4L); PrismReference targetRef = value4.findReference(AssignmentType.F_TARGET_REF); assertNotNull(targetRef); assertEquals(1, targetRef.getValues().size()); PrismReferenceValue refValue = targetRef.getValue(); assertEquals(NEW_ASSIGNMENT_4_TARGET_OID, refValue.getOid()); assertEquals(RoleType.COMPLEX_TYPE, refValue.getTargetType()); }
@Test public void test021ModifyInducement() throws Exception { //given ObjectDelta<RoleType> delta = deltaFor(RoleType.class) .item(RoleType.F_INDUCEMENT, 5L, AssignmentType.F_TARGET_REF) .replace(new ObjectReferenceType().oid(NEW_INDUCEMENT_5_TARGET_OID).type(RoleType.COMPLEX_TYPE)) .asObjectDeltaCast(ROLE_OID); OperationResult result = new OperationResult("modify inducement"); // WHEN repositoryService.modifyObject(RoleType.class, delta.getOid(), delta.getModifications(), result); // THEN assertSuccess(result); PrismObject<RoleType> repoRole = getObject(RoleType.class, ROLE_OID); PrismContainer<AssignmentType> inducement = repoRole.findContainer(RoleType.F_INDUCEMENT); assertNotNull(inducement); assertEquals(3, inducement.getValues().size()); PrismContainer<AssignmentType> assignment = repoRole.findContainer(AbstractRoleType.F_ASSIGNMENT); assertNotNull(assignment); assertEquals(2, assignment.getValues().size()); PrismContainerValue<AssignmentType> value5 = inducement.getValue(5L); PrismReference targetRef = value5.findReference(AssignmentType.F_TARGET_REF); assertNotNull(targetRef); assertEquals(1, targetRef.getValues().size()); PrismReferenceValue refValue = targetRef.getValue(); assertEquals(NEW_INDUCEMENT_5_TARGET_OID, refValue.getOid()); assertEquals(RoleType.COMPLEX_TYPE, refValue.getTargetType()); PrismProperty accConstruction = value5.findProperty(AssignmentType.F_CONSTRUCTION); AssertJUnit.assertNull(accConstruction); }