public AtlasEnumElementDef getEnumElementDef(Number ordinal) { if (ordinal != null) { for (AtlasEnumElementDef elementDef : elementDefs.values()) { if (elementDef.getOrdinal().longValue() == ordinal.longValue()) { return elementDef; } } } return null; } }
public AtlasEnumElementDef getEnumElementDef(Number ordinal) { if (ordinal != null) { for (AtlasEnumElementDef elementDef : elementDefs.values()) { if (elementDef.getOrdinal().longValue() == ordinal.longValue()) { return elementDef; } } } return null; } }
private static List<EnumValue> getEnumValues(List<AtlasEnumElementDef> enumDefs) { List<EnumValue> ret = new ArrayList<EnumValue>(); if (CollectionUtils.isNotEmpty(enumDefs)) { for (AtlasEnumElementDef enumDef : enumDefs) { if (enumDef != null) { ret.add(new EnumValue(enumDef.getValue(), enumDef.getOrdinal())); } } } return ret; }
private void toVertex(AtlasEnumDef enumDef, AtlasVertex vertex) throws AtlasBaseException { if (CollectionUtils.isEmpty(enumDef.getElementDefs())) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "values"); } List<String> values = new ArrayList<>(enumDef.getElementDefs().size()); for (AtlasEnumElementDef element : enumDef.getElementDefs()) { // Validate the enum element if (StringUtils.isEmpty(element.getValue()) || null == element.getOrdinal()) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "elementValue"); } String elemKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef, element.getValue()); AtlasGraphUtilsV2.setProperty(vertex, elemKey, element.getOrdinal()); if (StringUtils.isNotBlank(element.getDescription())) { String descKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(elemKey, "description"); AtlasGraphUtilsV2.setProperty(vertex, descKey, element.getDescription()); } values.add(element.getValue()); } AtlasGraphUtilsV2.setProperty(vertex, AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef), values); String defaultValueKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef, "defaultValue"); AtlasGraphUtilsV2.setProperty(vertex, defaultValueKey, enumDef.getDefaultValue()); }
private void toVertex(AtlasEnumDef enumDef, AtlasVertex vertex) throws AtlasBaseException { if (CollectionUtils.isEmpty(enumDef.getElementDefs())) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "values"); } List<String> values = new ArrayList<>(enumDef.getElementDefs().size()); for (AtlasEnumElementDef element : enumDef.getElementDefs()) { // Validate the enum element if (StringUtils.isEmpty(element.getValue()) || null == element.getOrdinal()) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, enumDef.getName(), "elementValue"); } String elemKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef, element.getValue()); AtlasGraphUtilsV2.setProperty(vertex, elemKey, element.getOrdinal()); if (StringUtils.isNotBlank(element.getDescription())) { String descKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(elemKey, "description"); AtlasGraphUtilsV2.setProperty(vertex, descKey, element.getDescription()); } values.add(element.getValue()); } AtlasGraphUtilsV2.setProperty(vertex, AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef), values); String defaultValueKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef, "defaultValue"); AtlasGraphUtilsV2.setProperty(vertex, defaultValueKey, enumDef.getDefaultValue()); }
@Override public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException { EnumValue ret = null; if (v2Obj == null || !(type instanceof AtlasEnumType)) { return ret; } AtlasEnumType enumType = (AtlasEnumType) type; AtlasEnumElementDef elementDef = enumType.getEnumElementDef(v2Obj.toString()); if (elementDef != null) { ret = new EnumValue(elementDef.getValue(), elementDef.getOrdinal()); } return ret; } }
public AtlasEnumElementDef(AtlasEnumElementDef other) { if (other != null) { setValue(other.getValue()); setDescription(other.getDescription()); setOrdinal(other.getOrdinal()); } }
public AtlasEnumElementDef(AtlasEnumElementDef other) { if (other != null) { setValue(other.getValue()); setDescription(other.getDescription()); setOrdinal(other.getOrdinal()); } }