Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #296 from cmgrote/master
Browse files Browse the repository at this point in the history
Revises mappings for HBase metadata
  • Loading branch information
cmgrote authored May 28, 2021
2 parents f344ef0 + 6bb7ec6 commit 5308e2c
Show file tree
Hide file tree
Showing 9 changed files with 595 additions and 422 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ private static AtlasTypesDef setupClassificationType(ClassificationDef omrsClass
for (TypeDefLink typeDefLink : validEntities) {
String omrsEntityName = typeDefLink.getName();
// TODO: assumes all classifications remain one-to-one (never generated, so never a prefix)
String atlasEntityName = typeDefStore.getMappedAtlasTypeDefName(omrsEntityName, null);
Set<String> atlasEntityName = typeDefStore.getMappedAtlasTypeDefNames(omrsEntityName, null);
if (atlasEntityName != null) {
entitiesForAtlas.add(atlasEntityName);
entitiesForAtlas.addAll(atlasEntityName);
}
}
if (entitiesForAtlas.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ public List<Relationship> getRelationships(String relationshipTypeGUID,
TypeDef typeDef = typeDefStore.getTypeDefByGUID(relationshipTypeGUID);
if (typeDef != null) {
String omrsTypeDefName = typeDef.getName();
Map<String, String> atlasTypesByPrefix = typeDefStore.getAllMappedAtlasTypeDefNames(omrsTypeDefName);
for (Map.Entry<String, String> entry : atlasTypesByPrefix.entrySet()) {
Map<String, Set<String>> atlasTypesByPrefix = typeDefStore.getAllMappedAtlasTypeDefNames(omrsTypeDefName);
for (Map.Entry<String, Set<String>> entry : atlasTypesByPrefix.entrySet()) {
String prefixForType = entry.getKey();
String atlasTypeName = entry.getValue();
Set<String> atlasTypeNames = entry.getValue();
// TODO: Only generate the generated relationships (normally-mapped should be covered already above)
if (prefixForType != null) {
log.info("Have not yet implemented this relationship: ({}) {}", prefixForType, atlasTypeName);
log.info("Have not yet implemented this relationship: ({}) {}", prefixForType, atlasTypeNames);
}
}
}
Expand Down Expand Up @@ -551,6 +551,13 @@ private final class EntityMapping {
public String getAtlasTypeName() { return atlasTypeName; }
public String getOmrsTypeName() { return omrsTypeName; }

@Override
public String toString() {
return "EntityMapping{" +
"atlasTypeName='" + atlasTypeName + '\'' +
", omrsTypeName='" + omrsTypeName + '\'' +
'}';
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* Class that generically handles converting between Apache Atlas and OMRS Relationship TypeDefs.
Expand Down Expand Up @@ -196,8 +197,22 @@ private static boolean setupRelationshipEnds(RelationshipDef omrsRelationshipDef

// TODO: at the moment this method is only used when adding new relationship types to Atlas,
// so this assumes that we will not use generated objects / prefixes for these net-new relationship types
String atlasTypeName1 = typeDefStore.getMappedAtlasTypeDefName(omrsTypeName1, null);
String atlasTypeName2 = typeDefStore.getMappedAtlasTypeDefName(omrsTypeName2, null);
Set<String> atlasTypeNames1 = typeDefStore.getMappedAtlasTypeDefNames(omrsTypeName1, null);
if (atlasTypeNames1.size() > 1) {
log.warn("Found multiple mapped types, when expected only one: {}", omrsTypeName1);
}
String atlasTypeName1 = null;
for (String candidate : atlasTypeNames1) {
atlasTypeName1 = candidate;
}
Set<String> atlasTypeNames2 = typeDefStore.getMappedAtlasTypeDefNames(omrsTypeName2, null);
if (atlasTypeNames2.size() > 1) {
log.warn("Found multiple mapped types, when expected only one: {}", omrsTypeName2);
}
String atlasTypeName2 = null;
for (String candidate : atlasTypeNames2) {
atlasTypeName2 = candidate;
}

// These look inverted - see comment above for rationale
String attrNameForAtlas1 = omrs2.getAttributeName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TypeDefStore {

// Mapping details
private Map<String, String> prefixToOmrsTypeName;
private Map<String, Map<String, String>> omrsNameToAtlasNamesByPrefix;
private Map<String, Map<String, Set<String>>> omrsNameToAtlasNamesByPrefix;
private Map<String, Map<String, String>> atlasNameToOmrsNamesByPrefix;
private Map<String, Map<String, Map<String, String>>> omrsNameToAttributeMapByPrefix;
private Map<String, Map<String, Map<String, String>>> atlasNameToAttributeMapByPrefix;
Expand Down Expand Up @@ -92,7 +92,10 @@ private void loadMappings() {
if (!omrsNameToAtlasNamesByPrefix.containsKey(omrsName)) {
omrsNameToAtlasNamesByPrefix.put(omrsName, new HashMap<>());
}
omrsNameToAtlasNamesByPrefix.get(omrsName).put(prefix, atlasName);
if (!omrsNameToAtlasNamesByPrefix.get(omrsName).containsKey(prefix)) {
omrsNameToAtlasNamesByPrefix.get(omrsName).put(prefix, new HashSet<>());
}
omrsNameToAtlasNamesByPrefix.get(omrsName).get(prefix).add(atlasName);
if (!atlasNameToOmrsNamesByPrefix.containsKey(atlasName)) {
atlasNameToOmrsNamesByPrefix.put(atlasName, new HashMap<>());
}
Expand Down Expand Up @@ -279,14 +282,16 @@ public Map<String, EndpointMapping> getAllEndpointMappingsFromAtlasName(String a
* name for that prefix.
*
* @param omrsName the name of the OMRS TypeDef
* @return {@code Map<String, String>}
* @return {@code Map<String, Set<String>>}
*/
public Map<String, String> getAllMappedAtlasTypeDefNames(String omrsName) {
public Map<String, Set<String>> getAllMappedAtlasTypeDefNames(String omrsName) {
if (isTypeDefMapped(omrsName)) {
return omrsNameToAtlasNamesByPrefix.get(omrsName);
} else if (omrsNameToGuid.containsKey(omrsName)) {
Map<String, String> map = new HashMap<>();
map.put(null, omrsName);
Map<String, Set<String>> map = new HashMap<>();
Set<String> set = new HashSet<>();
set.add(omrsName);
map.put(null, set);
return map;
} else {
return Collections.emptyMap();
Expand All @@ -299,15 +304,17 @@ public Map<String, String> getAllMappedAtlasTypeDefNames(String omrsName) {
*
* @param omrsName the name of the OMRS TypeDef
* @param prefix the prefix (if any) when mappings to multiple types exist
* @return String
* @return {@code <Set>String}
*/
public String getMappedAtlasTypeDefName(String omrsName, String prefix) {
public Set<String> getMappedAtlasTypeDefNames(String omrsName, String prefix) {
if (isTypeDefMapped(omrsName)) {
return omrsNameToAtlasNamesByPrefix.get(omrsName).getOrDefault(prefix, null);
return omrsNameToAtlasNamesByPrefix.get(omrsName).getOrDefault(prefix, Collections.emptySet());
} else if (omrsNameToGuid.containsKey(omrsName)) {
return omrsName;
Set<String> set = new HashSet<>();
set.add(omrsName);
return set;
} else {
return null;
return Collections.emptySet();
}
}

Expand Down
Loading

0 comments on commit 5308e2c

Please sign in to comment.