public void removeAttribute(String attrName) { List<AtlasAttributeDef> a = this.attributeDefs; if (hasAttribute(a, attrName)) { List<AtlasAttributeDef> tmpList = new ArrayList<>(); // copy existing attributes, except ones having same name as the attribute being removed for (AtlasAttributeDef existingAttrDef : a) { if (!StringUtils.equalsIgnoreCase(existingAttrDef.getName(), attrName)) { tmpList.add(existingAttrDef); } } this.attributeDefs = tmpList; } }
public void removeAttribute(String attrName) { List<AtlasAttributeDef> a = this.attributeDefs; if (hasAttribute(a, attrName)) { List<AtlasAttributeDef> tmpList = new ArrayList<>(); // copy existing attributes, except ones having same name as the attribute being removed for (AtlasAttributeDef existingAttrDef : a) { if (!StringUtils.equalsIgnoreCase(existingAttrDef.getName(), attrName)) { tmpList.add(existingAttrDef); } } this.attributeDefs = tmpList; } }
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); } } }
@Test public void testStructDefHasAttribute() { AtlasStructDef structDef = ModelTestUtil.getStructDef(); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { assertTrue(structDef.hasAttribute(attributeDef.getName())); } assertFalse(structDef.hasAttribute("01234-xyzabc-;''-)(")); }
@Test public void testStructDefHasAttribute() { AtlasStructDef structDef = ModelTestUtil.getStructDef(); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { assertTrue(structDef.hasAttribute(attributeDef.getName())); } assertFalse(structDef.hasAttribute("01234-xyzabc-;''-)(")); }
@Test public void testStructDefRemoveAttribute() { AtlasStructDef structDef = ModelTestUtil.newStructDef(); String attrName = structDef.getAttributeDefs().get(0).getName(); assertTrue(structDef.hasAttribute(attrName)); structDef.removeAttribute(attrName); assertFalse(structDef.hasAttribute(attrName)); }
@Test public void testStructDefRemoveAttribute() { AtlasStructDef structDef = ModelTestUtil.newStructDef(); String attrName = structDef.getAttributeDefs().get(0).getName(); assertTrue(structDef.hasAttribute(attrName)); structDef.removeAttribute(attrName); assertFalse(structDef.hasAttribute(attrName)); }
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 testStructDefSetAttributeDefs() { AtlasStructDef structDef = ModelTestUtil.newStructDef(); List<AtlasAttributeDef> oldAttributes = structDef.getAttributeDefs(); List<AtlasAttributeDef> newttributes = ModelTestUtil.newAttributeDefsWithAllBuiltInTypes("newAttributes"); structDef.setAttributeDefs(newttributes); for (AtlasAttributeDef attributeDef : oldAttributes) { assertFalse(structDef.hasAttribute(attributeDef.getName())); } for (AtlasAttributeDef attributeDef : newttributes) { assertTrue(structDef.hasAttribute(attributeDef.getName())); } } }
@Test public void testStructDefSetAttributeDefs() { AtlasStructDef structDef = ModelTestUtil.newStructDef(); List<AtlasAttributeDef> oldAttributes = structDef.getAttributeDefs(); List<AtlasAttributeDef> newttributes = ModelTestUtil.newAttributeDefsWithAllBuiltInTypes("newAttributes"); structDef.setAttributeDefs(newttributes); for (AtlasAttributeDef attributeDef : oldAttributes) { assertFalse(structDef.hasAttribute(attributeDef.getName())); } for (AtlasAttributeDef attributeDef : newttributes) { assertTrue(structDef.hasAttribute(attributeDef.getName())); } } }