use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail in project egeria-connector-sas-viya by odpi.
the class RepositoryEventMapper method processRemovedEntity.
/**
* Processes and sends an OMRS event for the removed Catalog entity.
*
* @param entity the deleted Catalog entity information
*/
private void processRemovedEntity(SASCatalogObject entity) {
// Send an event for every entity: normal and generated
String sasTypeName = entity.getTypeName();
Map<String, String> omrsTypesByPrefix = typeDefStore.getAllMappedOMRSTypeDefNames(sasTypeName);
if (omrsTypesByPrefix == null) {
log.info("No mappings found while processing removed SAS entity with type name: {}", sasTypeName);
return;
}
for (String prefix : omrsTypesByPrefix.keySet()) {
EntityDetail entityDetail = getMappedEntity(entity, prefix);
if (entityDetail != null) {
if (prefix != null) {
List<Relationship> generatedRelationships = getGeneratedRelationshipsForEntity(entity, entityDetail);
for (Relationship generatedRelationship : generatedRelationships) {
repositoryEventProcessor.processDeletedRelationshipEvent(sourceName, metadataCollectionId, originatorServerName, originatorServerType, localOrganizationName, generatedRelationship);
}
}
repositoryEventProcessor.processDeletedEntityEvent(sourceName, metadataCollectionId, originatorServerName, originatorServerType, localOrganizationName, entityDetail);
}
}
}
use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail in project egeria-connector-sas-viya by odpi.
the class RepositoryEventMapper method getMappedEntity.
/**
* Retrieve the mapped OMRS entity for the provided SAS Catalog entity.
*
* @param entity the SAS Catalog entity to translate to OMRS
* @return EntityDetail
*/
private EntityDetail getMappedEntity(SASCatalogObject entity, String prefix) {
EntityDetail result = null;
EntityMappingSASCatalog2OMRS mapping = new EntityMappingSASCatalog2OMRS(catalogOMRSRepositoryConnector, catalogOMRSMetadataCollection.getTypeDefStore(), null, /*catalogOMRSMetadataCollection.getAttributeTypeDefStore(),*/
entity, prefix, null);
try {
result = mapping.getEntityDetail();
} catch (RepositoryErrorException e) {
log.error("Unable to map entity to OMRS EntityDetail: {}", entity, e);
}
return result;
}
use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail in project egeria-connector-sas-viya by odpi.
the class RepositoryEventMapper method processUpdatedEntity.
/**
* Processes and sends an OMRS event for the updated Catalog entity.
*
* @param updatedEntity the updated Catalog entity information
*/
private void processUpdatedEntity(SASCatalogObject updatedEntity) {
// Send an event for every entity: normal and generated
String sasTypeName = updatedEntity.getTypeName();
Map<String, String> omrsTypesByPrefix = typeDefStore.getAllMappedOMRSTypeDefNames(sasTypeName);
if (omrsTypesByPrefix == null) {
log.info("No mappings found while processing updated SAS entity with type name: {}", sasTypeName);
return;
}
for (String prefix : omrsTypesByPrefix.keySet()) {
EntityDetail entityDetail = getMappedEntity(updatedEntity, prefix);
if (entityDetail != null) {
// TODO: find a way to pull back the old version to send in the update event
repositoryEventProcessor.processUpdatedEntityEvent(sourceName, metadataCollectionId, originatorServerName, originatorServerType, localOrganizationName, null, entityDetail);
if (prefix != null) {
List<Relationship> generatedRelationships = getGeneratedRelationshipsForEntity(updatedEntity, entityDetail);
for (Relationship generatedRelationship : generatedRelationships) {
// TODO: find a way to pull back the old version to send in the update event
repositoryEventProcessor.processUpdatedRelationshipEvent(sourceName, metadataCollectionId, originatorServerName, originatorServerType, localOrganizationName, null, generatedRelationship);
}
}
}
}
}
use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail in project egeria-connector-sas-viya by odpi.
the class MetadataCollection method isEntityKnown.
/**
* {@inheritDoc}
*/
@Override
public EntityDetail isEntityKnown(String userId, String guid) throws InvalidParameterException, RepositoryErrorException {
final String methodName = "isEntityKnown";
super.getInstanceParameterValidation(userId, guid, methodName);
EntityDetail detail = null;
try {
detail = getEntityDetail(userId, guid);
} catch (EntityNotKnownException e) {
log.info("Entity {} not known to the repository, or only a proxy.", guid, e);
}
return detail;
}
use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail in project egeria-connector-sas-viya by odpi.
the class EntityMappingSASCatalog2OMRS method getEntityDetail.
/**
* Retrieve the mapped OMRS EntityDetail from the sas EntityInstance used to
* construct this mapping object.
*
* @return EntityDetail
* @throws RepositoryErrorException when unable to retrieve the EntityDetail
*/
public EntityDetail getEntityDetail() throws RepositoryErrorException {
final String attribute = "attribute";
final String methodName = "getEntityDetail";
String sasTypeDefName = sasEntity.getTypeName();
String omrsTypeDefName = typeDefStore.getMappedOMRSTypeDefName(sasTypeDefName, prefix);
log.info("Found mapped type for Sas type '{}' with prefix '{}': {}", sasTypeDefName, prefix, omrsTypeDefName);
EntityDetail detail = null;
if (omrsTypeDefName != null) {
// Create the basic skeleton
detail = getSkeletonEntityDetail(omrsTypeDefName, prefix);
// Then apply the instance-specific mapping
if (detail != null) {
InstanceProperties instanceProperties = new InstanceProperties();
Map<String, String> additionalProperties = new HashMap<>();
OMRSRepositoryHelper omrsRepositoryHelper = sasRepositoryConnector.getRepositoryHelper();
String repositoryName = sasRepositoryConnector.getRepositoryName();
Map<String, TypeDefAttribute> omrsAttributeMap = typeDefStore.getAllTypeDefAttributesForName(omrsTypeDefName);
// Iterate through the provided mappings to set an OMRS instance property for
// each one
Map<String, String> sasToOmrsProperties = typeDefStore.getPropertyMappingsForCatalogTypeDef(sasTypeDefName, prefix);
if (sasEntity != null) {
Set<String> alreadyMapped = new HashSet<>();
for (Map.Entry<String, String> property : sasToOmrsProperties.entrySet()) {
String sasProperty = property.getKey();
String omrsProperty = property.getValue();
// If omrsProperty is of the form "additionalProperties.xxxxx" then extract
// "xxxxx" as the
// name of the property to add under additionalProperties (and extract value and
// actually
// add the entry in the following IF block
String additionalPropertyName = "";
if (omrsProperty.startsWith(OMRSPROPERTY_ADDITIONALPROPERTIES_PREFIX)) {
additionalPropertyName = omrsProperty.substring(OMRSPROPERTY_ADDITIONALPROPERTIES_PREFIX.length());
}
if (sasProperty.startsWith(SASPROPERTY_CONSTANT_PREFIX)) {
String constantVal = sasProperty.substring(SASPROPERTY_CONSTANT_PREFIX.length());
log.info("Adding constant value: '" + constantVal + "' for property " + omrsProperty);
if (StringUtils.isNotEmpty(additionalPropertyName)) {
additionalProperties.put(additionalPropertyName, constantVal);
} else {
instanceProperties = omrsRepositoryHelper.addStringPropertyToInstance(repositoryName, instanceProperties, omrsProperty, constantVal, methodName);
}
} else if (StringUtils.isNotEmpty(additionalPropertyName)) {
log.info("Mapping {} to additionalProperties '{}'", sasProperty, omrsProperty);
Object propertyValue = sasEntity.get(sasProperty);
if (propertyValue != null) {
additionalProperties.put(additionalPropertyName, propertyValue.toString());
} else {
log.warn("Null property value for SAS property '{}'.", sasProperty);
}
} else if (omrsAttributeMap.containsKey(omrsProperty)) {
log.info("Mapping {} to {}", sasProperty, omrsProperty);
TypeDefAttribute typeDefAttribute = omrsAttributeMap.get(omrsProperty);
instanceProperties = AttributeMapping.addPropertyToInstance(omrsRepositoryHelper, repositoryName, typeDefAttribute, instanceProperties, sasEntity.get(sasProperty), methodName);
if (instanceProperties.getPropertyValue(omrsProperty) != null) {
if (sasProperty.startsWith(attribute)) {
sasProperty = sasProperty.substring(attribute.length());
}
alreadyMapped.add(sasProperty);
}
} else {
log.warn("No OMRS attribute {} defined for asset type {} -- skipping mapping.", omrsProperty, omrsTypeDefName);
}
}
// And map any other simple (non-relationship) properties that are not otherwise
// mapped into 'additionalProperties'
Set<String> nonRelationshipSet = sasEntity.getAttributes().keySet();
// Remove all of the already-mapped properties from our list of non-relationship
// properties
nonRelationshipSet.removeAll(alreadyMapped);
// to strings (even arrays of values, we'll concatenate into a single string)
for (String propertyName : nonRelationshipSet) {
Object propertyValue = sasEntity.getAttributes().get(propertyName);
if (propertyValue != null) {
additionalProperties.put(propertyName, propertyValue.toString());
}
}
// and finally setup the 'additionalProperties' attribute using this map
instanceProperties = omrsRepositoryHelper.addStringMapPropertyToInstance(repositoryName, instanceProperties, "additionalProperties", additionalProperties, methodName);
}
detail.setProperties(instanceProperties);
// TODO: detail.setReplicatedBy();
addClassifications(detail);
}
} else {
log.warn("No mapping defined from Sas type '{}' with prefix '{}'", sasTypeDefName, prefix);
}
return detail;
}
Aggregations