use of com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem in project midpoint by Evolveum.
the class DataModelVisualizerImpl method createDataItems.
private void createDataItems(DataModel model, List<PrismObject<ResourceType>> resources) throws SchemaException {
LOGGER.debug("createDataItems starting");
for (PrismObject<ResourceType> resource : resources) {
final ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
if (resourceSchema == null) {
LOGGER.debug("Resource schema is null, skipping the resource.");
continue;
}
RefinedResourceSchema refinedResourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
if (refinedResourceSchema == null) {
// actually shouldn't be null if resource schema exists
LOGGER.debug("Refined resource schema is null, skipping the resource.");
continue;
}
model.registerResource(resource);
List<? extends RefinedObjectClassDefinition> refinedDefinitions = refinedResourceSchema.getRefinedDefinitions();
for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) {
LOGGER.debug("Processing refined definition {} in {}", refinedDefinition, resource);
Collection<? extends RefinedAttributeDefinition<?>> attributeDefinitions = refinedDefinition.getAttributeDefinitions();
//Collection<? extends ResourceAttributeDefinition> rawAttributeDefinitions = refinedDefinition.getObjectClassDefinition().getAttributeDefinitions();
final ShadowKindType kind = def(refinedDefinition.getKind());
final String intent = def(refinedDefinition.getIntent());
for (RefinedAttributeDefinition<?> attributeDefinition : attributeDefinitions) {
if (attributeDefinition.isIgnored()) {
continue;
}
LOGGER.debug("Registering refined attribute definition for {}", attributeDefinition.getName());
ResourceDataItem attrItem = new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, attributeDefinition.getName());
attrItem.setRefinedAttributeDefinition(attributeDefinition);
// TODO check the name
model.registerDataItem(attrItem);
}
// TODO check attributes not mentioned in schema handling
Collection<RefinedAssociationDefinition> associationDefinitions = refinedDefinition.getAssociationDefinitions();
for (RefinedAssociationDefinition associationDefinition : associationDefinitions) {
if (associationDefinition.isIgnored()) {
continue;
}
LOGGER.debug("Registering refined association definition for {}", associationDefinition.getName());
ResourceDataItem assocItem = new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, associationDefinition.getName());
model.registerDataItem(assocItem);
}
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ACTIVATION_EXISTENCE)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));
}
}
// createRepoDataItems(UserType.class);
// createRepoDataItems(RoleType.class);
// createRepoDataItems(OrgType.class);
// createRepoDataItems(ServiceType.class);
LOGGER.debug("createDataItems finished");
}
use of com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem in project midpoint by Evolveum.
the class DataModelVisualizerImpl method processResourceMappings.
private void processResourceMappings(DataModel model, List<PrismObject<ResourceType>> resources) throws SchemaException {
for (PrismObject<ResourceType> resource : resources) {
LOGGER.debug("Processing {}", ObjectTypeUtil.toShortString(resource));
RefinedResourceSchema refinedResourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
if (refinedResourceSchema == null) {
LOGGER.debug("Refined resource schema is null, skipping the resource.");
continue;
}
List<? extends RefinedObjectClassDefinition> refinedDefinitions = refinedResourceSchema.getRefinedDefinitions();
for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) {
LOGGER.debug("Processing refined definition {}", refinedDefinition);
Collection<? extends RefinedAttributeDefinition<?>> attributeDefinitions = refinedDefinition.getAttributeDefinitions();
final ShadowKindType kind = def(refinedDefinition.getKind());
final String intent = def(refinedDefinition.getIntent());
for (RefinedAttributeDefinition<?> attributeDefinition : attributeDefinitions) {
if (attributeDefinition.isIgnored()) {
continue;
}
LOGGER.debug("Processing refined attribute definition for {}", attributeDefinition.getName());
ResourceDataItem attrItem = model.findResourceItem(resource.getOid(), kind, intent, getObjectClassName(refinedDefinition), new ItemPath(attributeDefinition.getName()));
if (attributeDefinition.getOutboundMappingType() != null) {
processOutboundMapping(model, attrItem, attributeDefinition.getOutboundMappingType(), null);
}
processInboundMappings(model, attrItem, attributeDefinition.getInboundMappingTypes());
}
Collection<RefinedAssociationDefinition> associationDefinitions = refinedDefinition.getAssociationDefinitions();
for (RefinedAssociationDefinition associationDefinition : associationDefinitions) {
if (associationDefinition.isIgnored()) {
continue;
}
LOGGER.debug("Processing refined association definition for {}", associationDefinition.getName());
ResourceDataItem assocItem = model.findResourceItem(resource.getOid(), kind, intent, getObjectClassName(refinedDefinition), new ItemPath(associationDefinition.getName()));
if (associationDefinition.getOutboundMappingType() != null) {
processOutboundMapping(model, assocItem, associationDefinition.getOutboundMappingType(), null);
}
// if (associationDefinition.getAssociationTarget() != null) {
// RefinedObjectClassDefinition target = associationDefinition.getAssociationTarget();
// boolean objectToSubject = associationDefinition.getResourceObjectAssociationType().getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT;
// associationDefinition.getResourceObjectAssociationType().getAssociationAttribute()
// }
}
ResourceActivationDefinitionType actMapping = refinedDefinition.getActivationSchemaHandling();
if (actMapping != null) {
QName objectClassName = getObjectClassName(refinedDefinition);
processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), actMapping.getAdministrativeStatus());
processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), actMapping.getValidFrom());
processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), actMapping.getValidTo());
processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS), actMapping.getLockoutStatus());
processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ACTIVATION_EXISTENCE), actMapping.getExistence());
}
ResourcePasswordDefinitionType pwdDef = refinedDefinition.getPasswordDefinition();
if (pwdDef != null) {
final ItemPath pwdPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD);
ResourceDataItem resourceDataItem = model.findResourceItem(resource.getOid(), kind, intent, getObjectClassName(refinedDefinition), pwdPath);
if (resourceDataItem == null) {
throw new IllegalStateException("No resource item for " + resource.getOid() + ":" + kind + ":" + intent + ":" + pwdPath);
}
if (pwdDef.getOutbound() != null) {
for (MappingType outbound : pwdDef.getOutbound()) {
processOutboundMapping(model, resourceDataItem, outbound, pwdPath);
}
}
for (MappingType inbound : pwdDef.getInbound()) {
processInboundMapping(model, resourceDataItem, inbound, pwdPath);
}
}
}
}
}
use of com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem in project midpoint by Evolveum.
the class DataModelVisualizerImpl method processInboundMapping.
private void processInboundMapping(@NotNull DataModel model, @NotNull ResourceDataItem sourceItem, @NotNull MappingType mapping, @Nullable ItemPath defaultTargetItemPath) {
LOGGER.debug("Processing inbound mapping: {} for {}", mapping, sourceItem);
List<DataItem> sources = new ArrayList<>();
for (VariableBindingDefinitionType sourceDecl : mapping.getSource()) {
LOGGER.debug(" - src: {}", sourceDecl.getPath());
DataItem explicitSourceItem = resolveSourceItem(model, sourceItem, mapping, sourceDecl, null);
sources.add(explicitSourceItem);
}
if (!sources.contains(sourceItem)) {
sources.add(sourceItem);
}
DataItem targetItem = null;
VariableBindingDefinitionType targetDecl = mapping.getTarget();
if (mapping.getTarget() != null) {
LOGGER.debug(" - target: {}", targetDecl.getPath());
targetItem = resolveTargetItem(model, sourceItem, mapping, targetDecl, ExpressionConstants.VAR_FOCUS);
} else if (defaultTargetItemPath != null) {
targetItem = resolveTargetItem(model, sourceItem, mapping, defaultTargetItemPath, ExpressionConstants.VAR_FOCUS);
}
model.registerMappingRelation(sources, targetItem, mapping);
}
use of com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem in project midpoint by Evolveum.
the class DataModelVisualizerImpl method resolveSourceItem.
// for outbound (but sometimes also inbound) mappings
@NotNull
private DataItem resolveSourceItem(@NotNull DataModel model, @NotNull ResourceDataItem currentItem, @NotNull MappingType mapping, @NotNull ItemPath path, @Nullable QName defaultVariable) {
if (!(path.first() instanceof NameItemPathSegment)) {
LOGGER.warn("Probably incorrect path ({}) - does not start with a name - skipping", path);
return createAdHocDataItem(model, path);
}
QName varName;
ItemPath itemPath;
NameItemPathSegment firstNameSegment = (NameItemPathSegment) path.first();
if (firstNameSegment.isVariable()) {
varName = firstNameSegment.getName();
itemPath = path.tail();
} else {
if (defaultVariable == null) {
LOGGER.warn("No default variable for mapping source");
return createAdHocDataItem(model, path);
}
varName = defaultVariable;
itemPath = path;
}
if (QNameUtil.match(ExpressionConstants.VAR_ACCOUNT, varName)) {
return resolveResourceItem(model, currentItem, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_USER, varName)) {
return model.resolveRepositoryItem(UserType.class, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_ACTOR, varName)) {
// TODO
return model.resolveRepositoryItem(UserType.class, itemPath);
} else if (QNameUtil.match(ExpressionConstants.VAR_FOCUS, varName)) {
Class<? extends ObjectType> guessedClass = guessFocusClass(currentItem.getResourceOid(), currentItem.getKind(), currentItem.getIntent());
DataItem item = model.resolveRepositoryItem(guessedClass, itemPath);
if (item != null) {
return item;
}
// TODO guess e.g. by item existence in schema
LOGGER.warn("Couldn't resolve {} in $focus", path);
} else if (QNameUtil.match(ExpressionConstants.VAR_INPUT, varName)) {
return currentItem;
} else {
LOGGER.warn("Unsupported variable {} in {}", varName, path);
}
return createAdHocDataItem(model, path);
}
use of com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem in project midpoint by Evolveum.
the class DataModelVisualizerImpl method processOutboundMapping.
private void processOutboundMapping(@NotNull DataModel model, @NotNull ResourceDataItem targetItem, @NotNull MappingType mapping, @Nullable ItemPath defaultSourceItemPath) {
LOGGER.debug("Processing outbound mapping: {} for {}", mapping, targetItem);
List<DataItem> sources = new ArrayList<>();
for (VariableBindingDefinitionType sourceDecl : mapping.getSource()) {
LOGGER.debug(" - src: {}", sourceDecl.getPath());
DataItem sourceItem = resolveSourceItem(model, targetItem, mapping, sourceDecl, ExpressionConstants.VAR_FOCUS);
sources.add(sourceItem);
}
if (defaultSourceItemPath != null) {
DataItem defaultSource = resolveSourceItem(model, targetItem, mapping, defaultSourceItemPath, ExpressionConstants.VAR_FOCUS);
if (!sources.contains(defaultSource)) {
sources.add(defaultSource);
}
}
VariableBindingDefinitionType targetDecl = mapping.getTarget();
if (targetDecl != null) {
LOGGER.warn(" - ignoring target (mapping is outbound): {}; using {} instead", targetDecl.getPath(), targetItem);
}
model.registerMappingRelation(sources, targetItem, mapping);
}
Aggregations