Skip to content

Commit

Permalink
Merge pull request #255 from planetf1/geomasserver9
Browse files Browse the repository at this point in the history
GE OMAS - map classification properties to string for getAssets
  • Loading branch information
mandy-chessell authored Sep 27, 2018
2 parents d5cfd74 + f64acac commit be18717
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -118,15 +121,31 @@ public List<GovernedAsset> getGovernedAssets(String userId,
}

private void addToAssetListByType(List<GovernedAsset> assetsToReturn, String type,
List<String>classification, String userId ) {
List<String> 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<TypeDef> 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);
});
}

Expand All @@ -141,14 +160,15 @@ private void addToAssetListByClassification(List<GovernedAsset> 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) {
Expand Down Expand Up @@ -177,6 +197,7 @@ private void addToAssetListByClassification(List<GovernedAsset> 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
Expand All @@ -185,6 +206,8 @@ private void addClassificationInfoToEntry(GovernedAsset entry, EntityDetail enti

// Get the current list of assigned classification
List<GovernanceClassificationUsage> usageList = entry.getAssignedGovernanceClassifications();
if (usageList == null)
usageList = new ArrayList<GovernanceClassificationUsage>();

// Add the new assignment locally (in case of copying)
GovernanceClassificationUsage usage = new GovernanceClassificationUsage();
Expand All @@ -205,15 +228,21 @@ private void addClassificationInfoToEntry(GovernedAsset entry, EntityDetail enti

// And now let's pull in the properties
Map<String,String> m = new HashMap<>();
Map<String, InstancePropertyValue> 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<String, InstancePropertyValue> 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);
Expand Down Expand Up @@ -246,9 +275,9 @@ private GovernedAsset addEntityIfDoesntExist(List<GovernedAsset> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 "";
}
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2989,9 +2989,7 @@ public boolean verifyEntityIsClassified(List<String> requiredClassifications,
}
}
}
}
else
{
} else {
return true;
}
return false;
Expand Down

0 comments on commit be18717

Please sign in to comment.