Search in sources :

Example 1 with 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 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);
        }
    }
}
Also used : Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)

Example 2 with 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;
}
Also used : RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) EntityMappingSASCatalog2OMRS(org.odpi.openmetadata.connector.sas.repository.connector.mapping.EntityMappingSASCatalog2OMRS) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)

Example 3 with 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 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);
                }
            }
        }
    }
}
Also used : Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)

Example 4 with EntityDetail

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;
}
Also used : EntityNotKnownException(org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)

Example 5 with EntityDetail

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;
}
Also used : TypeDefAttribute(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefAttribute) InstanceProperties(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties) HashMap(java.util.HashMap) OMRSRepositoryHelper(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

EntityDetail (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)11 Relationship (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)4 ArrayList (java.util.ArrayList)3 InstanceProperties (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties)3 EntityNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException)3 TypeErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Instance (org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance)2 SASCatalogGuid (org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid)2 PagingErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PagingErrorException)2 RepositoryErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)2 EntityMappingSASCatalog2OMRS (org.odpi.openmetadata.connector.sas.repository.connector.mapping.EntityMappingSASCatalog2OMRS)1 InstanceGraph (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceGraph)1 InstancePropertyValue (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstancePropertyValue)1 TypeDefAttribute (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefAttribute)1 OMRSRepositoryHelper (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper)1 FunctionNotSupportedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.FunctionNotSupportedException)1 InvalidParameterException (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException)1