Skip to content

Commit

Permalink
added download button on representation information page #1177; added…
Browse files Browse the repository at this point in the history
… verification before moving AIPs and changed dialog title #1163
  • Loading branch information
nunovieira220 committed Mar 13, 2018
1 parent 7538884 commit 7485b41
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public enum DateGranularity {
public static final String API_REST_V1_DIPFILES = "api/v1/dipfiles/";
public static final String API_REST_V1_EVENTS = "api/v1/events/";
public static final String API_REST_V1_AGENTS = "api/v1/agents/";
public static final String API_REST_V1_REPRESENTATION_INFORMATION = "api/v1/representation_information/";
// sub-resources strings
public static final String API_DATA = "data";
public static final Object API_FILE = "file";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,14 @@ public interface ClientMessages extends Messages {

String removingSuccessMessage(Long size);

String moveConfirmDialogTitle();

String moveAllConfirmDialogMessageSingle(String aipTitle);

String moveAllConfirmDialogMessage();

String moveSelectedConfirmDialogMessage(Long size);

/************* Browse ****************/
String browseLoading();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,139 +220,181 @@ private void download(IndexedAIP aip, AsyncCallback<ActionImpact> callback) {
}

private void move(final IndexedAIP aip, final AsyncCallback<ActionImpact> callback) {
final String aipId = aip.getId();
boolean justActive = AIPState.ACTIVE.equals(aip.getState());
Dialogs.showConfirmDialog(messages.moveConfirmDialogTitle(),
messages.moveAllConfirmDialogMessageSingle(aip.getTitle()), messages.dialogNo(), messages.dialogYes(),
new AsyncCallback<Boolean>() {

Filter filter = new Filter(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, aipId));
SelectAipDialog selectAipDialog = new SelectAipDialog(messages.moveItemTitle(), filter, justActive, false);
selectAipDialog.setEmptyParentButtonVisible(true);
selectAipDialog.setSingleSelectionMode();
selectAipDialog.showAndCenter();
selectAipDialog.addValueChangeHandler(new ValueChangeHandler<IndexedAIP>() {
@Override
public void onFailure(Throwable caught) {
// nothing to do
}

@Override
public void onValueChange(ValueChangeEvent<IndexedAIP> event) {
final IndexedAIP parentAIP = event.getValue();
final String parentId = (parentAIP != null) ? parentAIP.getId() : null;
final SelectedItemsList<IndexedAIP> selected = new SelectedItemsList<>(Arrays.asList(aipId),
IndexedAIP.class.getName());
@Override
public void onSuccess(Boolean confirmed) {
if (confirmed) {
final String aipId = aip.getId();
boolean justActive = AIPState.ACTIVE.equals(aip.getState());

Dialogs.showPromptDialog(messages.outcomeDetailTitle(), null, null, messages.outcomeDetailPlaceholder(),
RegExp.compile(".*"), messages.cancelButton(), messages.confirmButton(), false, false,
new AsyncCallback<String>() {
Filter filter = new Filter(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, aipId));
SelectAipDialog selectAipDialog = new SelectAipDialog(messages.moveItemTitle() + " " + aip.getTitle(),
filter, justActive, false);
selectAipDialog.setEmptyParentButtonVisible(true);
selectAipDialog.setSingleSelectionMode();
selectAipDialog.showAndCenter();
selectAipDialog.addValueChangeHandler(new ValueChangeHandler<IndexedAIP>() {

@Override
public void onFailure(Throwable caught) {
// do nothing
}

@Override
public void onSuccess(String details) {
BrowserService.Util.getInstance().moveAIPInHierarchy(selected, parentId, details,
new AsyncCallback<Job>() {
@Override
public void onValueChange(ValueChangeEvent<IndexedAIP> event) {
final IndexedAIP parentAIP = event.getValue();
final String parentId = (parentAIP != null) ? parentAIP.getId() : null;
final SelectedItemsList<IndexedAIP> selected = new SelectedItemsList<>(Arrays.asList(aipId),
IndexedAIP.class.getName());

@Override
public void onSuccess(Job result) {
Toast.showInfo(messages.moveItemTitle(), messages.movingAIP());
Dialogs.showPromptDialog(messages.outcomeDetailTitle(), null, null, messages.outcomeDetailPlaceholder(),
RegExp.compile(".*"), messages.cancelButton(), messages.confirmButton(), false, false,
new AsyncCallback<String>() {

if (result != null) {
HistoryUtils.newHistory(ShowJob.RESOLVER, result.getId());
} else {
HistoryUtils.newHistory(InternalProcess.RESOLVER);
@Override
public void onFailure(Throwable caught) {
// do nothing
}
}

@Override
public void onFailure(Throwable caught) {
if (caught instanceof NotFoundException) {
Toast.showError(messages.moveNoSuchObject(caught.getMessage()));
} else {
callback.onFailure(caught);
@Override
public void onSuccess(String details) {
BrowserService.Util.getInstance().moveAIPInHierarchy(selected, parentId, details,
new AsyncCallback<Job>() {

@Override
public void onSuccess(Job result) {
Toast.showInfo(messages.moveItemTitle(), messages.movingAIP());

if (result != null) {
HistoryUtils.newHistory(ShowJob.RESOLVER, result.getId());
} else {
HistoryUtils.newHistory(InternalProcess.RESOLVER);
}
}

@Override
public void onFailure(Throwable caught) {
if (caught instanceof NotFoundException) {
Toast.showError(messages.moveNoSuchObject(caught.getMessage()));
} else {
callback.onFailure(caught);
}
}
});
}
}
});
}
});
}
});
});
}
});
}
}
});
}

private void move(final SelectedItems<IndexedAIP> selected, final AsyncCallback<ActionImpact> callback) {
int counter = 0;
boolean justActive = parentAipState != null ? AIPState.ACTIVE.equals(parentAipState) : true;
Filter filter = new Filter();

if (selected instanceof SelectedItemsList) {
SelectedItemsList<IndexedAIP> list = (SelectedItemsList<IndexedAIP>) selected;
counter = list.getIds().size();
if (counter <= RodaConstants.DIALOG_FILTER_LIMIT_NUMBER) {
for (String id : list.getIds()) {
filter.add(new NotSimpleFilterParameter(RodaConstants.AIP_ANCESTORS, id));
filter.add(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, id));
}
}
ClientSelectedItemsUtils.size(IndexedAIP.class, selected, new AsyncCallback<Long>() {

if (parentAipId != null) {
filter.add(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, parentAipId));
@Override
public void onFailure(Throwable caught) {
AsyncCallbackUtils.defaultFailureTreatment(caught);
}
} else if (selected instanceof SelectedItemsFilter && parentAipId != null) {
filter.add(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, parentAipId));
}

SelectAipDialog selectAipDialog = new SelectAipDialog(messages.moveItemTitle(), filter, justActive, true);
selectAipDialog.setEmptyParentButtonVisible(parentAipId != null);
selectAipDialog.showAndCenter();
if (counter > 0 && counter <= RodaConstants.DIALOG_FILTER_LIMIT_NUMBER) {
selectAipDialog.addStyleName("object-dialog");
}

selectAipDialog.addValueChangeHandler(new ValueChangeHandler<IndexedAIP>() {

@Override
public void onValueChange(ValueChangeEvent<IndexedAIP> event) {
final IndexedAIP parentAIP = event.getValue();
final String parentId = (parentAIP != null) ? parentAIP.getId() : null;

Dialogs.showPromptDialog(messages.outcomeDetailTitle(), null, null, messages.outcomeDetailPlaceholder(),
RegExp.compile(".*"), messages.cancelButton(), messages.confirmButton(), false, false,
new AsyncCallback<String>() {
public void onSuccess(final Long size) {
Dialogs.showConfirmDialog(messages.moveConfirmDialogTitle(), messages.moveSelectedConfirmDialogMessage(size),
messages.dialogNo(), messages.dialogYes(), new AsyncCallback<Boolean>() {

@Override
public void onFailure(Throwable caught) {
// do nothing
// nothing to do
}

@Override
public void onSuccess(String details) {
BrowserService.Util.getInstance().moveAIPInHierarchy(selected, parentId, details,
new LoadingAsyncCallback<Job>() {

@Override
public void onSuccessImpl(Job result) {
Toast.showInfo(messages.runningInBackgroundTitle(), messages.runningInBackgroundDescription());

if (result != null) {
HistoryUtils.newHistory(ShowJob.RESOLVER, result.getId());
} else {
HistoryUtils.newHistory(InternalProcess.RESOLVER);
public void onSuccess(Boolean confirmed) {
if (confirmed) {
int counter = 0;
boolean justActive = parentAipState != null ? AIPState.ACTIVE.equals(parentAipState) : true;
Filter filter = new Filter();

if (selected instanceof SelectedItemsList) {
SelectedItemsList<IndexedAIP> list = (SelectedItemsList<IndexedAIP>) selected;
counter = list.getIds().size();
if (counter <= RodaConstants.DIALOG_FILTER_LIMIT_NUMBER) {
for (String id : list.getIds()) {
filter.add(new NotSimpleFilterParameter(RodaConstants.AIP_ANCESTORS, id));
filter.add(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, id));
}
callback.onSuccess(ActionImpact.UPDATED);
}

if (parentAipId != null) {
filter.add(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, parentAipId));
}
} else if (selected instanceof SelectedItemsFilter && parentAipId != null) {
filter.add(new NotSimpleFilterParameter(RodaConstants.INDEX_UUID, parentAipId));
}

SelectAipDialog selectAipDialog = new SelectAipDialog(messages.moveItemTitle(), filter, justActive,
true);
selectAipDialog.setEmptyParentButtonVisible(parentAipId != null);
selectAipDialog.showAndCenter();
if (counter > 0 && counter <= RodaConstants.DIALOG_FILTER_LIMIT_NUMBER) {
selectAipDialog.addStyleName("object-dialog");
}

selectAipDialog.addValueChangeHandler(new ValueChangeHandler<IndexedAIP>() {

@Override
public void onFailureImpl(Throwable caught) {
if (caught instanceof NotFoundException) {
Toast.showError(messages.moveNoSuchObject(caught.getMessage()));
} else {
callback.onFailure(caught);
}
public void onValueChange(ValueChangeEvent<IndexedAIP> event) {
final IndexedAIP parentAIP = event.getValue();
final String parentId = (parentAIP != null) ? parentAIP.getId() : null;

Dialogs.showPromptDialog(messages.outcomeDetailTitle(), null, null,
messages.outcomeDetailPlaceholder(), RegExp.compile(".*"), messages.cancelButton(),
messages.confirmButton(), false, false, new AsyncCallback<String>() {

@Override
public void onFailure(Throwable caught) {
// do nothing
}

@Override
public void onSuccess(String details) {
BrowserService.Util.getInstance().moveAIPInHierarchy(selected, parentId, details,
new LoadingAsyncCallback<Job>() {

@Override
public void onSuccessImpl(Job result) {
Toast.showInfo(messages.runningInBackgroundTitle(),
messages.runningInBackgroundDescription());

if (result != null) {
HistoryUtils.newHistory(ShowJob.RESOLVER, result.getId());
} else {
HistoryUtils.newHistory(InternalProcess.RESOLVER);
}
callback.onSuccess(ActionImpact.UPDATED);
}

@Override
public void onFailureImpl(Throwable caught) {
if (caught instanceof NotFoundException) {
Toast.showError(messages.moveNoSuchObject(caught.getMessage()));
} else {
callback.onFailure(caught);
}
}
});
}
});
}
});
}
}
});
}
});

}

private void updatePermissions(IndexedAIP aip, AsyncCallback<ActionImpact> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.roda.wui.common.client.tools.HistoryUtils;
import org.roda.wui.common.client.tools.Humanize;
import org.roda.wui.common.client.tools.ListUtils;
import org.roda.wui.common.client.tools.RestUtils;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
Expand All @@ -58,9 +59,11 @@
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.safehtml.shared.SafeUri;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
Expand Down Expand Up @@ -159,10 +162,7 @@ interface MyUiBinder extends UiBinder<Widget, ShowRepresentationInformation> {
FlowPanel extras;

@UiField
Button buttonEdit;

@UiField
Button buttonCancel;
Button buttonEdit, buttonDownload, buttonCancel;

private List<FilterParameter> aipParams = new ArrayList<>();
private List<FilterParameter> representationParams = new ArrayList<>();
Expand Down Expand Up @@ -563,6 +563,12 @@ void handleButtonEdit(ClickEvent e) {
EditRepresentationInformation.RESOLVER.getHistoryToken(), ri.getId());
}

@UiHandler("buttonDownload")
void handleButtonDownload(ClickEvent e) {
SafeUri downloadUri = RestUtils.createRepresentationInformationDownloadUri(ri.getId());
Window.Location.assign(downloadUri.asString());
}

@UiHandler("buttonCancel")
void handleButtonCancel(ClickEvent e) {
cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
ui:field="buttonEdit">
<ui:text from='{messages.editButton}' />
</g:Button>
<g:Button addStyleNames="btn btn-block btn-download" ui:field="buttonDownload">
<ui:text from='{messages.downloadButton}' />
</g:Button>
<g:Button addStyleNames="btn btn-block btn-default btn-times-circle"
ui:field="buttonCancel">
<ui:text from='{messages.cancelButton}' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@ public static SafeUri createTransferredResourceDownloadUri(String resourceId) {
return UriUtils.fromSafeConstant(b.toString());
}

public static SafeUri createRepresentationInformationDownloadUri(String riId) {
// api/v1/representation_information/{representation_information_id}?acceptFormat=xml
StringBuilder b = new StringBuilder();
// base uri
b.append(RodaConstants.API_REST_V1_REPRESENTATION_INFORMATION).append(riId).append(RodaConstants.API_QUERY_START)
.append(RodaConstants.API_QUERY_KEY_ACCEPT_FORMAT).append(RodaConstants.API_QUERY_ASSIGN_SYMBOL)
.append(RodaConstants.API_QUERY_VALUE_ACCEPT_FORMAT_XML);

return UriUtils.fromSafeConstant(b.toString());
}

public static SafeUri createThemeResourceUri(String resourceId, String defaultResourceId, boolean inline) {
// api/v1/theme/?resource_id={resourceId}&default_resource_od={defaultResourceId}
StringBuilder b = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ removeSelectedConfirmDialogMessage: Are you sure you want to remove the selected
removeAllSelectedConfirmDialogMessage: Are you sure you want to remove all selected items?
removingSuccessTitle: Removing items
removingSuccessMessage: Executing action to remove {0} items
moveConfirmDialogTitle: Confirm moving of intellectual entities
moveAllConfirmDialogMessageSingle: Are you sure you want to move the intellectual entity "{0}", including all its nested items?
moveAllConfirmDialogMessage: Are you sure you want to move the selected items, including all their nested items?
moveSelectedConfirmDialogMessage: Are you sure you want to move the selected {0} items?

# Generic Buttons
backButton: Back
Expand Down
Loading

0 comments on commit 7485b41

Please sign in to comment.