org.apache.atlas.model.typedef.AtlasEntityDef Java Examples
The following examples show how to use
org.apache.atlas.model.typedef.AtlasEntityDef.
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: TestAtlasEntityType.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Test public void testConstraintInValidInverseRef_NonExistingAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING, "expected invalid constraint failure - non-existing refAttribute"); }
Example #2
Source File: TestAtlasEntityType.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testConstraintInValidInverseRef_MissingParams() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithMissingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_MISSING_PARAMS, "expected invalid constraint failure - missing refAttribute"); }
Example #3
Source File: TypedefsJerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "testCreate") public void testGetDefinition() throws Exception { if (CollectionUtils.isNotEmpty(typeDefinitions.getEnumDefs())) { for (AtlasEnumDef atlasEnumDef : typeDefinitions.getEnumDefs()) { verifyByNameAndGUID(atlasEnumDef); } } if (CollectionUtils.isNotEmpty(typeDefinitions.getStructDefs())) { for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) { verifyByNameAndGUID(structDef); } } if (CollectionUtils.isNotEmpty(typeDefinitions.getClassificationDefs())) { for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) { verifyByNameAndGUID(classificationDef); } } if (CollectionUtils.isNotEmpty(typeDefinitions.getEntityDefs())) { for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) { verifyByNameAndGUID(entityDef); } } }
Example #4
Source File: EntityV2JerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testUTF8() throws Exception { String classType = randomString(); String attrName = randomUTF8(); String attrValue = randomUTF8(); AtlasEntityDef classTypeDef = AtlasTypeUtil .createClassTypeDef(classType, Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string")); AtlasTypesDef atlasTypesDef = new AtlasTypesDef(); atlasTypesDef.getEntityDefs().add(classTypeDef); createType(atlasTypesDef); AtlasEntity instance = new AtlasEntity(classType); instance.setAttribute(attrName, attrValue); AtlasEntityHeader entity = createEntity(instance); assertNotNull(entity); assertNotNull(entity.getGuid()); AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid()); assertEquals(entityByGuid.getAttribute(attrName), attrValue); }
Example #5
Source File: TestAtlasEntityType.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute"); }
Example #6
Source File: DefaultTypeSystem.java From incubator-atlas with Apache License 2.0 | 6 votes |
private void createTraitType(AtlasClassificationDef classificationDef) throws AtlasBaseException { try { typeDefStore.getClassificationDefByName(classificationDef.getName()); } catch (AtlasBaseException tne) { //Type not found . Create if (tne.getAtlasErrorCode() == AtlasErrorCode.TYPE_NAME_NOT_FOUND) { AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.of(classificationDef), ImmutableList.<AtlasEntityDef>of()); typeDefStore.createTypesDef(typesDef); } else { throw tne; } } }
Example #7
Source File: AtlasEntityDefStoreV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override public AtlasEntityDef create(AtlasEntityDef entityDef, Object preCreateResult) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.create({}, {})", entityDef, preCreateResult); } AtlasVertex vertex; if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) { vertex = preCreate(entityDef); } else { vertex = (AtlasVertex)preCreateResult; } updateVertexAddReferences(entityDef, vertex); AtlasEntityDef ret = toEntityDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.create({}, {}): {}", entityDef, preCreateResult, ret); } return ret; }
Example #8
Source File: AtlasEntityDefStoreV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override public List<AtlasEntityDef> getAll() throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.getAll()"); } List<AtlasEntityDef> ret = new ArrayList<>(); Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.CLASS); while (vertices.hasNext()) { ret.add(toEntityDef(vertices.next())); } if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.getAll(): count={}", ret.size()); } return ret; }
Example #9
Source File: TypedefsJerseyResourceIT.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Test public void testDuplicateCreate() throws Exception { AtlasEntityDef type = createClassTypeDef(randomString(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string")); AtlasTypesDef typesDef = new AtlasTypesDef(); typesDef.getEntityDefs().add(type); AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef); assertNotNull(created); try { created = clientV2.createAtlasTypeDefs(typesDef); fail("Expected 409"); } catch (AtlasServiceException e) { assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode()); } }
Example #10
Source File: AtlasTypeUtil.java From atlas with Apache License 2.0 | 6 votes |
public static AtlasTypesDef getTypesDef(AtlasBaseTypeDef typeDef) { AtlasTypesDef ret = new AtlasTypesDef(); if (typeDef != null) { if (typeDef.getClass().equals(AtlasEntityDef.class)) { ret.getEntityDefs().add((AtlasEntityDef) typeDef); } else if (typeDef.getClass().equals(AtlasRelationshipDef.class)) { ret.getRelationshipDefs().add((AtlasRelationshipDef) typeDef); } else if (typeDef.getClass().equals(AtlasClassificationDef.class)) { ret.getClassificationDefs().add((AtlasClassificationDef) typeDef); } else if (typeDef.getClass().equals(AtlasStructDef.class)) { ret.getStructDefs().add((AtlasStructDef) typeDef); } else if (typeDef.getClass().equals(AtlasEnumDef.class)) { ret.getEnumDefs().add((AtlasEnumDef) typeDef); } } return ret; }
Example #11
Source File: AtlasEntityStoreV2Test.java From atlas with Apache License 2.0 | 6 votes |
@BeforeClass public void setUp() throws Exception { super.setUp(); AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), TestUtilsV2.defineHiveTypes(), TestUtilsV2.defineTypeWithNestedCollectionAttributes(), TestUtilsV2.defineEnumTypes(), TestUtilsV2.defineBusinessMetadataTypes() }; createTypesDef(testTypesDefs); deptEntity = TestUtilsV2.createDeptEg2(); dbEntity = TestUtilsV2.createDBEntityV2(); tblEntity = TestUtilsV2.createTableEntityV2(dbEntity.getEntity()); nestedCollectionAttrEntity = TestUtilsV2.createNestedCollectionAttrEntity(); primitiveEntity = TestUtilsV2.createprimitiveEntityV2(); AtlasTypesDef typesDef11 = new AtlasTypesDef(); List primitiveEntityDef = new ArrayList<AtlasEntityDef>(); primitiveEntityDef.add(TestUtilsV2.createPrimitiveEntityDef()); typesDef11.setEntityDefs(primitiveEntityDef); typeDefStore.createTypesDef(typesDef11); }
Example #12
Source File: GraphBackedSearchIndexer.java From atlas with Apache License 2.0 | 6 votes |
private void createEdgeLabelsForStruct(AtlasGraphManagement management, AtlasEntityDef entityDef) { try { AtlasType type = typeRegistry.getType(entityDef.getName()); if (!(type instanceof AtlasEntityType)) { return; } AtlasEntityType entityType = (AtlasEntityType) type; for (AtlasAttributeDef attributeDef : entityDef.getAttributeDefs()) { AtlasAttribute attribute = entityType.getAttribute(attributeDef.getName()); if (attribute.getAttributeType().getTypeCategory() == TypeCategory.STRUCT) { String relationshipLabel = attribute.getRelationshipEdgeLabel(); createEdgeLabelUsingLabelName(management, relationshipLabel); } } } catch (AtlasBaseException e) { LOG.error("Error fetching type: {}", entityDef.getName(), e); } }
Example #13
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 #14
Source File: TestAtlasEntityType.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testConstraintInValidInverseRef_NonExistingAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING, "expected invalid constraint failure - non-existing refAttribute"); }
Example #15
Source File: AtlasEntityDefStoreV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override public AtlasEntityDef getByName(String name) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.getByName({})", name); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class); AtlasEntityDef ret = toEntityDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.getByName({}): {}", name, ret); } return ret; }
Example #16
Source File: TestAtlasEntityType.java From atlas with Apache License 2.0 | 6 votes |
private AtlasEntityDef createTableEntityDefWithOptions() { AtlasEntityDef table = new AtlasEntityDef(TYPE_TABLE); AtlasAttributeDef attrName = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING); AtlasAttributeDef attrColumns = new AtlasAttributeDef(ATTR_COLUMNS, AtlasBaseTypeDef.getArrayTypeName(TYPE_COLUMN)); AtlasAttributeDef attrOwner = new AtlasAttributeDef(ATTR_OWNER, AtlasBaseTypeDef.ATLAS_TYPE_STRING); attrColumns.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF)); table.addAttribute(attrName); table.addAttribute(attrColumns); table.addAttribute(attrOwner); Map<String,String> options = new HashMap<>(); String key = "dynAttribute:" + ATTR_OWNER; String value = "{" + ATTR_NAME + "}"; options.put(key,value); table.setOptions(options); return table; }
Example #17
Source File: TestUtilsV2.java From incubator-atlas with Apache License 2.0 | 6 votes |
public static AtlasTypesDef simpleType(){ AtlasEntityDef superTypeDefinition = AtlasTypeUtil.createClassTypeDef("h_type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef("attr", "string")); AtlasStructDef structTypeDefinition = new AtlasStructDef("s_type", "structType", "1.0", Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string"))); AtlasClassificationDef traitTypeDefinition = AtlasTypeUtil.createTraitTypeDef("t_type", "traitType", ImmutableSet.<String>of()); AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType", "1.0", Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1))); return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition), ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition)); }
Example #18
Source File: AtlasEntityDefStoreV1.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override public AtlasEntityDef updateByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.updateByGuid({})", guid); } validateType(entityDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex); updateVertexAddReferences(entityDef, vertex); AtlasEntityDef ret = toEntityDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
Example #19
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 #20
Source File: TypeAttributeDifferenceTest.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Test public void different_ReturnsDifference() throws Exception { AtlasEntityDef existing = getAtlasEntityDefWithAttributes("name"); AtlasEntityDef incoming = getAtlasEntityDefWithAttributes("name", "qualifiedName"); List<AtlasStructDef.AtlasAttributeDef> expectedAttributes = getAtlasAttributeDefs( "qualifiedName"); List<AtlasStructDef.AtlasAttributeDef> actualAttributes = invokeGetAttributesAbsentInExisting(existing, incoming); Assert.assertEquals(actualAttributes, expectedAttributes); }
Example #21
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 #22
Source File: AtlasEntityDefStoreV1Test.java From incubator-atlas with Apache License 2.0 | 5 votes |
@DataProvider public Object[][] invalidAttributeNameWithReservedKeywords(){ AtlasEntityDef invalidAttrNameType = AtlasTypeUtil.createClassTypeDef("Invalid_Attribute_Type", "description", ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("order", "string"), AtlasTypeUtil.createRequiredAttrDef("limit", "string")); return new Object[][] {{ invalidAttrNameType }}; }
Example #23
Source File: TypeConverterUtil.java From incubator-atlas with Apache License 2.0 | 5 votes |
public static AtlasTypesDef toAtlasTypesDef(String typeDefinition, AtlasTypeRegistry registry) throws AtlasBaseException { AtlasTypesDef ret = new AtlasTypesDef(); try { if (StringUtils.isEmpty(typeDefinition)) { throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition); } TypesDef typesDef = TypesSerialization.fromJson(typeDefinition); if (CollectionUtils.isNotEmpty(typesDef.enumTypesAsJavaList())) { List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.enumTypesAsJavaList()); ret.setEnumDefs(enumDefs); } if (CollectionUtils.isNotEmpty(typesDef.structTypesAsJavaList())) { List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.structTypesAsJavaList()); ret.setStructDefs(structDefs); } if (CollectionUtils.isNotEmpty(typesDef.classTypesAsJavaList())) { List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.classTypesAsJavaList(), registry); ret.setEntityDefs(entityDefs); } if (CollectionUtils.isNotEmpty(typesDef.traitTypesAsJavaList())) { List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.traitTypesAsJavaList()); ret.setClassificationDefs(classificationDefs); } } catch (Exception e) { LOG.error("Invalid type definition = {}", typeDefinition, e); throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition); } return ret; }
Example #24
Source File: TypeAttributeDifferenceTest.java From atlas with Apache License 2.0 | 5 votes |
@Test public void different_ReturnsDifference() throws Exception { AtlasEntityDef existing = getAtlasEntityDefWithAttributes("name"); AtlasEntityDef incoming = getAtlasEntityDefWithAttributes("name", "qualifiedName"); List<AtlasStructDef.AtlasAttributeDef> expectedAttributes = getAtlasAttributeDefs( "qualifiedName"); List<AtlasStructDef.AtlasAttributeDef> actualAttributes = invokeGetAttributesAbsentInExisting(existing, incoming); Assert.assertEquals(actualAttributes, expectedAttributes); }
Example #25
Source File: TypeAttributeDifferenceTest.java From atlas with Apache License 2.0 | 5 votes |
@Test public void entityDefWithNoAttributes() throws Exception { AtlasEntityDef existing = new AtlasEntityDef(); AtlasEntityDef incoming = new AtlasEntityDef(); List<AtlasStructDef.AtlasAttributeDef> expectedAttributes = new ArrayList<>(); List<AtlasStructDef.AtlasAttributeDef> actualAttributes = invokeGetAttributesAbsentInExisting(existing, incoming); Assert.assertEquals(actualAttributes, expectedAttributes); }
Example #26
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 #27
Source File: ReplicationEntityAttributeTest.java From atlas with Apache License 2.0 | 5 votes |
@BeforeClass public void setup() throws IOException, AtlasBaseException { basicSetup(typeDefStore, typeRegistry); createEntities(entityStore, ENTITIES_SUB_DIR, new String[]{"db", "table-columns"}); AtlasType refType = typeRegistry.getType("Referenceable"); AtlasEntityDef entityDef = (AtlasEntityDef) typeDefStore.getByName(refType.getTypeName()); assertNotNull(entityDef); }
Example #28
Source File: TestAtlasEntityType.java From incubator-atlas with Apache License 2.0 | 5 votes |
private AtlasEntityDef createColumnEntityDefWithNonExistingInverseAttribute() { AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN); AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE); Map<String, Object> params = new HashMap<>(); params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "non-existing:" + ATTR_COLUMNS); attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params)); column.addAttribute(attrTable); return column; }
Example #29
Source File: AtlasEntityDefStoreV2.java From atlas with Apache License 2.0 | 5 votes |
@Override public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.preDeleteByGuid({})", guid); } AtlasEntityDef existingDef = typeRegistry.getEntityDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete entity-def ", (existingDef != null ? existingDef.getName() : guid)); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS); String typeName = AtlasGraphUtilsV2.getEncodedProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); if (AtlasGraphUtilsV2.typeHasInstanceVertex(typeName)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); } if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } // error if we are trying to delete an entityDef that has a relationshipDef if (typeDefStore.hasIncomingEdgesWithLabel(ret, AtlasGraphUtilsV2.RELATIONSHIPTYPE_EDGE_LABEL)){ throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_RELATIONSHIPS, typeName); } typeDefStore.deleteTypeVertexOutEdges(ret); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.preDeleteByGuid({}): {}", guid, ret); } return ret; }
Example #30
Source File: TestAtlasEntityType.java From atlas with Apache License 2.0 | 5 votes |
private AtlasEntityDef createColumnEntityDef() { AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN); AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE); Map<String, Object> params = new HashMap<>(); params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_COLUMNS); attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params)); column.addAttribute(attrTable); return column; }