Search in sources :

Example 1 with RepositoryErrorException

use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException 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 2 with RepositoryErrorException

use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException 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 3 with RepositoryErrorException

use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException 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 4 with RepositoryErrorException

use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException 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)

Example 5 with RepositoryErrorException

use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException in project egeria-connector-sas-viya by odpi.

the class MetadataCollection method getRelationshipsForEntity.

@Override
public List<Relationship> getRelationshipsForEntity(String userId, String entityGUID, String relationshipTypeGUID, int fromRelationshipElement, List<InstanceStatus> limitResultsByStatus, Date asOfTime, String sequencingProperty, SequencingOrder sequencingOrder, int pageSize) throws InvalidParameterException, TypeErrorException, RepositoryErrorException, EntityNotKnownException, PagingErrorException, FunctionNotSupportedException, UserNotAuthorizedException {
    final String methodName = "getRelationshipsForEntity";
    getRelationshipsForEntityParameterValidation(userId, entityGUID, relationshipTypeGUID, fromRelationshipElement, limitResultsByStatus, asOfTime, sequencingProperty, sequencingOrder, pageSize);
    List<Relationship> alRelationships = null;
    // Immediately throw unimplemented exception if trying to retrieve historical view or sequence by property
    if (asOfTime != null) {
        raiseFunctionNotSupportedException(ErrorCode.NO_HISTORY, methodName, repositoryName);
    } else if (limitResultsByStatus == null || (limitResultsByStatus.size() == 1 && limitResultsByStatus.contains(InstanceStatus.ACTIVE))) {
        // Otherwise, only bother searching if we are after ACTIVE (or "all") entities -- non-ACTIVE means we
        // will just return an empty list
        // Guid cannot be null here, as validation above ensures it is non-null
        SASCatalogGuid sasCatalogGuid = SASCatalogGuid.fromGuid(entityGUID);
        String prefix = sasCatalogGuid.getGeneratedPrefix();
        // 1. retrieve entity from Catalog by GUID (and its relationships)
        SASCatalogObject asset = null;
        List<SASCatalogObject> relationships = null;
        try {
            asset = repositoryConnector.getEntityByGUID(sasCatalogGuid.getSASCatalogGuid());
            relationships = repositoryConnector.getRelationshipsForEntity(sasCatalogGuid.getSASCatalogGuid());
        } catch (Exception e) {
            raiseEntityNotKnownException(ErrorCode.ENTITY_NOT_KNOWN, methodName, e, entityGUID, methodName, repositoryName);
        }
        // Ensure the entity actually exists (if not, throw error to that effect)
        if (asset == null || relationships == null) {
            raiseEntityNotKnownException(ErrorCode.ENTITY_NOT_KNOWN, methodName, null, entityGUID, methodName, repositoryName);
        } else {
            EntityMappingSASCatalog2OMRS entityMap = new EntityMappingSASCatalog2OMRS(repositoryConnector, typeDefStore, attributeTypeDefStore, asset, prefix, userId);
            // 2. Apply the mapping to the object, and retrieve the resulting relationships
            alRelationships = entityMap.getRelationships(relationships, relationshipTypeGUID, fromRelationshipElement, sequencingProperty, sequencingOrder, pageSize);
        }
    }
    return alRelationships;
}
Also used : SASCatalogObject(org.odpi.openmetadata.connector.sas.repository.connector.mapping.SASCatalogObject) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) EntityMappingSASCatalog2OMRS(org.odpi.openmetadata.connector.sas.repository.connector.mapping.EntityMappingSASCatalog2OMRS) ArrayList(java.util.ArrayList) List(java.util.List) SASCatalogGuid(org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid) TypeDefNotSupportedException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefNotSupportedException) FunctionNotSupportedException(org.odpi.openmetadata.repositoryservices.ffdc.exception.FunctionNotSupportedException) TypeDefConflictException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefConflictException) TypeDefKnownException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefKnownException) PagingErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.PagingErrorException) RelationshipNotKnownException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RelationshipNotKnownException) PropertyErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.PropertyErrorException) InvalidTypeDefException(org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidTypeDefException) EntityNotKnownException(org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException) TypeErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException) UserNotAuthorizedException(org.odpi.openmetadata.repositoryservices.ffdc.exception.UserNotAuthorizedException) RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) InvalidParameterException(org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException)

Aggregations

RepositoryErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)12 Relationship (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)9 TypeErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException)7 SASCatalogGuid (org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 EntityNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException)4 FunctionNotSupportedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.FunctionNotSupportedException)4 InvalidParameterException (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException)4 InvalidTypeDefException (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidTypeDefException)4 PagingErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PagingErrorException)4 PropertyErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PropertyErrorException)4 RelationshipNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RelationshipNotKnownException)4 TypeDefConflictException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefConflictException)4 TypeDefKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefKnownException)4 TypeDefNotSupportedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefNotSupportedException)4 UserNotAuthorizedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.UserNotAuthorizedException)4 HashMap (java.util.HashMap)3 Instance (org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance)3 EntityMappingSASCatalog2OMRS (org.odpi.openmetadata.connector.sas.repository.connector.mapping.EntityMappingSASCatalog2OMRS)3