use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestFilterSimplifier method test160OrLevel1WithoutAll.
@Test
public void test160OrLevel1WithoutAll() throws Exception {
System.out.println("===[ test160OrLevel1WithoutAll ]===");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN
ObjectFilter filter = QueryBuilder.queryFor(UserType.class, prismContext).none().or().undefined().buildFilter();
System.out.println("Original filter:\n" + filter.debugDump());
// THEN
ObjectFilter simplified = ObjectQueryUtil.simplify(filter);
System.out.println("Simplified filter:\n" + DebugUtil.debugDump(simplified));
assertTrue("Wrong simplified filter: " + simplified, simplified instanceof NoneFilter);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestFilterExpression method evaluateExpressionAssertFilter.
private ObjectFilter evaluateExpressionAssertFilter(String filename, String input, Class<? extends ObjectFilter> expectedType, Task task, OperationResult result) throws SchemaException, IOException, ObjectNotFoundException, ExpressionEvaluationException {
PrismContext prismContext = PrismTestUtil.getPrismContext();
SearchFilterType filterType = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, filename), SearchFilterType.COMPLEX_TYPE);
ObjectFilter filter = QueryJaxbConvertor.createObjectFilter(UserType.class, filterType, prismContext);
Map<QName, Object> params = new HashMap<>();
PrismPropertyValue<String> pval = null;
if (input != null) {
pval = new PrismPropertyValue<String>(input);
}
params.put(ExpressionConstants.VAR_INPUT, pval);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinitions(params);
// WHEN
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(filter, variables, expressionFactory, prismContext, "evaluating filter with null value not allowed", task, result);
// THEN
display("Evaluated filter", evaluatedFilter);
AssertJUnit.assertTrue("Expression should be evaluated to " + expectedType + ", but was " + evaluatedFilter, expectedType.isAssignableFrom(evaluatedFilter.getClass()));
return evaluatedFilter;
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestProtectedString method testParseProtectedStringEncrypted.
@Test
public void testParseProtectedStringEncrypted() throws Exception {
final String TEST_NAME = "testParseProtectedStringEncrypted";
displayTestTitle(TEST_NAME);
// GIVEN
Protector protector = PrismInternalTestUtil.createProtector(XMLCipher.AES_128);
ProtectedStringType protectedStringType = protector.encryptString("salalala");
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN
MapXNode protectedStringTypeXNode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(protectedStringType, null);
System.out.println("Protected string type XNode: " + protectedStringTypeXNode.debugDump());
// THEN
ProtectedStringType unmarshalled = new ProtectedStringType();
XNodeProcessorUtil.parseProtectedType(unmarshalled, protectedStringTypeXNode, prismContext, ParsingContext.createDefault());
System.out.println("Unmarshalled value: " + unmarshalled);
assertEquals("Unmarshalled value differs from the original", protectedStringType, unmarshalled);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class TestProtectedString method testParseProtectedStringHashed.
@Test
public void testParseProtectedStringHashed() throws Exception {
final String TEST_NAME = "testParseProtectedStringHashed";
displayTestTitle(TEST_NAME);
// GIVEN
ProtectedStringType protectedStringType = new ProtectedStringType();
protectedStringType.setClearValue("blabla");
Protector protector = PrismInternalTestUtil.createProtector(XMLCipher.AES_128);
protector.hash(protectedStringType);
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN
MapXNode protectedStringTypeXNode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(protectedStringType, null);
System.out.println("Protected string type XNode: " + protectedStringTypeXNode.debugDump());
// THEN
ProtectedStringType unmarshalled = new ProtectedStringType();
XNodeProcessorUtil.parseProtectedType(unmarshalled, protectedStringTypeXNode, prismContext, ParsingContext.createDefault());
System.out.println("Unmarshalled value: " + unmarshalled);
assertEquals("Unmarshalled value differs from the original", protectedStringType, unmarshalled);
}
use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.
the class AssignmentEditorDto method prepareAssignmentAttributes.
private List<ACAttributeDto> prepareAssignmentAttributes(AssignmentType assignment, PageBase pageBase) {
List<ACAttributeDto> acAtrList = new ArrayList<>();
if (assignment == null || assignment.getConstruction() == null || assignment.getConstruction().getAttribute() == null || assignment.getConstruction() == null) {
return acAtrList;
}
OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
ConstructionType construction = assignment.getConstruction();
PrismObject<ResourceType> resource = construction.getResource() != null ? construction.getResource().asPrismObject() : null;
if (resource == null) {
resource = getReference(construction.getResourceRef(), result, pageBase);
}
try {
PrismContext prismContext = pageBase.getPrismContext();
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.PRESENTATION, prismContext);
RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
if (objectClassDefinition == null) {
return attributes;
}
PrismContainerDefinition definition = objectClassDefinition.toResourceAttributeContainerDefinition();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
}
Collection<ItemDefinition> definitions = definition.getDefinitions();
for (ResourceAttributeDefinitionType attribute : assignment.getConstruction().getAttribute()) {
for (ItemDefinition attrDef : definitions) {
if (attrDef instanceof PrismPropertyDefinition) {
PrismPropertyDefinition propertyDef = (PrismPropertyDefinition) attrDef;
if (propertyDef.isOperational() || propertyDef.isIgnored()) {
continue;
}
if (ItemPathUtil.getOnlySegmentQName(attribute.getRef()).equals(propertyDef.getName())) {
acAtrList.add(ACAttributeDto.createACAttributeDto(propertyDef, attribute, prismContext));
break;
}
}
}
}
result.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
result.recordFatalError("Exception occurred during assignment attribute loading.", ex);
} finally {
result.recomputeStatus();
}
return acAtrList;
}
Aggregations