use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class Expression method processInnerVariables.
private VariablesMap processInnerVariables(VariablesMap variables, String contextDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (expressionType == null) {
// shortcut
return variables;
}
VariablesMap newVariables = new VariablesMap();
// We need to add actor variable before we switch user identity (runAs)
ExpressionUtil.addActorVariable(newVariables, securityContextManager, prismContext);
boolean actorDefined = newVariables.get(ExpressionConstants.VAR_ACTOR) != null;
for (Entry<String, TypedValue> entry : variables.entrySet()) {
String key = entry.getKey();
if (ExpressionConstants.VAR_ACTOR.equals(key) && actorDefined) {
// avoid pointless warning about redefined value of actor
continue;
}
newVariables.put(key, entry.getValue());
if (variables.isAlias(key)) {
newVariables.registerAlias(key, variables.getAliasResolution(key));
}
}
for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) {
String varName = variableDefType.getName().getLocalPart();
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, varObject.asPrismObject().getDefinition());
} else if (variableDefType.getValue() != null) {
// Only string is supported now
Object valueObject = variableDefType.getValue();
if (valueObject instanceof String) {
MutablePrismPropertyDefinition<Object> def = prismContext.definitionFactory().createPropertyDefinition(new ItemName(SchemaConstants.NS_C, varName), PrimitiveType.STRING.getQname());
newVariables.addVariableDefinition(varName, valueObject, def);
} else if (valueObject instanceof Element) {
MutablePrismPropertyDefinition<Object> def = prismContext.definitionFactory().createPropertyDefinition(new ItemName(SchemaConstants.NS_C, varName), PrimitiveType.STRING.getQname());
newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent(), def);
} else if (valueObject instanceof RawType) {
ItemName varQName = new ItemName(SchemaConstants.NS_C, varName);
MutablePrismPropertyDefinition<Object> def = prismContext.definitionFactory().createPropertyDefinition(varQName, PrimitiveType.STRING.getQname());
newVariables.addVariableDefinition(varName, ((RawType) valueObject).getParsedValue(null, varQName), def);
} else {
throw new SchemaException("Unexpected type " + valueObject.getClass() + " in variable definition " + varName + " in " + contextDescription);
}
} else if (variableDefType.getPath() != null) {
ItemPath itemPath = variableDefType.getPath().getItemPath();
TypedValue resolvedValueAndDefinition = ExpressionUtil.resolvePathGetTypedValue(itemPath, variables, false, null, objectResolver, prismContext, contextDescription, task, result);
newVariables.put(varName, resolvedValueAndDefinition);
} else {
throw new SchemaException("No value for variable " + varName + " in " + contextDescription);
}
}
return newVariables;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class PropertyRestriction method adaptValueType.
private Object adaptValueType(Object value, ValueFilter filter) throws QueryException {
Class<?> expectedType = linkDefinition.getTargetDefinition().getJaxbClass();
if (expectedType == null || value == null) {
// nothing to check here
return value;
}
Class<?> expectedWrappedType;
if (expectedType.isPrimitive()) {
expectedWrappedType = ClassUtils.primitiveToWrapper(expectedType);
} else {
expectedWrappedType = expectedType;
}
Object adaptedValue;
// attempt to fix value type for polystring (if it was string in filter we create polystring from it)
if (PolyString.class.equals(expectedWrappedType) && value instanceof String) {
LOGGER.debug("Trying to query PolyString value but filter contains String '{}'.", filter);
String orig = (String) value;
adaptedValue = new PolyString(orig, context.getPrismContext().getDefaultPolyStringNormalizer().normalize(orig));
} else if (PolyString.class.equals(expectedWrappedType) && value instanceof PolyStringType) {
// attempt to fix value type for polystring (if it was polystring type in filter we create polystring from it)
LOGGER.debug("Trying to query PolyString value but filter contains PolyStringType '{}'.", filter);
PolyStringType type = (PolyStringType) value;
adaptedValue = new PolyString(type.getOrig(), type.getNorm());
} else if (String.class.equals(expectedWrappedType) && value instanceof QName) {
// eg. shadow/objectClass
adaptedValue = RUtil.qnameToString((QName) value);
} else if (value instanceof RawType) {
// MID-3850: but it's quite a workaround. Maybe we should treat RawType's earlier than this.
try {
adaptedValue = ((RawType) value).getParsedRealValue(expectedWrappedType);
} catch (SchemaException e) {
throw new QueryException("Couldn't parse value " + value + " as " + expectedWrappedType + ": " + e.getMessage(), e);
}
} else {
adaptedValue = value;
}
if (expectedWrappedType.isAssignableFrom(adaptedValue.getClass())) {
return adaptedValue;
} else {
throw new QueryException("Value should be type of '" + expectedWrappedType + "' but it's '" + value.getClass() + "', filter '" + filter + "'.");
}
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class TestConsistencyMechanism method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
// GIVEN
openDJController.assumeRunning();
Task task = getTestTask();
OperationResult result = task.getResult();
dummyAuditService.clear();
// prepare new OU in opendj
openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILE);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(prismContext.xnodeFactory().primitive("uid=morgan,ou=users,dc=example,dc=com").frozen(), prismContext);
JAXBElement<?> val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(ItemPath.create(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo, prismContext));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
// noinspection unchecked
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
when();
modelService.executeChanges(deltas, null, task, result);
// THEN
then();
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
provisioningService.applyDefinition(accountShadow, task, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute<?> attributes = ShadowUtil.getAttribute(accountModel, new QName(MidPointConstants.NS_RI, "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class RAnyConverter method extractValue.
@NotNull
private <T> T extractValue(PrismPropertyValue value, Class<T> returnType) throws SchemaException {
ItemDefinition definition = value.getParent().getDefinition();
// todo raw types
Object object = value.getValue();
if (object instanceof Element) {
object = getRealRepoValue(definition, (Element) object, prismContext);
} else if (object instanceof RawType) {
RawType raw = (RawType) object;
// todo this can return null!
object = raw.getParsedRealValue(returnType);
} else {
object = getAggregatedRepoObject(object);
}
if (returnType.isAssignableFrom(object.getClass())) {
// noinspection unchecked
return (T) object;
}
throw new IllegalStateException("Can't extract value for saving from prism property value " + value + " expected return type " + returnType + ", actual type " + (object == null ? null : object.getClass()));
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class TestAbstractRestService method extractItemProcessingResults.
private <X extends OperationSpecificData> List<ItemProcessingResult<X>> extractItemProcessingResults(ExecuteScriptResponseType response, Function<Object, X> operationDataExtractor) throws SchemaException {
List<PipelineItemType> outputItems = response.getOutput().getDataOutput().getItem();
List<ItemProcessingResult<X>> extractedResults = new ArrayList<>(outputItems.size());
for (PipelineItemType outputItem : outputItems) {
ItemProcessingResult<X> extractedResult = new ItemProcessingResult<>();
Object value = outputItem.getValue();
if (value instanceof RawType) {
value = ((RawType) value).getParsedRealValue(Object.class);
}
if (value instanceof ObjectType) {
ObjectType object = (ObjectType) value;
extractedResult.oid = object.getOid();
extractedResult.name = PolyString.getOrig(object.getName());
if (operationDataExtractor != null) {
extractedResult.data = operationDataExtractor.apply(value);
}
} else if (value instanceof Referencable) {
extractedResult.oid = ((Referencable) value).getOid();
} else {
throw new IllegalStateException("Unexpected item value: " + value);
}
if (outputItem.getResult() != null) {
extractedResult.status = outputItem.getResult().getStatus();
extractedResult.message = outputItem.getResult().getMessage();
}
extractedResults.add(extractedResult);
}
return extractedResults;
}
Aggregations