Skip to content

Commit

Permalink
#246 Add type conversion for classification properties (primitives & …
Browse files Browse the repository at this point in the history
…enumerations) -> String

Signed-off-by: Nigel Jones <nigel.l.jones+git@gmail.com>
  • Loading branch information
planetf1 committed Sep 26, 2018
1 parent 879cd24 commit f64acac
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -236,7 +237,9 @@ private void addClassificationInfoToEntry(GovernedAsset entry, EntityDetail enti
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(), props.getValue().toString());
m.put(props.getKey(), PropertyUtils.getStringForPropertyValue(props.getValue()));

});
}
}
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 "";
}
}

}


}

0 comments on commit f64acac

Please sign in to comment.