use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class TestRefinedSchema method assertAccountShadow.
private void assertAccountShadow(PrismObject<ShadowType> accObject, PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException, JAXBException {
ResourceType resourceType = resource.asObjectable();
QName objectClassQName = new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass");
PrismAsserts.assertPropertyValue(accObject, ShadowType.F_NAME, createPolyString("jack"));
PrismAsserts.assertPropertyValue(accObject, ShadowType.F_OBJECT_CLASS, objectClassQName);
PrismAsserts.assertPropertyValue(accObject, ShadowType.F_INTENT, SchemaConstants.INTENT_DEFAULT);
PrismContainer<?> attributes = accObject.findOrCreateContainer(SchemaConstants.C_ATTRIBUTES);
assertEquals("Wrong type of <attributes> definition in account", ResourceAttributeContainerDefinitionImpl.class, attributes.getDefinition().getClass());
ResourceAttributeContainerDefinition attrDef = (ResourceAttributeContainerDefinition) attributes.getDefinition();
assertAttributeDefs(attrDef, resourceType, null, LayerType.MODEL);
PrismAsserts.assertPropertyValue(attributes, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "cn"), "Jack Sparrow");
PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "givenName"), "Jack");
PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "sn"), "Sparrow");
PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "uid"), "jack");
assertEquals("JAXB class name doesn't match (1)", ShadowType.class, accObject.getCompileTimeClass());
accObject.checkConsistence();
ShadowType accObjectType = accObject.asObjectable();
assertEquals("Wrong JAXB name", createPolyStringType("jack"), accObjectType.getName());
assertEquals("Wrong JAXB objectClass", objectClassQName, accObjectType.getObjectClass());
ShadowAttributesType attributesType = accObjectType.getAttributes();
assertNotNull("null ResourceObjectShadowAttributesType (JAXB)", attributesType);
List<Object> attributeElements = attributesType.getAny();
TestUtil.assertElement(attributeElements, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
TestUtil.assertElement(attributeElements, getAttrQName(resource, "cn"), "Jack Sparrow");
TestUtil.assertElement(attributeElements, getAttrQName(resource, "givenName"), "Jack");
TestUtil.assertElement(attributeElements, getAttrQName(resource, "sn"), "Sparrow");
TestUtil.assertElement(attributeElements, getAttrQName(resource, "uid"), "jack");
String accString = PrismTestUtil.serializeObjectToString(accObjectType.asPrismObject());
System.out.println("Result of JAXB marshalling:\n" + accString);
accObject.checkConsistence(true, true, ConsistencyCheckScope.THOROUGH);
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class GenerateExpressionEvaluator method evaluate.
/*
* (non-Javadoc)
*
* @see
* com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java
* .util.Collection, java.util.Map, boolean, java.lang.String,
* com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
StringPolicyType stringPolicyType = null;
ObjectReferenceType generateEvaluatorValuePolicyRef = generateEvaluatorType.getValuePolicyRef();
if (generateEvaluatorValuePolicyRef != null) {
if (generateEvaluatorType.getValuePolicyRef() != null) {
ValuePolicyType valuePolicyType = objectResolver.resolve(generateEvaluatorValuePolicyRef, ValuePolicyType.class, null, "resolving value policy reference in generateExpressionEvaluator", context.getTask(), context.getResult());
stringPolicyType = valuePolicyType.getStringPolicy();
}
}
// would be generated
if (stringPolicyType == null) {
StringPolicyResolver stringPolicyResolver = context.getStringPolicyResolver();
if (stringPolicyResolver != null) {
stringPolicyType = stringPolicyResolver.resolve();
}
}
elementStringPolicy = stringPolicyType;
// } else {
// stringPolicyType = elementStringPolicy;
// }
//
String stringValue = null;
GenerateExpressionEvaluatorModeType mode = generateEvaluatorType.getMode();
Item<V, D> output = outputDefinition.instantiate();
if (mode == null || mode == GenerateExpressionEvaluatorModeType.POLICY) {
PrismObject<? extends ObjectType> object = getObject(context);
// TODO: generate value based on stringPolicyType (if not null)
if (stringPolicyType != null) {
if (isNotEmptyMinLength(stringPolicyType)) {
stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, true, object, context.getContextDescription(), context.getTask(), context.getResult());
} else {
stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, false, object, context.getContextDescription(), context.getTask(), context.getResult());
}
context.getResult().computeStatus();
if (context.getResult().isError()) {
throw new ExpressionEvaluationException("Failed to generate value according to policy: " + stringPolicyType.getDescription() + ". " + context.getResult().getMessage());
}
}
if (stringValue == null) {
int length = DEFAULT_LENGTH;
RandomString randomString = new RandomString(length);
stringValue = randomString.nextString();
}
} else if (mode == GenerateExpressionEvaluatorModeType.UUID) {
UUID randomUUID = UUID.randomUUID();
stringValue = randomUUID.toString();
} else {
throw new ExpressionEvaluationException("Unknown mode for generate expression: " + mode);
}
Object value = ExpressionUtil.convertToOutputValue(stringValue, outputDefinition, protector);
if (output instanceof PrismProperty) {
PrismPropertyValue<Object> pValue = new PrismPropertyValue<Object>(value);
((PrismProperty<Object>) output).add(pValue);
} else {
throw new UnsupportedOperationException("Can only generate values of property, not " + output.getClass());
}
return ItemDelta.toDeltaSetTriple(output, null);
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class LazyXPathVariableResolver method convertToXml.
// May return primitive types or DOM Node
public static Object convertToXml(Object variableValue, QName variableName, final PrismContext prismContext, String contextDescription) throws SchemaException {
try {
if (variableValue instanceof Objectable) {
variableValue = ((Objectable) variableValue).asPrismObject();
}
if (variableValue instanceof PrismObject) {
PrismObject<?> prismObject = (PrismObject<?>) variableValue;
variableValue = prismObject.getPrismContext().domSerializer().serialize(prismObject);
} else if (variableValue instanceof PrismProperty<?>) {
PrismProperty<?> prismProperty = (PrismProperty<?>) variableValue;
final List<Element> elementList = new ArrayList<Element>();
for (PrismPropertyValue<?> value : prismProperty.getValues()) {
Element valueElement = prismContext.domSerializer().serialize(value, prismProperty.getElementName());
elementList.add(valueElement);
}
NodeList nodeList = new AdHocNodeList(elementList);
variableValue = nodeList;
} else if (variableValue instanceof PrismValue) {
PrismValue pval = (PrismValue) variableValue;
if (pval.getParent() == null) {
// Set a fake parent to allow serialization
pval.setParent(new AdHocItemable(prismContext));
}
variableValue = prismContext.domSerializer().serialize(pval, variableName);
}
if (!((variableValue instanceof Node) || variableValue instanceof NodeList) && !(variableValue.getClass().getPackage().getName().startsWith("java."))) {
throw new SchemaException("Unable to convert value of variable " + variableName + " to XML, still got " + variableValue.getClass().getName() + ":" + variableValue + " value at the end");
}
return variableValue;
} catch (SchemaException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new SchemaException(e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
} catch (RuntimeException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new RuntimeException(e.getClass().getName() + ": " + e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
}
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method executeSearchAttempt.
private <O extends ObjectType> List<V> executeSearchAttempt(final List<PrismObject> rawResult, Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, boolean searchOnResource, boolean tryAlsoRepository, final List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
final List<V> list = new ArrayList<V>();
Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
if (!searchOnResource) {
options.add(SelectorOptions.create(GetOperationOptions.createNoFetch()));
}
extendOptions(options, searchOnResource);
ResultHandler<O> handler = new ResultHandler<O>() {
@Override
public boolean handle(PrismObject<O> object, OperationResult parentResult) {
if (rawResult != null) {
rawResult.add(object);
}
list.add(createPrismValue(object.getOid(), targetTypeQName, additionalAttributeDeltas, params));
return true;
}
};
try {
objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
} catch (IllegalStateException e) {
// this comes from checkConsistence methods
throw new IllegalStateException(e.getMessage() + " in " + contextDescription, e);
} catch (SchemaException e) {
throw new SchemaException(e.getMessage() + " in " + contextDescription, e);
} catch (SystemException e) {
throw new SystemException(e.getMessage() + " in " + contextDescription, e);
} catch (CommunicationException | ConfigurationException | SecurityViolationException e) {
if (searchOnResource && tryAlsoRepository) {
options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
try {
objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
} catch (SchemaException e1) {
throw new SchemaException(e1.getMessage() + " in " + contextDescription, e1);
} catch (CommunicationException | ConfigurationException | SecurityViolationException e1) {
// shadow for group doesn't exist? (MID-2107)
throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
}
} else {
throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
}
} catch (ObjectNotFoundException e) {
throw e;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Assignment expression resulted in {} objects, using query:\n{}", list.size(), query.debugDump());
}
return list;
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class TestCorrelationConfiramtionEvaluator method test001CorrelationOrFilter.
@Test
public void test001CorrelationOrFilter() throws Exception {
String TEST_NAME = "test001CorrelationOrFilter";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
OperationResult result = task.getResult();
importObjectFromFile(USER_JACK_FILE);
PrismObject<UserType> userType = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
//assert jack
assertNotNull(userType);
ShadowType shadow = parseObjectType(ACCOUNT_SHADOW_JACK_DUMMY_FILE, ShadowType.class);
ConditionalSearchFilterType filter = PrismTestUtil.parseAtomicValue(new File(CORRELATION_OR_FILTER), ConditionalSearchFilterType.COMPLEX_TYPE);
List<ConditionalSearchFilterType> filters = new ArrayList<>();
filters.add(filter);
ResourceType resourceType = parseObjectType(RESOURCE_DUMMY_FILE, ResourceType.class);
IntegrationTestTools.display("Queries", filters);
// WHEN
List<PrismObject<UserType>> matchedUsers = evaluator.findFocusesByCorrelationRule(UserType.class, shadow, filters, resourceType, getSystemConfiguration(), task, result);
// THEN
assertNotNull("Correlation evaluator returned null collection of matched users.", matchedUsers);
assertEquals("Found more than one user.", 1, matchedUsers.size());
PrismObject<UserType> jack = matchedUsers.get(0);
assertUser(jack, "c0c010c0-d34d-b33f-f00d-111111111111", "jack", "Jack Sparrow", "Jack", "Sparrow");
}
Aggregations