private boolean addAttributes(AtlasStructDef def, List<AtlasStructDef.AtlasAttributeDef> list) { for (AtlasStructDef.AtlasAttributeDef ad : list) { def.addAttribute(ad); } return list.size() > 0; }
private static boolean updateTypeAttributes(AtlasStructDef oldStructDef, AtlasStructDef newStructDef) { boolean ret = isTypeUpdateApplicable(oldStructDef, newStructDef); if (ret) { // make sure that all attributes in oldDef are in newDef as well if (CollectionUtils.isNotEmpty(oldStructDef.getAttributeDefs())){ for (AtlasAttributeDef oldAttrDef : oldStructDef.getAttributeDefs()) { if (!newStructDef.hasAttribute(oldAttrDef.getName())) { newStructDef.addAttribute(oldAttrDef); } } } } return ret; }
private void addOrUpdateAttributes(AtlasStructDef structDef, List<AtlasAttributeDef> attributesToUpdate) { for (AtlasAttributeDef attributeToUpdate : attributesToUpdate) { String attrName = attributeToUpdate.getName(); if (structDef.hasAttribute(attrName)) { structDef.removeAttribute(attrName); } structDef.addAttribute(attributeToUpdate); } } }
private void addOrUpdateAttributes(AtlasStructDef structDef, List<AtlasAttributeDef> attributesToUpdate) { for (AtlasAttributeDef attributeToUpdate : attributesToUpdate) { String attrName = attributeToUpdate.getName(); if (structDef.hasAttribute(attrName)) { structDef.removeAttribute(attrName); } structDef.addAttribute(attributeToUpdate); } } }
private static boolean updateTypeAttributes(AtlasStructDef oldStructDef, AtlasStructDef newStructDef, boolean checkTypeVersion) { boolean ret = isTypeUpdateApplicable(oldStructDef, newStructDef, checkTypeVersion); if (ret) { // make sure that all attributes in oldDef are in newDef as well if (CollectionUtils.isNotEmpty(oldStructDef.getAttributeDefs())){ for (AtlasAttributeDef oldAttrDef : oldStructDef.getAttributeDefs()) { if (!newStructDef.hasAttribute(oldAttrDef.getName())) { newStructDef.addAttribute(oldAttrDef); } } } } return ret; }
@Test public void testStructDefAddAttribute() { AtlasStructDef structDef = ModelTestUtil.newStructDef(); structDef.addAttribute(new AtlasAttributeDef("newAttribute", AtlasBaseTypeDef.ATLAS_TYPE_INT)); assertTrue(structDef.hasAttribute("newAttribute")); }
@Test public void testStructDefAddAttribute() { AtlasStructDef structDef = ModelTestUtil.newStructDef(); structDef.addAttribute(new AtlasAttributeDef("newAttribute", AtlasBaseTypeDef.ATLAS_TYPE_INT)); assertTrue(structDef.hasAttribute("newAttribute")); }
@Test public void testInvalidStructDef_MultiValuedAttributeNotArray() { AtlasAttributeDef invalidMultiValuedAttrib = new AtlasAttributeDef("invalidAttributeDef", ATLAS_TYPE_INT); invalidMultiValuedAttrib.setCardinality(Cardinality.LIST); AtlasStructDef invalidStructDef = ModelTestUtil.newStructDef(); invalidStructDef.addAttribute(invalidMultiValuedAttrib); try { AtlasStructType invalidStructType = new AtlasStructType(invalidStructDef, ModelTestUtil.getTypesRegistry()); fail("invalidStructDef not detected: structDef=" + invalidStructDef + "; structType=" + invalidStructType); } catch (AtlasBaseException excp) { assertTrue(excp.getAtlasErrorCode() == AtlasErrorCode.INVALID_ATTRIBUTE_TYPE_FOR_CARDINALITY); invalidStructDef.removeAttribute("invalidAttributeDef"); } }
@Test public void testInvalidStructDef_MultiValuedAttributeNotArray() { AtlasAttributeDef invalidMultiValuedAttrib = new AtlasAttributeDef("invalidAttributeDef", ATLAS_TYPE_INT); invalidMultiValuedAttrib.setCardinality(Cardinality.LIST); AtlasStructDef invalidStructDef = ModelTestUtil.newStructDef(); invalidStructDef.addAttribute(invalidMultiValuedAttrib); try { AtlasStructType invalidStructType = new AtlasStructType(invalidStructDef, ModelTestUtil.getTypesRegistry()); fail("invalidStructDef not detected: structDef=" + invalidStructDef + "; structType=" + invalidStructType); } catch (AtlasBaseException excp) { assertTrue(excp.getAtlasErrorCode() == AtlasErrorCode.INVALID_ATTRIBUTE_TYPE_FOR_CARDINALITY); invalidStructDef.removeAttribute("invalidAttributeDef"); } }
updatedDef.addAttribute(attributeDef);