Skip to content

Commit

Permalink
Merge pull request #258 from danielaotelea/event-mapper-refactoring
Browse files Browse the repository at this point in the history
Event Mapper - update term from IGC
  • Loading branch information
mandy-chessell authored Sep 27, 2018
2 parents be18717 + c95de19 commit e97f3d5
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,7 @@ private void processAsset(IGCKafkaEvent igcKafkaEvent) {
igcObject.getId(),
GLOSSARY_TERM);
} else if (igcKafkaEvent.getAction().equals(MODIFY)) {
if (igcObject.getRelatedTerms() != null && igcObject.getRelatedTerms().getItems() != null) {
for (Item item : igcObject.getRelatedTerms().getItems()) {
updateTerm(igcObject, CONFIDENTIALITY, item);
}
}
updateGlossaryTerm(igcObject);
}
break;
case CATEGORY:
Expand Down Expand Up @@ -373,19 +369,34 @@ private void sendNewRelationshipEvent(Relationship relationship) {

}

private void updateTerm(IGCObject igcObject, String classificationTypeName, Item item) {
private void updateGlossaryTerm(IGCObject igcObject) {

final List<Classification> classifications = createClassifications(igcObject, CONFIDENTIALITY);
InstanceProperties instanceProperties = getEntityProperties(GLOSSARY_TERM, igcObject);

EntityDetail entity = createClassificationForGlossaryTerm(igcObject.getId(), classificationTypeName, item);
EntityDetail entity = getEntityDetail(igcObject.getId(),
GLOSSARY_TERM,
false,
igcObject.getCreatedBy(),
instanceProperties,
classifications);

repositoryEventProcessor.processClassifiedEntityEvent(
sendUpdateEntityEvent(entity);
}

private void sendUpdateEntityEvent(EntityDetail entity) {

repositoryEventProcessor.processUpdatedEntityEvent(
sourceName,
metadataCollectionId,
originatorServerName,
originatorServerType,
originatorOrganizationName,
entity);
null,
entity
);

log.info("Classification created " + classificationTypeName + " for " + igcObject.getId());
log.info("[Entity] update the entity with type = " + entity.getType().getTypeDefName() + "; guid = " + entity.getGUID());
}

private void createEntity(IGCColumn igcColumn, String typeName, boolean avoidDuplicate) {
Expand All @@ -409,15 +420,11 @@ private void createEntity(IGCColumn igcColumn, String typeName, boolean avoidDup
private void createEntity(IGCObject igcObject, String typeName, boolean avoidDuplicate) {

List<Classification> classifications = new ArrayList<>();
if (typeName.equals(GLOSSARY_TERM) && igcObject.getRelatedTerms() != null) {
classifications = getConfidentialityClassification(igcObject);
if (GLOSSARY_TERM.equals(typeName)) {
classifications = createClassifications(igcObject, CONFIDENTIALITY);
}

InstanceProperties instanceProperties = getEntityProperties(typeName,
igcObject.getId(),
igcObject.getName(),
igcObject.getShortDescription(),
igcObject.getLongDescription());
InstanceProperties instanceProperties = getEntityProperties(typeName, igcObject);

EntityDetail entityDetail = getEntityDetail(igcObject.getId(),
typeName,
Expand Down Expand Up @@ -558,33 +565,23 @@ private List<Classification> getPrimaryKeyClassification() {
return classificationList;
}

private List<Classification> getConfidentialityClassification(IGCObject igcObject) {
private List<Classification> createClassifications(IGCObject igcObject, String classificationTypeName) {

List<Classification> classifications = new ArrayList<>();

if (igcObject.getRelatedTerms().getItems() != null) {
if (igcObject.getRelatedTerms() != null && igcObject.getRelatedTerms().getItems() != null) {
for (Item item : igcObject.getRelatedTerms().getItems()) {
classifications.addAll(getClassification(CONFIDENTIALITY, item.getName()));
final Classification classification = getClassification(classificationTypeName, item.getName());
if(classification != null){
classifications.add(classification);
}
}
}
return classifications;
}

private EntityDetail createClassificationForGlossaryTerm(String id, String classificationTypeName, Item item) {

List<Classification> classifications = getClassification(classificationTypeName, item.getName());

InstanceProperties instanceProperties = getMandatoryProperty(GLOSSARY_TERM, id);
return getEntityDetail(id,
GLOSSARY_TERM,
false,
null,
instanceProperties,
classifications);
return classifications;
}

private List<Classification> getClassification(String classificationTypeName, String name) {

List<Classification> classifications = new ArrayList<>(1);
private Classification getClassification(String classificationTypeName, String name) {

try {
Classification classification = repositoryHelper.getNewClassification(
Expand All @@ -598,12 +595,12 @@ private List<Classification> getClassification(String classificationTypeName, St

InstanceProperties classificationProperties = getClassificationProperties(name);
classification.setProperties(classificationProperties);
classifications.add(classification);
return classification;
} catch (TypeErrorException e) {
log.info("Unable to create Classification [type = " + classificationTypeName + "] :" + e.getErrorMessage());
}

return classifications;
return null;
}


Expand All @@ -617,6 +614,35 @@ private InstanceProperties getMandatoryProperty(String typeName, String id) {
return instanceProperties;
}

private InstanceProperties getEntityProperties(String typeName, IGCObject igcObject) {

InstanceProperties instanceProperties = getEntityProperties(typeName,
igcObject.getId(),
igcObject.getName(),
igcObject.getShortDescription(),
igcObject.getLongDescription());


if (GLOSSARY_TERM.equals(typeName)) {
Map<String, InstancePropertyValue> properties = new HashMap<>();

PrimitivePropertyValue example = getStringPropertyValue(igcObject.getExample());
properties.put("examples", example);

PrimitivePropertyValue abbreviation = getStringPropertyValue(igcObject.getAbbreviation());
properties.put("abbreviation", abbreviation);

PrimitivePropertyValue usage = getStringPropertyValue(igcObject.getUsage());
properties.put("usage", usage);

Map<String, InstancePropertyValue> instanceProperties1 = instanceProperties.getInstanceProperties();
properties.putAll(instanceProperties1);
instanceProperties.setInstanceProperties(properties);
}

return instanceProperties;
}


private InstanceProperties getEntityProperties(String typeName, String id, String name, String shortDescription, String longDescription) {
Map<String, InstancePropertyValue> properties = new HashMap<>();
Expand All @@ -627,9 +653,6 @@ private InstanceProperties getEntityProperties(String typeName, String id, Strin
PrimitivePropertyValue displayName = getStringPropertyValue(name);
properties.put("displayName", displayName);

PrimitivePropertyValue name_property = getStringPropertyValue(name);
properties.put("name", name_property);

PrimitivePropertyValue summary = getStringPropertyValue(shortDescription);
properties.put("summary", summary);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"unique",
"assigned_to_terms",
"related_terms",
"assignedAssets",
"assigned_assets",
"_context",
"created_on",
"allows_null_values",
Expand All @@ -38,11 +38,14 @@
"odbc_type",
"database_table_or_view",
"is_a_type_of",
"shortDescription",
"longDescription",
"DatabaseColumns",
"dataConnections",
"dataConnectors"
"short_description",
"long_description",
"database_columns",
"usage",
"example",
"abbreviation",
"data_connections",
"data_connectors"
})

public class IGCObject {
Expand Down Expand Up @@ -103,6 +106,12 @@ public class IGCObject {
private DataConnectors dataConnectors;
@JsonProperty("data_connections")
private DataConnections dataConnections;
@JsonProperty("usage")
private String usage;
@JsonProperty("example")
private String example;
@JsonProperty("abbreviation")
private String abbreviation;

@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<>();
Expand Down Expand Up @@ -410,4 +419,35 @@ public void setDataConnections(DataConnections dataConnections) {
public void setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
}

@JsonProperty("usage")
public String getUsage() {
return usage;
}

@JsonProperty("usage")
public void setUsage(String usage) {
this.usage = usage;
}

@JsonProperty("example")
public String getExample() {
return example;
}

@JsonProperty("example")
public void setExample(String example) {
this.example = example;
}

@JsonProperty("abbreviation")
public String getAbbreviation() {
return abbreviation;
}

@JsonProperty("abbreviation")
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}

}

0 comments on commit e97f3d5

Please sign in to comment.