Search in sources :

Example 1 with InstancePropertyValue

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

the class SequencingUtils method getEntityDetailComparator.

public static Comparator<EntityDetail> getEntityDetailComparator(SequencingOrder sequencingOrder, String sequencingProperty) {
    Comparator<EntityDetail> comparator = null;
    if (sequencingOrder != null) {
        switch(sequencingOrder) {
            case GUID:
                comparator = Comparator.comparing(EntityDetail::getGUID);
                break;
            case LAST_UPDATE_OLDEST:
                comparator = Comparator.comparing(EntityDetail::getUpdateTime);
                break;
            case LAST_UPDATE_RECENT:
                comparator = Comparator.comparing(EntityDetail::getUpdateTime).reversed();
                break;
            case CREATION_DATE_OLDEST:
                comparator = Comparator.comparing(EntityDetail::getCreateTime);
                break;
            case CREATION_DATE_RECENT:
                comparator = Comparator.comparing(EntityDetail::getCreateTime).reversed();
                break;
            case PROPERTY_ASCENDING:
                if (sequencingProperty != null) {
                    comparator = (a, b) -> {
                        InstanceProperties p1 = a.getProperties();
                        InstanceProperties p2 = b.getProperties();
                        InstancePropertyValue v1 = null;
                        InstancePropertyValue v2 = null;
                        if (p1 != null) {
                            v1 = p1.getPropertyValue(sequencingProperty);
                        }
                        if (p2 != null) {
                            v2 = p2.getPropertyValue(sequencingProperty);
                        }
                        return AttributeMapping.compareInstanceProperty(v1, v2);
                    };
                }
                break;
            case PROPERTY_DESCENDING:
                if (sequencingProperty != null) {
                    comparator = (b, a) -> {
                        InstanceProperties p1 = a.getProperties();
                        InstanceProperties p2 = b.getProperties();
                        InstancePropertyValue v1 = null;
                        InstancePropertyValue v2 = null;
                        if (p1 != null) {
                            v1 = p1.getPropertyValue(sequencingProperty);
                        }
                        if (p2 != null) {
                            v2 = p2.getPropertyValue(sequencingProperty);
                        }
                        return AttributeMapping.compareInstanceProperty(v1, v2);
                    };
                }
                break;
            default:
                // Do nothing -- no sorting
                break;
        }
    }
    return comparator;
}
Also used : InstancePropertyValue(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstancePropertyValue) InstanceProperties(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)

Example 2 with InstancePropertyValue

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

the class MetadataCollection method buildAndRunDSLSearch.

/**
 * Build an Atlas domain-specific language (DSL) query based on the provided parameters, and return its results.
 *
 * @param methodName the name of the calling method
 * @param entityTypeGUID unique identifier for the type of entity requested.  Null means any type of entity
 *                       (but could be slow so not recommended.
 * @param limitResultsByClassification list of classifications by which to limit the results.
 * @param matchProperties Optional list of entity properties to match (contains wildcards).
 * @param matchCriteria Enum defining how the match properties should be matched to the classifications in the repository.
 * @param fromEntityElement the starting element number of the entities to return.
 *                                This is used when retrieving elements
 *                                beyond the first page of results. Zero means start from the first element.
 * @param limitResultsByStatus By default, entities in all statuses are returned.  However, it is possible
 *                             to specify a list of statuses (eg ACTIVE) to restrict the results to.  Null means all
 *                             status values.
 * @param sequencingProperty String name of the entity property that is to be used to sequence the results.
 *                           Null means do not sequence on a property name (see SequencingOrder).
 * @param sequencingOrder Enum defining how the results should be ordered.
 * @param pageSize the maximum number of result entities that can be returned on this request.  Zero means
 *                 unrestricted return results size.
 * @param userId the user through which to run the search
 * @return {@code List<AtlasEntityHeader>}
 * @throws FunctionNotSupportedException when trying to search using a status that is not supported in Atlas
 * @throws RepositoryErrorException when there is some error running the search against Atlas
 */
private List<Instance> buildAndRunDSLSearch(String methodName, String incomingEntityTypeGUID, String entityTypeGUID, List<String> limitResultsByClassification, InstanceProperties matchProperties, MatchCriteria matchCriteria, int fromEntityElement, List<InstanceStatus> limitResultsByStatus, String sequencingProperty, SequencingOrder sequencingOrder, int pageSize, String userId) throws FunctionNotSupportedException, RepositoryErrorException {
    List<Instance> results = null;
    Map<String, String> queryParams = new HashMap<>();
    Map<String, String> attributeFilter = new HashMap<>();
    String catalogTypeName = "";
    String propertyMatchDelim = "and";
    if (matchCriteria != null && matchCriteria.equals(MatchCriteria.ANY)) {
        propertyMatchDelim = "or";
    }
    // Run multiple searches, if there are multiple types mapped to the OMRS type...
    Map<String, Map<String, String>> mappingsToSearch = getMappingsToSearch(entityTypeGUID, userId);
    for (Map.Entry<String, Map<String, String>> entryToSearch : mappingsToSearch.entrySet()) {
        String filter = "";
        String typeFilter = "";
        String propertyFilter = "";
        String omrsTypeName = entryToSearch.getKey();
        Map<String, String> catalogTypeNamesByPrefix = entryToSearch.getValue();
        int typeCount = catalogTypeNamesByPrefix.size();
        Map<String, InstancePropertyValue> properties = matchProperties.getInstanceProperties();
        Map<String, TypeDefAttribute> omrsAttrTypeDefs = typeDefStore.getAllTypeDefAttributesForName(omrsTypeName);
        for (Map.Entry<String, String> entry : catalogTypeNamesByPrefix.entrySet()) {
            propertyFilter = "";
            String prefix = entry.getKey();
            catalogTypeName = entry.getValue();
            Map<String, String> omrsPropertyMap = typeDefStore.getPropertyMappingsForOMRSTypeDef(omrsTypeName, prefix);
            // Add match properties, if requested
            if (matchProperties != null) {
                // across ALL entity types)//
                if (properties != null) {
                    for (Map.Entry<String, InstancePropertyValue> property : properties.entrySet()) {
                        String omrsPropertyName = property.getKey();
                        String catalogName = omrsPropertyMap.get(omrsPropertyName);
                        String catalogPropertyName = catalogName.substring(catalogName.indexOf(".") + 1);
                        InstancePropertyValue value = property.getValue();
                        if (catalogName.startsWith("attribute.")) {
                            attributeFilter.put(catalogPropertyName, value.valueAsString());
                        } else {
                            if (propertyFilter.isEmpty()) {
                                propertyFilter = String.format("contains(%s,\"%s\")", catalogPropertyName, value.valueAsString());
                            } else {
                                propertyFilter = String.format("%s(%s,contains(%s,\"%s\"))", propertyMatchDelim, propertyFilter, catalogPropertyName, value.valueAsString());
                            }
                        }
                    }
                }
            }
            String typeFilterStr = String.format("eq(type,\"%s\")", catalogTypeName);
            // Handle reference types differently since they all have a type of "reference"
            if (catalogTypeName.startsWith("reference.")) {
                // Extract reference name after "reference."
                String refName = catalogTypeName.substring(catalogTypeName.indexOf(".") + 1);
                typeFilterStr = "eq(type,\"reference\")";
                attributeFilter.put("referencedType", refName);
            }
            if (typeFilter.isEmpty() && propertyFilter.isEmpty()) {
                typeFilter = typeFilterStr;
            } else if (typeFilter.isEmpty() && !propertyFilter.isEmpty()) {
                typeFilter = String.format("and(%s,%s)", typeFilterStr, propertyFilter);
            } else if (!typeFilter.isEmpty() && propertyFilter.isEmpty()) {
                typeFilter = String.format("and(%s,%s)", typeFilter, typeFilter);
            } else {
                typeFilter = String.format("or(and(%s,%s), %s)", typeFilterStr, propertyFilter, typeFilter);
            }
            // If searching by property value across all entity types, we'll only need property filter
            if (incomingEntityTypeGUID == null && methodName.equals("findEntitiesByPropertyValue")) {
                queryParams.put("filter", propertyFilter);
            } else {
                queryParams.put("filter", typeFilter);
            }
        }
        // Add paging criteria, if requested
        if (pageSize > 0) {
            queryParams.put("limit", pageSize + "");
        }
        if (fromEntityElement > 0) {
            queryParams.put("offset", fromEntityElement + "");
        }
        try {
            results = repositoryConnector.getInstancesWithParams(queryParams, attributeFilter);
        } catch (Exception e) {
            raiseRepositoryErrorException(ErrorCode.INVALID_SEARCH, methodName, e, filter);
            log.error("Repository error exception for method {} and filter {} : {}", methodName, filter, e);
        }
    }
    return results;
}
Also used : InstancePropertyValue(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstancePropertyValue) Instance(org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance) HashMap(java.util.HashMap) 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with InstancePropertyValue

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

the class SequencingUtils method getRelationshipComparator.

public static Comparator<Relationship> getRelationshipComparator(SequencingOrder sequencingOrder, String sequencingProperty) {
    Comparator<Relationship> comparator = null;
    if (sequencingOrder != null) {
        switch(sequencingOrder) {
            case GUID:
                comparator = Comparator.comparing(Relationship::getGUID);
                break;
            case LAST_UPDATE_OLDEST:
                comparator = Comparator.comparing(Relationship::getUpdateTime);
                break;
            case LAST_UPDATE_RECENT:
                comparator = Comparator.comparing(Relationship::getUpdateTime).reversed();
                break;
            case CREATION_DATE_OLDEST:
                comparator = Comparator.comparing(Relationship::getCreateTime);
                break;
            case CREATION_DATE_RECENT:
                comparator = Comparator.comparing(Relationship::getCreateTime).reversed();
                break;
            case PROPERTY_ASCENDING:
                if (sequencingProperty != null) {
                    comparator = (a, b) -> {
                        InstanceProperties p1 = a.getProperties();
                        InstanceProperties p2 = b.getProperties();
                        InstancePropertyValue v1 = null;
                        InstancePropertyValue v2 = null;
                        if (p1 != null) {
                            v1 = p1.getPropertyValue(sequencingProperty);
                        }
                        if (p2 != null) {
                            v2 = p2.getPropertyValue(sequencingProperty);
                        }
                        return AttributeMapping.compareInstanceProperty(v1, v2);
                    };
                }
                break;
            case PROPERTY_DESCENDING:
                if (sequencingProperty != null) {
                    comparator = (b, a) -> {
                        InstanceProperties p1 = a.getProperties();
                        InstanceProperties p2 = b.getProperties();
                        InstancePropertyValue v1 = null;
                        InstancePropertyValue v2 = null;
                        if (p1 != null) {
                            v1 = p1.getPropertyValue(sequencingProperty);
                        }
                        if (p2 != null) {
                            v2 = p2.getPropertyValue(sequencingProperty);
                        }
                        return AttributeMapping.compareInstanceProperty(v1, v2);
                    };
                }
                break;
            default:
                // Do nothing -- no sorting
                break;
        }
    }
    return comparator;
}
Also used : InstancePropertyValue(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstancePropertyValue) InstanceProperties(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)

Aggregations

InstancePropertyValue (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstancePropertyValue)3 InstanceProperties (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Instance (org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance)1 EntityDetail (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail)1 Relationship (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)1 EntityNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException)1 FunctionNotSupportedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.FunctionNotSupportedException)1 InvalidParameterException (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException)1 InvalidTypeDefException (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidTypeDefException)1 PagingErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PagingErrorException)1 PropertyErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.PropertyErrorException)1 RelationshipNotKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RelationshipNotKnownException)1 RepositoryErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)1 TypeDefConflictException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefConflictException)1 TypeDefKnownException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefKnownException)1 TypeDefNotSupportedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeDefNotSupportedException)1 TypeErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException)1 UserNotAuthorizedException (org.odpi.openmetadata.repositoryservices.ffdc.exception.UserNotAuthorizedException)1