use of edu.harvard.iq.dataverse.authorization.DataverseRolePermissionHelper in project dataverse by IQSS.
the class DataRetrieverAPI method retrieveMyDataAsJsonString.
/**
* @todo This should support the "X-Dataverse-key" header like the other
* APIs.
*/
@Path(retrieveDataPartialAPIPath)
@GET
@Produces({ "application/json" })
public String retrieveMyDataAsJsonString(@QueryParam("dvobject_types") List<String> dvobject_types, @QueryParam("published_states") List<String> published_states, @QueryParam("selected_page") Integer selectedPage, @QueryParam("mydata_search_term") String searchTerm, @QueryParam("role_ids") List<Long> roleIds, @QueryParam("userIdentifier") String userIdentifier, @QueryParam("key") String apiToken) {
// String myDataParams) {
// System.out.println("_YE_OLDE_QUERY_COUNTER_");
// msgt("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes
boolean DEBUG_MODE = false;
boolean OTHER_USER = false;
// For, superusers, the searchUser may differ from the authUser
//
AuthenticatedUser searchUser = null;
if (DEBUG_MODE == true) {
// DEBUG: use userIdentifier
authUser = getUserFromIdentifier(userIdentifier);
if (authUser == null) {
return this.getJSONErrorString("Requires authentication", "retrieveMyDataAsJsonString. User not found! Shouldn't be using this anyway");
}
} else if ((session.getUser() != null) && (session.getUser().isAuthenticated())) {
authUser = (AuthenticatedUser) session.getUser();
// and use that instead
if ((authUser.isSuperuser()) && (userIdentifier != null) && (!userIdentifier.isEmpty())) {
searchUser = getUserFromIdentifier(userIdentifier);
if (searchUser != null) {
authUser = searchUser;
OTHER_USER = true;
} else {
return this.getJSONErrorString("No user found for: \"" + userIdentifier + "\"", null);
}
}
} else if (apiToken != null) {
// Is this being accessed by an API Token?
authUser = findUserByApiToken(apiToken);
if (authUser == null) {
return this.getJSONErrorString("Requires authentication. Please login.", "retrieveMyDataAsJsonString. User not found! Shouldn't be using this anyway");
} else {
// and use that instead
if ((authUser.isSuperuser()) && (userIdentifier != null) && (!userIdentifier.isEmpty())) {
searchUser = getUserFromIdentifier(userIdentifier);
if (searchUser != null) {
authUser = searchUser;
OTHER_USER = true;
} else {
return this.getJSONErrorString("No user found for: \"" + userIdentifier + "\"", null);
}
}
}
} else {
return this.getJSONErrorString("Requires authentication. Please login.", "retrieveMyDataAsJsonString. User not found! Shouldn't be using this anyway");
}
roleList = dataverseRoleService.findAll();
rolePermissionHelper = new DataverseRolePermissionHelper(roleList);
List<String> dtypes;
if (dvobject_types != null) {
dtypes = dvobject_types;
} else {
dtypes = MyDataFilterParams.defaultDvObjectTypes;
}
List<String> pub_states = null;
if (published_states != null) {
pub_states = published_states;
}
// ---------------------------------
// (1) Initialize filterParams and check for Errors
// ---------------------------------
DataverseRequest dataverseRequest = createDataverseRequest(authUser);
MyDataFilterParams filterParams = new MyDataFilterParams(dataverseRequest, dtypes, pub_states, roleIds, searchTerm);
if (filterParams.hasError()) {
return this.getJSONErrorString(filterParams.getErrorMessage(), filterParams.getErrorMessage());
}
// ---------------------------------
// (2) Initialize MyDataFinder and check for Errors
// ---------------------------------
myDataFinder = new MyDataFinder(rolePermissionHelper, roleAssigneeService, dvObjectServiceBean, groupService);
this.myDataFinder.runFindDataSteps(filterParams);
if (myDataFinder.hasError()) {
return this.getJSONErrorString(myDataFinder.getErrorMessage(), myDataFinder.getErrorMessage());
}
// ---------------------------------
// (3) Make Solr Query
// ---------------------------------
int paginationStart = 1;
if (selectedPage != null) {
paginationStart = selectedPage;
}
int solrCardStart = (paginationStart - 1) * SearchConstants.NUM_SOLR_DOCS_TO_RETRIEVE;
//
if (searchUser == null) {
searchUser = authUser;
}
// msg("search with user: " + searchUser.getIdentifier());
List<String> filterQueries = this.myDataFinder.getSolrFilterQueries();
if (filterQueries == null) {
logger.fine("No ids found for this search");
return this.getJSONErrorString(DataRetrieverAPI.MSG_NO_RESULTS_FOUND, null);
}
try {
solrQueryResponse = searchService.search(dataverseRequest, // subtree, default it to Dataverse for now
null, // "*", //
filterParams.getSearchTerm(), // filterQueries,
filterQueries, // SearchFields.NAME_SORT, SortBy.ASCENDING,
SearchFields.RELEASE_OR_CREATE_DATE, SortBy.DESCENDING, // paginationStart,
solrCardStart, // dataRelatedToMe
true, // 10 // SearchFields.NUM_SOLR_DOCS_TO_RETRIEVE
SearchConstants.NUM_SOLR_DOCS_TO_RETRIEVE);
// msgt("getSolrSearchResults: " + this.solrQueryResponse.getSolrSearchResults().toString());
if (this.solrQueryResponse.getNumResultsFound() == 0) {
return this.getJSONErrorString(DataRetrieverAPI.MSG_NO_RESULTS_FOUND, null);
}
} catch (SearchException ex) {
solrQueryResponse = null;
this.logger.severe("Solr SearchException: " + ex.getMessage());
}
if (solrQueryResponse == null) {
return this.getJSONErrorString("Sorry! There was an error with the search service.", "Sorry! There was a SOLR Error");
}
// ---------------------------------
// (4) Build JSON document including:
// - Pager
// - Formatted solr docs
// - Num results found
// - Search term
// - DvObject counts
// ---------------------------------
// Initialize JSON response
JsonObjectBuilder jsonData = Json.createObjectBuilder();
Pager pager = new Pager(solrQueryResponse.getNumResultsFound().intValue(), SearchConstants.NUM_SOLR_DOCS_TO_RETRIEVE, paginationStart);
RoleTagRetriever roleTagRetriever = new RoleTagRetriever(this.rolePermissionHelper, this.roleAssigneeSvc, this.dvObjectServiceBean);
roleTagRetriever.loadRoles(dataverseRequest, solrQueryResponse);
jsonData.add(DataRetrieverAPI.JSON_SUCCESS_FIELD_NAME, true).add(DataRetrieverAPI.JSON_DATA_FIELD_NAME, Json.createObjectBuilder().add("pagination", pager.asJsonObjectBuilderUsingCardTerms()).add(SearchConstants.SEARCH_API_ITEMS, this.formatSolrDocs(solrQueryResponse, roleTagRetriever)).add(SearchConstants.SEARCH_API_TOTAL_COUNT, solrQueryResponse.getNumResultsFound()).add(SearchConstants.SEARCH_API_START, solrQueryResponse.getResultsStart()).add("search_term", filterParams.getSearchTerm()).add("dvobject_counts", this.getDvObjectTypeCounts(solrQueryResponse)).add("pubstatus_counts", this.getPublicationStatusCounts(solrQueryResponse)).add("selected_filters", this.myDataFinder.getSelectedFilterParamsAsJSON()));
if (OTHER_USER == true) {
jsonData.add("other_user", searchUser.getIdentifier());
}
return jsonData.build().toString();
}
use of edu.harvard.iq.dataverse.authorization.DataverseRolePermissionHelper in project dataverse by IQSS.
the class RolePermissionHelperPage method init.
public String init() {
// msgt("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes
List<DataverseRole> roleList = dataverseRoleService.findAll();
rolePermissionHelper = new DataverseRolePermissionHelper(roleList);
List<String> dtypes = MyDataFilterParams.defaultDvObjectTypes;
return null;
}
use of edu.harvard.iq.dataverse.authorization.DataverseRolePermissionHelper in project dataverse by IQSS.
the class ManagePermissionsPage method init.
public String init() {
// @todo deal with any kind of dvObject
if (dvObject.getId() != null) {
dvObject = dvObjectService.findDvObject(dvObject.getId());
}
// check if dvObject exists and user has permission
if (dvObject == null) {
return permissionsWrapper.notFound();
}
// for dataFiles, check the perms on its owning dataset
DvObject checkPermissionsdvObject = dvObject instanceof DataFile ? dvObject.getOwner() : dvObject;
if (!permissionService.on(checkPermissionsdvObject).has(checkPermissionsdvObject instanceof Dataverse ? Permission.ManageDataversePermissions : Permission.ManageDatasetPermissions)) {
return permissionsWrapper.notAuthorized();
}
// initialize the configure settings
if (dvObject instanceof Dataverse) {
initAccessSettings();
}
roleList = roleService.findAll();
roleAssignments = initRoleAssignments();
dataverseRolePermissionHelper = new DataverseRolePermissionHelper(roleList);
return "";
}
use of edu.harvard.iq.dataverse.authorization.DataverseRolePermissionHelper in project dataverse by IQSS.
the class MyDataPage method init.
public String init() {
if ((session.getUser() != null) && (session.getUser().isAuthenticated())) {
authUser = (AuthenticatedUser) session.getUser();
} else {
return permissionsWrapper.notAuthorized();
// redirect to login OR give some type ‘you must be logged in message'
}
// Initialize a filterParams object to buid the Publication Status checkboxes
//
HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
DataverseRequest dataverseRequest = new DataverseRequest(authUser, httpServletRequest);
this.filterParams = new MyDataFilterParams(dataverseRequest, MyDataFilterParams.defaultDvObjectTypes, null, null, null);
// Temp DataverseRolePermissionHelper -- not in its normal role but for creating initial checkboxes
//
rolePermissionHelper = new DataverseRolePermissionHelper(getRolesUsedToCreateCheckboxes(dataverseRequest));
// this.setUserCountTotals(authUser, rolePermissionHelper);
return null;
}
Aggregations