public static ObjectReferenceType createObjectReference(String oid, QName type) { ObjectReferenceType ref = new ObjectReferenceType(); ref.setOid(oid); ref.setType(type); return ref; }
public static List<PrismReferenceValue> createReferences(Collection<String> oids, RelationKindType kind, RelationRegistry relationRegistry) { List<PrismReferenceValue> rv = new ArrayList<>(); for (QName relation : relationRegistry.getAllRelationsFor(kind)) { for (String oid : oids) { rv.add(new ObjectReferenceType().oid(oid).relation(relation).asReferenceValue()); } } return rv; }
public ObjectReferenceType toObjectReferenceType() { ObjectReferenceType retval = new ObjectReferenceType(); retval.setOid(oid); retval.setDescription(description); retval.setType(type); retval.setTargetName(fromOrig(targetName)); return retval; }
public LightweightObjectRefImpl(ObjectReferenceType objectReferenceType) { this.oid = objectReferenceType.getOid(); this.type = objectReferenceType.getType(); this.description = objectReferenceType.getDescription(); this.targetName = getOrig(objectReferenceType.getTargetName()); }
lhsDescription = this.getDescription(); String rhsDescription; rhsDescription = that.getDescription(); if (!strategy.equals(LocatorUtils.property(thisLocator, "description", lhsDescription), LocatorUtils.property(thatLocator, "description", rhsDescription), lhsDescription, rhsDescription)) { return false; lhsFilter = this.getFilter(); SearchFilterType rhsFilter; rhsFilter = that.getFilter(); if (!strategy.equals(LocatorUtils.property(thisLocator, "filter", lhsFilter), LocatorUtils.property(thatLocator, "filter", rhsFilter), lhsFilter, rhsFilter)) { return false; lhsResolutionTime = this.getResolutionTime(); EvaluationTimeType rhsResolutionTime; rhsResolutionTime = that.getResolutionTime(); if (!strategy.equals(LocatorUtils.property(thisLocator, "resolutionTime", lhsResolutionTime), LocatorUtils.property(thatLocator, "resolutionTime", rhsResolutionTime), lhsResolutionTime, rhsResolutionTime)) { return false; lhsTargetName = this.getTargetName(); com.evolveum.prism.xml.ns._public.types_3.PolyStringType rhsTargetName; rhsTargetName = that.getTargetName(); if (!strategy.equals(LocatorUtils.property(thisLocator, "targetName", lhsTargetName), LocatorUtils.property(thatLocator, "targetName", rhsTargetName), lhsTargetName, rhsTargetName)) { return false; lhsOid = this.getOid(); String rhsOid; rhsOid = that.getOid(); if (!strategy.equals(LocatorUtils.property(thisLocator, "oid", lhsOid), LocatorUtils.property(thatLocator, "oid", rhsOid), lhsOid, rhsOid)) { return false;
@NotNull public static ObjectReferenceType stringToRef(@NotNull String s) { String[] parts = s.split(CommonProcessVariableNames.TYPE_NAME_SEPARATOR); if (parts.length == 0 || parts.length > 2) { throw new IllegalArgumentException("Incorrect reference string representation: " + s); } else if (parts.length == 1) { return new ObjectReferenceType().oid(parts[0]).type(UserType.COMPLEX_TYPE); } else { // TODO support namespaces other than c: QName type = StringUtils.isEmpty(parts[0]) ? UserType.COMPLEX_TYPE : new QName(SchemaConstants.NS_C, parts[0]); return new ObjectReferenceType().oid(parts[1]).type(type); } }
public static void fromJaxb(ObjectReferenceType jaxb, REmbeddedReference repo, RelationRegistry relationRegistry) { Validate.notNull(repo, "Repo object must not be null."); Validate.notNull(jaxb, "JAXB object must not be null."); if (jaxb.getFilter() == null) { Validate.notEmpty(jaxb.getOid(), "Target oid must not be null."); } repo.setType(ClassMapper.getHQLTypeForQName(jaxb.getType())); repo.setRelation(qnameToString(relationRegistry.normalizeRelation(jaxb.getRelation()))); repo.setTargetOid(jaxb.getOid()); }
private ObjectReferenceType createRef(QName type, String oid, QName relation) { ObjectReferenceType ref = new ObjectReferenceType(); ref.setType(type); ref.setOid(oid); ref.setRelation(relation); return ref; }
private List<OrgType> generateOrgStructure(int level, int[] levels, String name, ObjectReferenceType parentRef) throws Exception { List<OrgType> orgs = new ArrayList<>(); if (level >= levels.length) { return orgs; } for (int i = 0; i < levels[level]; i++) { OrgType org = createOrgType(name + " " + i, parentRef != null ? parentRef.clone() : null); orgs.add(org); ObjectReferenceType ref = new ObjectReferenceType(); ref.setOid(org.getOid()); ref.setType(OrgType.COMPLEX_TYPE); orgs.addAll(generateOrgStructure(level + 1, levels, org.getName().getOrig(), ref)); } return orgs; }
ObjectReferenceType approver1 = new ObjectReferenceType().oid("approver1-oid"); ObjectReferenceType approver1AsUser = new ObjectReferenceType().oid("approver1-oid").type(UserType.COMPLEX_TYPE); ObjectReferenceType approver2AsUser = new ObjectReferenceType().oid("approver2-oid").type(UserType.COMPLEX_TYPE); .item(UserType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF).replace(approver1.clone()) .asItemDeltas(); repositoryService.modifyObject(UserType.class, user.getOid(), itemDeltas, getModifyOptions(), result); .item(UserType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF).replace(approver1AsUser.clone(), approver2AsUser.clone()) .asItemDeltas(); repositoryService.modifyObject(UserType.class, user.getOid(), itemDeltas, getModifyOptions(), result); .item(UserType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF).ref(approver1.getOid()) .build(); SearchResultList<PrismObject<UserType>> users = repositoryService
public ReferenceResolver createReferenceResolver(ModelContext modelContext, Task taskFromModel, OperationResult result) { return (ref, sourceDescription) -> { if (ref == null) { return Collections.emptyList(); } else if (ref.getOid() != null) { return Collections.singletonList(ref.clone()); } else { Class<? extends ObjectType> clazz; if (ref.getType() != null) { clazz = prismContext.getSchemaRegistry().determineCompileTimeClass(ref.getType()); if (clazz == null) { throw new SchemaException("Cannot determine type from " + ref.getType() + " in approver reference in " + sourceDescription); } } else { throw new SchemaException("Missing type in target reference in " + sourceDescription); } return resolveReferenceFromFilter(clazz, ref.getFilter(), sourceDescription, (LensContext) modelContext, taskFromModel, result); } }; }
private boolean referenceMatches(ObjectReferenceType ref, String targetOid, QName relation) { if (targetOid != null && !targetOid.equals(ref.getOid())) { return false; } if (relation != null && !QNameUtil.match(relation, ref.getRelation())) { return false; } return true; }
AssignmentType assignmentType = getAssignmentType(segment, ctx); ObjectReferenceType targetRef = assignmentType.getTargetRef(); String oid = targetRef.getOid(); if (targetRef.getType() != null) { targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetRef.getType()); if (targetClass == null) { throw new SchemaException("Cannot determine type from " + targetRef.getType() + " in target reference in " + assignmentType + " in " + segment.sourceDescription); if (targetRef.getFilter() == null){ throw new SchemaException("The OID and filter are both null in assignment targetRef in "+segment.source); return resolveTargetsFromFilter(targetClass, targetRef.getFilter(), segment, ctx); } else { LOGGER.trace("Resolving target {}:{} from repository", targetClass.getSimpleName(), oid);
private static List<PrismReferenceValue> getGroupsForUser(String userOid, RepositoryService repositoryService, RelationRegistry relationRegistry, OperationResult result) throws SchemaException { List<PrismReferenceValue> rv = new ArrayList<>(); UserType userType; try { userType = repositoryService.getObject(UserType.class, userOid, null, result).asObjectable(); } catch (ObjectNotFoundException e) { return rv; } userType.getRoleMembershipRef().stream() .filter(ref -> relationRegistry.isMember(ref.getRelation())) .forEach(ref -> rv.add(ref.clone().asReferenceValue())); userType.getDelegatedRef().stream() .filter(ref -> relationRegistry.isMember(ref.getRelation())) .filter(ref -> !QNameUtil.match(ref.getType(), UserType.COMPLEX_TYPE)) // we are not interested in deputies (but this should be treated above) .forEach(ref -> rv.add(ref.clone().asReferenceValue())); return rv; }
protected void assertObjectRefs(String contextDesc, boolean checkNames, Collection<ObjectReferenceType> real, String... expected) { List<String> refOids = new ArrayList<>(); for (ObjectReferenceType ref: real) { refOids.add(ref.getOid()); assertNotNull("Missing type in "+ref.getOid()+" in "+contextDesc, ref.getType()); if (checkNames) { assertNotNull("Missing name in " + ref.getOid() + " in " + contextDesc, ref.getTargetName()); } } PrismAsserts.assertSets("Wrong values in "+contextDesc, refOids, expected); }
public ObjectReferenceType clone() { ObjectReferenceType object = new ObjectReferenceType(); PrismReferenceValue value = asReferenceValue().clone(); object.setupReferenceValue(value); return object; }
public static ObjectReference copyFromJAXB(ObjectReferenceType jaxb, ObjectReference repo, RelationRegistry relationRegistry) { Validate.notNull(repo, "Repo object must not be null."); Validate.notNull(jaxb, "JAXB object must not be null."); Validate.notEmpty(jaxb.getOid(), "Target oid must not be null."); repo.setType(ClassMapper.getHQLTypeForQName(jaxb.getType())); repo.setRelation(qnameToString(relationRegistry.normalizeRelation(jaxb.getRelation()))); repo.setTargetOid(jaxb.getOid()); return repo; }
public static Function<Object, Object> createRefConvertor(QName defaultType) { return (o) -> { if (o == null || o instanceof ObjectReferenceType) { return o; } else if (o instanceof Referencable) { ObjectReferenceType rv = new ObjectReferenceType(); rv.setupReferenceValue(((Referencable) o).asReferenceValue()); return rv; } else if (o instanceof PrismReferenceValue) { ObjectReferenceType rv = new ObjectReferenceType(); rv.setupReferenceValue((PrismReferenceValue) o); return rv; } else if (o instanceof String) { return new ObjectReferenceType().oid((String) o).type(defaultType); } else { //throw new IllegalArgumentException("The value couldn't be converted to an object reference: " + o); return o; // let someone else complain at this } }; }
static boolean oidMatches(ObjectReferenceType targetRef, EvaluatedAssignmentTargetImpl assignmentTarget, PrismContext prismContext, MatchingRuleRegistry matchingRuleRegistry, String context) throws SchemaException { if (targetRef == null) { return true; // this means we rely on comparing relations } if (assignmentTarget.getOid() == null) { return false; // shouldn't occur } if (targetRef.getOid() != null) { return assignmentTarget.getOid().equals(targetRef.getOid()); } if (targetRef.getResolutionTime() == EvaluationTimeType.RUN) { SearchFilterType filterType = targetRef.getFilter(); if (filterType == null) { throw new SchemaException("No filter in " + context); } QName typeQName = targetRef.getType(); @SuppressWarnings("rawtypes") PrismObjectDefinition objDef = prismContext.getSchemaRegistry().findObjectDefinitionByType(typeQName); ObjectFilter filter = prismContext.getQueryConverter().parseFilter(filterType, objDef); PrismObject<? extends AssignmentHolderType> target = assignmentTarget.getTarget(); return filter.match(target.getValue(), matchingRuleRegistry); } else { throw new SchemaException("No OID in " + context); } }