use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ResourceDetailsTabPanel method getTaskFor.
private List<TaskType> getTaskFor(List<PrismObject<TaskType>> tasks, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
List<TaskType> syncTasks = new ArrayList<>();
for (PrismObject<TaskType> task : tasks) {
ShadowKindType taskKindValue = null;
String taskIntentValue = null;
QName taskObjectClassValue = null;
@Nullable ResourceObjectSetType resourceSet = ResourceObjectSetUtil.fromTask(task.asObjectable());
if (!java.util.Objects.isNull(resourceSet)) {
taskKindValue = resourceSet.getKind();
taskIntentValue = resourceSet.getIntent();
taskObjectClassValue = resourceSet.getObjectclass();
}
// is not accessible in admin-gui)
if (taskObjectClassValue == null) {
ResourceObjectDefinition taskObjectClassDef = null;
ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
if (schema == null) {
throw new SchemaException("No schema defined in resource. Possible configuration problem?");
}
if (taskKindValue == null && taskIntentValue == null) {
// TODO ok?
taskObjectClassDef = schema.findObjectDefinition(ShadowKindType.ACCOUNT, null);
}
if (taskKindValue != null) {
if (StringUtils.isEmpty(taskIntentValue)) {
// TODO ok?
taskObjectClassDef = schema.findObjectDefinition(taskKindValue, null);
} else {
taskObjectClassDef = schema.findObjectDefinition(taskKindValue, taskIntentValue);
}
}
if (taskObjectClassDef != null) {
taskObjectClassValue = taskObjectClassDef.getTypeName();
}
}
if (SynchronizationUtils.isPolicyApplicable(taskObjectClassValue, taskKindValue, taskIntentValue, synchronizationPolicy, resource, true)) {
syncTasks.add(task.asObjectable());
}
}
return syncTasks;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ProjectionValuesProcessor method checkSchemaAndPolicies.
/**
* Check that the primary deltas do not violate schema and policies
* TODO: implement schema check
*/
private void checkSchemaAndPolicies(LensProjectionContext accountContext, String activityDescription) throws SchemaException, PolicyViolationException {
ObjectDelta<ShadowType> primaryDelta = accountContext.getPrimaryDelta();
if (primaryDelta == null || primaryDelta.isDelete()) {
return;
}
ResourceObjectDefinition rAccountDef = accountContext.getCompositeObjectDefinition();
if (rAccountDef == null) {
throw new SchemaException("No definition for account type '" + accountContext.getResourceShadowDiscriminator() + "' in " + accountContext.getResource());
}
if (primaryDelta.isAdd()) {
PrismObject<ShadowType> accountToAdd = primaryDelta.getObjectToAdd();
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(accountToAdd);
if (attributesContainer != null) {
for (ResourceAttribute<?> attribute : attributesContainer.getAttributes()) {
ResourceAttributeDefinition<?> rAttrDef = requireNonNull(rAccountDef.findAttributeDefinition(attribute.getElementName()));
if (!rAttrDef.isTolerant()) {
throw new PolicyViolationException("Attempt to add object with non-tolerant attribute " + attribute.getElementName() + " in " + "account " + accountContext.getResourceShadowDiscriminator() + " during " + activityDescription);
}
}
}
} else if (primaryDelta.isModify()) {
for (ItemDelta<?, ?> modification : primaryDelta.getModifications()) {
if (modification.getParentPath().equivalent(SchemaConstants.PATH_ATTRIBUTES)) {
PropertyDelta<?> attrDelta = (PropertyDelta<?>) modification;
ResourceAttributeDefinition<?> rAttrDef = requireNonNull(rAccountDef.findAttributeDefinition(attrDelta.getElementName()));
if (!rAttrDef.isTolerant()) {
throw new PolicyViolationException("Attempt to modify non-tolerant attribute " + attrDelta.getElementName() + " in " + "account " + accountContext.getResourceShadowDiscriminator() + " during " + activityDescription);
}
}
}
} else {
throw new IllegalStateException("Whoops!");
}
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class EvaluatedPlainResourceObjectConstructionImpl method getAssociationsToEvaluate.
@Override
protected List<AssociationEvaluation<AH>> getAssociationsToEvaluate(ConstructionEvaluation<AH, ?> constructionEvaluation) {
List<AssociationEvaluation<AH>> associationsToEvaluate = new ArrayList<>();
ResourceObjectDefinition objectDefinition = construction.getResourceObjectDefinitionRequired();
for (ResourceAssociationDefinition associationDefinition : objectDefinition.getAssociationDefinitions()) {
MappingType outboundMappingBean = associationDefinition.getOutboundMappingType();
if (outboundMappingBean == null) {
continue;
}
associationsToEvaluate.add(new AssociationEvaluation<>(constructionEvaluation, associationDefinition, outboundMappingBean, OriginType.OUTBOUND, MappingKindType.OUTBOUND));
}
return associationsToEvaluate;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class PlainResourceObjectConstruction method initializeDefinitions.
protected void initializeDefinitions() throws SchemaException {
ResourceObjectDefinition rOcDef = projectionContext.getStructuralObjectDefinition();
if (rOcDef == null) {
LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", projectionContext.getResourceShadowDiscriminator(), lensContext.debugDump(1));
throw new IllegalStateException("Definition for " + projectionContext.getResourceShadowDiscriminator() + " not found in the context, but it should be there");
}
setResourceObjectDefinition(rOcDef);
Collection<ResourceObjectDefinition> auxiliaryObjectClassDefinitions = getResourceObjectDefinition().getAuxiliaryDefinitions();
for (ResourceObjectDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
addAuxiliaryObjectClassDefinition(auxiliaryObjectClassDefinition);
}
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class TestRefinedSchema method test120DetermineObjectClassObjectClassModel.
@Test
public void test120DetermineObjectClassObjectClassModel() throws Exception {
OperationResult result = createOperationResult();
importObjectFromFile(TASK_RECONCILE_DUMMY_OBJECTCLASS_FILE);
Task task = taskManager.getTaskPlain(TASK_RECONCILE_DUMMY_OBJECTCLASS_OID, result);
display("Task", task);
// WHEN
ResourceObjectDefinition objectClass = ModelImplUtils.determineObjectDefinition(refinedSchemaModel, task);
// THEN
displayDumpable("Object class", objectClass);
displayValue("Object class (toString)", objectClass.toString());
deleteObject(TaskType.class, TASK_RECONCILE_DUMMY_OBJECTCLASS_OID);
assertObjectClass(objectClass, RESOURCE_DUMMY_ACCOUNT_OBJECTCLASS_QNAME);
}
Aggregations