Java Code Examples for org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#setIsUnique()
The following examples show how to use
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#setIsUnique() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeConverterUtil.java From atlas with Apache License 2.0 | 4 votes |
public static AtlasAttributeDef toAtlasAttributeDef(final AttributeDefinition attrDefinition) { AtlasAttributeDef ret = new AtlasAttributeDef(attrDefinition.getName(), attrDefinition.getDataTypeName(), attrDefinition.getSearchWeight(), attrDefinition.getIndexType()); ret.setIsIndexable(attrDefinition.getIsIndexable()); ret.setIsUnique(attrDefinition.getIsUnique()); if (attrDefinition.getIsComposite()) { ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF)); } if (StringUtils.isNotBlank(attrDefinition.getReverseAttributeName())) { ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {{ put(CONSTRAINT_PARAM_ATTRIBUTE, attrDefinition.getReverseAttributeName()); }})); } // Multiplicity attribute mapping Multiplicity multiplicity = attrDefinition.getMultiplicity(); int minCount = multiplicity.getLower(); int maxCount = multiplicity.getUpper(); boolean isUnique = multiplicity.getIsUnique(); if (minCount == 0) { ret.setIsOptional(true); ret.setValuesMinCount(0); } else { ret.setIsOptional(false); ret.setValuesMinCount(minCount); } if (maxCount < 2) { ret.setCardinality(Cardinality.SINGLE); ret.setValuesMaxCount(1); } else { if (!isUnique) { ret.setCardinality(Cardinality.LIST); } else { ret.setCardinality(Cardinality.SET); } ret.setValuesMaxCount(maxCount); } return ret; }
Example 2
Source File: AtlasStructDefStoreV2.java From atlas with Apache License 2.0 | 4 votes |
@VisibleForTesting public static AtlasAttributeDef toAttributeDefFromJson(AtlasStructDef structDef, Map attribInfo, AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException { AtlasAttributeDef ret = new AtlasAttributeDef(); ret.setName((String) attribInfo.get("name")); ret.setTypeName((String) attribInfo.get("dataType")); ret.setIsUnique((Boolean) attribInfo.get("isUnique")); ret.setIsIndexable((Boolean) attribInfo.get("isIndexable")); ret.setIncludeInNotification((Boolean) attribInfo.get("includeInNotification")); ret.setDefaultValue((String) attribInfo.get("defaultValue")); ret.setDescription((String) attribInfo.get("description")); if(attribInfo.get("options") != null) { ret.setOptions(AtlasType.fromJson((String) attribInfo.get("options"), Map.class)); } ret.setDisplayName((String) attribInfo.get("displayName")); if ((Boolean)attribInfo.get("isComposite")) { ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF)); } final String reverseAttributeName = (String) attribInfo.get("reverseAttributeName"); if (StringUtils.isNotBlank(reverseAttributeName)) { ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {{ put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, reverseAttributeName); }})); } Map multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class); Number minCount = (Number) multiplicity.get("lower"); Number maxCount = (Number) multiplicity.get("upper"); Boolean isUnique = (Boolean) multiplicity.get("isUnique"); if (minCount == null || minCount.intValue() == 0) { ret.setIsOptional(true); ret.setValuesMinCount(0); } else { ret.setIsOptional(false); ret.setValuesMinCount(minCount.intValue()); } if (maxCount == null || maxCount.intValue() < 2) { ret.setCardinality(AtlasAttributeDef.Cardinality.SINGLE); ret.setValuesMaxCount(1); } else { if (isUnique == null || isUnique == Boolean.FALSE) { ret.setCardinality(AtlasAttributeDef.Cardinality.LIST); } else { ret.setCardinality(AtlasAttributeDef.Cardinality.SET); } ret.setValuesMaxCount(maxCount.intValue()); } Number searchWeight = (Number) attribInfo.get("searchWeight"); if( searchWeight != null ) { ret.setSearchWeight(searchWeight.intValue()); } else { ret.setSearchWeight(-1); } String indexType = (String) attribInfo.get("indexType"); if(!StringUtils.isEmpty(indexType)) { ret.setIndexType(AtlasAttributeDef.IndexType.valueOf(indexType)); } return ret; }
Example 3
Source File: AtlasStructDefStoreV1.java From incubator-atlas with Apache License 2.0 | 4 votes |
@VisibleForTesting public static AtlasAttributeDef toAttributeDefFromJson(AtlasStructDef structDef, Map attribInfo, AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException { AtlasAttributeDef ret = new AtlasAttributeDef(); ret.setName((String) attribInfo.get("name")); ret.setTypeName((String) attribInfo.get("dataType")); ret.setIsUnique((Boolean) attribInfo.get("isUnique")); ret.setIsIndexable((Boolean) attribInfo.get("isIndexable")); ret.setDefaultValue((String) attribInfo.get("defaultValue")); if ((Boolean)attribInfo.get("isComposite")) { ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF)); } final String reverseAttributeName = (String) attribInfo.get("reverseAttributeName"); if (StringUtils.isNotBlank(reverseAttributeName)) { ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {{ put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, reverseAttributeName); }})); } Map multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class); Number minCount = (Number) multiplicity.get("lower"); Number maxCount = (Number) multiplicity.get("upper"); Boolean isUnique = (Boolean) multiplicity.get("isUnique"); if (minCount == null || minCount.intValue() == 0) { ret.setIsOptional(true); ret.setValuesMinCount(0); } else { ret.setIsOptional(false); ret.setValuesMinCount(minCount.intValue()); } if (maxCount == null || maxCount.intValue() < 2) { ret.setCardinality(AtlasAttributeDef.Cardinality.SINGLE); ret.setValuesMaxCount(1); } else { if (isUnique == null || isUnique == Boolean.FALSE) { ret.setCardinality(AtlasAttributeDef.Cardinality.LIST); } else { ret.setCardinality(AtlasAttributeDef.Cardinality.SET); } ret.setValuesMaxCount(maxCount.intValue()); } return ret; }