Java Code Examples for org.apache.atlas.type.AtlasType#toJson()

The following examples show how to use org.apache.atlas.type.AtlasType#toJson() . 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: TestAtlasRelationshipDef.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testRelationshipDefSerDeEmpty() throws AtlasBaseException {

    AtlasRelationshipEndDef ep1 = new AtlasRelationshipEndDef("typeA", "attr1", Cardinality.SINGLE);
    AtlasRelationshipEndDef ep2 = new AtlasRelationshipEndDef("typeB", "attr2", Cardinality.SINGLE);
    AtlasRelationshipDef relationshipDef = new AtlasRelationshipDef("emptyRelationshipDef", "desc 1", "version1",
            RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, ep1, ep2);

    String jsonString = AtlasType.toJson(relationshipDef);
    System.out.println(jsonString);
    assertNotNull(jsonString);

    AtlasRelationshipDef relationshipDef2 = AtlasType.fromJson(jsonString, AtlasRelationshipDef.class);
    String jsonString2 = AtlasType.toJson(relationshipDef2);

    assertEquals(jsonString, jsonString2);
    assertEquals(relationshipDef2, relationshipDef,
            "Incorrect serialization/deserialization of AtlasRelationshipDef");
}
 
Example 2
Source File: EntityJerseyResourceIT.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testUTF8() throws Exception {
    String              attrName            = randomUTF8();
    String              attrValue           = randomUTF8();
    String              classType           = randomString(); //Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
    ClassTypeDefinition classTypeDefinition = TypesUtil.createClassTypeDef(classType, null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef(attrName, AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef            typesDef            = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Collections.singletonList(classTypeDefinition));

    createType(typesDef);

    Referenceable entityToCreate  = new Referenceable(classType, Collections.singletonMap(attrName, attrValue));
    Id            guid            = createInstance(entityToCreate);
    ObjectNode    response        = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
    Object        objResponse     = response.get(AtlasClient.DEFINITION);
    String        jsonResponse    = AtlasType.toJson(objResponse);
    Referenceable createdEntity   = AtlasType.fromV1Json(jsonResponse, Referenceable.class);
    Object        entityAttrValue = createdEntity.get(attrName);

    Assert.assertEquals(entityAttrValue, attrValue,
                        "attrName=" + attrName + "; attrValue=" + attrValue + "; entityToCreate=" + entityToCreate + "; entityId=" + guid + "; getEntityResponse_Obj=" + objResponse + "; getEntityResponse_Json=" + jsonResponse + "; getEntityResponse_Entity=" + createdEntity);
}
 
Example 3
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
AtlasEntity serDeserEntity(AtlasEntity entity) throws IOException {
    //Convert from json to object and back to trigger the case where it gets translated to a map for attributes instead of AtlasEntity
    String      jsonString = AtlasType.toJson(entity);
    AtlasEntity newEntity  = AtlasType.fromJson(jsonString, AtlasEntity.class);

    return newEntity;
}
 
Example 4
Source File: TestAtlasClassificationDef.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testClassificationDefSerDe() {
    AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDef();

    String jsonString = AtlasType.toJson(classificationDef);

    AtlasClassificationDef classificationDef2 = AtlasType.fromJson(jsonString, AtlasClassificationDef.class);

    assertEquals(classificationDef2, classificationDef,
                 "Incorrect serialization/deserialization of AtlasClassificationDef");
}
 
Example 5
Source File: TestEntitiesREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
AtlasEntity serDeserEntity(AtlasEntity entity) throws IOException {
    //Convert from json to object and back to trigger the case where it gets translated to a map for attributes instead of AtlasEntity
    String      jsonString = AtlasType.toJson(entity);
    AtlasEntity newEntity  = AtlasType.fromJson(jsonString, AtlasEntity.class);

    return newEntity;
}
 
Example 6
Source File: AtlasGlossaryTerm.java    From atlas with Apache License 2.0 5 votes vote down vote up
@JsonIgnore
public String toAuditString() {
    AtlasGlossaryTerm t = new AtlasGlossaryTerm();
    t.setGuid(this.getGuid());
    t.setName(this.getName());
    t.setQualifiedName(this.getQualifiedName());

    return AtlasType.toJson(t);
}
 
Example 7
Source File: TestAtlasClassification.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testClassificationSerDe() throws AtlasBaseException {
    AtlasClassificationDef  classificationDef  = ModelTestUtil.getClassificationDef();
    AtlasTypeRegistry       typeRegistry       = ModelTestUtil.getTypesRegistry();
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());

    assertNotNull(classificationType);

    AtlasClassification ent1 = ModelTestUtil.newClassification(classificationDef, typeRegistry);

    String jsonString = AtlasType.toJson(ent1);

    AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);

    classificationType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification");
}
 
Example 8
Source File: TestAtlasClassification.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testClassificationSerDeWithSuperType() throws AtlasBaseException {
    AtlasClassificationDef  classificationDef  = ModelTestUtil.getClassificationDefWithSuperType();
    AtlasTypeRegistry       typeRegistry       = ModelTestUtil.getTypesRegistry();
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());

    assertNotNull(classificationType);

    AtlasClassification ent1 =  classificationType.createDefaultValue();

    String jsonString = AtlasType.toJson(ent1);

    AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);

    classificationType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification with superType");
}
 
Example 9
Source File: TestAtlasEntity.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testEntitySerDeWithSuperType() throws AtlasBaseException {
    AtlasEntityDef    entityDef    = ModelTestUtil.getEntityDefWithSuperType();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType   entityType   = typeRegistry.getEntityTypeByName(entityDef.getName());

    assertNotNull(entityType);

    AtlasEntity ent1 =  entityType.createDefaultValue();

    String jsonString = AtlasType.toJson(ent1);

    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);

    entityType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity with superType");
}
 
Example 10
Source File: AtlasClient.java    From atlas with Apache License 2.0 4 votes vote down vote up
public TypesDef getType(String typeName) throws AtlasServiceException {
    ObjectNode response = callAPIWithBodyAndParams(API_V1.GET_TYPE, null, typeName);
    String     typeJson = AtlasType.toJson(response.get(DEFINITION));
    return AtlasType.fromV1Json(typeJson, TypesDef.class);
}
 
Example 11
Source File: TestAtlasClassification.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testClassificationSerDeWithSuperTypes() throws AtlasBaseException {
    AtlasClassificationDef  classificationDef  = ModelTestUtil.getClassificationDefWithSuperTypes();
    AtlasTypeRegistry       typeRegistry       = ModelTestUtil.getTypesRegistry();
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());

    assertNotNull(classificationType);

    AtlasClassification ent1 =  classificationType.createDefaultValue();

    String jsonString = AtlasType.toJson(ent1);

    AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);

    classificationType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification with superTypes");
}
 
Example 12
Source File: TestAtlasClassification.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testClassificationSerDeWithSuperTypes() throws AtlasBaseException {
    AtlasClassificationDef  classificationDef  = ModelTestUtil.getClassificationDefWithSuperTypes();
    AtlasTypeRegistry       typeRegistry       = ModelTestUtil.getTypesRegistry();
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());

    assertNotNull(classificationType);

    AtlasClassification ent1 =  classificationType.createDefaultValue();

    String jsonString = AtlasType.toJson(ent1);

    AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);

    classificationType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification with superTypes");
}
 
Example 13
Source File: AtlasServer.java    From atlas with Apache License 2.0 4 votes vote down vote up
private void updateReplicationMap(Map<String, Object> replicationDetailsMap) {
    String json = AtlasType.toJson(replicationDetailsMap);

    setAdditionalInfo(KEY_REPLICATION_DETAILS, json);
}
 
Example 14
Source File: TestAtlasEntity.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testEntitySerDe() throws AtlasBaseException {
    AtlasEntityDef    entityDef    = ModelTestUtil.getEntityDef();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType   entityType   = typeRegistry.getEntityTypeByName(entityDef.getName());

    assertNotNull(entityType);

    AtlasEntity ent1 =  entityType.createDefaultValue();

    String jsonString = AtlasType.toJson(ent1);

    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);

    entityType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity");
}
 
Example 15
Source File: ZipSinkTest.java    From atlas with Apache License 2.0 4 votes vote down vote up
private boolean compareJsonWithObject(String s, AtlasExportResult defaultExportResult) {
    String json = AtlasType.toJson(defaultExportResult);
    return json.equals(s);
}
 
Example 16
Source File: TestAtlasEntity.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testEntitySerDeWithSuperType() throws AtlasBaseException {
    AtlasEntityDef    entityDef    = ModelTestUtil.getEntityDefWithSuperType();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType   entityType   = typeRegistry.getEntityTypeByName(entityDef.getName());

    assertNotNull(entityType);

    AtlasEntity ent1 =  entityType.createDefaultValue();

    String jsonString = AtlasType.toJson(ent1);

    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);

    entityType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity with superType");
}
 
Example 17
Source File: TestAtlasEntity.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testEntitySerDeWithSuperTypes() throws AtlasBaseException {
    AtlasEntityDef    entityDef    = ModelTestUtil.getEntityDefWithSuperTypes();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType   entityType   = typeRegistry.getEntityTypeByName(entityDef.getName());

    assertNotNull(entityType);

    AtlasEntity ent1 =  entityType.createDefaultValue();

    String jsonString = AtlasType.toJson(ent1);

    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);

    entityType.normalizeAttributeValues(ent2);

    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity with superTypes");
}
 
Example 18
Source File: TestAtlasEntityDef.java    From atlas with Apache License 2.0 3 votes vote down vote up
@Test
public void testEntityDefSerDe() {
    AtlasEntityDef entityDef = ModelTestUtil.getEntityDef();

    String jsonString = AtlasType.toJson(entityDef);

    AtlasEntityDef entityDef2 = AtlasType.fromJson(jsonString, AtlasEntityDef.class);

    assertEquals(entityDef2, entityDef, "Incorrect serialization/deserialization of AtlasEntityDef");
}
 
Example 19
Source File: TestAtlasEnumDef.java    From atlas with Apache License 2.0 3 votes vote down vote up
@Test
public void testEnumDefSerDeEmpty() {
    AtlasEnumDef enumDef1 = new AtlasEnumDef();

    String jsonString = AtlasType.toJson(enumDef1);

    AtlasEnumDef enumDef2 = AtlasType.fromJson(jsonString, AtlasEnumDef.class);

    assertEquals(enumDef1, enumDef2, "Incorrect serialization/deserialization of AtlasEnumDef");
}
 
Example 20
Source File: AtlasClient.java    From atlas with Apache License 2.0 2 votes vote down vote up
/**
 * Get an entity given the entity id
 * @param guid entity id
 * @return result object
 * @throws AtlasServiceException
 */
public Referenceable getEntity(String guid) throws AtlasServiceException {
    ObjectNode jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ENTITY, null, guid);
    String entityInstanceDefinition = AtlasType.toJson(jsonResponse.get(AtlasClient.DEFINITION));
    return AtlasType.fromV1Json(entityInstanceDefinition, Referenceable.class);
}