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