Skip to content

Commit

Permalink
Fixed abstract mappings model generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Apr 25, 2017
1 parent ca3f364 commit 47e24e3
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 53 deletions.
Expand Up @@ -68,11 +68,12 @@ public RefinedResourceSchema getRefinedResourceSchema(String resourceOid) {
}
}

public ResourceDataItem findResourceItem(@NotNull String resourceOid, @Nullable ShadowKindType kind, @Nullable String intent, @NotNull ItemPath path) {
public ResourceDataItem findResourceItem(@NotNull String resourceOid, @Nullable ShadowKindType kind, @Nullable String intent,
QName objectClassName, @NotNull ItemPath path) {
kind = DataModelVisualizerImpl.def(kind);
intent = DataModelVisualizerImpl.def(intent);
for (ResourceDataItem item : getResourceDataItems()) {
if (item.matches(resourceOid, kind, intent, path)) {
if (item.matches(resourceOid, kind, intent, objectClassName, path)) {
return item;
}
}
Expand Down
Expand Up @@ -134,7 +134,8 @@ private void processResourceMappings(DataModel model, List<PrismObject<ResourceT
continue;
}
LOGGER.debug("Processing refined attribute definition for {}", attributeDefinition.getName());
ResourceDataItem attrItem = model.findResourceItem(resource.getOid(), kind, intent, new ItemPath(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);
}
Expand All @@ -146,7 +147,8 @@ private void processResourceMappings(DataModel model, List<PrismObject<ResourceT
continue;
}
LOGGER.debug("Processing refined association definition for {}", associationDefinition.getName());
ResourceDataItem assocItem = model.findResourceItem(resource.getOid(), kind, intent, new ItemPath(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);
}
Expand All @@ -158,16 +160,18 @@ private void processResourceMappings(DataModel model, List<PrismObject<ResourceT
}
ResourceActivationDefinitionType actMapping = refinedDefinition.getActivationSchemaHandling();
if (actMapping != null) {
processBidirectionalMapping(model, resource.getOid(), kind, intent, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), actMapping.getAdministrativeStatus());
processBidirectionalMapping(model, resource.getOid(), kind, intent, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), actMapping.getValidFrom());
processBidirectionalMapping(model, resource.getOid(), kind, intent, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), actMapping.getValidTo());
processBidirectionalMapping(model, resource.getOid(), kind, intent, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS), actMapping.getLockoutStatus());
processBidirectionalMapping(model, resource.getOid(), kind, intent, new ItemPath(FocusType.F_ACTIVATION, ACTIVATION_EXISTENCE), actMapping.getExistence());
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, pwdPath);
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);
}
Expand All @@ -184,14 +188,14 @@ private void processResourceMappings(DataModel model, List<PrismObject<ResourceT
}
}

private void processBidirectionalMapping(DataModel model, String oid, ShadowKindType kind, String intent, ItemPath itemPath,
private void processBidirectionalMapping(DataModel model, String oid, ShadowKindType kind, String intent, QName objectClassName, ItemPath itemPath,
ResourceBidirectionalMappingType mapping) {
if (mapping == null) {
return;
}
ResourceDataItem resourceDataItem = model.findResourceItem(oid, kind, intent, itemPath);
ResourceDataItem resourceDataItem = model.findResourceItem(oid, kind, intent, objectClassName, itemPath);
if (resourceDataItem == null) {
throw new IllegalStateException("No resource item for " + oid + ":" + kind + ":" + intent + ":" + itemPath);
throw new IllegalStateException("No resource item for " + oid + ":" + kind + ":" + intent + ":" + objectClassName + ":" + itemPath);
}
for (MappingType outbound : mapping.getOutbound()) {
processOutboundMapping(model, resourceDataItem, outbound, itemPath);
Expand Down Expand Up @@ -229,9 +233,7 @@ private void createDataItems(DataModel model, List<PrismObject<ResourceType>> re
continue;
}
LOGGER.debug("Registering refined attribute definition for {}", attributeDefinition.getName());
ResourceDataItem attrItem = new ResourceDataItem(model, resource.getOid(), kind, intent, attributeDefinition.getName());
attrItem.setRefinedResourceSchema(refinedResourceSchema);
attrItem.setRefinedObjectClassDefinition(refinedDefinition);
ResourceDataItem attrItem = new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, attributeDefinition.getName());
attrItem.setRefinedAttributeDefinition(attributeDefinition);
// TODO check the name
model.registerDataItem(attrItem);
Expand All @@ -243,15 +245,15 @@ private void createDataItems(DataModel model, List<PrismObject<ResourceType>> re
continue;
}
LOGGER.debug("Registering refined association definition for {}", associationDefinition.getName());
ResourceDataItem assocItem = new ResourceDataItem(model, resource.getOid(), kind, intent, 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, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, new ItemPath(ShadowType.F_ACTIVATION, ACTIVATION_EXISTENCE)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, new ItemPath(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));
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);
Expand Down Expand Up @@ -421,7 +423,8 @@ private Class<? extends ObjectType> guessFocusClass(@NotNull String resourceOid,
}

private ResourceDataItem resolveResourceItem(DataModel model, ResourceDataItem currentItem, ItemPath path) {
return model.findResourceItem(currentItem.getResourceOid(), currentItem.getKind(), currentItem.getIntent(), path);
return model.findResourceItem(currentItem.getResourceOid(), currentItem.getKind(), currentItem.getIntent(),
currentItem.getObjectClassName(), path);
}

private void processOutboundMapping(@NotNull DataModel model, @NotNull ResourceDataItem targetItem, @NotNull MappingType mapping,
Expand All @@ -446,4 +449,9 @@ private void processOutboundMapping(@NotNull DataModel model, @NotNull ResourceD
model.registerMappingRelation(sources, targetItem, mapping);
}

// TODO move to appropriate place
private QName getObjectClassName(RefinedObjectClassDefinition def) {
return def != null ? def.getTypeName() : null;
}

}
Expand Up @@ -36,6 +36,7 @@
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.util.*;

/**
Expand Down Expand Up @@ -115,28 +116,35 @@ public String exportDot() {
if (attrDef.isIgnored()) {
continue;
}
ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(attrDef.getName()));
ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(attrDef.getName()));
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, item);
}
for (RefinedAssociationDefinition assocDef : def.getAssociationDefinitions()) {
if (assocDef.isIgnored()) {
continue;
}
ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(assocDef.getName()));
ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(),
getObjectClassName(def), new ItemPath(assocDef.getName()));
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, item);
}
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName,
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def),
new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName,
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(ShadowType.F_ACTIVATION, DataModelVisualizerImpl.ACTIVATION_EXISTENCE)));
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def),
new ItemPath(ShadowType.F_ACTIVATION, DataModelVisualizerImpl.ACTIVATION_EXISTENCE)));
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName,
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def),
new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName,
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def),
new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName,
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def),
new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName,
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), new ItemPath(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));
dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def),
new ItemPath(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));

indent--;
sb1.append(indent(indent)).append("}\n");
Expand Down Expand Up @@ -200,6 +208,10 @@ public String exportDot() {
return dot;
}

private QName getObjectClassName(RefinedObjectClassDefinition def) {
return def != null ? def.getTypeName() : null;
}

private String addResourceItem(Set<DataItem> itemsShown, int indent, StringBuilder sb1, String previousNodeName, ResourceDataItem item) {
if (showUnusedItems || isUsed(item)) {
showNodeIfNeeded(sb1, indent, itemsShown, item);
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.impl.dataModel.DataModel;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import org.apache.commons.lang3.ObjectUtils;
import org.jetbrains.annotations.NotNull;
Expand All @@ -43,16 +44,22 @@ public class ResourceDataItem extends DataItem {
private RefinedObjectClassDefinition refinedObjectClassDefinition;
private RefinedAttributeDefinition<?> refinedAttributeDefinition;

public ResourceDataItem(@NotNull DataModel ctx, @NotNull String resourceOid, @NotNull ShadowKindType kind, @NotNull String intent, @NotNull QName itemName) {
public ResourceDataItem(@NotNull DataModel ctx, @NotNull String resourceOid, @NotNull ShadowKindType kind,
@NotNull String intent, RefinedResourceSchema refinedResourceSchema,
RefinedObjectClassDefinition refinedDefinition, @NotNull QName itemName) {
this.ctx = ctx;
this.resourceOid = resourceOid;
this.kind = kind;
this.intent = intent;
this.itemPath = new ItemPath(itemName);
this.hasItemDefinition = true;
this.refinedResourceSchema = refinedResourceSchema;
this.refinedObjectClassDefinition = refinedDefinition;
}

public ResourceDataItem(@NotNull DataModel ctx, @NotNull String resourceOid, @NotNull ShadowKindType kind, @NotNull String intent, @NotNull ItemPath itemPath) {
public ResourceDataItem(@NotNull DataModel ctx, @NotNull String resourceOid, @NotNull ShadowKindType kind,
@NotNull String intent, RefinedResourceSchema refinedResourceSchema,
RefinedObjectClassDefinition refinedDefinition, @NotNull ItemPath itemPath) {
this.ctx = ctx;
this.resourceOid = resourceOid;
this.kind = kind;
Expand All @@ -62,6 +69,8 @@ public ResourceDataItem(@NotNull DataModel ctx, @NotNull String resourceOid, @No
throw new IllegalArgumentException("Wrong itemPath (must end with a named segment): " + itemPath);
}
this.hasItemDefinition = itemPath.size() == 1; // TODO
this.refinedResourceSchema = refinedResourceSchema;
this.refinedObjectClassDefinition = refinedDefinition;
}

@NotNull
Expand Down Expand Up @@ -100,14 +109,6 @@ public RefinedResourceSchema getRefinedResourceSchema() {
return refinedResourceSchema;
}

public void setRefinedResourceSchema(RefinedResourceSchema refinedResourceSchema) {
this.refinedResourceSchema = refinedResourceSchema;
}

public void setRefinedObjectClassDefinition(RefinedObjectClassDefinition refinedObjectClassDefinition) {
this.refinedObjectClassDefinition = refinedObjectClassDefinition;
}

public RefinedObjectClassDefinition getRefinedObjectClassDefinition() {
if (refinedObjectClassDefinition == null) {
RefinedResourceSchema schema = getRefinedResourceSchema();
Expand Down Expand Up @@ -142,17 +143,17 @@ public String toString() {
'}';
}

public boolean matches(String resourceOid, ShadowKindType kind, String intent, ItemPath path) {
if (!this.resourceOid.equals(resourceOid)) {
return false;
}
if (this.kind != kind) {
return false;
}
if (!ObjectUtils.equals(this.intent, intent)) {
return false;
}
return this.itemPath.equivalent(path);
public QName getObjectClassName() {
return refinedObjectClassDefinition != null ? refinedObjectClassDefinition.getTypeName() : null;
}

public boolean matches(String resourceOid, ShadowKindType kind, String intent, QName objectClassName,
ItemPath path) {
return this.resourceOid.equals(resourceOid)
&& this.kind == kind
&& ObjectUtils.equals(this.intent, intent)
&& QNameUtil.match(getObjectClassName(), objectClassName)
&& this.itemPath.equivalent(path);
}

}
Expand Up @@ -25,6 +25,7 @@
import org.testng.annotations.Test;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;

import static com.evolveum.midpoint.test.IntegrationTestTools.display;
Expand Down Expand Up @@ -64,4 +65,24 @@ public void test100VisualizeOneResource() throws Exception {
TestUtil.assertSuccess(result);
}

@Test
public void test110VisualizeTwoResources() throws Exception {
final String TEST_NAME = "test110VisualizeTwoResources";

TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestModelVisualization.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

// WHEN
String output = modelDiagnosticService.exportDataModel(Arrays.asList(RESOURCE_DUMMY_OID, RESOURCE_DUMMY_BLACK_OID),
DataModelVisualizer.Target.DOT, task, result);

// THEN
display("Visualization output", output);
result.computeStatus();
TestUtil.assertSuccess(result);
}

}

0 comments on commit 47e24e3

Please sign in to comment.