/** * This method must merge new value with potential existing value of the reference. * E.g. it is possible to call setResource(..) and then setResourceRef(..) with the * same OID. In that case the result should be one reference that has both OID/type/filter * and object. * Assumes single-value reference */ public static void setReferenceValueAsObject(PrismContainerValue parentValue, QName referenceQName, PrismObject targetObject) { Validate.notNull(parentValue, "Prism container value must not be null."); Validate.notNull(referenceQName, "QName must not be null."); PrismReference reference; try { reference = parentValue.findOrCreateReference(referenceQName); } 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); } if (reference == null) { throw new IllegalArgumentException("No reference "+referenceQName+" in "+parentValue); } PrismReferenceValue referenceValue = reference.getValue(); referenceValue.setObject(targetObject); }
protected ObjectDelta<UserType> createParametricAssignmentDelta(String userOid, String roleOid, String orgOid, String tenantOid, boolean adding) throws SchemaException { Collection<ItemDelta<?,?>> modifications = new ArrayList<>(); ContainerDelta<AssignmentType> assignmentDelta = prismContext.deltaFactory().container().createDelta(UserType.F_ASSIGNMENT, getUserDefinition()); PrismContainerValue<AssignmentType> cval = prismContext.itemFactory().createContainerValue(); if (adding) { assignmentDelta.addValueToAdd(cval); } else { assignmentDelta.addValueToDelete(cval); } PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF); targetRef.getValue().setOid(roleOid); targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE); if (orgOid != null) { PrismReference orgRef = cval.findOrCreateReference(AssignmentType.F_ORG_REF); orgRef.getValue().setOid(orgOid); } if (tenantOid != null) { PrismReference tenantRef = cval.findOrCreateReference(AssignmentType.F_TENANT_REF); tenantRef.getValue().setOid(tenantOid); } modifications.add(assignmentDelta); return prismContext.deltaFactory().object().createModifyDelta(userOid, modifications, UserType.class ); }
protected <F extends AssignmentHolderType> ContainerDelta<AssignmentType> createAssignmentModification(Class<F> type, QName elementName, String roleOid, QName refType, QName relation, Consumer<AssignmentType> modificationBlock, boolean add) throws SchemaException { ContainerDelta<AssignmentType> assignmentDelta = prismContext.deltaFactory().container().createDelta(ItemName.fromQName(elementName), getObjectDefinition(type)); PrismContainerValue<AssignmentType> cval = prismContext.itemFactory().createContainerValue(); if (add) { assignmentDelta.addValueToAdd(cval); } else { assignmentDelta.addValueToDelete(cval); } PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF); targetRef.getValue().setOid(roleOid); targetRef.getValue().setTargetType(refType); targetRef.getValue().setRelation(relation); if (modificationBlock != null) { modificationBlock.accept(cval.asContainerable()); } return assignmentDelta; }
PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF); targetRef.getValue().setOid(ROLE_FIGHT_OID); targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);
PrismContainerValue<AssignmentType> cval = prismContext.itemFactory().createContainerValue(); assignmentDelta1.addValueToAdd(cval); PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF); targetRef.getValue().setOid(ROLE_BUSINESS_2_OID); targetRef.getValue().setTargetType(RoleType.COMPLEX_TYPE);