Search in sources :

Example 16 with AtlasUserSavedSearch

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

the class UserProfileServiceTest method deleteUsingGuid.

@Test(dependsOnMethods = { "updateSearch" })
public void deleteUsingGuid() throws AtlasBaseException {
    String userName = getIndexBasedUserName(0);
    String queryName = getIndexBasedQueryName(1);
    AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName);
    assertNotNull(expected);
    userProfileService.deleteSavedSearch(expected.getGuid());
    try {
        userProfileService.getSavedSearch(userName, queryName);
    } catch (AtlasBaseException ex) {
        assertEquals(ex.getAtlasErrorCode().name(), AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND.name());
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 17 with AtlasUserSavedSearch

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

the class UserProfileServiceTest method deleteSavedQuery.

@Test(dependsOnMethods = { "deleteUsingGuid" })
public void deleteSavedQuery() throws AtlasBaseException {
    String userName = getIndexBasedUserName(0);
    AtlasUserProfile expected = userProfileService.getUserProfile(userName);
    assertNotNull(expected);
    int searchCount = expected.getSavedSearches().size();
    String queryNameToBeDeleted = getIndexBasedQueryName(NUM_SEARCHES - 2);
    userProfileService.deleteSearchBySearchName(userName, queryNameToBeDeleted);
    List<AtlasUserSavedSearch> savedSearchList = userProfileService.getSavedSearches(userName);
    assertEquals(savedSearchList.size(), searchCount - 1);
}
Also used : AtlasUserProfile(org.apache.atlas.model.profile.AtlasUserProfile) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 18 with AtlasUserSavedSearch

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

the class UserProfileServiceTest method createUserWithSavedQueries.

private void createUserWithSavedQueries(String userName) throws AtlasBaseException {
    SearchParameters actualSearchParameter = getActualSearchParameters();
    saveQueries(userName, actualSearchParameter);
    for (int i = 0; i < max_searches; i++) {
        AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName, getIndexBasedQueryName(i));
        assertEquals(savedSearch.getName(), getIndexBasedQueryName(i));
        assertEquals(savedSearch.getSearchParameters(), actualSearchParameter);
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch)

Example 19 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) AbstractDataTransferObject(org.apache.atlas.repository.ogm.AbstractDataTransferObject) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 20 with AtlasUserSavedSearch

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

the class AtlasUserProfileDTO method toEntityWithExtInfo.

@Override
public AtlasEntityWithExtInfo toEntityWithExtInfo(AtlasUserProfile obj) throws AtlasBaseException {
    AtlasEntity entity = toEntity(obj);
    AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity);
    AtlasObjectId userProfileId = new AtlasObjectId(entity.getGuid(), AtlasUserProfileDTO.ENTITY_TYPE_NAME, Collections.singletonMap(AtlasUserProfileDTO.PROPERTY_USER_NAME, obj.getName()));
    List<AtlasObjectId> objectIds = new ArrayList<>();
    for (AtlasUserSavedSearch ss : obj.getSavedSearches()) {
        AtlasEntity ssEntity = savedSearchDTO.toEntity(ss);
        ssEntity.setAttribute(AtlasSavedSearchDTO.PROPERTY_USER_PROFILE, userProfileId);
        entityWithExtInfo.addReferredEntity(ssEntity);
        objectIds.add(new AtlasObjectId(ssEntity.getGuid(), savedSearchDTO.getEntityType().getTypeName(), savedSearchDTO.getUniqueAttributes(ss)));
    }
    if (objectIds.size() > 0) {
        entity.setAttribute(PROPERTY_SAVED_SEARCHES, objectIds);
    }
    return entityWithExtInfo;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) 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