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());
}
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;
}
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());
}
}
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);
}
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;
}
Aggregations