Search in sources :

Example 1 with AtlasUserSavedSearch

use of org.apache.atlas.model.profile.AtlasUserSavedSearch in project atlas by apache.

the class UserProfileServiceTest method atteptsToAddAlreadyExistingQueryForAnExistingUser.

@Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser" }, expectedExceptions = AtlasBaseException.class)
public void atteptsToAddAlreadyExistingQueryForAnExistingUser() throws AtlasBaseException {
    SearchParameters expectedSearchParameter = getActualSearchParameters();
    for (int i = 0; i < 2; i++) {
        String userName = getIndexBasedUserName(i);
        for (int j = 0; j < max_searches; j++) {
            String queryName = getIndexBasedQueryName(j);
            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());
        }
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 2 with AtlasUserSavedSearch

use of org.apache.atlas.model.profile.AtlasUserSavedSearch in project atlas by apache.

the class UserProfileServiceTest method savesQueryForAnNonExistentUser.

@Test(dependsOnMethods = "createsNewProfile")
public void savesQueryForAnNonExistentUser() throws AtlasBaseException {
    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);
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 3 with AtlasUserSavedSearch

use of org.apache.atlas.model.profile.AtlasUserSavedSearch in project atlas by apache.

the class UserProfileServiceTest method savesExistingQueryForAnExistingUser.

@Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser", "atteptsToAddAlreadyExistingQueryForAnExistingUser" })
public void savesExistingQueryForAnExistingUser() throws AtlasBaseException {
    SearchParameters expectedSearchParameter = getActualSearchParameters();
    for (int i = 0; i < 2; i++) {
        String userName = getIndexBasedUserName(i);
        for (int j = 4; j < max_searches + 6; j++) {
            String queryName = getIndexBasedQueryName(j);
            AtlasUserSavedSearch actual = userProfileService.addSavedSearch(getDefaultSavedSearch(userName, queryName, expectedSearchParameter));
            assertNotNull(actual);
            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName, queryName);
            assertNotNull(savedSearch);
            assertEquals(savedSearch.getSearchParameters(), expectedSearchParameter);
        }
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 4 with AtlasUserSavedSearch

use of org.apache.atlas.model.profile.AtlasUserSavedSearch in project atlas by apache.

the class AtlasSavedSearchDTO method from.

@Override
public AtlasUserSavedSearch from(AtlasEntity entity) {
    AtlasUserSavedSearch savedSearch = new AtlasUserSavedSearch();
    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);
    if (StringUtils.isNotEmpty(jsonSearchParams)) {
        savedSearch.setSearchParameters(AtlasType.fromJson(jsonSearchParams, SearchParameters.class));
    }
    savedSearch.setUiParameters((String) entity.getAttribute(PROPERTY_UI_PARAMETERS));
    return savedSearch;
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch)

Example 5 with AtlasUserSavedSearch

use of org.apache.atlas.model.profile.AtlasUserSavedSearch in project atlas by apache.

the class AtlasUserProfileDTO method from.

public AtlasUserProfile from(AtlasEntityWithExtInfo entityWithExtInfo) {
    AtlasUserProfile userProfile = from(entityWithExtInfo.getEntity());
    Object savedSearches = entityWithExtInfo.getEntity().getAttribute(PROPERTY_SAVED_SEARCHES);
    if (savedSearches instanceof Collection) {
        for (Object o : (Collection) savedSearches) {
            if (o instanceof AtlasObjectId) {
                AtlasObjectId ssObjId = (AtlasObjectId) o;
                AtlasEntity ssEntity = entityWithExtInfo.getReferredEntity(ssObjId.getGuid());
                if (ssEntity != null && ssEntity.getStatus() == AtlasEntity.Status.ACTIVE) {
                    AtlasUserSavedSearch savedSearch = savedSearchDTO.from(ssEntity);
                    userProfile.getSavedSearches().add(savedSearch);
                }
            }
        }
    }
    return userProfile;
}
Also used : AtlasUserProfile(org.apache.atlas.model.profile.AtlasUserProfile) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Aggregations

AtlasUserSavedSearch (org.apache.atlas.model.profile.AtlasUserSavedSearch)26 Test (org.testng.annotations.Test)13 SearchParameters (org.apache.atlas.model.discovery.SearchParameters)12 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 AtlasUserProfile (org.apache.atlas.model.profile.AtlasUserProfile)5 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 Timed (org.apache.atlas.annotation.Timed)2 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 IOException (java.io.IOException)1 QuickSearchParameters (org.apache.atlas.model.discovery.QuickSearchParameters)1 AbstractDataTransferObject (org.apache.atlas.repository.ogm.AbstractDataTransferObject)1