Skip to content

Commit

Permalink
Clean up BrowserService
Browse files Browse the repository at this point in the history
  • Loading branch information
hmiguim committed Jun 12, 2024
1 parent 45ef086 commit 979c15e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,33 +320,6 @@ public static <T extends IsIndexed> T retrieve(final User user, final Class<T> c
}
}

public static <T extends IsIndexed> List<T> retrieve(final User user, final Class<T> classToReturn,
final SelectedItems<T> selectedItems, final List<String> fieldsToReturn)
throws AuthorizationDeniedException, GenericException, NotFoundException, RequestNotValidException {
final ControllerAssistant controllerAssistant = new ControllerAssistant() {};

// check user permissions
controllerAssistant.checkRoles(user, classToReturn);

LogEntryState state = LogEntryState.SUCCESS;

try {
// delegate
final List<T> objects = BrowserHelper.retrieve(classToReturn, selectedItems, fieldsToReturn);
for (T obj : objects) {
controllerAssistant.checkObjectPermissions(user, obj, classToReturn);
}

return objects;
} catch (RODAException e) {
state = LogEntryState.FAILURE;
throw e;
} finally {
// register action
controllerAssistant.registerAction(user, state, RodaConstants.CONTROLLER_SELECTED_ITEMS_PARAM, selectedItems);
}
}

public static <T extends IsIndexed> void delete(final User user, final Class<T> classToReturn,
final SelectedItems<T> ids) throws AuthorizationDeniedException, GenericException, RequestNotValidException {
final ControllerAssistant controllerAssistant = new ControllerAssistant() {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,27 +572,6 @@ protected static <T extends IsIndexed> void commit(Class<T> returnClass)
RodaCoreFactory.getIndexService().commit(returnClass);
}

protected static <T extends IsIndexed> List<T> retrieve(Class<T> returnClass, SelectedItems<T> selectedItems,
List<String> fieldsToReturn) throws GenericException, NotFoundException, RequestNotValidException {
List<T> ret;

if (selectedItems instanceof SelectedItemsList) {
SelectedItemsList<T> selectedList = (SelectedItemsList<T>) selectedItems;
ret = RodaCoreFactory.getIndexService().retrieve(returnClass, selectedList.getIds(), fieldsToReturn);
} else if (selectedItems instanceof SelectedItemsFilter) {
SelectedItemsFilter<T> selectedFilter = (SelectedItemsFilter<T>) selectedItems;
int counter = RodaCoreFactory.getIndexService().count(returnClass, selectedFilter.getFilter()).intValue();
ret = RodaCoreFactory.getIndexService()
.find(returnClass, selectedFilter.getFilter(), Sorter.NONE, new Sublist(0, counter), fieldsToReturn)
.getResults();
} else {
throw new RequestNotValidException(
"Unsupported SelectedItems implementation: " + selectedItems.getClass().getName());
}

return ret;
}

public static void validateGetFileParams(String acceptFormat) throws RequestNotValidException {
if (!RodaConstants.API_QUERY_VALUE_ACCEPT_FORMAT_BIN.equals(acceptFormat)
&& !RodaConstants.API_QUERY_VALUE_ACCEPT_FORMAT_JSON.equals(acceptFormat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ void deleteDescriptiveMetadataVersion(String aipId, String representationId, Str
String versionId)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, GenericException;

<T extends IsIndexed> List<T> retrieve(String classNameToReturn, SelectedItems<T> selectedItems,
List<String> fieldsToReturn)
throws GenericException, AuthorizationDeniedException, NotFoundException, RequestNotValidException;

Job updateAIPPermissions(SelectedItems<IndexedAIP> aips, Permissions permissions, String details, boolean recursive)
throws GenericException, AuthorizationDeniedException, RequestNotValidException, NotFoundException,
JobAlreadyStartedException;
Expand Down Expand Up @@ -142,36 +138,12 @@ void deleteDistributedInstance(String distributedInstancesId)
DistributedInstance updateDistributedInstance(DistributedInstance distributedInstance)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, GenericException;

AccessKey createAccessKey(AccessKey accessKey) throws AuthorizationDeniedException, AlreadyExistsException,
NotFoundException, GenericException, RequestNotValidException, IOException;

AccessKeys listAccessKey()
throws AuthorizationDeniedException, IOException, GenericException, RequestNotValidException;

AccessKey retrieveAccessKey(String accessKeyId)
throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException;

void deleteAccessKey(String accessKeyId)
throws NotFoundException, GenericException, AuthorizationDeniedException, RequestNotValidException;

AccessKey updateAccessKey(AccessKey accessKey)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, GenericException;

AccessKeys listAccessKeyByUser(String userId)
throws AuthorizationDeniedException, IOException, GenericException, RequestNotValidException;

void deactivateUserAccessKeys(String userId)
throws AuthorizationDeniedException, RequestNotValidException, GenericException, NotFoundException;

void deleteUserAccessKeys(String userId)
throws AuthorizationDeniedException, RequestNotValidException, GenericException, NotFoundException;

AccessKey regenerateAccessKey(AccessKey accessKey) throws AuthorizationDeniedException, RequestNotValidException,
NotFoundException, GenericException, AuthenticationDeniedException;

AccessKey revokeAccessKey(AccessKey accessKey)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, GenericException;

void createLocalInstance(LocalInstance localInstance) throws AuthorizationDeniedException, GenericException;

LocalInstance retrieveLocalInstance() throws AuthorizationDeniedException, GenericException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ void revertDescriptiveMetadataVersion(String aipId, String representationId, Str
void deleteDescriptiveMetadataVersion(String aipId, String representationId, String descriptiveMetadataId,
String versionId, AsyncCallback<Void> callback);

<T extends IsIndexed> void retrieve(String classNameToReturn, SelectedItems<T> selectedItems,
List<String> fieldsToReturn, AsyncCallback<List<T>> asyncCallback);

void updateAIPPermissions(SelectedItems<IndexedAIP> aips, Permissions permissions, String details, boolean recursive,
AsyncCallback<Job> callback);

Expand All @@ -106,26 +103,10 @@ void changeAIPType(SelectedItems<IndexedAIP> selectedAIP, String newType, String

void deleteDistributedInstance(String distributedInstanceId, AsyncCallback<Void> async);

void createAccessKey(AccessKey accessKey, AsyncCallback<AccessKey> async);

void listAccessKey(AsyncCallback<AccessKeys> async);

void retrieveAccessKey(String accessKeyId, AsyncCallback<AccessKey> async);

void deleteAccessKey(String accessKeyId, AsyncCallback<Void> async);

void updateAccessKey(AccessKey accessKey, AsyncCallback<AccessKey> async);

void listAccessKeyByUser(String userId, AsyncCallback<AccessKeys> async);

void deactivateUserAccessKeys(String userId, AsyncCallback<Void> async);

void deleteUserAccessKeys(String userId, AsyncCallback<Void> async);

void regenerateAccessKey(AccessKey accessKey, AsyncCallback<AccessKey> async);

void revokeAccessKey(AccessKey accessKey, AsyncCallback<AccessKey> async);

void createLocalInstance(LocalInstance localInstance, AsyncCallback async);

void retrieveLocalInstance(AsyncCallback async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ public void onSuccess(final Void nothing) {
@UiHandler("buttonApply")
void buttonApplyHandler(ClickEvent e) {
apply(false);
}

@UiHandler("buttonApplyToAll")
void buttonApplyToAllHandler(ClickEvent e) {
apply(true);
} public static final HistoryResolver AIP_RESOLVER = new HistoryResolver() {

@Override
Expand Down Expand Up @@ -481,11 +486,6 @@ public String getHistoryToken() {
}
};

@UiHandler("buttonApplyToAll")
void buttonApplyToAllHandler(ClickEvent e) {
apply(true);
}

@UiHandler("buttonClose")
void buttonCancelHandler(ClickEvent e) {
if (objectId != null) {
Expand Down Expand Up @@ -659,25 +659,34 @@ public void resolve(List<String> historyTokens, final AsyncCallback<Widget> call
});
} else if (historyTokens.isEmpty()) {
LastSelectedItemsSingleton selectedItems = LastSelectedItemsSingleton.getInstance();
final SelectedItems<IndexedDIP> selected = (SelectedItems<IndexedDIP>) selectedItems.getSelectedItems();

if (!ClientSelectedItemsUtils.isEmpty(selected)) {
BrowserService.Util.getInstance().retrieve(IndexedDIP.class.getName(), selected,
RodaConstants.DIP_PERMISSIONS_FIELDS_TO_RETURN, new AsyncCallback<List<IndexedDIP>>() {

@Override
public void onFailure(Throwable caught) {
HistoryUtils.newHistory(BrowseTop.RESOLVER);
callback.onSuccess(null);
}

@Override
public void onSuccess(List<IndexedDIP> dips) {
List<? extends HasPermissions> hasPermissionsObjects = dips;
EditPermissions edit = new EditPermissions(IndexedDIP.class.getName(), selected, hasPermissionsObjects);
callback.onSuccess(edit);
}
});
SelectedItems<? extends IsIndexed> selected = selectedItems.getSelectedItems();
if (selected instanceof SelectedItemsList<?>) {
if (!ClientSelectedItemsUtils.isEmpty(selected)) {
List<String> ids = ((SelectedItemsList<? extends IsIndexed>) selected).getIds();
List<FilterParameter> collect = ids.stream()
.map(m -> new SimpleFilterParameter(RodaConstants.INDEX_UUID, m)).collect(Collectors.toList());
OrFiltersParameters orFiltersParameters = new OrFiltersParameters(collect);
FindRequest findRequest = FindRequest
.getBuilder(IndexedAIP.class.getName(), new Filter(orFiltersParameters), true)
.withSublist(new Sublist(0, 20)).build();
Services services = new Services("Find DIPs", "get");
services.aipResource(s -> s.find(findRequest, LocaleInfo.getCurrentLocale().getLocaleName()))
.whenComplete((result, throwable) -> {
if (throwable != null) {
HistoryUtils.newHistory(BrowseTop.RESOLVER);
callback.onFailure(throwable);
} else {
List<? extends HasPermissions> hasPermissionsObjects = result.getResults();
EditPermissions edit = new EditPermissions(IndexedDIP.class.getName(),
(SelectedItems<IndexedAIP>) selectedItems.getSelectedItems(), hasPermissionsObjects);
callback.onSuccess(edit);
}
});
}
} else {
EditPermissions editPermissions = new EditPermissions(IndexedDIP.class.getName(), selected);
callback.onSuccess(editPermissions);
}
} else {
HistoryUtils.newHistory(BrowseTop.RESOLVER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,6 @@ public DescriptiveMetadataEditBundle retrieveDescriptiveMetadataEditBundle(Strin
return Browser.retrieveDescriptiveMetadataEditBundle(user, aipId, representationId, descId, locale);
}

@Override
public <T extends IsIndexed> List<T> retrieve(String classNameToReturn, SelectedItems<T> selectedItems,
List<String> fieldsToReturn)
throws GenericException, AuthorizationDeniedException, NotFoundException, RequestNotValidException {
User user = UserUtility.getUser(getThreadLocalRequest());
Class<T> classToReturn = SelectedItemsUtils.parseClass(classNameToReturn);
return Browser.retrieve(user, classToReturn, selectedItems, fieldsToReturn);
}

@Override
public Job moveAIPInHierarchy(SelectedItems<IndexedAIP> selected, String parentId, String details)
throws AuthorizationDeniedException, GenericException, NotFoundException, RequestNotValidException {
Expand Down Expand Up @@ -357,13 +348,6 @@ public void deleteDistributedInstance(String distributedInstanceId)
RODAInstance.deleteDistributedInstance(user, distributedInstanceId);
}

@Override
public AccessKey createAccessKey(AccessKey accessKey) throws AuthorizationDeniedException, AlreadyExistsException,
NotFoundException, GenericException, RequestNotValidException, IOException {
User user = UserUtility.getUser(getThreadLocalRequest());
return ApplicationAuth.createAccessKey(user, accessKey);
}

@Override
public AccessKeys listAccessKey()
throws AuthorizationDeniedException, IOException, GenericException, RequestNotValidException {
Expand All @@ -378,55 +362,6 @@ public AccessKey retrieveAccessKey(String accessKeyId)
return ApplicationAuth.retrieveAccessKey(user, accessKeyId);
}

@Override
public AccessKey updateAccessKey(AccessKey accessKey)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, GenericException {
User user = UserUtility.getUser(getThreadLocalRequest());
return ApplicationAuth.updateAccessKey(user, accessKey);
}

@Override
public void deleteAccessKey(String accessKeyId)
throws NotFoundException, GenericException, AuthorizationDeniedException, RequestNotValidException {
User user = UserUtility.getUser(getThreadLocalRequest());
ApplicationAuth.deleteAccessKey(user, accessKeyId);
}

@Override
public AccessKeys listAccessKeyByUser(String userId)
throws AuthorizationDeniedException, IOException, GenericException, RequestNotValidException {
User user = UserUtility.getUser(getThreadLocalRequest());
return ApplicationAuth.listAccessKeyByUser(user, userId);
}

@Override
public void deactivateUserAccessKeys(String userId)
throws AuthorizationDeniedException, RequestNotValidException, GenericException, NotFoundException {
User user = UserUtility.getUser(getThreadLocalRequest());
ApplicationAuth.deactivateUserAccessKeys(user, userId);
}

@Override
public void deleteUserAccessKeys(String userId)
throws AuthorizationDeniedException, RequestNotValidException, GenericException, NotFoundException {
User user = UserUtility.getUser(getThreadLocalRequest());
ApplicationAuth.deleteUserAccessKeys(user, userId);
}

@Override
public AccessKey regenerateAccessKey(AccessKey accessKey) throws AuthorizationDeniedException,
RequestNotValidException, NotFoundException, GenericException, AuthenticationDeniedException {
User user = UserUtility.getUser(getThreadLocalRequest());
return ApplicationAuth.regenerateAccessKey(user, accessKey);
}

@Override
public AccessKey revokeAccessKey(AccessKey accessKey)
throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, GenericException {
User user = UserUtility.getUser(getThreadLocalRequest());
return ApplicationAuth.revokeAccessKey(user, accessKey);
}

@Override
public void createLocalInstance(LocalInstance localInstance) throws AuthorizationDeniedException, GenericException {
User user = UserUtility.getUser(getThreadLocalRequest());
Expand Down

0 comments on commit 979c15e

Please sign in to comment.