use of org.odpi.openmetadata.repositoryservices.ffdc.exception.PropertyErrorException 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;
}
Aggregations