Search in sources :

Example 1 with TypeErrorException

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

the class EntityMappingSASCatalog2OMRS method getSkeletonEntityDetail.

/**
 * Create the base skeleton of an EntityDetail, irrespective of the specific sas
 * object.
 *
 * @param omrsTypeDefName the name of the OMRS TypeDef for which to create a
 *                        skeleton EntityDetail
 * @param prefix          the prefix for a generated entity (if any)
 * @return EntityDetail
 */
private EntityDetail getSkeletonEntityDetail(String omrsTypeDefName, String prefix) {
    EntityDetail detail = null;
    try {
        detail = sasRepositoryConnector.getRepositoryHelper().getSkeletonEntity(sasRepositoryConnector.getRepositoryName(), sasRepositoryConnector.getMetadataCollectionId(), InstanceProvenanceType.LOCAL_COHORT, userId, omrsTypeDefName);
        String guid = sasEntity.getGuid();
        SASCatalogGuid sasCatalogGuid = new SASCatalogGuid(guid, prefix);
        detail.setGUID(sasCatalogGuid.toString());
        detail.setInstanceURL(getInstanceURL(guid));
        detail.setStatus(InstanceStatus.ACTIVE);
        setModAndVersionDetails(detail);
    } catch (TypeErrorException e) {
        log.error("Unable to get skeleton detail entity.", e);
    }
    return detail;
}
Also used : TypeErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail) SASCatalogGuid(org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid)

Example 2 with TypeErrorException

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

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

the class MetadataCollection method getEntityDetailsFromCatalogResults.

/**
 * Retrieves a list of EntityDetail objects given a list of AtlasEntityHeader objects.
 *
 * @param instances the Atlas entities for which to retrieve details
 * @param entityTypeGUID the type of entity that was requested (or null for all)
 * @param userId the user through which to do the retrieval
 * @return {@code List<EntityDetail>}
 * @throws InvalidParameterException the guid is null.
 * @throws RepositoryErrorException there is a problem communicating with the metadata repository where
 *                                  the metadata collection is stored.
 * @throws UserNotAuthorizedException the userId is not permitted to perform this operation.
 */
private List<EntityDetail> getEntityDetailsFromCatalogResults(List<Instance> instances, String entityTypeGUID, String userId) throws InvalidParameterException, RepositoryErrorException, UserNotAuthorizedException {
    List<EntityDetail> entityDetails = new ArrayList<>();
    if (instances != null) {
        for (Instance instance : instances) {
            try {
                // TODO: See if we can do this without making another REST request
                EntityDetail detail = getEntityDetail(userId, instance.getId());
                if (detail != null) {
                    String typeName = detail.getType().getTypeDefName();
                    log.debug("getEntityDetailsFromCatalogResults: typeName {}", typeName);
                    try {
                        TypeDef typeDef = repositoryHelper.getTypeDef(repositoryName, "entityTypeGUID", entityTypeGUID, "getEntityDetailsFromAtlasResults");
                        if (repositoryHelper.isTypeOf(repositoryName, typeName, typeDef.getName())) {
                            entityDetails.add(detail);
                        }
                    } catch (TypeErrorException e) {
                        log.error("Unable to find any TypeDef for entityTypeGUID: {}", entityTypeGUID);
                    }
                } else {
                    log.error("Entity with GUID {} not known -- excluding from results.", instance.getId());
                }
            } catch (EntityNotKnownException e) {
                log.error("Entity with GUID {} not known -- excluding from results.", instance.getId());
            }
        }
    }
    return entityDetails;
}
Also used : TypeErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException) Instance(org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance) ArrayList(java.util.ArrayList) EntityNotKnownException(org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)

Example 4 with TypeErrorException

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

Example 5 with TypeErrorException

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

the class MetadataCollection method findEntitiesByPropertyValue.

@Override
public List<EntityDetail> findEntitiesByPropertyValue(String userId, String entityTypeGUID, String searchCriteria, int fromEntityElement, List<InstanceStatus> limitResultsByStatus, List<String> limitResultsByClassification, Date asOfTime, String sequencingProperty, SequencingOrder sequencingOrder, int pageSize) throws InvalidParameterException, TypeErrorException, RepositoryErrorException, PropertyErrorException, PagingErrorException, FunctionNotSupportedException, UserNotAuthorizedException {
    final String methodName = "findEntitiesByPropertyValue";
    findEntitiesByPropertyValueParameterValidation(userId, entityTypeGUID, searchCriteria, fromEntityElement, limitResultsByStatus, limitResultsByClassification, asOfTime, sequencingProperty, sequencingOrder, pageSize);
    List<Instance> results = new ArrayList<Instance>();
    // Immediately throw unimplemented exception if trying to retrieve historical view
    if (asOfTime != null) {
        raiseFunctionNotSupportedException(ErrorCode.NO_HISTORY, methodName, repositoryName);
    }
    // Search criteria is not allowed to be empty for this method, so cannot be null or empty string.
    if (!searchCriteria.isEmpty()) {
        // Otherwise we need to do an OR-based search across all string properties in Atlas, using whatever the
        // regex of searchCriteria contains for each property
        // Add all textual properties of the provided entity as matchProperties,
        // for an OR-based search of their values
        Map<String, Map<String, String>> mappingsToSearch = new HashMap<>();
        if (entityTypeGUID != null) {
            // We are searching for a particular entity type, get the associated mappings
            mappingsToSearch = getMappingsToSearch(entityTypeGUID, userId);
        } else {
            // We are searching across all entity types, get all mappings
            // We will need to send the request only once, so we'll only use the first mapping
            mappingsToSearch = typeDefStore.getAllOmrsNameToCatalogNameMappings();
        }
        for (Map.Entry<String, Map<String, String>> entryToSearch : mappingsToSearch.entrySet()) {
            InstanceProperties matchProperties = new InstanceProperties();
            String omrsTypeName = entryToSearch.getKey();
            String omrsTypeGUID = typeDefStore.getTypeDefByName(omrsTypeName).getGUID();
            Map<String, TypeDefAttribute> typeDefAttributeMap = typeDefStore.getAllTypeDefAttributesForName(omrsTypeName);
            if (typeDefAttributeMap != null) {
                // This will look at all OMRS attributes, but buildAndRunDSLSearch (later) should limit to only those mapped to catalog
                for (Map.Entry<String, TypeDefAttribute> attributeEntry : typeDefAttributeMap.entrySet()) {
                    String attributeName = attributeEntry.getKey();
                    // Only supporting search by name value for now
                    if (attributeName.equals("qualifiedName")) {
                        TypeDefAttribute typeDefAttribute = attributeEntry.getValue();
                        // Only need to retain string-based attributes for the full text search
                        AttributeTypeDef attributeTypeDef = typeDefAttribute.getAttributeType();
                        if (attributeTypeDef.getCategory().equals(AttributeTypeDefCategory.PRIMITIVE)) {
                            PrimitiveDefCategory primitiveDefCategory = ((PrimitiveDef) attributeTypeDef).getPrimitiveDefCategory();
                            if (primitiveDefCategory.equals(PrimitiveDefCategory.OM_PRIMITIVE_TYPE_STRING) || primitiveDefCategory.equals(PrimitiveDefCategory.OM_PRIMITIVE_TYPE_BYTE) || primitiveDefCategory.equals(PrimitiveDefCategory.OM_PRIMITIVE_TYPE_CHAR)) {
                                matchProperties = repositoryHelper.addStringPropertyToInstance(repositoryName, matchProperties, attributeName, searchCriteria, methodName);
                            } else {
                                log.debug("Skipping inclusion of non-string attribute: {}", attributeName);
                            }
                        } else {
                            log.debug("Skipping inclusion of non-string attribute: {}", attributeName);
                        }
                    }
                }
            }
            List<Instance> innerResults = new ArrayList<Instance>();
            try {
                innerResults = buildAndRunDSLSearch(methodName, entityTypeGUID, omrsTypeGUID, limitResultsByClassification, matchProperties, MatchCriteria.ANY, fromEntityElement, limitResultsByStatus, sequencingProperty, sequencingOrder, pageSize, userId);
            } catch (Exception e) {
                log.error("Exception from findEntitiesByPropertyValue inner search for omrsTypeName {}: {}", omrsTypeName, e.getMessage());
            }
            if (innerResults != null) {
                results.addAll(innerResults);
            }
            // so can break out of the loop
            if (entityTypeGUID == null) {
                break;
            }
        }
    }
    List<EntityDetail> entityDetails = null;
    if (results != null) {
        entityDetails = sortAndLimitFinalResults(results, entityTypeGUID, fromEntityElement, sequencingProperty, sequencingOrder, pageSize, userId);
    }
    return (entityDetails == null || entityDetails.isEmpty()) ? null : entityDetails;
}
Also used : InstanceProperties(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties) Instance(org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TypeErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException)7 SASCatalogGuid (org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid)4 ArrayList (java.util.ArrayList)3 EntityDetail (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)3 EntityNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException)3 RepositoryErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)3 Instance (org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance)2 InstanceProperties (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties)2 Relationship (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)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 PagingErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PagingErrorException)2 PropertyErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PropertyErrorException)2 RelationshipNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RelationshipNotKnownException)2 TypeDefConflictException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefConflictException)2 TypeDefKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefKnownException)2 TypeDefNotSupportedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefNotSupportedException)2 UserNotAuthorizedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.UserNotAuthorizedException)2 ParseException (java.text.ParseException)1