@VisibleForTesting public static List<Struct> getAllTraits(Referenceable entityDefinition, AtlasTypeRegistry typeRegistry) throws AtlasException { List<Struct> ret = new ArrayList<>(); for (String traitName : entityDefinition.getTraitNames()) { Struct trait = entityDefinition.getTrait(traitName); AtlasClassificationType traitType = typeRegistry.getClassificationTypeByName(traitName); Set<String> superTypeNames = traitType != null ? traitType.getAllSuperTypes() : null; ret.add(trait); if (CollectionUtils.isNotEmpty(superTypeNames)) { for (String superTypeName : superTypeNames) { Struct superTypeTrait = new Struct(superTypeName); if (MapUtils.isNotEmpty(trait.getValues())) { AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName); if (superType != null && MapUtils.isNotEmpty(superType.getAllAttributes())) { Map<String, Object> superTypeTraitAttributes = new HashMap<>(); for (Map.Entry<String, Object> attrEntry : trait.getValues().entrySet()) { String attrName = attrEntry.getKey(); if (superType.getAllAttributes().containsKey(attrName)) { superTypeTraitAttributes.put(attrName, attrEntry.getValue()); } } superTypeTrait.setValues(superTypeTraitAttributes); } } ret.add(superTypeTrait); } } } return ret; }
AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName); if (superType != null && MapUtils.isNotEmpty(superType.getAllAttributes())) { Map<String, Object> superTypeTraitAttributes = new HashMap<>(); String attrName = attrEntry.getKey(); if (superType.getAllAttributes().containsKey(attrName)) { superTypeTraitAttributes.put(attrName, attrEntry.getValue());
AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName); if (superType != null && MapUtils.isNotEmpty(superType.getAllAttributes())) { Map<String, Object> superTypeTraitAttributes = new HashMap<>(); String attrName = attrEntry.getKey(); if (superType.getAllAttributes().containsKey(attrName)) { superTypeTraitAttributes.put(attrName, attrEntry.getValue());
AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName); if (superType != null && MapUtils.isNotEmpty(superType.getAllAttributes())) { Map<String, Object> superTypeClassificationAttributes = new HashMap<>(); String attrName = attrEntry.getKey(); if (superType.getAllAttributes().containsKey(attrName)) { superTypeClassificationAttributes.put(attrName, attrEntry.getValue());
private void validateAttributeNames(AtlasTypeRegistry typeRegistry, String typeName, Set<String> attributeNames) { AtlasType type = null; try { type = typeRegistry.getType(typeName); } catch (AtlasBaseException excp) { } Map<String, AtlasStructType.AtlasAttribute> attributes = null; if (type != null) { if (type instanceof AtlasEntityType) { attributes = ((AtlasEntityType) type).getAllAttributes(); } else if (type instanceof AtlasClassificationType) { attributes = ((AtlasClassificationType) type).getAllAttributes(); } } assertNotNull(attributes); assertEquals(attributes.keySet(), attributeNames); } }
@Test(dataProvider = "hdfs_path1", expectedExceptions = AtlasBaseException.class) public void importHdfs_path1(ZipSource zipSource) throws IOException, AtlasBaseException { loadBaseModel(); loadFsModel(); loadModelFromResourcesJson("tag1.json", typeDefStore, typeRegistry); try { runImportWithNoParameters(importService, zipSource); } catch (AtlasBaseException e) { assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.INVALID_IMPORT_ATTRIBUTE_TYPE_CHANGED); AtlasClassificationType tag1 = typeRegistry.getClassificationTypeByName("tag1"); assertNotNull(tag1); assertEquals(tag1.getAllAttributes().size(), 2); throw e; } }