use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.
the class SchemaProcessorTest method testRoundTripGeneric.
@Test
public void testRoundTripGeneric() throws SchemaException {
// GIVEN
PrismSchemaImpl schema = new PrismSchemaImpl(MidPointConstants.NS_RI);
// Ordinary property
schema.createPropertyDefinition("number1", DOMUtil.XSD_INT);
// Property container
MutablePrismContainerDefinition<?> containerDefinition = schema.createContainerDefinition("ContainerType");
// ... in it ordinary property
containerDefinition.createPropertyDefinition("login", DOMUtil.XSD_STRING);
// ... and local property with a type from another schema
containerDefinition.createPropertyDefinition("password", ProtectedStringType.COMPLEX_TYPE);
// ... property reference
containerDefinition.createPropertyDefinition(SchemaConstants.C_CREDENTIALS, CredentialsType.COMPLEX_TYPE);
// ... read-only int property
PrismPropertyDefinition counterProperty = containerDefinition.createPropertyDefinition("counter", DOMUtil.XSD_INT);
counterProperty.toMutable().toMutable().setReadOnly();
System.out.println("Generic schema before serializing to XSD: ");
System.out.println(schema.debugDump());
System.out.println();
// WHEN
Document xsd = schema.serializeToXsd();
String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
System.out.println("Generic schema after serializing to XSD: ");
System.out.println(stringXmlSchema);
System.out.println();
Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext());
System.out.println("Generic schema after parsing from XSD: ");
System.out.println(newSchema.debugDump());
System.out.println();
// THEN
PrismPropertyDefinition number1def = newSchema.findItemDefinitionByElementName(new ItemName(MidPointConstants.NS_RI, "number1"), PrismPropertyDefinition.class);
assertEquals(new ItemName(MidPointConstants.NS_RI, "number1"), number1def.getItemName());
assertEquals(DOMUtil.XSD_INT, number1def.getTypeName());
PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new ItemName(MidPointConstants.NS_RI, "ContainerType"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "ContainerType"), newContainerDef.getTypeName());
PrismPropertyDefinition loginDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "login"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "login"), loginDef.getItemName());
assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
assertTrue("Read flag is wrong", loginDef.canRead());
assertTrue("Create flag is wrong", loginDef.canAdd());
assertTrue("Update flag is wrong", loginDef.canModify());
PrismPropertyDefinition passwdDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "password"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "password"), passwdDef.getItemName());
assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
PrismPropertyDefinition credDef = newContainerDef.findPropertyDefinition(new ItemName(SchemaConstants.NS_C, "credentials"));
assertEquals(new ItemName(SchemaConstants.NS_C, "credentials"), credDef.getItemName());
assertEquals(new ItemName(SchemaConstants.NS_C, "CredentialsType"), credDef.getTypeName());
PrismPropertyDefinition countDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "counter"));
assertEquals(new ItemName(MidPointConstants.NS_RI, "counter"), countDef.getItemName());
assertEquals(DOMUtil.XSD_INT, countDef.getTypeName());
assertTrue("Read flag is wrong", countDef.canRead());
assertFalse("Create flag is wrong", countDef.canAdd());
assertFalse("Update flag is wrong", countDef.canModify());
}
use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.
the class AssignmentCollector method evaluateAssignments.
private <AH extends AssignmentHolderType> Collection<EvaluatedAssignment<AH>> evaluateAssignments(AH focus, Collection<AssignmentType> assignments, AssignmentOrigin origin, AssignmentEvaluator<AH> assignmentEvaluator, Task task, OperationResult result) {
List<EvaluatedAssignment<AH>> evaluatedAssignments = new ArrayList<>();
RepositoryCache.enterLocalCaches(cacheConfigurationManager);
try {
PrismContainerDefinition<AssignmentType> standardAssignmentDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AssignmentHolderType.class).findContainerDefinition(AssignmentHolderType.F_ASSIGNMENT);
for (AssignmentType assignmentType : emptyIfNull(assignments)) {
try {
// noinspection unchecked
PrismContainerDefinition<AssignmentType> definition = defaultIfNull(assignmentType.asPrismContainerValue().getDefinition(), standardAssignmentDefinition);
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType), definition);
EvaluatedAssignment<AH> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, focus, focus.toString(), origin, task, result);
evaluatedAssignments.add(assignment);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException | SecurityViolationException | ConfigurationException | CommunicationException e) {
LOGGER.error("Error while processing assignment of {}: {}; assignment: {}", focus, e.getMessage(), assignmentType, e);
}
}
} finally {
RepositoryCache.exitLocalCaches();
}
return evaluatedAssignments;
}
use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.
the class SqlQueryContext method orderingPath.
/**
* @param <CQ> current entity query path type, can change during multi-segment path resolution
* @param <CR> row type related to {@link CQ}
*/
@SuppressWarnings("unchecked")
private <CQ extends FlexibleRelationalPathBase<CR>, CR> Expression<?> orderingPath(ItemPath orderByItemPath) throws RepositoryException {
ItemPath path = orderByItemPath;
QueryModelMapping<?, CQ, CR> mapping = (QueryModelMapping<?, CQ, CR>) entityPathMapping;
SqlQueryContext<?, CQ, CR> context = (SqlQueryContext<?, CQ, CR>) this;
// We need definition for proper extension support.
// For other cases it's safe for this to become null.
PrismContainerDefinition<?> containerDefinition = (PrismContainerDefinition<?>) entityPathMapping.itemDefinition();
while (path.size() > 1) {
// Resolves only first element
ItemRelationResolver<CQ, CR, ?, ?> resolver = mapping.relationResolver(path);
ItemRelationResolver.ResolutionResult<?, ?> resolution = resolver.resolve(context);
if (resolution.subquery) {
throw new QueryException("Item path '" + orderByItemPath + "' cannot be used for ordering because subquery is used to resolve it.");
}
// CQ/CR for the next loop may be actually different from before, but that's OK
mapping = (QueryModelMapping<?, CQ, CR>) resolution.mapping;
context = (SqlQueryContext<?, CQ, CR>) resolution.context;
if (containerDefinition != null) {
containerDefinition = containerDefinition.findLocalItemDefinition(path.firstToName(), PrismContainerDefinition.class, false);
}
path = path.rest();
}
QName first = path.firstToQName();
ItemDefinition<?> definition = first instanceof ItemName && containerDefinition != null ? containerDefinition.findItemDefinition((ItemName) first) : null;
ItemSqlMapper<CQ, CR> mapper = mapping.itemMapper(first);
return mapper.primaryPath(context.path(), definition);
}
use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.
the class TestAssignmentProcessor2 method test062JackDeputyOfGuybrushDeputyOfBarbossaInLoginMode.
// goes through assignmentEvaluator in order to employ login mode
// MID-4176
@Test(enabled = FIRST_PART)
public void test062JackDeputyOfGuybrushDeputyOfBarbossaInLoginMode() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = getTestOperationResult();
PrismObject<UserType> jack = getUser(USER_JACK_OID);
AssignmentType jackGuybrushAssignment = new AssignmentType(prismContext).targetRef(USER_GUYBRUSH_OID, UserType.COMPLEX_TYPE, SchemaConstants.ORG_DEPUTY);
jackGuybrushAssignment.beginLimitTargetContent().allowTransitive(true);
jack.asObjectable().getAssignment().add(jackGuybrushAssignment);
LensContext<UserType> context = new LensContextPlaceholder<>(jack);
AssignmentEvaluator<UserType> assignmentEvaluator = new AssignmentEvaluator.Builder<UserType>().referenceResolver(referenceResolver).focusOdo(new ObjectDeltaObject<>(jack, null, jack, jack.getDefinition())).lensContext(context).channel(context.getChannel()).modelBeans(modelBeans).objectResolver(objectResolver).systemObjectCache(systemObjectCache).relationRegistry(relationRegistry).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).contextLoader(contextLoader).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).systemConfiguration(context.getSystemConfiguration()).loginMode(true).build();
// noinspection unchecked,rawtypes
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(jackGuybrushAssignment), jackGuybrushAssignment.asPrismContainerValue().getDefinition());
// WHEN
when();
EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, jack.asObjectable(), jack.toString(), AssignmentOrigin.createInObject(), task, result);
// THEN
then();
displayDumpable("Output context", context);
displayDumpable("Evaluated assignment", evaluatedAssignment);
assertSuccess("Assignment evaluator failed (result)", result);
assertEquals("Wrong evaluatedAssignment.isValid", true, evaluatedAssignment.isValid());
assertTargets(evaluatedAssignment, true, "R1 R2 O3 R4 R5 R6", null, null, null, null, null);
assertTargets(evaluatedAssignment, false, "guybrush barbossa MR1 MR2 MR3 MR4 MMR1", null, null, null, null, null);
assertMembershipRef(evaluatedAssignment, "");
assertOrgRef(evaluatedAssignment, "O3");
assertDelegation(evaluatedAssignment, "guybrush barbossa R1 R2 O3 R4 R5 R6");
PrismReferenceValue guybrushRef = evaluatedAssignment.getDelegationRefVals().stream().filter(v -> USER_GUYBRUSH_OID.equals(v.getOid())).findFirst().orElseThrow(() -> new AssertionError("No guybrush ref in delegation ref vals"));
assertEquals("Wrong relation for guybrush delegation", SchemaConstants.ORG_DEPUTY, guybrushRef.getRelation());
// the following entities are not evaluated in login mode
assertConstructions(evaluatedAssignment, (String) null, null, null, null, null, null);
assertFocusMappings(evaluatedAssignment, (String) null);
assertFocusPolicyRules(evaluatedAssignment, (String) null);
assertTargetPolicyRules(evaluatedAssignment, (String) null, null);
assertAuthorizations(evaluatedAssignment, "R1 R2 O3 R4 R5 R6");
assertGuiConfig(evaluatedAssignment, "R1 R2 O3 R4 R5 R6");
assertSerializable(context);
}
use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.
the class ExtensionItemDeltaProcessor method process.
@Override
public void process(ItemDelta<?, ?> modification) throws RepositoryException, SchemaException {
ItemPath itemPath = modification.getPath();
if (modification.getDefinition() instanceof PrismContainerDefinition<?>) {
// We do not index containers
return;
}
Item<PrismValue, ?> item = context.findValueOrItem(itemPath);
Collection<?> realValues = item != null ? item.getRealValues() : null;
ItemDefinition<?> definition = modification.getDefinition();
Objects.requireNonNull(definition, "Item '" + itemPath + "' without definition can't be saved.");
ExtensionProcessor extProcessor = new ExtensionProcessor(context.repositoryContext());
ExtensionProcessor.ExtItemInfo extItemInfo = extProcessor.findExtensionItem(definition, holderType);
if (extItemInfo == null) {
// not-indexed, no action
return;
}
// If the extension is single value (and we know it now, we should proceed with deletion of
// multivalue variant and vice-versa (this variants may be indroduced during raw import
// or changes in multiplicity of extension definition or resource definition
context.deleteItem(reverseCardinality(extProcessor, extItemInfo.item));
if (realValues == null || realValues.isEmpty()) {
context.deleteItem(extItemInfo.getId());
return;
}
// changed value
context.setChangedItem(extItemInfo.getId(), extProcessor.extItemValue(item, extItemInfo));
}
Aggregations