Skip to content

Commit

Permalink
DD-526 create url for custom terms (IQSS#99)
Browse files Browse the repository at this point in the history
* updated Datasets.java, DatasetPage.java and dataset.xhtml

* refactored getCustomTermsTab function, added logic to switch to all dataset tabs

* allow guestaccess and return 404 if no custom license
  • Loading branch information
mderuijter authored Jul 8, 2021
1 parent fab2f99 commit 20e4360
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
27 changes: 27 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public enum DisplayMode {
private Long ownerId;
private Long versionId;
private int selectedTabIndex;
private String selectTab = "";
private List<DataFile> newFiles = new ArrayList<>();
private List<DataFile> uploadedFiles = new ArrayList<>();
private MutableBoolean uploadInProgress = new MutableBoolean(false);
Expand Down Expand Up @@ -1548,6 +1549,14 @@ public int getSelectedTabIndex() {
return selectedTabIndex;
}

public String getSelectTab() {
return selectTab;
}

public void setSelectTab(String selectTab) {
this.selectTab = selectTab;
}

public void setSelectedTabIndex(int selectedTabIndex) {
this.selectedTabIndex = selectedTabIndex;
}
Expand Down Expand Up @@ -1616,6 +1625,8 @@ public void setSelectedTemplate(Template selectedTemplate) {
this.selectedTemplate = selectedTemplate;
}



public void updateSelectedTemplate(ValueChangeEvent event) {

selectedTemplate = (Template) event.getNewValue();
Expand Down Expand Up @@ -1840,6 +1851,20 @@ private String init(boolean initFull) {
return permissionsWrapper.notFound();
}

switch (selectTab){
case "dataFilesTab":
selectedTabIndex = 0;
break;
case "metadataMapTab":
selectedTabIndex = 1;
break;
case "termsTab":
selectedTabIndex = 2;
break;
case "versionsTab":
selectedTabIndex = 3;
break;
}

//this.dataset = this.workingVersion.getDataset();

Expand Down Expand Up @@ -2725,6 +2750,8 @@ public String refresh() {
retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(dataset.getVersions(), version);
}



if (retrieveDatasetVersionResponse == null) {
// TODO:
// should probably redirect to the 404 page, if we can't find
Expand Down
32 changes: 22 additions & 10 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
import edu.harvard.iq.dataverse.privateurl.PrivateUrl;
import edu.harvard.iq.dataverse.S3PackageImporter;
import static edu.harvard.iq.dataverse.api.AbstractApiBean.error;
import edu.harvard.iq.dataverse.api.dto.RoleAssignmentDTO;
import edu.harvard.iq.dataverse.batch.util.LoggingUtil;
import edu.harvard.iq.dataverse.dataaccess.DataAccess;
Expand Down Expand Up @@ -112,22 +111,17 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URI;
import java.sql.Timestamp;
import java.text.MessageFormat;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonArray;
Expand Down Expand Up @@ -162,7 +156,7 @@
import org.glassfish.jersey.media.multipart.FormDataParam;

import com.amazonaws.services.s3.model.PartETag;
import edu.harvard.iq.dataverse.FileMetadata;

import java.util.Map.Entry;

@Path("datasets")
Expand Down Expand Up @@ -1151,6 +1145,24 @@ public Response linkDataset(@PathParam("linkedDatasetId") String linkedDatasetId
return ex.getResponse();
}
}

@GET
@Path("{id}/versions/{versionId}/customlicense")
public Response getCustomTermsTab(@PathParam("id") String id, @PathParam("versionId") String versionId, @Context UriInfo uriInfo, @Context HttpHeaders headers){
User user = session.getUser();
String persistentId;
try {
if (getDatasetVersionOrDie(createDataverseRequest(user), versionId, findDatasetOrDie(id), uriInfo, headers).getTermsOfUseAndAccess().getLicense() != null){
return error(Status.NOT_FOUND, "This Dataset has no custom license");
}
persistentId = getRequestParameter(":persistentId".substring(1));
if (versionId.equals(":draft")) versionId = "DRAFT";
} catch (WrappedResponse wrappedResponse) {
return wrappedResponse.getResponse();
}
return Response.temporaryRedirect(URI.create(systemConfig.getDataverseSiteUrl() + "/dataset.xhtml?persistentId=" + persistentId + "&version=" + versionId + "&selectTab=termsTab")).build();
}


@GET
@Path("{id}/links")
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<f:viewParam name="fileTypeGroupFacet" value="#{DatasetPage.fileTypeFacet}"/>
<f:viewParam name="fileAccess" value="#{DatasetPage.fileAccessFacet}"/>
<f:viewParam name="fileTag" value="#{DatasetPage.fileTagsFacet}"/>
<o:viewParam name="selectTab" value="#{DatasetPage.selectTab}" default="dataFilesTab"/>
<f:viewAction action="#{dataverseSession.updateLocaleInViewRoot}"/>
<f:viewAction action="#{DatasetPage.init}" rendered="true"/>
<f:viewAction action="#{dataverseHeaderFragment.initBreadcrumbs(DatasetPage.dataset)}"/>
Expand Down

0 comments on commit 20e4360

Please sign in to comment.