Repository: atlas Updated Branches: refs/heads/master 6812a7d57 -> 75415862c
http://git-wip-us.apache.org/repos/asf/atlas/blob/75415862/webapp/src/main/java/org/apache/atlas/notification/EntityNotificationListenerV2.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/notification/EntityNotificationListenerV2.java b/webapp/src/main/java/org/apache/atlas/notification/EntityNotificationListenerV2.java index 01a95cf..ac097b6 100644 --- a/webapp/src/main/java/org/apache/atlas/notification/EntityNotificationListenerV2.java +++ b/webapp/src/main/java/org/apache/atlas/notification/EntityNotificationListenerV2.java @@ -17,9 +17,7 @@ */ package org.apache.atlas.notification; -import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasErrorCode; -import org.apache.atlas.AtlasException; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.listener.EntityChangeListenerV2; import org.apache.atlas.model.instance.AtlasClassification; @@ -46,26 +44,23 @@ import java.util.Set; import static org.apache.atlas.notification.NotificationEntityChangeListener.ATLAS_ENTITY_NOTIFICATION_PROPERTY; import static org.apache.atlas.notification.NotificationInterface.NotificationType.ENTITIES; -import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.CLASSIFICATION_ADD; -import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.CLASSIFICATION_DELETE; -import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.CLASSIFICATION_UPDATE; import static org.apache.atlas.repository.graph.GraphHelper.isInternalType; -import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.ENTITY_CREATE; -import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.ENTITY_DELETE; -import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.ENTITY_UPDATE; +import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.*; @Component public class EntityNotificationListenerV2 implements EntityChangeListenerV2 { private final AtlasTypeRegistry typeRegistry; private final NotificationInterface notificationInterface; + private final Configuration configuration; private final Map<String, List<String>> notificationAttributesCache = new HashMap<>(); - private static Configuration APPLICATION_PROPERTIES = null; - @Inject - public EntityNotificationListenerV2(AtlasTypeRegistry typeRegistry, NotificationInterface notificationInterface) { + public EntityNotificationListenerV2(AtlasTypeRegistry typeRegistry, + NotificationInterface notificationInterface, + Configuration configuration) { this.typeRegistry = typeRegistry; this.notificationInterface = notificationInterface; + this.configuration = configuration; } @Override @@ -186,13 +181,11 @@ public class EntityNotificationListenerV2 implements EntityChangeListenerV2 { private List<String> getNotificationAttributes(String entityType) { List<String> ret = null; - initApplicationProperties(); - if (notificationAttributesCache.containsKey(entityType)) { ret = notificationAttributesCache.get(entityType); - } else if (APPLICATION_PROPERTIES != null) { - String[] notificationAttributes = APPLICATION_PROPERTIES.getStringArray(ATLAS_ENTITY_NOTIFICATION_PROPERTY + "." + - entityType + "." + "attributes.include"); + } else if (configuration != null) { + String attributesToIncludeKey = ATLAS_ENTITY_NOTIFICATION_PROPERTY + "." + entityType + "." + "attributes.include"; + String[] notificationAttributes = configuration.getStringArray(attributesToIncludeKey); if (notificationAttributes != null) { ret = Arrays.asList(notificationAttributes); @@ -203,14 +196,4 @@ public class EntityNotificationListenerV2 implements EntityChangeListenerV2 { return ret; } - - private void initApplicationProperties() { - if (APPLICATION_PROPERTIES == null) { - try { - APPLICATION_PROPERTIES = ApplicationProperties.get(); - } catch (AtlasException ex) { - // ignore - } - } - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/atlas/blob/75415862/webapp/src/main/java/org/apache/atlas/web/rest/GlossaryREST.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/GlossaryREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/GlossaryREST.java new file mode 100644 index 0000000..6779dee --- /dev/null +++ b/webapp/src/main/java/org/apache/atlas/web/rest/GlossaryREST.java @@ -0,0 +1,839 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.web.rest; + +import org.apache.atlas.AtlasErrorCode; +import org.apache.atlas.SortOrder; +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.glossary.GlossaryService; +import org.apache.atlas.model.glossary.AtlasGlossary; +import org.apache.atlas.model.glossary.AtlasGlossaryCategory; +import org.apache.atlas.model.glossary.AtlasGlossaryTerm; +import org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader; +import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader; +import org.apache.atlas.model.instance.AtlasEntityHeader; +import org.apache.atlas.utils.AtlasPerfTracer; +import org.apache.atlas.web.util.Servlets; +import org.apache.commons.collections.MapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import javax.ws.rs.*; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import static org.apache.atlas.web.util.Servlets.JSON_MEDIA_TYPE; + +@Path("v2/glossary") +@Service +@Consumes(JSON_MEDIA_TYPE) +@Produces(JSON_MEDIA_TYPE) +public class GlossaryREST { + private static final Logger LOG = LoggerFactory.getLogger(GlossaryREST.class); + private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.GlossaryREST"); + + private final GlossaryService glossaryService; + + @Inject + public GlossaryREST(final GlossaryService glossaryService) { + this.glossaryService = glossaryService; + } + + /** + * Retrieve all glossaries registered with Atlas + * @param limit page size - by default there is no paging + * @param offset offset for pagination purpose + * @param sort Sort order, ASC (default) or DESC + * @return List of glossary entities fitting the above criteria + * @HTTP 200 List of existing glossaries fitting the search criteria or empty list if nothing matches + * @throws AtlasBaseException + */ + @GET + public List<AtlasGlossary> getGlossaries(@DefaultValue("-1") @QueryParam("limit") final String limit, + @DefaultValue("0") @QueryParam("offset") final String offset, + @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { + AtlasPerfTracer perf = null; + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaries()"); + } + + + return glossaryService.getGlossaries(Integer.parseInt(limit), Integer.parseInt(offset), toSortOrder(sort)); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get a specific Glossary + * @param glossaryGuid unique glossary identifier + * @return Glossary + * @throws AtlasBaseException + * @HTTP 200 If glossary with given guid exists + * @HTTP 404 If glossary GUID is invalid + */ + @GET + @Path("/{glossaryGuid}") + public AtlasGlossary getGlossary(@PathParam("glossaryGuid") String glossaryGuid) throws AtlasBaseException { + Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid); + + AtlasPerfTracer perf = null; + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossary(" + glossaryGuid + ")"); + } + AtlasGlossary ret = glossaryService.getGlossary(glossaryGuid); + + if (ret == null) { + throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND); + } + + return ret; + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get a specific Glossary + * @param glossaryGuid unique glossary identifier + * @return Glossary + * @throws AtlasBaseException + * @HTTP 200 If glossary exists for given GUID + * @HTTP 404 If glossary GUID is invalid + */ + @GET + @Path("/{glossaryGuid}/detailed") + public AtlasGlossary.AtlasGlossaryExtInfo getDetailedGlossary(@PathParam("glossaryGuid") String glossaryGuid) throws AtlasBaseException { + Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid); + + AtlasPerfTracer perf = null; + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getDetailedGlossary(" + glossaryGuid + ")"); + } + AtlasGlossary.AtlasGlossaryExtInfo ret = glossaryService.getDetailedGlossary(glossaryGuid); + + if (ret == null) { + throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND); + } + + return ret; + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get specific glossary term + * @param termGuid unique identifier for glossary term + * @return Glossary term + * @throws AtlasBaseException + * @HTTP 200 If glossary term exists for given GUID + * @HTTP 404 If glossary term GUID is invalid + */ + @GET + @Path("/term/{termGuid}") + public AtlasGlossaryTerm getGlossaryTerm(@PathParam("termGuid") String termGuid) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + + AtlasPerfTracer perf = null; + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaryTerm(" + termGuid + ")"); + } + AtlasGlossaryTerm ret = glossaryService.getTerm(termGuid); + if (ret == null) { + throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND); + } + + return ret; + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * 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}") + 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); + } + } + + /** + * Create a glossary + * @param atlasGlossary Glossary definition, terms & categories can be anchored to a glossary + * using the anchor attribute when creating the Term/Category + * @return + * @throws AtlasBaseException + * @HTTP 200 If glossary creation was successful + * @HTTP 400 If Glossary definition has invalid or missing information + */ + @POST + public AtlasGlossary createGlossary(AtlasGlossary atlasGlossary) throws AtlasBaseException { + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.createGlossary()"); + } + return glossaryService.createGlossary(atlasGlossary); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Create a glossary term + * @param glossaryTerm Glossary term definition, a term must be anchored to a Glossary at the time of creation + * optionally it can be categorized as well + * @return + * @throws AtlasBaseException + * @HTTP 200 If glossary term creation was successful + * @HTTP 400 If Glossary term definition has invalid or missing information + */ + @POST + @Path("/term") + public AtlasGlossaryTerm createGlossaryTerm(AtlasGlossaryTerm glossaryTerm) throws AtlasBaseException { + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.createGlossaryTerm()"); + } + if (Objects.isNull(glossaryTerm.getAnchor())) { + throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR); + } + return glossaryService.createTerm(glossaryTerm); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Create glossary terms in bulk + * @param glossaryTerm glossary term definitions + * @return + * @throws AtlasBaseException + * @HTTP 200 If Bulk glossary terms creation was successful + * @HTTP 400 If any glossary term definition has invalid or missing information + */ + @POST + @Path("/terms") + public List<AtlasGlossaryTerm> createGlossaryTerms(List<AtlasGlossaryTerm> glossaryTerm) throws AtlasBaseException { + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.createGlossaryTerms()"); + } + for (AtlasGlossaryTerm term : glossaryTerm) { + if (Objects.isNull(term.getAnchor())) { + throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR); + } + } + return glossaryService.createTerms(glossaryTerm); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Create glossary category + * @param glossaryCategory glossary category definition, a category must be anchored to a Glossary when creating + * Optionally, terms belonging to the category and the hierarchy can also be defined during creation + * @return + * @throws AtlasBaseException + * @HTTP 200 If glossary category creation was successful + * @HTTP 400 If Glossary category definition has invalid or missing information + */ + @POST + @Path("/category") + public AtlasGlossaryCategory createGlossaryCategory(AtlasGlossaryCategory glossaryCategory) throws AtlasBaseException { + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.createGlossaryCategory()"); + } + if (Objects.isNull(glossaryCategory.getAnchor())) { + throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR); + } + return glossaryService.createCategory(glossaryCategory); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Create glossary category in bulk + * @param glossaryCategory glossary category definitions + * @return + * @throws AtlasBaseException + * @HTTP 200 If BULK glossary category creation was successful + * @HTTP 400 If ANY Glossary category definition has invalid or missing information + */ + @POST + @Path("/categories") + public List<AtlasGlossaryCategory> createGlossaryCategories(List<AtlasGlossaryCategory> glossaryCategory) throws AtlasBaseException { + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.createGlossaryCategories()"); + } + for (AtlasGlossaryCategory category : glossaryCategory) { + if (Objects.isNull(category.getAnchor())) { + throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR); + } + + } + return glossaryService.createCategories(glossaryCategory); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Update the given glossary + * @param glossaryGuid unique identifier for glossary + * @param updatedGlossary Updated glossary definition + * @return Glossary + * @throws AtlasBaseException + * @HTTP 200 If glossary update was successful + * @HTTP 404 If glossary guid in invalid + * @HTTP 400 If Glossary definition has invalid or missing information + */ + @PUT + @Path("/{glossaryGuid}") + public AtlasGlossary updateGlossary(@PathParam("glossaryGuid") String glossaryGuid, AtlasGlossary updatedGlossary) throws AtlasBaseException { + Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid); + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.updateGlossary(" + glossaryGuid + ")"); + } + updatedGlossary.setGuid(glossaryGuid); + return glossaryService.updateGlossary(updatedGlossary); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Partially update the glossary + * @param glossaryGuid unique identifier for glossary term + * @param partialUpdates Map containing keys as attribute names and values as corresponding attribute values + * @return Updated glossary + * @throws AtlasBaseException + * @HTTP 200 If glossary partial update was successful + * @HTTP 404 If glossary guid in invalid + * @HTTP 400 If partial update parameters are invalid + */ + @PUT + @Path("/{glossaryGuid}/partial") + public AtlasGlossary partialUpdateGlossary(@PathParam("glossaryGuid") String glossaryGuid, Map<String, String> partialUpdates) throws AtlasBaseException { + Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid); + + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.partialUpdateGlossary()"); + } + + if (MapUtils.isEmpty(partialUpdates)) { + throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "PartialUpdates missing or empty"); + } + + AtlasGlossary glossary = glossaryService.getGlossary(glossaryGuid); + for (Map.Entry<String, String> entry : partialUpdates.entrySet()) { + glossary.setAttribute(entry.getKey(), entry.getValue()); + } + return glossaryService.updateGlossary(glossary); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Update the given glossary term + * @param termGuid unique identifier for glossary term + * @param glossaryTerm updated glossary term + * @return Updated glossary term + * @throws AtlasBaseException + * @HTTP 200 If glossary term update was successful + * @HTTP 404 If glossary term guid in invalid + * @HTTP 400 If Glossary temr definition has invalid or missing information + */ + @PUT + @Path("/term/{termGuid}") + public AtlasGlossaryTerm updateGlossaryTerm(@PathParam("termGuid") String termGuid, AtlasGlossaryTerm glossaryTerm) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.updateGlossaryTerm()"); + } + glossaryTerm.setGuid(termGuid); + return glossaryService.updateTerm(glossaryTerm); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Partially update the glossary term + * @param termGuid unique identifier for glossary term + * @param partialUpdates Map containing keys as attribute names and values as corresponding attribute values + * @return Updated glossary term + * @throws AtlasBaseException + * @HTTP 200 If glossary partial update was successful + * @HTTP 404 If glossary term guid in invalid + * @HTTP 400 If partial attributes are invalid + */ + @PUT + @Path("/term/{termGuid}/partial") + public AtlasGlossaryTerm partialUpdateGlossaryTerm(@PathParam("termGuid") String termGuid, Map<String, String> partialUpdates) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.partialUpdateGlossaryTerm()"); + } + + if (MapUtils.isEmpty(partialUpdates)) { + throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "PartialUpdates missing or empty"); + } + + AtlasGlossaryTerm glossaryTerm = glossaryService.getTerm(termGuid); + for (Map.Entry<String, String> entry : partialUpdates.entrySet()) { + glossaryTerm.setAttribute(entry.getKey(), entry.getValue()); + } + return glossaryService.updateTerm(glossaryTerm); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Update the given glossary category + * @param categoryGuid unique identifier for glossary category + * @param glossaryCategory updated glossary category + * @return glossary category + * @throws AtlasBaseException + * @HTTP 200 If glossary category partial update was successful + * @HTTP 404 If glossary category guid in invalid + * @HTTP 400 If Glossary category definition has invalid or missing information + */ + @PUT + @Path("/category/{categoryGuid}") + public AtlasGlossaryCategory updateGlossaryCategory(@PathParam("categoryGuid") String categoryGuid, AtlasGlossaryCategory glossaryCategory) throws AtlasBaseException { + Servlets.validateQueryParamLength("categoryGuid", categoryGuid); + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.updateGlossaryCategory()"); + } + glossaryCategory.setGuid(categoryGuid); + return glossaryService.updateCategory(glossaryCategory); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * 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") + 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()) { + glossaryCategory.setAttribute(entry.getKey(), entry.getValue()); + } + return glossaryService.updateCategory(glossaryCategory); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Delete a glossary + * @param glossaryGuid unique identifier for glossary + * @throws AtlasBaseException + * @HTTP 204 If glossary delete was successful + * @HTTP 404 If glossary guid in invalid + */ + @DELETE + @Path("/{glossaryGuid}") + public void deleteGlossary(@PathParam("glossaryGuid") String glossaryGuid) throws AtlasBaseException { + Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid); + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.deleteGlossary(" + glossaryGuid + ")"); + } + glossaryService.deleteGlossary(glossaryGuid); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Delete a glossary term + * @param termGuid unique identifier for glossary term + * @throws AtlasBaseException + * @HTTP 204 If glossary term delete was successful + * @HTTP 404 If glossary term guid in invalid + */ + @DELETE + @Path("/term/{termGuid}") + public void deleteGlossaryTerm(@PathParam("termGuid") String termGuid) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.deleteGlossaryTerm(" + termGuid + ")"); + } + glossaryService.deleteTerm(termGuid); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Delete a glossary category + * @param categoryGuid unique identifier for glossary category + * @throws AtlasBaseException + * @HTTP 204 If glossary category delete was successful + * @HTTP 404 If glossary category guid in invalid + */ + @DELETE + @Path("/category/{categoryGuid}") + public void deleteGlossaryCategory(@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.deleteGlossaryCategory(" + categoryGuid + ")"); + } + glossaryService.deleteCategory(categoryGuid); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get terms belonging to a specific glossary + * @param glossaryGuid unique identifier for glossary + * @param limit page size - by default there is no paging + * @param offset starting offset for loading terms + * @param sort ASC(default) or DESC + * @return List of terms associated with the glossary + * @throws AtlasBaseException + * @HTTP 200 List of glossary terms for the given glossary or an empty list + * @HTTP 404 If glossary guid in invalid + */ + @GET + @Path("/{glossaryGuid}/terms") + public List<AtlasGlossaryTerm> getGlossaryTerms(@PathParam("glossaryGuid") String glossaryGuid, + @DefaultValue("-1") @QueryParam("limit") String limit, + @DefaultValue("0") @QueryParam("offset") String offset, + @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { + Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid); + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaryTerms(" + glossaryGuid + ")"); + } + + return glossaryService.getGlossaryTerms(glossaryGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort)); + + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get the categories belonging to a specific glossary + * @param glossaryGuid unique identifier for glossary term + * @param limit page size - by default there is no paging + * @param offset offset for pagination purpose + * @param sort ASC (default) or DESC + * @return List of associated categories + * @throws AtlasBaseException + * @HTTP 200 List of glossary categories for the given glossary or an empty list + * @HTTP 404 If glossary guid in invalid + */ + @GET + @Path("/{glossaryGuid}/categories") + public List<AtlasRelatedCategoryHeader> getGlossaryCategories(@PathParam("glossaryGuid") String glossaryGuid, + @DefaultValue("-1") @QueryParam("limit") String limit, + @DefaultValue("0") @QueryParam("offset") String offset, + @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { + Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid); + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaryCategories(" + glossaryGuid + ")"); + } + + return glossaryService.getGlossaryCategories(glossaryGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort)); + + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get all terms associated with the specific category + * @param categoryGuid unique identifier for glossary category + * @param limit page size - by default there is no paging + * @param offset offset for pagination purpose + * @param sort ASC (default) or DESC + * @return List of associated terms + * @throws AtlasBaseException + * @HTTP 200 List of terms for the given category or an empty list + * @HTTP 404 If glossary category guid in invalid + */ + @GET + @Path("/category/{categoryGuid}/terms") + public List<AtlasRelatedTermHeader> getCategoryTerms(@PathParam("categoryGuid") String categoryGuid, + @DefaultValue("-1") @QueryParam("limit") String limit, + @DefaultValue("0") @QueryParam("offset") String offset, + @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { + Servlets.validateQueryParamLength("categoryGuid", categoryGuid); + + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getCategoryTerms(" + categoryGuid + ")"); + } + + return glossaryService.getCategoryTerms(categoryGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort)); + + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get all related terms for a specific term + * @param termGuid unique identifier for glossary term + * @param limit page size - by default there is no paging + * @param offset offset for pagination purpose + * @param sort ASC (default) or DESC + * @return List of all related terms + * @throws AtlasBaseException + * @HTTP 200 List of related glossary terms for the given glossary or an empty list + * @HTTP 404 If glossary term guid in invalid + */ + @GET + @Path("/terms/{termGuid}/related") + public Map<AtlasGlossaryTerm.Relation, Set<AtlasRelatedTermHeader>> getRelatedTerms(@PathParam("termGuid") String termGuid, + @DefaultValue("-1") @QueryParam("limit") String limit, + @DefaultValue("0") @QueryParam("offset") String offset, + @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getRelatedTermsInfo(" + termGuid + ")"); + } + + return glossaryService.getRelatedTerms(termGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort)); + + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Get all entity headers assigned with the specified term + * @param termGuid GUID of the term + * @param limit page size - by default there is no paging + * @param offset offset for pagination purpose + * @param sort ASC (default) or DESC + * @return + * @throws AtlasBaseException + * @HTTP 200 List of entity headers (if any) for the given glossary or an empty list + * @HTTP 404 If glossary term guid in invalid + */ + @GET + @Path("/terms/{termGuid}/assignedEntities") + public List<AtlasEntityHeader> getEntitiesAssignedWithTerm(@PathParam("termGuid") String termGuid, + @DefaultValue("-1") @QueryParam("limit") String limit, + @DefaultValue("0") @QueryParam("offset") String offset, + @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getEntitiesAssignedWithTerm(" + termGuid + ")"); + } + + return glossaryService.getAssignedEntities(termGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort)); + + } finally { + AtlasPerfTracer.log(perf); + } + } + + + /** + * Assign the given term to the provided list of entity headers + * @param termGuid Glossary term GUID + * @param entityHeaders Entity headers for which the term has to be associated + * @throws AtlasBaseException + * @HTTP 204 If the term assignment was successful + * @HTTP 400 If ANY of the entity header is invalid + * @HTTP 404 If glossary guid in invalid + */ + @POST + @Path("/terms/{termGuid}/assignedEntities") + public void assignTermToEntities(@PathParam("termGuid") String termGuid, List<AtlasEntityHeader> entityHeaders) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.assignTermToEntities(" + termGuid + ")"); + } + + glossaryService.assignTermToEntities(termGuid, entityHeaders); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** + * Remove the term assignment for the given list of entity headers + * @param termGuid Glossary term GUID + * @param entityHeaders List of entity headers from which the term has to be dissociated + * @throws AtlasBaseException + * @HTTP 204 If glossary term dissociation was successful + * @HTTP 400 If ANY of the entity header is invalid + * @HTTP 404 If glossary term guid in invalid + */ + @DELETE + @Path("/terms/{termGuid}/assignedEntities") + public void removeTermAssignmentFromEntities(@PathParam("termGuid") String termGuid, List<AtlasEntityHeader> entityHeaders) throws AtlasBaseException { + Servlets.validateQueryParamLength("termGuid", termGuid); + + AtlasPerfTracer perf = null; + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.removeTermAssignmentFromEntities(" + termGuid + ")"); + } + + glossaryService.removeTermFromEntities(termGuid, entityHeaders); + } finally { + AtlasPerfTracer.log(perf); + } + } + + + + /** + * Get all related categories (parent and children) + * @param categoryGuid unique identifier for glossary category + * @param limit page size - by default there is no paging + * @param offset offset for pagination purpose + * @param sort ASC (default) or DESC + * @return List of related categories + * @throws AtlasBaseException + */ + @GET + @Path("/category/{categoryGuid}/related") + public Map<String, List<AtlasRelatedCategoryHeader>> getRelatedCategories(@PathParam("categoryGuid") String categoryGuid, + @DefaultValue("-1") @QueryParam("limit") String limit, + @DefaultValue("0") @QueryParam("offset") String offset, + @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { + AtlasPerfTracer perf = null; + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getRelatedCategories()"); + } + + return glossaryService.getRelatedCategories(categoryGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort)); + + } finally { + AtlasPerfTracer.log(perf); + } + } + + private SortOrder toSortOrder(final String sort) { + SortOrder ret = SortOrder.ASCENDING; + if (!"ASC".equals(sort)) { + if ("DESC".equals(sort)) { + ret = SortOrder.DESCENDING; + } + } + return ret; + } + +}