Java Code Examples for org.apache.atlas.model.typedef.AtlasTypesDef#getEntityDefs()
The following examples show how to use
org.apache.atlas.model.typedef.AtlasTypesDef#getEntityDefs() .
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: RestUtilsTest.java From incubator-atlas with Apache License 2.0 | 6 votes |
private List<AtlasEntityDef> convertV1toV2(List<HierarchicalTypeDefinition<ClassType>> types) throws AtlasBaseException { ImmutableList<HierarchicalTypeDefinition<ClassType>> classTypeList = ImmutableList .<HierarchicalTypeDefinition<ClassType>> builder().addAll(types).build(); TypesDef toConvert = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition> of(), ImmutableList.<StructTypeDefinition> of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>> of(), classTypeList); String json = TypesSerialization.toJson(toConvert); AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry(); AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry); List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs(); return convertedEntityDefs; }
Example 2
Source File: RestUtilsTest.java From atlas with Apache License 2.0 | 5 votes |
private List<AtlasEntityDef> convertV1toV2(List<ClassTypeDefinition> types) throws AtlasBaseException { List<ClassTypeDefinition> classTypeList = new ArrayList(types); TypesDef toConvert = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), classTypeList); String json = AtlasType.toV1Json(toConvert); AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry(); AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry); List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs(); return convertedEntityDefs; }
Example 3
Source File: TestLoadModelUtils.java From atlas with Apache License 2.0 | 5 votes |
private static void addReplicationAttributes(AtlasTypesDef typesFromJson) throws IOException { if(typesFromJson.getEntityDefs() == null || typesFromJson.getEntityDefs().size() == 0) return; AtlasEntityDef ed = typesFromJson.getEntityDefs().get(0); if(!ed.getName().equals("Referenceable")) return; String replAttr1Json = TestResourceFileUtils.getJson("stocksDB-Entities","replicationAttrs"); String replAttr2Json = StringUtils.replace(replAttr1Json, "From", "To"); ed.addAttribute(AtlasType.fromJson(replAttr1Json, AtlasStructDef.AtlasAttributeDef.class)); ed.addAttribute(AtlasType.fromJson(replAttr2Json, AtlasStructDef.AtlasAttributeDef.class)); }
Example 4
Source File: AtlasTypeUtil.java From atlas with Apache License 2.0 | 5 votes |
public static List<AtlasTypeDefHeader> toTypeDefHeader(AtlasTypesDef typesDef) { List<AtlasTypeDefHeader> headerList = new LinkedList<>(); if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) { for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) { headerList.add(new AtlasTypeDefHeader(enumDef)); } } if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { for (AtlasStructDef structDef : typesDef.getStructDefs()) { headerList.add(new AtlasTypeDefHeader(structDef)); } } if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) { for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) { headerList.add(new AtlasTypeDefHeader(classificationDef)); } } if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) { for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) { headerList.add(new AtlasTypeDefHeader(entityDef)); } } if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { headerList.add(new AtlasTypeDefHeader(relationshipDef)); } } return headerList; }
Example 5
Source File: BaseResourceIT.java From incubator-atlas with Apache License 2.0 | 5 votes |
protected void batchCreateTypes(AtlasTypesDef typesDef) throws AtlasServiceException { AtlasTypesDef toCreate = new AtlasTypesDef(); for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) { if (atlasClientV2.typeWithNameExists(enumDef.getName())) { LOG.warn("Type with name {} already exists. Skipping", enumDef.getName()); } else { toCreate.getEnumDefs().add(enumDef); } } for (AtlasStructDef structDef : typesDef.getStructDefs()) { if (atlasClientV2.typeWithNameExists(structDef.getName())) { LOG.warn("Type with name {} already exists. Skipping", structDef.getName()); } else { toCreate.getStructDefs().add(structDef); } } for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) { if (atlasClientV2.typeWithNameExists(entityDef.getName())) { LOG.warn("Type with name {} already exists. Skipping", entityDef.getName()); } else { toCreate.getEntityDefs().add(entityDef); } } for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) { if (atlasClientV2.typeWithNameExists(classificationDef.getName())) { LOG.warn("Type with name {} already exists. Skipping", classificationDef.getName()); } else { toCreate.getClassificationDefs().add(classificationDef); } } atlasClientV2.createAtlasTypeDefs(toCreate); }
Example 6
Source File: TypeAttributeDifference.java From incubator-atlas with Apache License 2.0 | 5 votes |
private void updateEntityDef(AtlasTypesDef typeDefinitionMap, AtlasImportResult result) throws AtlasBaseException { for (AtlasEntityDef def: typeDefinitionMap.getEntityDefs()) { AtlasEntityDef existing = typeRegistry.getEntityDefByName(def.getName()); if(existing != null && addAttributes(existing, def)) { typeDefStore.updateEntityDefByName(existing.getName(), existing); result.incrementMeticsCounter("typedef:entitydef:update"); } } }
Example 7
Source File: AtlasAPIV2ServerEmulator.java From nifi with Apache License 2.0 | 5 votes |
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final AtlasTypesDef newTypes = readInputJSON(req, AtlasTypesDef.class); final Map<String, AtlasEntityDef> defs = new HashMap<>(); for (AtlasEntityDef existingDef : atlasTypesDef.getEntityDefs()) { defs.put(existingDef.getName(), existingDef); } for (AtlasEntityDef entityDef : newTypes.getEntityDefs()) { defs.put(entityDef.getName(), entityDef); } atlasTypesDef.setEntityDefs(defs.values().stream().collect(Collectors.toList())); respondWithJson(resp, atlasTypesDef); }
Example 8
Source File: TypedefsJerseyResourceIT.java From atlas with Apache License 2.0 | 4 votes |
@Test public void testUpdate() throws Exception { String entityType = randomString(); AtlasEntityDef typeDefinition = createClassTypeDef(entityType, Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string")); AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); atlasTypesDef.getEntityDefs().add(typeDefinition); AtlasTypesDef createdTypeDefs = clientV2.createAtlasTypeDefs(atlasTypesDef); assertNotNull(createdTypeDefs); assertEquals(createdTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size()); //Add attribute description typeDefinition = createClassTypeDef(typeDefinition.getName(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string")); emptyTypeDefs(atlasTypesDef); atlasTypesDef.getEntityDefs().add(typeDefinition); AtlasTypesDef updatedTypeDefs = clientV2.updateAtlasTypeDefs(atlasTypesDef); assertNotNull(updatedTypeDefs); assertEquals(updatedTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size()); assertEquals(updatedTypeDefs.getEntityDefs().get(0).getName(), atlasTypesDef.getEntityDefs().get(0).getName()); MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl(); filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY"); AtlasTypesDef allTypeDefs = clientV2.getAllTypeDefs(new SearchFilter(filterParams)); assertNotNull(allTypeDefs); Boolean entityDefFound = false; for (AtlasEntityDef atlasEntityDef : allTypeDefs.getEntityDefs()){ if (atlasEntityDef.getName().equals(typeDefinition.getName())) { assertEquals(atlasEntityDef.getAttributeDefs().size(), 2); entityDefFound = true; break; } } assertTrue(entityDefFound, "Required entityDef not found."); }
Example 9
Source File: AtlasTypeDefStoreInitializer.java From atlas with Apache License 2.0 | 4 votes |
public static AtlasTypesDef getTypesToCreate(AtlasTypesDef typesDef, AtlasTypeRegistry typeRegistry) { AtlasTypesDef typesToCreate = new AtlasTypesDef(); if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) { for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) { if (!typeRegistry.isRegisteredType(enumDef.getName())) { typesToCreate.getEnumDefs().add(enumDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { for (AtlasStructDef structDef : typesDef.getStructDefs()) { if (!typeRegistry.isRegisteredType(structDef.getName())) { typesToCreate.getStructDefs().add(structDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) { for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) { if (!typeRegistry.isRegisteredType(classificationDef.getName())) { typesToCreate.getClassificationDefs().add(classificationDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) { for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) { if (!typeRegistry.isRegisteredType(entityDef.getName())) { typesToCreate.getEntityDefs().add(entityDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { if (!typeRegistry.isRegisteredType(relationshipDef.getName())) { typesToCreate.getRelationshipDefs().add(relationshipDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) { for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) { if (!typeRegistry.isRegisteredType(businessMetadataDef.getName())) { typesToCreate.getBusinessMetadataDefs().add(businessMetadataDef); } } } return typesToCreate; }
Example 10
Source File: AtlasTypeDefStoreInitializer.java From atlas with Apache License 2.0 | 4 votes |
public static AtlasTypesDef getTypesToUpdate(AtlasTypesDef typesDef, AtlasTypeRegistry typeRegistry, boolean checkTypeVersion) { AtlasTypesDef typesToUpdate = new AtlasTypesDef(); if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { for (AtlasStructDef newStructDef : typesDef.getStructDefs()) { AtlasStructDef oldStructDef = typeRegistry.getStructDefByName(newStructDef.getName()); if (oldStructDef == null) { continue; } if (updateTypeAttributes(oldStructDef, newStructDef, checkTypeVersion)) { typesToUpdate.getStructDefs().add(newStructDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) { for (AtlasClassificationDef newClassifDef : typesDef.getClassificationDefs()) { AtlasClassificationDef oldClassifDef = typeRegistry.getClassificationDefByName(newClassifDef.getName()); if (oldClassifDef == null) { continue; } if (updateTypeAttributes(oldClassifDef, newClassifDef, checkTypeVersion)) { typesToUpdate.getClassificationDefs().add(newClassifDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) { for (AtlasEntityDef newEntityDef : typesDef.getEntityDefs()) { AtlasEntityDef oldEntityDef = typeRegistry.getEntityDefByName(newEntityDef.getName()); if (oldEntityDef == null) { continue; } if (updateTypeAttributes(oldEntityDef, newEntityDef, checkTypeVersion)) { typesToUpdate.getEntityDefs().add(newEntityDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) { for (AtlasEnumDef newEnumDef : typesDef.getEnumDefs()) { AtlasEnumDef oldEnumDef = typeRegistry.getEnumDefByName(newEnumDef.getName()); if (oldEnumDef == null) { continue; } if (isTypeUpdateApplicable(oldEnumDef, newEnumDef, checkTypeVersion)) { if (CollectionUtils.isNotEmpty(oldEnumDef.getElementDefs())) { for (AtlasEnumElementDef oldEnumElem : oldEnumDef.getElementDefs()) { if (!newEnumDef.hasElement(oldEnumElem.getValue())) { newEnumDef.addElement(oldEnumElem); } } } typesToUpdate.getEnumDefs().add(newEnumDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { AtlasRelationshipDef oldRelationshipDef = typeRegistry.getRelationshipDefByName(relationshipDef.getName()); if (oldRelationshipDef == null) { continue; } if (updateTypeAttributes(oldRelationshipDef, relationshipDef, checkTypeVersion)) { typesToUpdate.getRelationshipDefs().add(relationshipDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) { for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) { AtlasBusinessMetadataDef oldDef = typeRegistry.getBusinessMetadataDefByName(businessMetadataDef.getName()); if (oldDef == null) { continue; } if (updateTypeAttributes(oldDef, businessMetadataDef, checkTypeVersion)) { typesToUpdate.getBusinessMetadataDefs().add(businessMetadataDef); } } } return typesToUpdate; }
Example 11
Source File: TypesDefScrubber.java From atlas with Apache License 2.0 | 4 votes |
public AtlasTypesDef scrub(AtlasTypesDef typesDef) { this.typesDef = typesDef; display("incoming: ", typesDef); createClassificationNameIndexMap(typesDef.getClassificationDefs()); for (AtlasStructDef structDef : new ArrayList<>(typesDef.getStructDefs())) { // work on copy of typesDef.getStructDefs(), as the list is modified by checkAndUpdate() checkAndUpdate(structDef); } for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) { checkAndUpdate(entityDef); } display("scrubbed: ", typesDef); return typesDef; }
Example 12
Source File: TypedefsJerseyResourceIT.java From incubator-atlas with Apache License 2.0 | 4 votes |
@Test public void testUpdate() throws Exception { String entityType = randomString(); AtlasEntityDef typeDefinition = createClassTypeDef(entityType, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string")); AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); atlasTypesDef.getEntityDefs().add(typeDefinition); AtlasTypesDef createdTypeDefs = clientV2.createAtlasTypeDefs(atlasTypesDef); assertNotNull(createdTypeDefs); assertEquals(createdTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size()); //Add attribute description typeDefinition = createClassTypeDef(typeDefinition.getName(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string")); emptyTypeDefs(atlasTypesDef); atlasTypesDef.getEntityDefs().add(typeDefinition); AtlasTypesDef updatedTypeDefs = clientV2.updateAtlasTypeDefs(atlasTypesDef); assertNotNull(updatedTypeDefs); assertEquals(updatedTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size()); assertEquals(updatedTypeDefs.getEntityDefs().get(0).getName(), atlasTypesDef.getEntityDefs().get(0).getName()); MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl(); filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY"); AtlasTypesDef allTypeDefs = clientV2.getAllTypeDefs(new SearchFilter(filterParams)); assertNotNull(allTypeDefs); Boolean entityDefFound = false; for (AtlasEntityDef atlasEntityDef : allTypeDefs.getEntityDefs()){ if (atlasEntityDef.getName().equals(typeDefinition.getName())) { assertEquals(atlasEntityDef.getAttributeDefs().size(), 2); entityDefFound = true; break; } } assertTrue(entityDefFound, "Required entityDef not found."); }
Example 13
Source File: AtlasTypeDefStoreInitializer.java From incubator-atlas with Apache License 2.0 | 4 votes |
public static AtlasTypesDef getTypesToCreate(AtlasTypesDef typesDef, AtlasTypeRegistry typeRegistry) { AtlasTypesDef typesToCreate = new AtlasTypesDef(); if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) { for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) { if (!typeRegistry.isRegisteredType(enumDef.getName())) { typesToCreate.getEnumDefs().add(enumDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { for (AtlasStructDef structDef : typesDef.getStructDefs()) { if (!typeRegistry.isRegisteredType(structDef.getName())) { typesToCreate.getStructDefs().add(structDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) { for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) { if (!typeRegistry.isRegisteredType(classificationDef.getName())) { typesToCreate.getClassificationDefs().add(classificationDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) { for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) { if (!typeRegistry.isRegisteredType(entityDef.getName())) { typesToCreate.getEntityDefs().add(entityDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { if (!typeRegistry.isRegisteredType(relationshipDef.getName())) { typesToCreate.getRelationshipDefs().add(relationshipDef); } } } return typesToCreate; }
Example 14
Source File: AtlasTypeDefStoreInitializer.java From incubator-atlas with Apache License 2.0 | 4 votes |
public static AtlasTypesDef getTypesToUpdate(AtlasTypesDef typesDef, AtlasTypeRegistry typeRegistry) { AtlasTypesDef typesToUpdate = new AtlasTypesDef(); if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { for (AtlasStructDef newStructDef : typesDef.getStructDefs()) { AtlasStructDef oldStructDef = typeRegistry.getStructDefByName(newStructDef.getName()); if (oldStructDef == null) { continue; } if (updateTypeAttributes(oldStructDef, newStructDef)) { typesToUpdate.getStructDefs().add(newStructDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) { for (AtlasClassificationDef newClassifDef : typesDef.getClassificationDefs()) { AtlasClassificationDef oldClassifDef = typeRegistry.getClassificationDefByName(newClassifDef.getName()); if (oldClassifDef == null) { continue; } if (updateTypeAttributes(oldClassifDef, newClassifDef)) { typesToUpdate.getClassificationDefs().add(newClassifDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) { for (AtlasEntityDef newEntityDef : typesDef.getEntityDefs()) { AtlasEntityDef oldEntityDef = typeRegistry.getEntityDefByName(newEntityDef.getName()); if (oldEntityDef == null) { continue; } if (updateTypeAttributes(oldEntityDef, newEntityDef)) { typesToUpdate.getEntityDefs().add(newEntityDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) { for (AtlasEnumDef newEnumDef : typesDef.getEnumDefs()) { AtlasEnumDef oldEnumDef = typeRegistry.getEnumDefByName(newEnumDef.getName()); if (oldEnumDef == null) { continue; } if (isTypeUpdateApplicable(oldEnumDef, newEnumDef)) { if (CollectionUtils.isNotEmpty(oldEnumDef.getElementDefs())) { for (AtlasEnumElementDef oldEnumElem : oldEnumDef.getElementDefs()) { if (!newEnumDef.hasElement(oldEnumElem.getValue())) { newEnumDef.addElement(oldEnumElem); } } } typesToUpdate.getEnumDefs().add(newEnumDef); } } } if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { AtlasRelationshipDef oldRelationshipDef = typeRegistry.getRelationshipDefByName(relationshipDef.getName()); if (oldRelationshipDef == null) { continue; } if (updateTypeAttributes(oldRelationshipDef, relationshipDef)) { typesToUpdate.getRelationshipDefs().add(relationshipDef); } } } return typesToUpdate; }