Search in sources :

Example 1 with TypeDef

use of org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef 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 2 with TypeDef

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

the class TypeDefStore method getTypeDefByPrefix.

/**
 * Retrieves the OMRS TypeDef that is mapped to the provided prefix, or null if there is no mapping.
 *
 * @param prefix the prefix for the OMRS type to retrieve
 * @return TypeDef
 */
public TypeDef getTypeDefByPrefix(String prefix) {
    String omrsTypeName = getMappedOMRSTypeDefNameForPrefix(prefix);
    TypeDef typeDef = null;
    if (omrsTypeName != null) {
        typeDef = getTypeDefByName(omrsTypeName);
    }
    return typeDef;
}
Also used : TypeDef(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef)

Example 3 with TypeDef

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

the class TypeDefStore method addTypeDef.

/**
 * Adds the provided TypeDef to the list of those that are implemented in the repository.
 *
 * @param typeDef an implemented type definition
 */
public void addTypeDef(TypeDef typeDef) {
    String guid = typeDef.getGUID();
    omrsGuidToTypeDef.put(guid, typeDef);
    omrsNameToGuid.put(typeDef.getName(), guid);
    addAttributes(typeDef.getPropertiesDefinition(), guid, typeDef.getName());
    // No longer need to add this type
    superTypesToAdd.remove(typeDef.getGUID());
    // Add all super types that we've already seen
    TypeDefLink superType = typeDef.getSuperType();
    if (superType != null) {
        if (unimplementedTypeDefs.containsKey(superType.getGUID())) {
            // No longer unimplemented, remove
            TypeDef superTypeDef = unimplementedTypeDefs.remove(superType.getGUID());
            addTypeDef(superTypeDef);
        } else {
            // Haven't seen the super type yet, store it to add later
            superTypesToAdd.add(superType.getGUID());
        }
    }
}
Also used : TypeDef(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef) TypeDefLink(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefLink)

Example 4 with TypeDef

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

the class TypeDefStore method getAllTypeDefAttributesForGUID.

/**
 * Retrieves a map from attribute name to attribute definition for all attributes of the specified type definition,
 * including all of its supertypes' attributes.
 *
 * @param guid of the type definition
 * @return {@code Map<String, TypeDefAttribute>}
 */
private Map<String, TypeDefAttribute> getAllTypeDefAttributesForGUID(String guid) {
    Map<String, TypeDefAttribute> all = getTypeDefAttributesByGUID(guid);
    if (all != null) {
        TypeDef typeDef = getTypeDefByGUID(guid, false);
        if (typeDef == null) {
            typeDef = getUnimplementedTypeDefByGUID(guid);
        }
        TypeDefLink superType = typeDef.getSuperType();
        if (superType != null) {
            all.putAll(getAllTypeDefAttributesForGUID(superType.getGUID()));
        }
    }
    return all;
}
Also used : TypeDefAttribute(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefAttribute) TypeDef(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef) TypeDefLink(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefLink)

Aggregations

TypeDef (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef)4 TypeDefLink (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefLink)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SASCatalogGuid (org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid)1 Relationship (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)1 TypeDefAttribute (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefAttribute)1 RepositoryErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)1 TypeErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException)1