Search in sources :

Example 1 with AtlasUserProfile

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

the class UserProfileServiceTest method assertSaveLoadUserProfile.

private void assertSaveLoadUserProfile(int i) throws AtlasBaseException {
    String s = String.valueOf(i);
    AtlasUserProfile expected = getAtlasUserProfile(i);
    AtlasUserProfile actual = userProfileService.saveUserProfile(expected);
    assertNotNull(actual);
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getFullName(), actual.getFullName());
    assertNotNull(actual.getGuid());
}
Also used : AtlasUserProfile(org.apache.atlas.model.profile.AtlasUserProfile)

Example 2 with AtlasUserProfile

use of org.apache.atlas.model.profile.AtlasUserProfile 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)

Example 3 with AtlasUserProfile

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

the class UserProfileServiceTest method deleteUser.

@Test(dependsOnMethods = { "deleteSavedQuery" })
void deleteUser() throws AtlasBaseException {
    String userName = getIndexBasedUserName(0);
    AtlasUserProfile userProfile = userProfileService.getUserProfile(userName);
    if (userProfile.getSavedSearches() != null) {
        for (AtlasUserSavedSearch savedSearch : userProfile.getSavedSearches()) {
            userProfileService.deleteSavedSearch(savedSearch.getGuid());
        }
    }
    userProfileService.deleteUserProfile(userName);
    try {
        userProfileService.getUserProfile(userName);
    } catch (AtlasBaseException ex) {
        assertEquals(ex.getAtlasErrorCode().name(), AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND.name());
    }
}
Also used : AtlasUserProfile(org.apache.atlas.model.profile.AtlasUserProfile) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 4 with AtlasUserProfile

use of org.apache.atlas.model.profile.AtlasUserProfile 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 5 with AtlasUserProfile

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

the class UserProfileService method addSavedSearch.

public AtlasUserSavedSearch addSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException {
    String userName = savedSearch.getOwnerName();
    AtlasUserProfile userProfile = null;
    try {
        userProfile = getUserProfile(userName);
    } catch (AtlasBaseException excp) {
    // ignore
    }
    if (userProfile == null) {
        userProfile = new AtlasUserProfile(userName);
    }
    checkIfQueryAlreadyExists(savedSearch, userProfile);
    userProfile.getSavedSearches().add(savedSearch);
    userProfile = dataAccess.save(userProfile);
    for (AtlasUserSavedSearch s : userProfile.getSavedSearches()) {
        if (s.getName().equals(savedSearch.getName())) {
            return s;
        }
    }
    return savedSearch;
}
Also used : AtlasUserProfile(org.apache.atlas.model.profile.AtlasUserProfile) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch)

Aggregations

AtlasUserProfile (org.apache.atlas.model.profile.AtlasUserProfile)10 AtlasUserSavedSearch (org.apache.atlas.model.profile.AtlasUserSavedSearch)5 Test (org.testng.annotations.Test)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)2 AbstractDataTransferObject (org.apache.atlas.repository.ogm.AbstractDataTransferObject)1