public <O extends ObjectType> O resolveObject(ObjectReferenceType ref) { Validate.notNull(ref.getOid(), "Object oid must not be null"); Validate.notNull(ref.getType(), "Object type must not be null"); Class type = prismContext.getSchemaRegistry().determineCompileTimeClass(ref.getType()); return resolveObject(type, ref.getOid()); }
// Called from the ObjectResolver.resolve public ObjectType resolveRef( ObjectReferenceType ref, String contextDescription, OperationResult result) throws ObjectNotFoundException, SchemaException { Class<? extends ObjectType> type = ObjectType.class; if (ref.getType() != null) { ObjectTypes objectTypeType = ObjectTypes.getObjectTypeFromTypeQName(ref.getType()); type = objectTypeType.getClassDefinition(); } return repositoryService.getObject(type, ref.getOid(), null, result).asObjectable(); }
public <O extends ObjectType> List<PrismObject<O>> resolveLinkRefs( Collection<ObjectReferenceType> refs, Class type) { List<PrismObject<O>> objects = new ArrayList<>(); for (ObjectReferenceType ref : refs) { Class clazz = getClassForType(ref.getType()); if (!clazz.equals(type)) { continue; } Task task = taskManager.createTaskInstance(); OperationResult parentResult = task.getResult(); try { PrismObject<O> obj = model.getObject( type, ref.getOid(), SelectorOptions.createCollection(GetOperationOptions.createResolveNames()), task, parentResult); objects.add(obj); } catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException | ConfigurationException e) { // TODO Auto-generated catch block LOGGER.error( "Could not get object with oid " + ref.getOid() + ". Reason: " + e.getMessage()); } } return objects; }
private ExpressionVariables processInnerVariables( ExpressionVariables variables, String contextDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException { if (expressionType == null || expressionType.getVariable() == null || expressionType.getVariable().isEmpty()) { // shortcut return variables; } ExpressionVariables newVariables = new ExpressionVariables(); for (Entry<QName, Object> entry : variables.entrySet()) { newVariables.addVariableDefinition(entry.getKey(), entry.getValue()); } for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) { QName varName = variableDefType.getName(); if (varName == null) { throw new SchemaException("No variable name in expression in " + contextDescription); } if (variableDefType.getObjectRef() != null) { ObjectReferenceType ref = variableDefType.getObjectRef(); ref.setType(prismContext.getSchemaRegistry().qualifyTypeName(ref.getType())); ObjectType varObject = objectResolver.resolve( ref, ObjectType.class, null, "variable " + varName + " in " + contextDescription, task, result); newVariables.addVariableDefinition(varName, varObject); } else if (variableDefType.getValue() != null) { // Only string is supported now Object valueObject = variableDefType.getValue(); if (valueObject instanceof String) { newVariables.addVariableDefinition(varName, valueObject); } else if (valueObject instanceof Element) { newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent()); } else if (valueObject instanceof RawType) { newVariables.addVariableDefinition( varName, ((RawType) valueObject).getParsedValue(null, varName)); } else { throw new SchemaException( "Unexpected type " + valueObject.getClass() + " in variable definition " + varName + " in " + contextDescription); } } else if (variableDefType.getPath() != null) { ItemPath itemPath = variableDefType.getPath().getItemPath(); Object resolvedValue = ExpressionUtil.resolvePath( itemPath, variables, null, objectResolver, contextDescription, task, result); newVariables.addVariableDefinition(varName, resolvedValue); } else { throw new SchemaException("No value for variable " + varName + " in " + contextDescription); } } return newVariables; }