atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject atlas git commit: ATLAS-2160: added REST APIs to execute a saved-search
Date Sat, 23 Sep 2017 00:22:28 GMT
Repository: atlas
Updated Branches:
  refs/heads/master a9ca60e38 -> 7cce1c4af


ATLAS-2160: added REST APIs to execute a saved-search

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/7cce1c4a
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/7cce1c4a
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/7cce1c4a

Branch: refs/heads/master
Commit: 7cce1c4af84001c79b7e0d9ad2e566b8cbaf7ccb
Parents: a9ca60e
Author: ashutoshm <amestry@hortonworks.com>
Authored: Fri Sep 22 14:52:58 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Fri Sep 22 16:37:52 2017 -0700

----------------------------------------------------------------------
 .../model/profile/AtlasUserSavedSearch.java     |   4 -
 .../atlas/discovery/AtlasDiscoveryService.java  |  27 ++--
 .../atlas/discovery/EntityDiscoveryService.java |  96 ++++++++++++--
 .../repository/ogm/AtlasSavedSearchDTO.java     |   2 +-
 .../userprofile/UserProfileService.java         |  10 +-
 .../userprofile/UserProfileServiceTest.java     |  10 +-
 .../apache/atlas/web/rest/DiscoveryREST.java    | 126 ++++++++++++-------
 7 files changed, 193 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/7cce1c4a/intg/src/main/java/org/apache/atlas/model/profile/AtlasUserSavedSearch.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/profile/AtlasUserSavedSearch.java b/intg/src/main/java/org/apache/atlas/model/profile/AtlasUserSavedSearch.java
index 8ecd52d..0625a13 100644
--- a/intg/src/main/java/org/apache/atlas/model/profile/AtlasUserSavedSearch.java
+++ b/intg/src/main/java/org/apache/atlas/model/profile/AtlasUserSavedSearch.java
@@ -61,10 +61,6 @@ public class AtlasUserSavedSearch extends AtlasBaseModelObject implements
Serial
         this(ownerName, name, SavedSearchType.BASIC, null);
     }
 
-    public AtlasUserSavedSearch(String ownerName, String name, SavedSearchType searchType)
{
-        this(ownerName, name, searchType, null);
-    }
-
     public AtlasUserSavedSearch(String ownerName, String name, SavedSearchType savedSearchType,
SearchParameters searchParameters) {
         setOwnerName(ownerName);
         setName(name);

http://git-wip-us.apache.org/repos/asf/atlas/blob/7cce1c4a/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
b/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
index 630e776..4b3f6f7 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
@@ -24,7 +24,6 @@ import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.discovery.AtlasSearchResult;
 import org.apache.atlas.model.discovery.SearchParameters;
 import org.apache.atlas.model.profile.AtlasUserSavedSearch;
-import org.apache.atlas.model.profile.AtlasUserSavedSearch.SavedSearchType;
 
 import java.util.List;
 
@@ -40,6 +39,15 @@ public interface AtlasDiscoveryService {
 
     /**
      *
+     * @param query query
+     * @param typeName type name
+     * @param classification classification
+     * @return Query in DSL form
+     */
+    String getDslQueryUsingTypeNameClassification(String query, String typeName, String classification);
+
+    /**
+     *
      * @param query search query.
      * @param excludeDeletedEntities exclude deleted entities in search result.
      * @param limit number of resultant rows (for pagination). [ limit > 0 ] and [ limit
< maxlimit ]. -1 maps to atlas.search.defaultlimit property.
@@ -90,14 +98,14 @@ public interface AtlasDiscoveryService {
      * @param savedSearch Search to be saved
      * @throws AtlasBaseException
      */
-    AtlasUserSavedSearch addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException;
+    AtlasUserSavedSearch addSavedSearch(String currentUser, AtlasUserSavedSearch savedSearch)
throws AtlasBaseException;
 
     /**
      *
      * @param savedSearch Search to be saved
      * @throws AtlasBaseException
      */
-    AtlasUserSavedSearch updateSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException;
+    AtlasUserSavedSearch updateSavedSearch(String currentUser, AtlasUserSavedSearch savedSearch)
throws AtlasBaseException;
 
     /**
      *
@@ -105,7 +113,7 @@ public interface AtlasDiscoveryService {
      * @return List of saved searches for the user
      * @throws AtlasBaseException
      */
-    List<AtlasUserSavedSearch> getSavedSearches(String userName) throws AtlasBaseException;
+    List<AtlasUserSavedSearch> getSavedSearches(String currentUser, String userName)
throws AtlasBaseException;
 
     /**
      *
@@ -113,7 +121,7 @@ public interface AtlasDiscoveryService {
      * @return Search object identified by the guid
      * @throws AtlasBaseException
      */
-    AtlasUserSavedSearch getSavedSearch(String guid) throws AtlasBaseException;
+    AtlasUserSavedSearch getSavedSearchByGuid(String currentUser, String guid) throws AtlasBaseException;
 
     /**
      *
@@ -122,10 +130,13 @@ public interface AtlasDiscoveryService {
      * @return Search object identified by the name
      * @throws AtlasBaseException
      */
-    AtlasUserSavedSearch getSavedSearch(String userName, String searchName, SavedSearchType
searchType) throws AtlasBaseException;
+    AtlasUserSavedSearch getSavedSearchByName(String currentUser, String userName, String
searchName) throws AtlasBaseException;
 
     /**
-     * @param guid Guid for the saved search
+     *
+     * @param currentUser User requesting the operation
+     * @param guid Guid used to look up Saved Search
+     * @throws AtlasBaseException
      */
-    void deleteSavedSearch(String guid) throws AtlasBaseException;
+    void deleteSavedSearch(String currentUser, String guid) throws AtlasBaseException;
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/7cce1c4a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
index 102c329..40c66dd 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -34,7 +34,6 @@ import org.apache.atlas.model.discovery.SearchParameters;
 import org.apache.atlas.model.instance.AtlasEntityHeader;
 import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.profile.AtlasUserSavedSearch;
-import org.apache.atlas.model.profile.AtlasUserSavedSearch.SavedSearchType;
 import org.apache.atlas.query.Expressions.AliasExpression;
 import org.apache.atlas.query.Expressions.Expression;
 import org.apache.atlas.query.Expressions.SelectExpression;
@@ -807,8 +806,14 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
 
 
     @Override
-    public AtlasUserSavedSearch addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException
{
+    public AtlasUserSavedSearch addSavedSearch(String currentUser, AtlasUserSavedSearch savedSearch)
throws AtlasBaseException {
         try {
+            if (StringUtils.isEmpty(savedSearch.getOwnerName())) {
+                savedSearch.setOwnerName(currentUser);
+            }
+
+            checkSavedSearchOwnership(currentUser, savedSearch);
+
             return userProfileService.addSavedSearch(savedSearch);
         } catch (AtlasBaseException e) {
             LOG.error("addSavedSearch({})", savedSearch, e);
@@ -818,8 +823,14 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
 
 
     @Override
-    public AtlasUserSavedSearch updateSavedSearch(AtlasUserSavedSearch savedSearch) throws
AtlasBaseException {
+    public AtlasUserSavedSearch updateSavedSearch(String currentUser, AtlasUserSavedSearch
savedSearch) throws AtlasBaseException {
         try {
+            if (StringUtils.isEmpty(savedSearch.getOwnerName())) {
+                savedSearch.setOwnerName(currentUser);
+            }
+
+            checkSavedSearchOwnership(currentUser, savedSearch);
+
             return userProfileService.updateSavedSearch(savedSearch);
         } catch (AtlasBaseException e) {
             LOG.error("updateSavedSearch({})", savedSearch, e);
@@ -828,8 +839,14 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
     }
 
     @Override
-    public List<AtlasUserSavedSearch> getSavedSearches(String userName) throws AtlasBaseException
{
+    public List<AtlasUserSavedSearch> getSavedSearches(String currentUser, String userName)
throws AtlasBaseException {
         try {
+            if (StringUtils.isEmpty(userName)) {
+                userName = currentUser;
+            } else if (!StringUtils.equals(currentUser, userName)) {
+                throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "invalid data");
+            }
+
             return userProfileService.getSavedSearches(userName);
         } catch (AtlasBaseException e) {
             LOG.error("getSavedSearches({})", userName, e);
@@ -838,27 +855,82 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
     }
 
     @Override
-    public AtlasUserSavedSearch getSavedSearch(String guid) throws AtlasBaseException {
+    public AtlasUserSavedSearch getSavedSearchByGuid(String currentUser, String guid) throws
AtlasBaseException {
+        try {
+            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(guid);
+
+            checkSavedSearchOwnership(currentUser, savedSearch);
+
+            return savedSearch;
+        } catch (AtlasBaseException e) {
+            LOG.error("getSavedSearchByGuid({})", guid, e);
+            throw e;
+        }
+    }
+
+    @Override
+    public AtlasUserSavedSearch getSavedSearchByName(String currentUser, String userName,
String searchName) throws AtlasBaseException {
         try {
-            return userProfileService.getSavedSearch(guid);
+            if (StringUtils.isEmpty(userName)) {
+                userName = currentUser;
+            } else if (!StringUtils.equals(currentUser, userName)) {
+                throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "invalid data");
+            }
+
+            return userProfileService.getSavedSearch(userName, searchName);
         } catch (AtlasBaseException e) {
-            LOG.error("getSavedSearch({})", guid, e);
+            LOG.error("getSavedSearchByName({}, {})", userName, searchName, e);
             throw e;
         }
     }
 
     @Override
-    public AtlasUserSavedSearch getSavedSearch(String userName, String searchName, SavedSearchType
searchType) throws AtlasBaseException {
+    public void deleteSavedSearch(String currentUser, String guid) throws AtlasBaseException
{
         try {
-            return userProfileService.getSavedSearch(userName, searchName, searchType);
+            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(guid);
+
+            checkSavedSearchOwnership(currentUser, savedSearch);
+
+            userProfileService.deleteSavedSearch(guid);
         } catch (AtlasBaseException e) {
-            LOG.error("getSavedSearch({}, {})", userName, searchName, e);
+            LOG.error("deleteSavedSearch({})", guid, e);
             throw e;
         }
     }
 
     @Override
-    public void deleteSavedSearch(String guid) throws AtlasBaseException {
-        userProfileService.deleteSavedSearch(guid);
+    public String getDslQueryUsingTypeNameClassification(String query, String typeName, String
classification) {
+        String queryStr = query == null ? "" : query;
+
+        if (org.apache.commons.lang3.StringUtils.isNoneEmpty(typeName)) {
+            queryStr = escapeTypeName(typeName) + " " + queryStr;
+        }
+
+        if (org.apache.commons.lang3.StringUtils.isNoneEmpty(classification)) {
+            // isa works with a type name only - like hive_column isa PII; it doesn't work
with more complex query
+            if (StringUtils.isEmpty(query)) {
+                queryStr += (" isa " + classification);
+            }
+        }
+        return queryStr;
+    }
+
+    private String escapeTypeName(String typeName) {
+        String ret;
+
+        if (StringUtils.startsWith(typeName, "`") && StringUtils.endsWith(typeName,
"`")) {
+            ret = typeName;
+        } else {
+            ret = String.format("`%s`", typeName);
+        }
+
+        return ret;
+    }
+
+    private void checkSavedSearchOwnership(String claimedOwner, AtlasUserSavedSearch savedSearch)
throws AtlasBaseException {
+        // block attempt to delete another user's saved-search
+        if (savedSearch != null && !StringUtils.equals(savedSearch.getOwnerName(),
claimedOwner)) {
+            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "invalid data");
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/7cce1c4a/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasSavedSearchDTO.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasSavedSearchDTO.java
b/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasSavedSearchDTO.java
index aa8fc39..27575ce 100644
--- a/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasSavedSearchDTO.java
+++ b/repository/src/main/java/org/apache/atlas/repository/ogm/AtlasSavedSearchDTO.java
@@ -95,6 +95,6 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
     }
 
     private String getUniqueValue(AtlasUserSavedSearch obj) {
-        return String.format("%s:%s:%s", obj.getOwnerName(), obj.getName(), obj.getSearchType())
;
+        return String.format("%s:%s", obj.getOwnerName(), obj.getName()) ;
     }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/7cce1c4a/repository/src/main/java/org/apache/atlas/repository/userprofile/UserProfileService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/userprofile/UserProfileService.java
b/repository/src/main/java/org/apache/atlas/repository/userprofile/UserProfileService.java
index 99d13af..a428b92 100644
--- a/repository/src/main/java/org/apache/atlas/repository/userprofile/UserProfileService.java
+++ b/repository/src/main/java/org/apache/atlas/repository/userprofile/UserProfileService.java
@@ -22,7 +22,6 @@ import org.apache.atlas.annotation.AtlasService;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.profile.AtlasUserProfile;
 import org.apache.atlas.model.profile.AtlasUserSavedSearch;
-import org.apache.atlas.model.profile.AtlasUserSavedSearch.SavedSearchType;
 import org.apache.atlas.repository.ogm.DataAccess;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
@@ -70,7 +69,7 @@ public class UserProfileService {
         userProfile.getSavedSearches().add(savedSearch);
         userProfile = dataAccess.save(userProfile);
         for (AtlasUserSavedSearch s : userProfile.getSavedSearches()) {
-            if(s.getName().equals(savedSearch.getName()) && s.getSearchType().equals(savedSearch.getSearchType()))
{
+            if(s.getName().equals(savedSearch.getName())) {
                 return s;
             }
         }
@@ -81,8 +80,7 @@ public class UserProfileService {
     private void checkIfQueryAlreadyExists(AtlasUserSavedSearch savedSearch, AtlasUserProfile
userProfile) throws AtlasBaseException {
         for (AtlasUserSavedSearch exisingSearch : userProfile.getSavedSearches()) {
             if (StringUtils.equals(exisingSearch.getOwnerName(), savedSearch.getOwnerName())
&&
-                StringUtils.equals(exisingSearch.getName(), savedSearch.getName()) &&
-                exisingSearch.getSearchType().equals(savedSearch.getSearchType())) {
+                StringUtils.equals(exisingSearch.getName(), savedSearch.getName())) {
                 throw new AtlasBaseException(AtlasErrorCode.SAVED_SEARCH_ALREADY_EXISTS,
savedSearch.getName(), savedSearch.getOwnerName());
             }
         }
@@ -129,8 +127,8 @@ public class UserProfileService {
         return (profile != null) ? profile.getSavedSearches() : null;
     }
 
-    public AtlasUserSavedSearch getSavedSearch(String userName, String searchName, SavedSearchType
searchType) throws AtlasBaseException {
-        AtlasUserSavedSearch ss = new AtlasUserSavedSearch(userName, searchName, searchType);
+    public AtlasUserSavedSearch getSavedSearch(String userName, String searchName) throws
AtlasBaseException {
+        AtlasUserSavedSearch ss = new AtlasUserSavedSearch(userName, searchName);
 
         return dataAccess.load(ss);
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/7cce1c4a/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
b/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
index 713dade..0532f16 100644
--- a/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
@@ -111,7 +111,7 @@ public class UserProfileServiceTest {
                 AtlasUserSavedSearch actual = userProfileService.addSavedSearch(getDefaultSavedSearch(userName,
queryName, expectedSearchParameter));
                 assertNotNull(actual);
 
-                AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
queryName, BASIC);
+                AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
queryName);
                 assertNotNull(savedSearch);
                 assertEquals(savedSearch.getSearchParameters(), expectedSearchParameter);
             }
@@ -156,7 +156,7 @@ public class UserProfileServiceTest {
 
         saveQueries(userName, actualSearchParameter);
         for (int i = 0; i < max_searches; i++) {
-            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
getIndexBasedQueryName(i), BASIC);
+            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
getIndexBasedQueryName(i));
             assertEquals(savedSearch.getName(), getIndexBasedQueryName(i));
             assertEquals(savedSearch.getSearchParameters(), actualSearchParameter);
         }
@@ -194,7 +194,7 @@ public class UserProfileServiceTest {
     public void updateSearch() throws AtlasBaseException {
         final String queryName = getIndexBasedQueryName(0);
         String userName = getIndexBasedUserName(0);
-        AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName,
BASIC);
+        AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName);
         assertNotNull(expected);
 
         SearchParameters sp = expected.getSearchParameters();
@@ -212,11 +212,11 @@ public class UserProfileServiceTest {
         final String queryName = getIndexBasedQueryName(1);
         String userName = getIndexBasedUserName(0);
 
-        AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName,
BASIC);
+        AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName);
         assertNotNull(expected);
 
         userProfileService.deleteSavedSearch(expected.getGuid());
-        userProfileService.getSavedSearch(userName, queryName, BASIC);
+        userProfileService.getSavedSearch(userName, queryName);
     }
 
     @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser", "verifyQueryNameListForUser"})

http://git-wip-us.apache.org/repos/asf/atlas/blob/7cce1c4a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
index aed82ae..747fb4b 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
@@ -24,7 +24,6 @@ import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.discovery.AtlasSearchResult;
 import org.apache.atlas.model.discovery.SearchParameters;
 import org.apache.atlas.model.profile.AtlasUserSavedSearch;
-import org.apache.atlas.model.profile.AtlasUserSavedSearch.SavedSearchType;
 import org.apache.atlas.utils.AtlasPerfTracer;
 import org.apache.atlas.web.util.Servlets;
 import org.apache.commons.collections.CollectionUtils;
@@ -98,18 +97,7 @@ public class DiscoveryREST {
                         + "," + classification + "," + limit + "," + offset + ")");
             }
 
-            String queryStr = query == null ? "" : query;
-
-            if (StringUtils.isNoneEmpty(typeName)) {
-                queryStr = escapeTypeName(typeName) + " " + queryStr;
-            }
-
-            if (StringUtils.isNoneEmpty(classification)) {
-                // isa works with a type name only - like hive_column isa PII; it doesn't
work with more complex query
-                if (StringUtils.isEmpty(query)) {
-                    queryStr += (" isa " + classification);
-                }
-            }
+            String queryStr = atlasDiscoveryService.getDslQueryUsingTypeNameClassification(query,
typeName, classification);
 
             return atlasDiscoveryService.searchUsingDslQuery(queryStr, limit, offset);
         } finally {
@@ -117,6 +105,8 @@ public class DiscoveryREST {
         }
     }
 
+
+
     /**
      * Retrieve data for the specified fulltext query
      *
@@ -332,17 +322,15 @@ public class DiscoveryREST {
     @Path("saved")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
-    public AtlasUserSavedSearch createSavedSearch(AtlasUserSavedSearch savedSearch) throws
AtlasBaseException, IOException {
-        savedSearch.setOwnerName(Servlets.getUserName(httpServletRequest));
-
+    public AtlasUserSavedSearch addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException,
IOException {
         AtlasPerfTracer perf = null;
 
         try {
             if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.createSavedSearch(ownerName="
+ savedSearch.getOwnerName() + ", name=" + savedSearch.getName() + ", searchType=" + savedSearch.getSearchType()
+ ")");
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.addSavedSearch(userName="
+ savedSearch.getOwnerName() + ", name=" + savedSearch.getName() + ", searchType=" + savedSearch.getSearchType()
+ ")");
             }
 
-            return atlasDiscoveryService.addSavedSearch(savedSearch);
+            return atlasDiscoveryService.addSavedSearch(Servlets.getUserName(httpServletRequest),
savedSearch);
         } finally {
             AtlasPerfTracer.log(perf);
         }
@@ -359,16 +347,14 @@ public class DiscoveryREST {
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public AtlasUserSavedSearch updateSavedSearch(AtlasUserSavedSearch savedSearch) throws
AtlasBaseException {
-        savedSearch.setOwnerName(Servlets.getUserName(httpServletRequest));
-
         AtlasPerfTracer perf = null;
 
         try {
             if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.updateSavedSearch(ownerName="
+ savedSearch.getOwnerName() + ", name=" + savedSearch.getName() + ", searchType=" + savedSearch.getSearchType()
+ ")");
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.updateSavedSearch(userName="
+ savedSearch.getOwnerName() + ", name=" + savedSearch.getName() + ", searchType=" + savedSearch.getSearchType()
+ ")");
             }
 
-            return atlasDiscoveryService.updateSavedSearch(savedSearch);
+            return atlasDiscoveryService.updateSavedSearch(Servlets.getUserName(httpServletRequest),
savedSearch);
         } finally {
             AtlasPerfTracer.log(perf);
         }
@@ -376,34 +362,34 @@ public class DiscoveryREST {
 
     /**
      *
-     * @param userName User for whom the search is retrieved
      * @param searchName Name of the saved search
+     * @param userName User for whom the search is retrieved
      * @return
      * @throws AtlasBaseException
      */
     @GET
-    @Path("saved/{type}/{name}")
+    @Path("saved/{name}")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
-    public AtlasUserSavedSearch getSavedSearch(@PathParam("type") String searchType,
-                                               @PathParam("name") String searchName,
+    public AtlasUserSavedSearch getSavedSearch(@PathParam("name") String searchName,
                                                @QueryParam("user") String userName) throws
AtlasBaseException {
-        userName = StringUtils.isBlank(userName) ? Servlets.getUserName(httpServletRequest)
: userName;
-
         AtlasPerfTracer perf = null;
 
         try {
             if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSavedSearch(user="
+ userName + ", name=" + searchName + ", type=" + searchType + ")");
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSavedSearch(userName="
+ userName + ", name=" + searchName + ")");
             }
 
-            return atlasDiscoveryService.getSavedSearch(userName, searchName, SavedSearchType.to(searchType));
+            return atlasDiscoveryService.getSavedSearchByName(Servlets.getUserName(httpServletRequest),
userName, searchName);
         } finally {
             AtlasPerfTracer.log(perf);
         }
     }
 
     /**
+     *
+     * @param userName User for whom the search is retrieved
+     * @throws AtlasBaseException
      * @return list of all saved searches for given user
      */
     @GET
@@ -411,16 +397,14 @@ public class DiscoveryREST {
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public List<AtlasUserSavedSearch> getSavedSearches(@QueryParam("user") String userName)
throws AtlasBaseException {
-        userName = StringUtils.isBlank(userName) ? Servlets.getUserName(httpServletRequest)
: userName;
-
         AtlasPerfTracer perf = null;
 
         try {
             if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
-                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSavedSearches(user="
+ userName + ")");
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSavedSearches(userName="
+ userName + ")");
             }
 
-            return atlasDiscoveryService.getSavedSearches(userName);
+            return atlasDiscoveryService.getSavedSearches(Servlets.getUserName(httpServletRequest),
userName);
         } finally {
             AtlasPerfTracer.log(perf);
         }
@@ -441,34 +425,84 @@ public class DiscoveryREST {
                 perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.deleteSavedSearch(guid="
+ guid + ")");
             }
 
-            AtlasUserSavedSearch savedSearch = atlasDiscoveryService.getSavedSearch(guid);
+            atlasDiscoveryService.deleteSavedSearch(Servlets.getUserName(httpServletRequest),
guid);
+        } finally {
+            AtlasPerfTracer.log(perf);
+        }
+    }
+
+
+    /**
+     * Attribute based search for entities satisfying the search parameters
+     *
+     * @param searchName name of saved-search
+     * @param userName saved-search owner
+     * @return Atlas search result
+     * @throws AtlasBaseException
+     */
+    @Path("saved/execute/{name}")
+    @GET
+    @Consumes(Servlets.JSON_MEDIA_TYPE)
+    @Produces(Servlets.JSON_MEDIA_TYPE)
+    public AtlasSearchResult executeSavedSearchByName(@PathParam("name") String searchName,
+                                                      @QueryParam("user") String userName)
throws AtlasBaseException {
+        AtlasPerfTracer perf = null;
 
-            // block attempt to delete another user's saved-search
-            if (!StringUtils.equals(savedSearch.getOwnerName(), Servlets.getUserName(httpServletRequest)))
{
-                throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "invalid data");
+        try {
+            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG,
+                        "DiscoveryREST.executeSavedSearchByName(userName=" + userName + ",
" + "name=" + searchName + ")");
             }
 
-            atlasDiscoveryService.deleteSavedSearch(guid);
+            AtlasUserSavedSearch savedSearch = atlasDiscoveryService.getSavedSearchByName(Servlets.getUserName(httpServletRequest),
userName, searchName);
+
+            return executeSavedSearch(savedSearch);
         } finally {
             AtlasPerfTracer.log(perf);
         }
     }
 
+    /**
+     * Attribute based search for entities satisfying the search parameters
+     *
+     * @param searchGuid Guid identifying saved search
+     * @return Atlas search result
+     * @throws AtlasBaseException
+     */
+    @Path("saved/execute/guid/{guid}")
+    @GET
+    @Consumes(Servlets.JSON_MEDIA_TYPE)
+    @Produces(Servlets.JSON_MEDIA_TYPE)
+    public AtlasSearchResult executeSavedSearchByGuid(@PathParam("guid") String searchGuid)
throws AtlasBaseException {
+        AtlasPerfTracer perf = null;
+
+        try {
+            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.executeSavedSearchByGuid("
+ searchGuid + ")");
+            }
+
+            AtlasUserSavedSearch savedSearch = atlasDiscoveryService.getSavedSearchByGuid(Servlets.getUserName(httpServletRequest),
searchGuid);
+
+            return executeSavedSearch(savedSearch);
+        } finally {
+            AtlasPerfTracer.log(perf);
+        }
+    }
 
     private boolean isEmpty(SearchParameters.FilterCriteria filterCriteria) {
         return filterCriteria == null ||
                 (StringUtils.isEmpty(filterCriteria.getAttributeName()) && CollectionUtils.isEmpty(filterCriteria.getCriterion()));
     }
 
-    private String escapeTypeName(String typeName) {
-        String ret;
+    private AtlasSearchResult executeSavedSearch(AtlasUserSavedSearch savedSearch) throws
AtlasBaseException {
+        SearchParameters sp = savedSearch.getSearchParameters();
+
+        if(savedSearch.getSearchType() == AtlasUserSavedSearch.SavedSearchType.ADVANCED)
{
+            String dslQuery = atlasDiscoveryService.getDslQueryUsingTypeNameClassification(sp.getQuery(),
sp.getTypeName(), sp.getClassification());
 
-        if (StringUtils.startsWith(typeName, "`") && StringUtils.endsWith(typeName,
"`")) {
-            ret = typeName;
+            return atlasDiscoveryService.searchUsingDslQuery(dslQuery, sp.getLimit(), sp.getOffset());
         } else {
-            ret = String.format("`%s`", typeName);
+            return atlasDiscoveryService.searchWithParameters(sp);
         }
-
-        return ret;
     }
 }


Mime
View raw message