Search in sources :

Example 1 with Relationship

use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship 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 Relationship

use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship 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 3 with Relationship

use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship in project egeria-connector-sas-viya by odpi.

the class EntityMappingSASCatalog2OMRS method getRelationships.

/**
 * Retrieves relationships for this entity based on the provided criteria.
 *
 * @param relationships           the Catalog objects for which we wish to
 *                                return relationships
 * @param relationshipTypeGUID    the OMRS GUID of the relationship TypeDef to
 *                                which to limit the results
 * @param fromRelationshipElement the starting element for multiple pages of
 *                                relationships
 * @param sequencingProperty      the property by which to order results (or
 *                                null)
 * @param sequencingOrder         the ordering sequence to use for ordering
 *                                results
 * @param pageSize                the number of results to include per page
 * @return {@code List<Relationship>}
 * @throws RepositoryErrorException when unable to retrieve the mapped
 *                                  Relationships
 */
@SuppressWarnings("unchecked")
public List<Relationship> getRelationships(List<SASCatalogObject> relationships, String relationshipTypeGUID, int fromRelationshipElement, String sequencingProperty, SequencingOrder sequencingOrder, int pageSize) throws RepositoryErrorException {
    final String methodName = "getRelationships";
    List<Relationship> omrsRelationships = new ArrayList<>();
    String repositoryName = sasRepositoryConnector.getRepositoryName();
    for (SASCatalogObject relationship : relationships) {
        String catalogRelationshipType = relationship.getTypeName();
        String relationshipGuid = relationship.getGuid();
        Map<String, String> omrsPrefixToType = typeDefStore.getMappedOMRSTypeDefNameWithPrefixes(catalogRelationshipType);
        for (Map.Entry<String, String> entry : omrsPrefixToType.entrySet()) {
            String relationshipPrefix = entry.getKey();
            String omrsRelationshipType = entry.getValue();
            TypeDef omrsTypeDef = typeDefStore.getTypeDefByName(omrsRelationshipType);
            String omrsTypeDefGuid = omrsTypeDef.getGUID();
            // this type GUID
            if (relationshipTypeGUID == null || omrsTypeDefGuid.equals(relationshipTypeGUID)) {
                log.debug("EntityMappingSASCatalog2OMRS:create relationship mapping");
                RelationshipMapping mapping = new RelationshipMapping(sasRepositoryConnector, typeDefStore, null, new SASCatalogGuid(relationshipGuid, relationshipPrefix), relationship, userId);
                log.debug("EntityMappingSASCatalog2OMRS:get relationship from mapping");
                try {
                    Relationship omrsRelationship = mapping.getRelationship();
                    if (omrsRelationship != null) {
                        omrsRelationships.add(omrsRelationship);
                    }
                } catch (Exception e) {
                    log.error("Unable to find relationship with guid {} and prefix {}", relationshipGuid, relationshipPrefix);
                    log.error("Exception Message: {}", e.getMessage());
                }
            }
        }
    }
    // SAS but different entities in OMRS)
    if (relationshipTypeGUID == null) {
        Map<String, TypeDefStore.EndpointMapping> mappedRelationships = typeDefStore.getAllEndpointMappingsFromCatalogName(sasEntity.getTypeName());
        for (Map.Entry<String, TypeDefStore.EndpointMapping> entry : mappedRelationships.entrySet()) {
            String relationshipPrefix = entry.getKey();
            // already above)
            if (relationshipPrefix != null) {
                // TODO: assumes that all generated relationships have the same Catalog entity on
                // both ends ie relationshipTable <--> relationshipTableType
                SASCatalogGuid sasGuid = new SASCatalogGuid(sasEntity.getGuid(), relationshipPrefix);
                Relationship omrsRelationship = RelationshipMapping.getSelfReferencingRelationship(sasRepositoryConnector, typeDefStore, sasGuid, sasEntity);
                if (omrsRelationship != null) {
                    omrsRelationships.add(omrsRelationship);
                } else {
                    raiseRepositoryErrorException(ErrorCode.RELATIONSHIP_NOT_KNOWN, methodName, null, sasGuid.toString(), methodName, repositoryName);
                }
            }
        }
    } else {
        TypeDef typeDef = typeDefStore.getTypeDefByGUID(relationshipTypeGUID);
        if (typeDef != null) {
            String omrsTypeDefName = typeDef.getName();
            Map<String, String> sasTypesByPrefix = typeDefStore.getAllMappedCatalogTypeDefNames(omrsTypeDefName);
            for (Map.Entry<String, String> entry : sasTypesByPrefix.entrySet()) {
                String prefixForType = entry.getKey();
                String sasTypeNames = entry.getValue();
                // covered already above)
                if (prefixForType != null) {
                    log.info("Have not yet implemented this relationship: ({}) {}", prefixForType, sasTypeNames);
                }
            }
        }
    }
    if (omrsRelationships != null) {
        // Now sort the results, if requested
        Comparator<Relationship> comparator = SequencingUtils.getRelationshipComparator(sequencingOrder, sequencingProperty);
        if (comparator != null) {
            omrsRelationships.sort(comparator);
        }
        // And finally limit the results, if requested
        int endOfPageMarker = Math.min(fromRelationshipElement + pageSize, omrsRelationships.size());
        if (pageSize != 0) {
            // treating 0 as unlimited for now
            if (fromRelationshipElement != 0 || endOfPageMarker < omrsRelationships.size()) {
                omrsRelationships = omrsRelationships.subList(fromRelationshipElement, endOfPageMarker);
            }
        }
    }
    return (omrsRelationships.isEmpty() ? null : omrsRelationships);
}
Also used : ArrayList(java.util.ArrayList) TypeErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException) RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) TypeDef(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) SASCatalogGuid(org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Relationship

use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship in project egeria-connector-sas-viya by odpi.

the class RelationshipMapping method getSkeletonRelationship.

/**
 * Create the base skeleton of a Relationship, irrespective of the specific SAS object.
 *
 * @param SASRepositoryConnector connectivity to an SAS environment
 * @param omrsRelationshipDef the OMRS RelationshipDef for which to create a skeleton Relationship
 * @return Relationship
 * @throws RepositoryErrorException when unable to create a new skeletal Relationship
 */
static Relationship getSkeletonRelationship(RepositoryConnector SASRepositoryConnector, RelationshipDef omrsRelationshipDef) throws RepositoryErrorException {
    final String methodName = "getSkeletonRelationship";
    Relationship relationship = new Relationship();
    try {
        InstanceType instanceType = SASRepositoryConnector.getRepositoryHelper().getNewInstanceType(SASRepositoryConnector.getRepositoryName(), omrsRelationshipDef);
        relationship.setType(instanceType);
    } catch (TypeErrorException e) {
        throw new RepositoryErrorException(ErrorCode.INVALID_INSTANCE.getMessageDefinition(methodName, omrsRelationshipDef.getName()), RelationshipMapping.class.getName(), methodName, e);
    }
    return relationship;
}
Also used : RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) TypeErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) InstanceType(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceType)

Example 5 with Relationship

use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship in project egeria-connector-sas-viya by odpi.

the class RelationshipMapping method getRelationship.

/**
 * Create a mapped relationship based on the provided criteria
 *
 * @param SASRepositoryConnector connectivity to an SAS environment
 * @param typeDefStore store of TypeDef mappings
 * @param omrsRelationshipType the type of the OMRS relationship to map
 * @param relationshipGUID the GUID of the relationship
 * @param relationshipStatus the status of the relationship
 * @param ep1 the proxy to map to endpoint 1
 * @param ep2 the proxy to map to endpoint 2
 * @param createdBy the relationship creator
 * @param updatedBy the relationship updator
 * @param createTime the time the relationship was created
 * @param updateTime the time the relationship was updated
 * @param omrsRelationshipProperties the properties to set on the relationship
 * @return Relationship
 * @throws RepositoryErrorException when unable to map the Relationship
 */
private static Relationship getRelationship(RepositoryConnector SASRepositoryConnector, TypeDefStore typeDefStore, String omrsRelationshipType, SASCatalogGuid relationshipGUID, InstanceStatus relationshipStatus, EntityProxy ep1, EntityProxy ep2, String createdBy, String updatedBy, Date createTime, Date updateTime, InstanceProperties omrsRelationshipProperties) throws RepositoryErrorException {
    final String methodName = "getRelationship";
    String repositoryName = SASRepositoryConnector.getRepositoryName();
    Relationship omrsRelationship = RelationshipMapping.getSkeletonRelationship(SASRepositoryConnector, (RelationshipDef) typeDefStore.getTypeDefByName(omrsRelationshipType));
    omrsRelationship.setGUID(relationshipGUID.toString());
    omrsRelationship.setMetadataCollectionId(SASRepositoryConnector.getMetadataCollectionId());
    omrsRelationship.setStatus(relationshipStatus);
    omrsRelationship.setInstanceProvenanceType(InstanceProvenanceType.LOCAL_COHORT);
    omrsRelationship.setVersion(updateTime.getTime());
    omrsRelationship.setCreateTime(createTime);
    omrsRelationship.setCreatedBy(createdBy);
    omrsRelationship.setUpdatedBy(updatedBy);
    omrsRelationship.setUpdateTime(updateTime);
    if (ep1 != null && ep2 != null) {
        omrsRelationship.setEntityOneProxy(ep1);
        omrsRelationship.setEntityTwoProxy(ep2);
    } else {
        throw new RepositoryErrorException(ErrorCode.INVALID_RELATIONSHIP_ENDS.getMessageDefinition(methodName, repositoryName, omrsRelationshipType, ep1 == null ? "null" : ep1.getGUID(), ep2 == null ? "null" : ep2.getGUID()), RelationshipMapping.class.getName(), methodName);
    }
    if (omrsRelationshipProperties != null) {
        omrsRelationship.setProperties(omrsRelationshipProperties);
    }
    return omrsRelationship;
}
Also used : RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)

Aggregations

Relationship (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)14 RepositoryErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)8 SASCatalogGuid (org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid)6 TypeErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException)5 ArrayList (java.util.ArrayList)4 EntityDetail (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)4 PagingErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PagingErrorException)3 ParseException (java.text.ParseException)2 Map (java.util.Map)2 RelationshipMapping (org.odpi.openmetadata.connector.sas.repository.connector.mapping.RelationshipMapping)2 SASCatalogObject (org.odpi.openmetadata.connector.sas.repository.connector.mapping.SASCatalogObject)2 AttributeTypeDefStore (org.odpi.openmetadata.connector.sas.repository.connector.stores.AttributeTypeDefStore)2 TypeDefStore (org.odpi.openmetadata.connector.sas.repository.connector.stores.TypeDefStore)2 EntityProxy (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy)2 InstanceProperties (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties)2 EntityNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException)2 FunctionNotSupportedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.FunctionNotSupportedException)2 InvalidParameterException (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException)2 InvalidTypeDefException (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidTypeDefException)2 PropertyErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PropertyErrorException)2