diff --git a/open-metadata-implementation/access-services/governance-engine/governance-engine-server/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/server/handlers/GovernedAssetHandler.java b/open-metadata-implementation/access-services/governance-engine/governance-engine-server/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/server/handlers/GovernedAssetHandler.java index 5e0491a1c09..846bea00aaf 100644 --- a/open-metadata-implementation/access-services/governance-engine/governance-engine-server/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/server/handlers/GovernedAssetHandler.java +++ b/open-metadata-implementation/access-services/governance-engine/governance-engine-server/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/server/handlers/GovernedAssetHandler.java @@ -9,8 +9,11 @@ import org.odpi.openmetadata.accessservices.governanceengine.api.ffdc.exceptions.*; import org.odpi.openmetadata.accessservices.governanceengine.api.objects.GovernanceClassificationUsage; import org.odpi.openmetadata.accessservices.governanceengine.api.objects.GovernedAsset; +import org.odpi.openmetadata.accessservices.governanceengine.server.util.PropertyUtils; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.*; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefCategory; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryConnector; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper; import org.odpi.openmetadata.repositoryservices.ffdc.exception.*; @@ -118,15 +121,31 @@ public List getGovernedAssets(String userId, } private void addToAssetListByType(List assetsToReturn, String type, - Listclassification, String userId ) { + List classification, String userId) { - // We know the type, let's do this by classification now + // We know the type, let's do this by classification now if (classification == null) { - addToAssetListByClassification(assetsToReturn, type,null, userId); + List allClassifications = null; + //TypeDef classificationtypedef; + + try { + allClassifications = metadataCollection.findTypeDefsByCategory(userId, + TypeDefCategory.CLASSIFICATION_DEF); + } catch (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException e) { + } catch (RepositoryErrorException e) { + } catch (org.odpi.openmetadata.repositoryservices.ffdc.exception.UserNotAuthorizedException e) { + } + + if (allClassifications != null) { + allClassifications.forEach((classificationTypedef) -> { + addToAssetListByClassification(assetsToReturn, type, classificationTypedef.getName(), userId); + }); + } + } else { classification.forEach((classificationsearch) -> { - addToAssetListByClassification(assetsToReturn, type,classificationsearch, userId); + addToAssetListByClassification(assetsToReturn, type, classificationsearch, userId); }); } @@ -141,14 +160,15 @@ private void addToAssetListByClassification(List assetsToReturn, String typeGuid = getTypeGuidFromTypeName(type,userId); - +// findEntitiesByClassification requires a specific type to be provided. try { + entities = metadataCollection.findEntitiesByClassification(userId, typeGuid, classification, - null, null, 0, + null, null,0, null, - null, null, null, 0); - + null, null, null, 0);//TODO Handle exceptions from findEntitiesByClassification + //TODO remove stack traces } catch (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException e) { e.printStackTrace(); } catch (TypeErrorException e) { @@ -177,6 +197,7 @@ private void addToAssetListByClassification(List assetsToReturn, } } + private void addClassificationInfoToEntry(GovernedAsset entry, EntityDetail entity, String classification) { // Just add this classification info - the current methods are convoluted, but useful to prove out concept @@ -185,6 +206,8 @@ private void addClassificationInfoToEntry(GovernedAsset entry, EntityDetail enti // Get the current list of assigned classification List usageList = entry.getAssignedGovernanceClassifications(); + if (usageList == null) + usageList = new ArrayList(); // Add the new assignment locally (in case of copying) GovernanceClassificationUsage usage = new GovernanceClassificationUsage(); @@ -205,15 +228,21 @@ private void addClassificationInfoToEntry(GovernedAsset entry, EntityDetail enti // And now let's pull in the properties Map m = new HashMap<>(); - Map ip=entityClassification.getProperties().getInstanceProperties(); - - //mapping them to our map - ip.entrySet().stream().forEach(props -> { - // TODO Mapping of types between OMRS and Ranger should be abstracted - // TODO Mapping of alpha name is fragile - temporary for initial debug - m.put(props.getKey(),props.getValue().toString()); - }); + InstanceProperties ip2 = entityClassification.getProperties(); + if (ip2!=null) { + Map ip = ip2.getInstanceProperties(); + if (ip != null) { + //mapping them to our map + ip.entrySet().stream().forEach(props -> { + // TODO Mapping of types between OMRS and Ranger should be abstracted + // TODO Mapping of alpha name is fragile - temporary for initial debug + //m.put(props.getKey(), props.getValue().toString()); + m.put(props.getKey(), PropertyUtils.getStringForPropertyValue(props.getValue())); + + }); + } + } // And set them back usage.setAttributeValues(m); usageList.add(usage); @@ -246,9 +275,9 @@ private GovernedAsset addEntityIfDoesntExist(List assetsToReturn, private String getTypeGuidFromTypeName(String type, String userId) { - String guid = new String(); + String guid = null; - // TODO Decided how to handle exceptions. For now we'll ensure an empty String is returned + // TODO Decided how to handle exceptions. For now we'll return null try { guid = metadataCollection.getTypeDefByName(userId, type).getGUID(); } catch (org.odpi.openmetadata.repositoryservices.ffdc.exception.InvalidParameterException e) { diff --git a/open-metadata-implementation/access-services/governance-engine/governance-engine-server/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/server/util/PropertyUtils.java b/open-metadata-implementation/access-services/governance-engine/governance-engine-server/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/server/util/PropertyUtils.java new file mode 100644 index 00000000000..bba0cd9fdc0 --- /dev/null +++ b/open-metadata-implementation/access-services/governance-engine/governance-engine-server/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/server/util/PropertyUtils.java @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +package org.odpi.openmetadata.accessservices.governanceengine.server.util; + + +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EnumPropertyValue; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstancePropertyValue; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.PrimitivePropertyValue; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.PrimitiveDefCategory; + +public class PropertyUtils { + + public static String getStringForPropertyValue(InstancePropertyValue ipv) { + + // First deal with primitive types + if (ipv instanceof PrimitivePropertyValue) { + PrimitiveDefCategory primtype = + ((PrimitivePropertyValue) ipv).getPrimitiveDefCategory(); + switch (primtype) { + // case may be unnecessary since all of these types we expect .toString() to work 'sensibly' but leaving + // for future decoding options + case OM_PRIMITIVE_TYPE_STRING: + return (String) ((PrimitivePropertyValue) ipv).getPrimitiveValue(); + case OM_PRIMITIVE_TYPE_INT: + case OM_PRIMITIVE_TYPE_BIGDECIMAL: + case OM_PRIMITIVE_TYPE_BIGINTEGER: + case OM_PRIMITIVE_TYPE_BOOLEAN: + case OM_PRIMITIVE_TYPE_BYTE: + case OM_PRIMITIVE_TYPE_CHAR: + case OM_PRIMITIVE_TYPE_DATE: + case OM_PRIMITIVE_TYPE_DOUBLE: + case OM_PRIMITIVE_TYPE_FLOAT: + case OM_PRIMITIVE_TYPE_LONG: + case OM_PRIMITIVE_TYPE_SHORT: + // For these primitive types we will just use tostring + return ((PrimitivePropertyValue)ipv).getPrimitiveValue().toString(); + case OM_PRIMITIVE_TYPE_UNKNOWN: + default: + // We don't know how to convert to string, so will ignore / leave as null + return ""; + } + + } else + { + if (ipv instanceof EnumPropertyValue) { + return ((EnumPropertyValue) ipv).getSymbolicName(); + } + else + { + // We WILL NOT decode ArrayPropertyValue, InstancePropertyValueMock, MapPropertyValue, + // StructPropertyValue + return ""; + } + } + + } + + +} diff --git a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/localrepository/repositorycontentmanager/OMRSRepositoryContentValidator.java b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/localrepository/repositorycontentmanager/OMRSRepositoryContentValidator.java index ad12770a6fa..04e8097a050 100644 --- a/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/localrepository/repositorycontentmanager/OMRSRepositoryContentValidator.java +++ b/open-metadata-implementation/repository-services/repository-services-implementation/src/main/java/org/odpi/openmetadata/repositoryservices/localrepository/repositorycontentmanager/OMRSRepositoryContentValidator.java @@ -2989,9 +2989,7 @@ public boolean verifyEntityIsClassified(List requiredClassifications, } } } - } - else - { + } else { return true; } return false;