Search in sources :

Example 1 with AtlasGlossaryCategory

use of org.apache.atlas.model.glossary.AtlasGlossaryCategory in project atlas by apache.

the class GlossaryREST method partialUpdateGlossaryCategory.

/**
 * Partially update the glossary category
 * @param categoryGuid unique identifier for glossary term
 * @param partialUpdates Map containing keys as attribute names and values as corresponding attribute values
 * @return Updated glossary category
 * @throws AtlasBaseException
 * @HTTP 200 If glossary category partial update was successful
 * @HTTP 404 If glossary category guid in invalid
 * @HTTP 400 If category attributes are invalid
 */
@PUT
@Path("/category/{categoryGuid}/partial")
@Timed
public AtlasGlossaryCategory partialUpdateGlossaryCategory(@PathParam("categoryGuid") String categoryGuid, Map<String, String> partialUpdates) throws AtlasBaseException {
    Servlets.validateQueryParamLength("categoryGuid", categoryGuid);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.partialUpdateGlossaryCategory()");
        }
        if (MapUtils.isEmpty(partialUpdates)) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "PartialUpdates missing or empty");
        }
        AtlasGlossaryCategory glossaryCategory = glossaryService.getCategory(categoryGuid);
        for (Map.Entry<String, String> entry : partialUpdates.entrySet()) {
            try {
                glossaryCategory.setAttribute(entry.getKey(), entry.getValue());
            } catch (IllegalArgumentException e) {
                throw new AtlasBaseException(AtlasErrorCode.INVALID_PARTIAL_UPDATE_ATTR, "Glossary Category", entry.getKey());
            }
        }
        return glossaryService.updateCategory(glossaryCategory);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) Map(java.util.Map) Path(javax.ws.rs.Path) Timed(org.apache.atlas.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 2 with AtlasGlossaryCategory

use of org.apache.atlas.model.glossary.AtlasGlossaryCategory in project atlas by apache.

the class GlossaryREST method getGlossaryCategory.

/**
 * Get specific glossary category
 * @param categoryGuid unique identifier for glossary category
 * @return Glossary category
 * @throws AtlasBaseException
 * @HTTP 200 If glossary category exists for given GUID
 * @HTTP 404 If glossary category GUID is invalid
 */
@GET
@Path("/category/{categoryGuid}")
@Timed
public AtlasGlossaryCategory getGlossaryCategory(@PathParam("categoryGuid") String categoryGuid) throws AtlasBaseException {
    Servlets.validateQueryParamLength("categoryGuid", categoryGuid);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaryCategory(" + categoryGuid + ")");
        }
        AtlasGlossaryCategory ret = glossaryService.getCategory(categoryGuid);
        if (ret == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
        }
        return ret;
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) Path(javax.ws.rs.Path) Timed(org.apache.atlas.annotation.Timed) GET(javax.ws.rs.GET)

Example 3 with AtlasGlossaryCategory

use of org.apache.atlas.model.glossary.AtlasGlossaryCategory in project atlas by apache.

the class GlossaryClientV2IT method testCreateGlossaryCategories.

@Test(dependsOnMethods = "testCreateGlossaryCategory")
public void testCreateGlossaryCategories() throws Exception {
    List<AtlasGlossaryCategory> glossaryCategories = new ArrayList<>();
    AtlasGlossaryCategory category1 = new AtlasGlossaryCategory();
    AtlasGlossaryHeader header1 = new AtlasGlossaryHeader();
    header1.setGlossaryGuid(healthCareGlossary.getGuid());
    header1.setDisplayText(healthCareGlossary.getName());
    category1.setAnchor(header1);
    category1.setName("category1ForEducation");
    glossaryCategories.add(category1);
    // Setting different category
    AtlasGlossaryCategory category2 = new AtlasGlossaryCategory();
    category2.setAnchor(header1);
    category2.setName("category2ForEducation");
    glossaryCategories.add(category2);
    List<AtlasGlossaryCategory> list = atlasClientV2.createGlossaryCategories(glossaryCategories);
    assertNotNull(list);
    assertEquals(list.size(), 2);
}
Also used : AtlasGlossaryHeader(org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader) ArrayList(java.util.ArrayList) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) Test(org.testng.annotations.Test)

Example 4 with AtlasGlossaryCategory

use of org.apache.atlas.model.glossary.AtlasGlossaryCategory in project atlas by apache.

the class GlossaryClientV2IT method testPartialUpdateCategoryByGuid.

@Test(dependsOnMethods = "testCreateGlossary")
public void testPartialUpdateCategoryByGuid() throws Exception {
    Map<String, String> partialUpdates = new HashMap<>();
    partialUpdates.put("shortDescription", "shortDescriptionCategory");
    partialUpdates.put("longDescription", "longDescriptionCategory");
    AtlasGlossaryCategory category = atlasClientV2.partialUpdateCategoryByGuid(educationCategory.getGuid(), partialUpdates);
    assertNotNull(category);
    assertEquals(category.getShortDescription(), "shortDescriptionCategory");
    assertEquals(category.getLongDescription(), "longDescriptionCategory");
}
Also used : HashMap(java.util.HashMap) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) Test(org.testng.annotations.Test)

Example 5 with AtlasGlossaryCategory

use of org.apache.atlas.model.glossary.AtlasGlossaryCategory in project atlas by apache.

the class GlossaryServiceTest method testCategoryCreation.

@Test(groups = "Glossary.CREATE", dependsOnMethods = "testCreateGlossary")
public void testCategoryCreation() {
    try {
        customerCategory = glossaryService.createCategory(customerCategory);
        AtlasRelatedCategoryHeader parentHeader = new AtlasRelatedCategoryHeader();
        parentHeader.setCategoryGuid(customerCategory.getGuid());
        // Test parent relation
        accountCategory.setParentCategory(parentHeader);
        List<AtlasGlossaryCategory> categories = glossaryService.createCategories(Arrays.asList(accountCategory, mortgageCategory));
        accountCategory.setGuid(categories.get(0).getGuid());
        assertNotNull(accountCategory.getParentCategory());
        assertEquals(accountCategory.getParentCategory().getCategoryGuid(), customerCategory.getGuid());
        assertTrue(accountCategory.getQualifiedName().endsWith(customerCategory.getQualifiedName()));
        mortgageCategory.setGuid(categories.get(1).getGuid());
        assertNull(mortgageCategory.getParentCategory());
    } catch (AtlasBaseException e) {
        fail("Category creation should've succeeded", e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGlossaryCategory(org.apache.atlas.model.glossary.AtlasGlossaryCategory) AtlasRelatedCategoryHeader(org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader) Test(org.testng.annotations.Test)

Aggregations

AtlasGlossaryCategory (org.apache.atlas.model.glossary.AtlasGlossaryCategory)29 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)18 Test (org.testng.annotations.Test)10 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)9 AtlasRelatedCategoryHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader)8 ArrayList (java.util.ArrayList)7 AtlasGlossary (org.apache.atlas.model.glossary.AtlasGlossary)5 AtlasRelatedTermHeader (org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader)5 HashMap (java.util.HashMap)4 AtlasGlossaryTerm (org.apache.atlas.model.glossary.AtlasGlossaryTerm)4 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 AtlasGlossaryHeader (org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader)3 AtlasRelatedObjectId (org.apache.atlas.model.instance.AtlasRelatedObjectId)3 InputStream (java.io.InputStream)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 Objects (java.util.Objects)2 Set (java.util.Set)2