atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [5/7] atlas git commit: ATLAS-2148: saved-search API enhancement to support searchType
Date Fri, 22 Sep 2017 02:10:33 GMT
ATLAS-2148: saved-search API enhancement to support searchType

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/4f1129bd
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/4f1129bd
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/4f1129bd

Branch: refs/heads/branch-0.8
Commit: 4f1129bdb70bb143db7fbc2f09b0f914db3c43d9
Parents: ceb5c0c
Author: ashutoshm <amestry@hortonworks.com>
Authored: Tue Sep 19 16:20:52 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Thu Sep 21 19:10:04 2017 -0700

----------------------------------------------------------------------
 addons/models/0010-base_model.json              |   8 ++
 .../model/profile/AtlasUserSavedSearch.java     |  35 +++++-
 .../atlas/discovery/AtlasDiscoveryService.java  |  15 ++-
 .../atlas/discovery/EntityDiscoveryService.java |  23 +++-
 .../repository/ogm/AtlasSavedSearchDTO.java     |   5 +-
 .../apache/atlas/repository/ogm/DataAccess.java |   2 +-
 .../userprofile/UserProfileService.java         |  23 ++--
 .../userprofile/UserProfileServiceTest.java     |  47 ++++---
 .../apache/atlas/web/rest/DiscoveryREST.java    | 126 ++++++++++++++-----
 9 files changed, 215 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/addons/models/0010-base_model.json
----------------------------------------------------------------------
diff --git a/addons/models/0010-base_model.json b/addons/models/0010-base_model.json
index 8f38f59..0a0244c 100644
--- a/addons/models/0010-base_model.json
+++ b/addons/models/0010-base_model.json
@@ -185,6 +185,14 @@
           "isUnique": true
         },
         {
+          "name": "searchType",
+          "typeName": "string",
+          "cardinality": "SINGLE",
+          "isIndexable": true,
+          "isOptional": false,
+          "isUnique": false
+        },
+        {
           "name": "searchParameters",
           "typeName": "string",
           "cardinality": "SINGLE",

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/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 b0698fc..8ecd52d 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
@@ -34,26 +34,41 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONL
 public class AtlasUserSavedSearch extends AtlasBaseModelObject implements Serializable {
     private static final long serialVersionUID = 1L;
 
+    public enum SavedSearchType {
+        BASIC,
+        ADVANCED;
+
+        public static SavedSearchType to(String val) {
+            return SavedSearchType.ADVANCED.name().equalsIgnoreCase(val) ? SavedSearchType.ADVANCED
: SavedSearchType.BASIC;
+        }
+    }
+
     private String           ownerName;
     private String           name;
+    private SavedSearchType  searchType;
     private SearchParameters searchParameters;
 
 
     public AtlasUserSavedSearch() {
-        this(null, null, null);
+        this(null, null, SavedSearchType.BASIC, null);
     }
 
-    public AtlasUserSavedSearch(String name, SearchParameters searchParameters) {
-        this(null, name, searchParameters);
+    public AtlasUserSavedSearch(String name, SavedSearchType searchType, SearchParameters
searchParameters) {
+        this(null, name, searchType, searchParameters);
     }
 
     public AtlasUserSavedSearch(String ownerName, String name) {
-        this(ownerName, name, null);
+        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, SearchParameters searchParameters)
{
+    public AtlasUserSavedSearch(String ownerName, String name, SavedSearchType savedSearchType,
SearchParameters searchParameters) {
         setOwnerName(ownerName);
         setName(name);
+        setSearchType(savedSearchType);
         setSearchParameters(searchParameters);
     }
 
@@ -74,6 +89,14 @@ public class AtlasUserSavedSearch extends AtlasBaseModelObject implements
Serial
         this.name = name;
     }
 
+    public SavedSearchType getSearchType() {
+        return searchType;
+    }
+
+    public void setSearchType(SavedSearchType searchType) {
+        this.searchType = searchType;
+    }
+
     public SearchParameters getSearchParameters() {
         return searchParameters;
     }
@@ -82,11 +105,11 @@ public class AtlasUserSavedSearch extends AtlasBaseModelObject implements
Serial
         this.searchParameters = searchParameters;
     }
 
-
     @Override
     public StringBuilder toString(StringBuilder sb) {
         sb.append(", ownerName=").append(ownerName);
         sb.append(", name=").append(name);
+        sb.append(", searchType=").append(searchType);
         sb.append(", searchParameters=");
         if (searchParameters == null) {
             sb.append("null");

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/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 baaee85..630e776 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
@@ -24,6 +24,7 @@ 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;
 
@@ -89,14 +90,14 @@ public interface AtlasDiscoveryService {
      * @param savedSearch Search to be saved
      * @throws AtlasBaseException
      */
-    void addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException;
+    AtlasUserSavedSearch addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException;
 
     /**
      *
      * @param savedSearch Search to be saved
      * @throws AtlasBaseException
      */
-    void updateSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException;
+    AtlasUserSavedSearch updateSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException;
 
     /**
      *
@@ -108,12 +109,20 @@ public interface AtlasDiscoveryService {
 
     /**
      *
+     * @param guid Guid for the saved search
+     * @return Search object identified by the guid
+     * @throws AtlasBaseException
+     */
+    AtlasUserSavedSearch getSavedSearch(String guid) throws AtlasBaseException;
+
+    /**
+     *
      * @param userName Name of the user who the search belongs
      * @param searchName Name of the search to be retrieved
      * @return Search object identified by the name
      * @throws AtlasBaseException
      */
-    AtlasUserSavedSearch getSavedSearch(String userName, String searchName) throws AtlasBaseException;
+    AtlasUserSavedSearch getSavedSearch(String userName, String searchName, SavedSearchType
searchType) throws AtlasBaseException;
 
     /**
      * @param guid Guid for the saved search

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/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 ad21ee4..e701dff 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -33,6 +33,7 @@ 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;
@@ -804,9 +805,9 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
 
 
     @Override
-    public void addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException
{
+    public AtlasUserSavedSearch addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException
{
         try {
-            userProfileService.addSavedSearch(savedSearch);
+            return userProfileService.addSavedSearch(savedSearch);
         } catch (AtlasBaseException e) {
             LOG.error("addSavedSearch({})", savedSearch, e);
             throw e;
@@ -815,9 +816,9 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
 
 
     @Override
-    public void updateSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException
{
+    public AtlasUserSavedSearch updateSavedSearch(AtlasUserSavedSearch savedSearch) throws
AtlasBaseException {
         try {
-            userProfileService.updateSavedSearch(savedSearch);
+            return userProfileService.updateSavedSearch(savedSearch);
         } catch (AtlasBaseException e) {
             LOG.error("updateSavedSearch({})", savedSearch, e);
             throw e;
@@ -835,9 +836,19 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
     }
 
     @Override
-    public AtlasUserSavedSearch getSavedSearch(String userName, String searchName) throws
AtlasBaseException {
+    public AtlasUserSavedSearch getSavedSearch(String guid) throws AtlasBaseException {
         try {
-            return userProfileService.getSavedSearch(userName, searchName);
+            return userProfileService.getSavedSearch(guid);
+        } catch (AtlasBaseException e) {
+            LOG.error("getSavedSearch({})", guid, e);
+            throw e;
+        }
+    }
+
+    @Override
+    public AtlasUserSavedSearch getSavedSearch(String userName, String searchName, SavedSearchType
searchType) throws AtlasBaseException {
+        try {
+            return userProfileService.getSavedSearch(userName, searchName, searchType);
         } catch (AtlasBaseException e) {
             LOG.error("getSavedSearch({}, {})", userName, searchName, e);
             throw e;

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/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 26eee20..aa8fc39 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
@@ -35,6 +35,7 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
     private static final String PROPERTY_OWNER_NAME        = "ownerName";
     private static final String PROPERTY_SEARCH_PARAMETERS = "searchParameters";
     private static final String PROPERTY_UNIQUE_NAME       = "uniqueName";
+    private static final String PROPERTY_SEARCH_TYPE       = "searchType";
 
     public AtlasSavedSearchDTO(AtlasTypeRegistry typeRegistry) {
         super(typeRegistry, AtlasUserSavedSearch.class);
@@ -47,6 +48,7 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
         savedSearch.setGuid(entity.getGuid());
         savedSearch.setName((String) entity.getAttribute(PROPERTY_NAME));
         savedSearch.setOwnerName((String) entity.getAttribute(PROPERTY_OWNER_NAME));
+        savedSearch.setSearchType(AtlasUserSavedSearch.SavedSearchType.to((String) entity.getAttribute(PROPERTY_SEARCH_TYPE)));
 
         String jsonSearchParams = (String) entity.getAttribute(PROPERTY_SEARCH_PARAMETERS);
 
@@ -68,6 +70,7 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
 
         entity.setAttribute(PROPERTY_NAME, obj.getName());
         entity.setAttribute(PROPERTY_OWNER_NAME, obj.getOwnerName());
+        entity.setAttribute(PROPERTY_SEARCH_TYPE, obj.getSearchType());
         entity.setAttribute(PROPERTY_UNIQUE_NAME, getUniqueValue(obj));
 
         if (obj.getSearchParameters() != null) {
@@ -92,6 +95,6 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
     }
 
     private String getUniqueValue(AtlasUserSavedSearch obj) {
-        return obj.getOwnerName() + ":" + obj.getName();
+        return String.format("%s:%s:%s", obj.getOwnerName(), obj.getName(), obj.getSearchType())
;
     }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/repository/src/main/java/org/apache/atlas/repository/ogm/DataAccess.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/DataAccess.java b/repository/src/main/java/org/apache/atlas/repository/ogm/DataAccess.java
index bc93cc6..c99d2f8 100644
--- a/repository/src/main/java/org/apache/atlas/repository/ogm/DataAccess.java
+++ b/repository/src/main/java/org/apache/atlas/repository/ogm/DataAccess.java
@@ -51,7 +51,7 @@ public class DataAccess {
             throw new AtlasBaseException(AtlasErrorCode.DATA_ACCESS_SAVE_FAILED, obj.toString());
         }
 
-        return obj;
+        return this.load(obj);
     }
 
     public <T extends AtlasBaseModelObject> T load(T obj) throws AtlasBaseException
{

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/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 766d1c7..99d13af 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,6 +22,7 @@ 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;
@@ -41,8 +42,8 @@ public class UserProfileService {
         this.dataAccess = dataAccess;
     }
 
-    public void saveUserProfile(AtlasUserProfile profile) throws AtlasBaseException {
-        dataAccess.save(profile);
+    public AtlasUserProfile saveUserProfile(AtlasUserProfile profile) throws AtlasBaseException
{
+        return dataAccess.save(profile);
     }
 
     public AtlasUserProfile getUserProfile(String userName) throws AtlasBaseException {
@@ -51,7 +52,7 @@ public class UserProfileService {
         return dataAccess.load(profile);
     }
 
-    public AtlasUserProfile addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException
{
+    public AtlasUserSavedSearch addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException
{
         String userName = savedSearch.getOwnerName();
         AtlasUserProfile userProfile = null;
 
@@ -67,13 +68,21 @@ public class UserProfileService {
 
         checkIfQueryAlreadyExists(savedSearch, userProfile);
         userProfile.getSavedSearches().add(savedSearch);
-        return dataAccess.save(userProfile);
+        userProfile = dataAccess.save(userProfile);
+        for (AtlasUserSavedSearch s : userProfile.getSavedSearches()) {
+            if(s.getName().equals(savedSearch.getName()) && s.getSearchType().equals(savedSearch.getSearchType()))
{
+                return s;
+            }
+        }
+
+        return savedSearch;
     }
 
     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())) {
+                StringUtils.equals(exisingSearch.getName(), savedSearch.getName()) &&
+                exisingSearch.getSearchType().equals(savedSearch.getSearchType())) {
                 throw new AtlasBaseException(AtlasErrorCode.SAVED_SEARCH_ALREADY_EXISTS,
savedSearch.getName(), savedSearch.getOwnerName());
             }
         }
@@ -120,8 +129,8 @@ public class UserProfileService {
         return (profile != null) ? profile.getSavedSearches() : null;
     }
 
-    public AtlasUserSavedSearch getSavedSearch(String userName, String searchName) throws
AtlasBaseException {
-        AtlasUserSavedSearch ss = new AtlasUserSavedSearch(userName, searchName);
+    public AtlasUserSavedSearch getSavedSearch(String userName, String searchName, SavedSearchType
searchType) throws AtlasBaseException {
+        AtlasUserSavedSearch ss = new AtlasUserSavedSearch(userName, searchName, searchType);
 
         return dataAccess.load(ss);
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/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 4e83296..713dade 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
@@ -37,6 +37,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.apache.atlas.model.profile.AtlasUserSavedSearch.SavedSearchType.BASIC;
 import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadModelFromJson;
 import static org.testng.Assert.*;
 
@@ -77,7 +78,7 @@ public class UserProfileServiceTest {
     }
 
     @Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser" }, expectedExceptions
= AtlasBaseException.class)
-    public void savesAlreadyExistingQueryForAnExistingUser() throws AtlasBaseException {
+    public void atteptsToAddAlreadyExistingQueryForAnExistingUser() throws AtlasBaseException
{
         SearchParameters expectedSearchParameter = getActualSearchParameters();
 
         for (int i = 0; i < 2; i++) {
@@ -85,13 +86,20 @@ public class UserProfileServiceTest {
 
             for (int j = 0; j < max_searches; j++) {
                 String queryName = getIndexBasedQueryName(j);
-                AtlasUserProfile actual = userProfileService.addSavedSearch(new AtlasUserSavedSearch(userName,
queryName, expectedSearchParameter));
+                AtlasUserSavedSearch expected = getDefaultSavedSearch(userName, queryName,
expectedSearchParameter);
+                AtlasUserSavedSearch actual = userProfileService.addSavedSearch(expected);
+
                 assertNotNull(actual);
+                assertNotNull(actual.getGuid());
+                assertEquals(actual.getOwnerName(), expected.getOwnerName());
+                assertEquals(actual.getName(), expected.getName());
+                assertEquals(actual.getSearchType(), expected.getSearchType());
+                assertEquals(actual.getSearchParameters(), expected.getSearchParameters());
             }
         }
     }
 
-    @Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser", "savesAlreadyExistingQueryForAnExistingUser"
})
+    @Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser", "atteptsToAddAlreadyExistingQueryForAnExistingUser"
})
     public void savesExistingQueryForAnExistingUser() throws AtlasBaseException {
         SearchParameters expectedSearchParameter = getActualSearchParameters();
 
@@ -100,10 +108,10 @@ public class UserProfileServiceTest {
 
             for (int j = 4; j < max_searches + 6; j++) {
                 String queryName = getIndexBasedQueryName(j);
-                AtlasUserProfile actual = userProfileService.addSavedSearch(new AtlasUserSavedSearch(userName,
queryName, expectedSearchParameter));
+                AtlasUserSavedSearch actual = userProfileService.addSavedSearch(getDefaultSavedSearch(userName,
queryName, expectedSearchParameter));
                 assertNotNull(actual);
 
-                AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
queryName);
+                AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
queryName, BASIC);
                 assertNotNull(savedSearch);
                 assertEquals(savedSearch.getSearchParameters(), expectedSearchParameter);
             }
@@ -122,14 +130,19 @@ public class UserProfileServiceTest {
 
     @Test(dependsOnMethods = "createsNewProfile")
     public void savesQueryForAnNonExistentUser() throws AtlasBaseException {
-        String expectedUserName = "firstXYZ";
+        String expectedUserName = getIndexBasedUserName(0);
         String expectedQueryName = "testQuery";
         SearchParameters expectedSearchParam = getActualSearchParameters();
+        AtlasUserSavedSearch expectedSavedSearch = getDefaultSavedSearch(expectedUserName,
expectedQueryName, expectedSearchParam);
+
+        AtlasUserSavedSearch actual = userProfileService.addSavedSearch(expectedSavedSearch);
+        assertEquals(actual.getOwnerName(), expectedUserName);
+        assertEquals(actual.getName(), expectedQueryName);
+    }
 
-        AtlasUserProfile actual = userProfileService.addSavedSearch(new AtlasUserSavedSearch(expectedUserName,
expectedQueryName, expectedSearchParam));
-        assertEquals(actual.getName(), expectedUserName);
-        assertEquals(actual.getSavedSearches().size(), 1);
-        assertEquals(actual.getSavedSearches().get(0).getName(), expectedQueryName);
+    private AtlasUserSavedSearch getDefaultSavedSearch(String userName, String queryName,
SearchParameters expectedSearchParam) {
+        return new AtlasUserSavedSearch(userName, queryName,
+                BASIC, expectedSearchParam);
     }
 
     @Test(dependsOnMethods = "createsNewProfile")
@@ -143,7 +156,7 @@ public class UserProfileServiceTest {
 
         saveQueries(userName, actualSearchParameter);
         for (int i = 0; i < max_searches; i++) {
-            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
getIndexBasedQueryName(i));
+            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName,
getIndexBasedQueryName(i), BASIC);
             assertEquals(savedSearch.getName(), getIndexBasedQueryName(i));
             assertEquals(savedSearch.getSearchParameters(), actualSearchParameter);
         }
@@ -151,7 +164,7 @@ public class UserProfileServiceTest {
 
     private void saveQueries(String userName, SearchParameters sp) throws AtlasBaseException
{
         for (int i = 0; i < max_searches; i++) {
-            userProfileService.addSavedSearch(new AtlasUserSavedSearch(userName, getIndexBasedQueryName(i),
sp));
+            userProfileService.addSavedSearch(getDefaultSavedSearch(userName, getIndexBasedQueryName(i),
sp));
         }
     }
 
@@ -181,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);
+        AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName,
BASIC);
         assertNotNull(expected);
 
         SearchParameters sp = expected.getSearchParameters();
@@ -199,11 +212,11 @@ public class UserProfileServiceTest {
         final String queryName = getIndexBasedQueryName(1);
         String userName = getIndexBasedUserName(0);
 
-        AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName);
+        AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName,
BASIC);
         assertNotNull(expected);
 
         userProfileService.deleteSavedSearch(expected.getGuid());
-        userProfileService.getSavedSearch(userName, queryName);
+        userProfileService.getSavedSearch(userName, queryName, BASIC);
     }
 
     @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser", "verifyQueryNameListForUser"})
@@ -236,12 +249,12 @@ public class UserProfileServiceTest {
     private void assertSaveLoadUserProfile(int i) throws AtlasBaseException {
         String s = String.valueOf(i);
         AtlasUserProfile expected = getAtlasUserProfile(i);
-        userProfileService.saveUserProfile(expected);
 
-        AtlasUserProfile actual = userProfileService.getUserProfile(expected.getName());
+        AtlasUserProfile actual = userProfileService.saveUserProfile(expected);
         assertNotNull(actual);
         assertEquals(expected.getName(), actual.getName());
         assertEquals(expected.getFullName(), actual.getFullName());
+        assertNotNull(actual.getGuid());
     }
 
     public static AtlasUserProfile getAtlasUserProfile(Integer s) {

http://git-wip-us.apache.org/repos/asf/atlas/blob/4f1129bd/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 ad595c8..aed82ae 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,6 +24,7 @@ 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;
@@ -321,25 +322,9 @@ public class DiscoveryREST {
         }
     }
 
-    private boolean isEmpty(SearchParameters.FilterCriteria filterCriteria) {
-        return filterCriteria == null ||
-                (StringUtils.isEmpty(filterCriteria.getAttributeName()) && CollectionUtils.isEmpty(filterCriteria.getCriterion()));
-    }
-
-    private String escapeTypeName(String typeName) {
-        String ret;
-
-        if (StringUtils.startsWith(typeName, "`") && StringUtils.endsWith(typeName,
"`")) {
-            ret = typeName;
-        } else {
-            ret = String.format("`%s`", typeName);
-        }
-
-        return ret;
-    }
-
     /**
      * @param savedSearch
+     * @return the saved search-object
      * @throws AtlasBaseException
      * @throws IOException
      */
@@ -347,36 +332,75 @@ public class DiscoveryREST {
     @Path("saved")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
-    public void createSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException,
IOException {
+    public AtlasUserSavedSearch createSavedSearch(AtlasUserSavedSearch savedSearch) throws
AtlasBaseException, IOException {
         savedSearch.setOwnerName(Servlets.getUserName(httpServletRequest));
 
-        atlasDiscoveryService.addSavedSearch(savedSearch);
+        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()
+ ")");
+            }
+
+            return atlasDiscoveryService.addSavedSearch(savedSearch);
+        } finally {
+            AtlasPerfTracer.log(perf);
+        }
     }
 
-    /**
+    /***
+     *
      * @param savedSearch
+     * @return the updated search-object
      * @throws AtlasBaseException
-     * @throws IOException
      */
     @PUT
     @Path("saved")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
-    public void updateSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException
{
-        atlasDiscoveryService.updateSavedSearch(savedSearch);
+    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()
+ ")");
+            }
+
+            return atlasDiscoveryService.updateSavedSearch(savedSearch);
+        } finally {
+            AtlasPerfTracer.log(perf);
+        }
     }
 
     /**
+     *
+     * @param userName User for whom the search is retrieved
      * @param searchName Name of the saved search
      * @return
+     * @throws AtlasBaseException
      */
     @GET
-    @Path("saved/{name}")
+    @Path("saved/{type}/{name}")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
-    public AtlasUserSavedSearch getSavedSearch(@QueryParam("user") String userName, @PathParam("name")
String searchName) throws AtlasBaseException {
+    public AtlasUserSavedSearch getSavedSearch(@PathParam("type") String searchType,
+                                               @PathParam("name") String searchName,
+                                               @QueryParam("user") String userName) throws
AtlasBaseException {
         userName = StringUtils.isBlank(userName) ? Servlets.getUserName(httpServletRequest)
: userName;
-        return atlasDiscoveryService.getSavedSearch(userName, searchName);
+
+        AtlasPerfTracer perf = null;
+
+        try {
+            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSavedSearch(user="
+ userName + ", name=" + searchName + ", type=" + searchType + ")");
+            }
+
+            return atlasDiscoveryService.getSavedSearch(userName, searchName, SavedSearchType.to(searchType));
+        } finally {
+            AtlasPerfTracer.log(perf);
+        }
     }
 
     /**
@@ -388,7 +412,18 @@ public class DiscoveryREST {
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public List<AtlasUserSavedSearch> getSavedSearches(@QueryParam("user") String userName)
throws AtlasBaseException {
         userName = StringUtils.isBlank(userName) ? Servlets.getUserName(httpServletRequest)
: userName;
-        return atlasDiscoveryService.getSavedSearches(userName);
+
+        AtlasPerfTracer perf = null;
+
+        try {
+            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSavedSearches(user="
+ userName + ")");
+            }
+
+            return atlasDiscoveryService.getSavedSearches(userName);
+        } finally {
+            AtlasPerfTracer.log(perf);
+        }
     }
 
     /**
@@ -399,6 +434,41 @@ public class DiscoveryREST {
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
     public void deleteSavedSearch(@PathParam("guid") String guid) throws AtlasBaseException
{
-        atlasDiscoveryService.deleteSavedSearch(guid);
+        AtlasPerfTracer perf = null;
+
+        try {
+            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.deleteSavedSearch(guid="
+ guid + ")");
+            }
+
+            AtlasUserSavedSearch savedSearch = atlasDiscoveryService.getSavedSearch(guid);
+
+            // 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");
+            }
+
+            atlasDiscoveryService.deleteSavedSearch(guid);
+        } 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;
+
+        if (StringUtils.startsWith(typeName, "`") && StringUtils.endsWith(typeName,
"`")) {
+            ret = typeName;
+        } else {
+            ret = String.format("`%s`", typeName);
+        }
+
+        return ret;
     }
 }


Mime
View raw message