Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gdcc/8745 archival status UI #8748

75 changes: 75 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -343,6 +345,10 @@ public void setSelectedHostDataverse(Dataverse selectedHostDataverse) {
private boolean versionHasTabular = false;

private boolean showIngestSuccess;

private Boolean archivable = null;
private Boolean versionArchivable = null;
private Boolean someVersionArchived = null;

public boolean isShowIngestSuccess() {
return showIngestSuccess;
Expand Down Expand Up @@ -5568,6 +5574,75 @@ public void archiveVersion(Long id) {
}
}
}

public boolean isArchivable() {
if (archivable == null) {
archivable = false;
String className = settingsWrapper.getValueForKey(SettingsServiceBean.Key.ArchiverClassName, null);
if (className != null) {
try {
Class<?> clazz = Class.forName(className);
Method m = clazz.getMethod("isArchivable", Dataset.class, SettingsWrapper.class);
Object[] params = { dataset, settingsWrapper };
archivable = ((Boolean) m.invoke(null, params) == true);
} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
logger.warning("Failed to call is Archivable on configured archiver class: " + className);
e.printStackTrace();
}
}
}
return archivable;
}

public boolean isVersionArchivable() {
if (versionArchivable == null) {
// If this dataset isn't in an archivable collection return false
versionArchivable = false;
if (isArchivable()) {
boolean checkForArchivalCopy = false;
// Otherwise, we need to know if the archiver is single-version-only
// If it is, we have to check for an existing archived version to answer the
// question
String className = settingsWrapper.getValueForKey(SettingsServiceBean.Key.ArchiverClassName, null);
if (className != null) {
try {
Class<?> clazz = Class.forName(className);
Method m = clazz.getMethod("isSingleVersion", SettingsWrapper.class);
Object[] params = { settingsWrapper };
checkForArchivalCopy = (Boolean) m.invoke(null, params);

if (checkForArchivalCopy) {
// If we have to check (single version archiving), we can't allow archiving if
// one version is already archived (or attempted - any non-null status)
versionArchivable = !isSomeVersionArchived();
} else {
// If we allow multiple versions or didn't find one that has had archiving run
// on it, we can archive, so return true
versionArchivable = true;
}
} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
logger.warning("Failed to call is Archivable on configured archiver class: " + className);
e.printStackTrace();
}
}
}
}
return versionArchivable;
}

public boolean isSomeVersionArchived() {
if (someVersionArchived == null) {
someVersionArchived = false;
for (DatasetVersion dv : dataset.getVersions()) {
if (dv.getArchivalCopyLocation() != null) {
someVersionArchived = true;
}
}
}
return someVersionArchived;
}

private static Date getFileDateToCompare(FileMetadata fileMetadata) {
DataFile datafile = fileMetadata.getDataFile();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,12 @@ file.dataFilesTab.versions.headers.summary=Summary
file.dataFilesTab.versions.headers.contributors=Contributors
file.dataFilesTab.versions.headers.contributors.withheld=Contributor name(s) withheld
file.dataFilesTab.versions.headers.published=Published on
file.dataFilesTab.versions.headers.archived=Archival Status
file.dataFilesTab.versions.headers.archived.success=Archived
file.dataFilesTab.versions.headers.archived.pending=Pending
file.dataFilesTab.versions.headers.archived.failure=Failed
file.dataFilesTab.versions.headers.archived.notarchived=Not Archived
file.dataFilesTab.versions.headers.archived.submit=Submit
file.dataFilesTab.versions.viewDiffBtn=View Differences
file.dataFilesTab.versions.citationMetadata=Citation Metadata:
file.dataFilesTab.versions.added=Added
Expand Down
20 changes: 19 additions & 1 deletion src/main/webapp/dataset-versions.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
</p:column><!-- end: description column -->

<!-- contributor column -->
<p:column headerText="#{bundle['file.dataFilesTab.versions.headers.contributors']}" class="col-sm-3">
<p:column headerText="#{bundle['file.dataFilesTab.versions.headers.contributors']}" class="col-sm-2">
<ui:fragment rendered="#{!empty(versionTab.contributorNames) and !anonymized}">
<h:outputText value="#{versionTab.contributorNames}" />
</ui:fragment>
Expand All @@ -147,6 +147,24 @@
<h:outputText id="versionDate" value="#{versionTab.publicationDateAsString}" />
</ui:fragment>
</p:column><!-- end: date column -->
<p:column headerText="#{bundle['file.dataFilesTab.versions.headers.archived']}" class="col-sm-1" rendered="#{!empty(DatasetPage.dataset.id) and permissionServiceBean.on(DatasetPage.dataset).has('ViewUnpublishedDataset') and !versionTab.isDraft() and (DatasetPage.archivable or DatasetPage.someVersionArchived or not empty(versionTab.archivalCopyLocation))}">
<ui:fragment>
<ui:fragment rendered="#{'success' eq versionTab.archivalCopyLocationStatus}">
<h:outputLink id="archived" value="#{versionTab.archivalCopyLocationMessage}" target="_blank" rendered="#{DatasetPage.isSuperUser()}">
<h:outputText value="#{bundle['file.dataFilesTab.versions.headers.archived.success']}" />
</h:outputLink>
<h:outputText value="#{bundle['file.dataFilesTab.versions.headers.archived.success']}" rendered="#{!DatasetPage.isSuperUser()}"/>
</ui:fragment>
<h:outputText value="#{bundle['file.dataFilesTab.versions.headers.archived.pending']}" rendered="#{'pending' eq versionTab.archivalCopyLocationStatus}" title="#{DatasetPage.isSuperUser() ? versionTab.archivalCopyLocationMessage : ''}"/>
<h:outputText value="#{bundle['file.dataFilesTab.versions.headers.archived.failure']}" rendered="#{'failure' eq versionTab.archivalCopyLocationStatus}" title="#{DatasetPage.isSuperUser() ? versionTab.archivalCopyLocationMessage : ''}"/>
<p:commandLink rendered="#{DatasetPage.isSuperUser() and DatasetPage.versionArchivable and empty(versionTab.archivalCopyLocation)}" update="#{p:resolveClientId('datasetForm:tabView:versionsTable', view)},:messagePanel"
action="#{DatasetPage.archiveVersion(versionTab.id)}">
<h:outputText value="#{bundle['file.dataFilesTab.versions.headers.archived.submit']}"/>
</p:commandLink>
<h:outputText value="#{bundle['file.dataFilesTab.versions.headers.archived.notarchived']}" rendered="#{ empty(versionTab.archivalCopyLocation) and ((not DatasetPage.isSuperUser() and DatasetPage.someVersionArchived) or (DatasetPage.isSuperUser() and not DatasetPage.versionArchivable))}"/>

</ui:fragment>
</p:column><!-- end: archivalCopy column -->
</p:dataTable>
<!-- / VERSIONS -->
</ui:fragment>
Expand Down