diff --git a/scripts/database/upgrades/upgrade_v4.3.1_to_v4.4.sql b/scripts/database/upgrades/upgrade_v4.3.1_to_v4.4.sql new file mode 100644 index 00000000000..113e912518c --- /dev/null +++ b/scripts/database/upgrades/upgrade_v4.3.1_to_v4.4.sql @@ -0,0 +1 @@ +ALTER TABLE dataverse ADD COLUMN citationRedirectURL character varying(255); diff --git a/src/main/java/Bundle.properties b/src/main/java/Bundle.properties index 7271ed8dc73..3c71a61e86e 100755 --- a/src/main/java/Bundle.properties +++ b/src/main/java/Bundle.properties @@ -80,12 +80,17 @@ header.user.selectTab.apiToken=API Token head.meta.description=The Dataverse Project is an open source software application to share, cite and archive data. Dataverse provides a robust infrastructure for data stewards to host and archive data, while offering researchers an easy way to share and get credit for their data. body.skip=Skip to main content + +# dataverse_footer.xhtml + footer.codeAvailable=Code available at footer.dataverseOnGitHub=Dataverse On GitHub footer.dataverseProjectOn=Dataverse Project on footer.Twitter=Twitter -footer.dataScienceIQSS=Data Science at The Institute for Quantitative Social Science +footer.dataScienceIQSS=Developed at the Institute for Quantitative Social Science footer.copyright=Copyright © 2016, The President & Fellows of Harvard College +footer.widget.datastored=Data is stored at {0}. +footer.widget.login=Log in to footer.privacyPolicy=Privacy Policy footer.poweredby=Powered by footer.dataverseProject=The Dataverse Project @@ -483,11 +488,28 @@ dataverse.theme.website.watermark=Your personal site, http://... dataverse.theme.website.invalidMsg=Invalid URL. dataverse.widgets.title=Widgets -dataverse.widgets.tip=Copy and paste this code into the HTML on your site. +dataverse.widgets.notPublished.why.header=Why Use Widgets? +dataverse.widgets.notPublished.why.reason1=Increases the web visibility of your data by allowing you to embed your dataverse and datasets into your personal or project website. +dataverse.widgets.notPublished.why.reason2=Allows others to browse your dataverse and datasets without leaving your personal or project website. +dataverse.widgets.notPublished.how.header=How To Use Widgets +dataverse.widgets.notPublished.how.tip1=To use widgets, your dataverse and datasets need to be published. +dataverse.widgets.notPublished.how.tip2=After publishing, code will be available on this page for you to copy and add to your personal or project website. +dataverse.widgets.notPublished.how.tip3=Do you have an OpenScholar website? If so, learn more about adding the Dataverse widgets to your website here. +dataverse.widgets.notPublished.getStarted=To get started, publish your dataverse. To learn more about Widgets, visit the Theme + Widgets section of the User Guide. +dataverse.widgets.editAdvanced=Edit Advanced Options +dataverse.widgets.editAdvanced.tip=Advanced Options – Additional options for configuring your widget on your personal or project website. +dataverse.widgets.tip=Copy and paste this code into the HTML on your site. To learn more about Widgets, visit the Theme + Widgets section of the User Guide. dataverse.widgets.searchBox.txt=Dataverse Search Box dataverse.widgets.searchBox.tip=Add a way for visitors on your website to be able to search Dataverse. dataverse.widgets.dataverseListing.txt=Dataverse Listing dataverse.widgets.dataverseListing.tip=Add a way for visitors on your website to be able to view your dataverses and datasets, sort, or page through them. +dataverse.widgets.advanced.popup.header=Widget Advanced Options +dataverse.widgets.advanced.prompt=Forward persistent URL's in your dataset citation to your personal website. +dataverse.widgets.advanced.url.label=Personal Website URL +dataverse.widgets.advanced.url.watermark=http://www.example.com/page-name +dataverse.widgets.advanced.invalid.message=Please enter a valid URL +dataverse.widgets.advanced.success.message=Successfully updated your Personal Website URL +dataverse.widgets.advanced.failure.message=The dataverse Personal Website URL has not been updated. # permissions-manage.xhtml @@ -773,6 +795,7 @@ dataset.editBtn.itemLabel.upload=Files (Upload) dataset.editBtn.itemLabel.metadata=Metadata dataset.editBtn.itemLabel.terms=Terms dataset.editBtn.itemLabel.permissions=Permissions +dataset.editBtn.itemLabel.widgets=Widgets dataset.editBtn.itemLabel.deleteDataset=Delete Dataset dataset.editBtn.itemLabel.deleteDraft=Delete Draft Version dataset.editBtn.itemLabel.deaccession=Deaccession Dataset @@ -822,11 +845,11 @@ dataset.versionUI.deaccessioned=Deaccessioned dataset.cite.title.released=DRAFT VERSION will be replaced in the citation with V1 once the dataset has been published. dataset.cite.title.draft=DRAFT VERSION will be replaced in the citation with the selected version once the dataset has been published. dataset.cite.title.deassessioned=DEACCESSIONED VERSION has been added to the citation for this version since it is no longer available. -dataset.cite.standards.tip=If you use these data, please add this citation to your scholarly resources. Learn about Data Citation Standards. -dataset.cite.downloadBtn=Download Citation +dataset.cite.standards.tip=Learn about Data Citation Standards. +dataset.cite.downloadBtn=Cite Data dataset.cite.downloadBtn.xml=EndNote XML -dataset.cite.downloadBtn.ris=RIS Format -dataset.cite.downloadBtn.bib=BibTeX Format +dataset.cite.downloadBtn.ris=RIS +dataset.cite.downloadBtn.bib=BibTeX dataset.create.authenticatedUsersOnly=Only authenticated users can create datasets. dataset.deaccession.reason=Deaccession Reason dataset.beAccessedAt=The dataset can now be accessed at: @@ -964,8 +987,8 @@ file.downloadBtn.format.citation=Data File Citation file.more.information.link=Link to more file information for file.requestAccess=Request Access -file.requestAccess.dialog.msg=You need to Log In to request access to this file. -file.requestAccess.dialog.msg.signup=You need to Sign Up or Log In to request access to this file. +file.requestAccess.dialog.msg=You need to Log In to request access to this file. +file.requestAccess.dialog.msg.signup=You need to Sign Up or Log In to request access to this file. file.accessRequested=Access Requested file.ingestInproGress=Ingest in progress... @@ -1113,6 +1136,31 @@ file.results.btn.sort.option.oldest=Oldest file.results.btn.sort.option.size=Size file.results.btn.sort.option.type=Type +# dataset-widgets.xhtml +dataset.widgets.title=Dataset Widgets +dataset.widgets.notPublished.why.header=Why Use Widgets? +dataset.widgets.notPublished.why.reason1=Increases the web visibility of your data by allowing you to embed your dataverse and datasets into your personal or project website. +dataset.widgets.notPublished.why.reason2=Allows others to browse your dataverse and datasets without leaving your personal or project website. +dataset.widgets.notPublished.how.header=How To Use Widgets +dataset.widgets.notPublished.how.tip1=To use widgets, your dataverse and datasets need to be published. +dataset.widgets.notPublished.how.tip2=After publishing, code will be available on this page for you to copy and add to your personal or project website. +dataset.widgets.notPublished.how.tip3=Do you have an OpenScholar website? If so, learn more about adding the Dataverse widgets to your website here. +dataset.widgets.notPublished.getStarted=To get started, publish your dataset. To learn more about Widgets, visit the Widgets section of the User Guide. +dataset.widgets.editAdvanced=Edit Advanced Options +dataset.widgets.editAdvanced.tip=Advanced Options – Additional options for configuring your widget on your personal or project website. +dataset.widgets.tip=Copy and paste this code into the HTML on your site. To learn more about Widgets, visit the Widgets section of the User Guide. +dataset.widgets.citation.txt=Dataset Citation +dataset.widgets.citation.tip=Add a citation for your dataset to your personal or project website. +dataset.widgets.datasetFull.txt=Dataset +dataset.widgets.datasetFull.tip=Add a way for visitors on your website to be able to view your datasets, download files, etc. +dataset.widgets.advanced.popup.header=Widget Advanced Options +dataset.widgets.advanced.prompt=Forward persistent URL's in your dataset citation to your personal website. +dataset.widgets.advanced.url.label=Personal Website URL +dataset.widgets.advanced.url.watermark=http://www.example.com/page-name +dataset.widgets.advanced.invalid.message=Please enter a valid URL +dataset.widgets.advanced.success.message=Successfully updated your Personal Website URL +dataset.widgets.advanced.failure.message=The dataverse Personal Website URL has not been updated. + # file.xhtml file.title.label=Title file.citation.label=Citation @@ -1137,8 +1185,18 @@ error.500.message=Internal Server Error - An unexpected error w # 404.xhtml error.404.page.title=404 Not Found -error.404.message=Page Not Found - The page you are looking for was not found. To contact support, please press the Support link above. +error.404.message=Page Not Found - The page you are looking for was not found. # 403.xhtml error.403.page.title=403 Not Authorized -error.403.message=Not Authorized - You are not authorized to view this page. To contact support, please press the Support link above. +error.403.message=Not Authorized - You are not authorized to view this page. + +# general error - support message +error.support.message= If you believe this is an error, please contact {0} for assistance. + +# citation-frame.xhtml +citationFrame.banner.message=If the site below does not load, the archived data can be found in the {0} {1}. {2} +citationFrame.banner.message.here=here +citationFrame.banner.closeIcon=Close this message, go to dataset +citationFrame.banner.countdownMessage= This message will close in +citationFrame.banner.countdownMessage.seconds=seconds diff --git a/src/main/java/edu/harvard/iq/dataverse/BibtexCitation.java b/src/main/java/edu/harvard/iq/dataverse/BibtexCitation.java new file mode 100644 index 00000000000..742c86c70b8 --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/BibtexCitation.java @@ -0,0 +1,86 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.harvard.iq.dataverse; + +import java.net.URL; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; + +/** + * + * @author gdurand + */ +public class BibtexCitation { + + private List authors = new ArrayList(); + private String title; + private String year; + private GlobalId persistentId; + private String publisher; + + public BibtexCitation(DatasetVersion dsv) { + //authors + dsv.getDatasetAuthors().stream().forEach((author) -> { + authors.add(author.getName().getDisplayValue()); + }); + + // year + year = dsv.getVersionYear(); + + // title + title = dsv.getTitle(); + + // The Global Identifier: + persistentId = new GlobalId(dsv.getDataset()); + + // publisher + publisher = dsv.getRootDataverseNameforCitation(); + } + + public List getAuthors() { + return authors; + } + + public String getTitle() { + return title; + } + + public String getYear() { + return year; + } + + public GlobalId getPersistentId() { + return persistentId; + } + + public String getPublisher() { + return publisher; + } + + + @Override + public String toString() { + StringBuilder citation = new StringBuilder("@data{"); + citation.append(persistentId.getIdentifier() + "_" + year + "," + "\r\n"); + citation.append("author = {").append(String.join("; ", authors)).append("},\r\n"); + citation.append("publisher = {").append(publisher).append("},\r\n"); + citation.append("title = {").append(title).append("},\r\n"); + citation.append("year = {").append(year).append("},\r\n"); + citation.append("doi = {").append(persistentId.getAuthority()).append("/").append(persistentId.getIdentifier()).append("},\r\n"); + citation.append("url = {").append(persistentId.toURL().toString()).append("}\r\n"); + citation.append("}"); + + return citation.toString(); + } + +} + diff --git a/src/main/java/edu/harvard/iq/dataverse/CitationServlet.java b/src/main/java/edu/harvard/iq/dataverse/CitationServlet.java new file mode 100644 index 00000000000..f2d7340e176 --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/CitationServlet.java @@ -0,0 +1,93 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.harvard.iq.dataverse; + +import edu.harvard.iq.dataverse.util.StringUtil; +import java.io.IOException; +import java.io.PrintWriter; +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author gdurand + */ +public class CitationServlet extends HttpServlet { + + @EJB + DatasetServiceBean datasetService; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String persistentId = request.getParameter("persistentId"); + if (persistentId != null) { + Dataset ds = datasetService.findByGlobalId(persistentId); + if (ds != null) { + if (StringUtil.isEmpty(ds.getOwner().getCitationRedirectURL())) { + response.sendRedirect("dataset.xhtml?persistentId=" + persistentId); + return; + } else { + response.sendRedirect("citation-frame.xhtml?persistentId=" + persistentId); + return; + } + } + } + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Servlet for redirecting requests from persistent identifier references."; + }// + +} diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java index 8e4176b5d4a..b511580914d 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java +++ b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java @@ -49,7 +49,7 @@ public String createIdentifier(String identifier, HashMap metada metadataTemplate.setDescription(dataset.getLatestVersion().getDescription()); metadataTemplate.setContacts(dataset.getLatestVersion().getDatasetContacts()); metadataTemplate.setProducers(dataset.getLatestVersion().getDatasetProducers()); - metadataTemplate.setTitle(metadata.get("datacite.title")); + metadataTemplate.setTitle(dataset.getLatestVersion().getTitle()); metadataTemplate.setPublisher(metadata.get("datacite.publisher")); metadataTemplate.setPublisherYear(metadata.get("datacite.publicationyear")); diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java index 964c4aaff2d..fa070b9cbec 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteServiceBean.java @@ -6,6 +6,7 @@ package edu.harvard.iq.dataverse; import edu.harvard.iq.dataverse.settings.SettingsServiceBean; +import edu.harvard.iq.dataverse.util.SystemConfig; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Calendar; @@ -35,6 +36,8 @@ public class DOIDataCiteServiceBean { SettingsServiceBean settingsService; @EJB DOIDataCiteRegisterService doiDataCiteRegisterService; + @EJB + SystemConfig systemConfig; private String DOISHOULDER = ""; @@ -228,67 +231,32 @@ private HashMap getMetadataFromStudyForCreateIndicator(Dataset datasetIn) { metadata.put("datacite.title", datasetIn.getLatestVersion().getTitle()); metadata.put("datacite.publisher", producerString); metadata.put("datacite.publicationyear", generateYear()); - String inetAddress = getSiteUrl(); - String targetUrl = ""; - DOISHOULDER = "doi:" + datasetIn.getAuthority(); - - if (inetAddress.equals("localhost")) { - targetUrl = "http://localhost:8080" + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } else { - targetUrl = inetAddress + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } - metadata.put("_target", targetUrl); + metadata.put("_target", getTargetUrl(datasetIn)); return metadata; } public HashMap getMetadataFromDatasetForTargetURL(Dataset datasetIn) { - HashMap metadata = new HashMap(); - - String inetAddress = getSiteUrl(); - String targetUrl = ""; - DOISHOULDER = "doi:" + datasetIn.getAuthority(); - - if (inetAddress.equals("localhost")){ - targetUrl ="http://localhost:8080" + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } else{ - targetUrl = inetAddress + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } - metadata.put("_target", targetUrl); + HashMap metadata = new HashMap<>(); + metadata.put("_target", getTargetUrl(datasetIn)); return metadata; } - - public String getSiteUrl() { - String hostUrl = System.getProperty("dataverse.siteUrl"); - if (hostUrl != null && !"".equals(hostUrl)) { - return hostUrl; - } - String hostName = System.getProperty("dataverse.fqdn"); - if (hostName == null) { - try { - hostName = InetAddress.getLocalHost().getCanonicalHostName(); - } catch (UnknownHostException e) { - return null; - } - } - hostUrl = "https://" + hostName; - return hostUrl; + + private String getTargetUrl(Dataset datasetIn){ + return systemConfig.getDataverseSiteUrl() + Dataset.TARGET_URL + datasetIn.getGlobalId(); } private String getIdentifierFromDataset(Dataset dataset) { return dataset.getGlobalId(); } - public void publicizeIdentifier(Dataset studyIn) throws Exception { - updateIdentifierStatus(studyIn, "public"); + public void publicizeIdentifier(Dataset dataset) throws Exception { + updateIdentifierStatus(dataset, "public"); } private void updateIdentifierStatus(Dataset dataset, String statusIn) throws Exception { String identifier = getIdentifierFromDataset(dataset); HashMap metadata = getUpdateMetadataFromDataset(dataset); + metadata.put("_target", getTargetUrl(dataset)); metadata.put("_status", statusIn); try { doiDataCiteRegisterService.createIdentifier(identifier, metadata, dataset); diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java index bb7c54b848b..4c16cfcfd68 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DOIEZIdServiceBean.java @@ -8,6 +8,7 @@ import edu.harvard.iq.dataverse.settings.SettingsServiceBean; +import edu.harvard.iq.dataverse.util.SystemConfig; import edu.ucsb.nceas.ezid.EZIDException; import edu.ucsb.nceas.ezid.EZIDService; import edu.ucsb.nceas.ezid.EZIDServiceRequest; @@ -29,6 +30,8 @@ public class DOIEZIdServiceBean { DataverseServiceBean dataverseService; @EJB SettingsServiceBean settingsService; + @EJB + SystemConfig systemConfig; EZIDService ezidService; EZIDServiceRequest ezidServiceRequest; String baseURLString = "https://ezid.cdlib.org"; @@ -229,69 +232,34 @@ public HashMap getMetadataFromStudyForCreateIndicator(Dataset da metadata.put("datacite.publisher", producerString); metadata.put("datacite.publicationyear", generateYear()); metadata.put("datacite.resourcetype", "Dataset"); - String inetAddress = getSiteUrl(); - String targetUrl = ""; - DOISHOULDER = "doi:" + datasetIn.getAuthority(); - - if (inetAddress.equals("localhost")) { - targetUrl ="http://localhost:8080" + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } else { - targetUrl = inetAddress + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } - metadata.put("_target", targetUrl); + metadata.put("_target", getTargetUrl(datasetIn)); return metadata; } public HashMap getMetadataFromDatasetForTargetURL(Dataset datasetIn) { - HashMap metadata = new HashMap<>(); - - String inetAddress = getSiteUrl(); - String targetUrl = ""; - DOISHOULDER = "doi:" + datasetIn.getAuthority(); - - if (inetAddress.equals("localhost")){ - targetUrl ="http://localhost:8080" + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } else{ - targetUrl = inetAddress + "/dataset.xhtml?persistentId=" + DOISHOULDER - + datasetIn.getDoiSeparator() + datasetIn.getIdentifier(); - } - metadata.put("_target", targetUrl); + HashMap metadata = new HashMap<>(); + metadata.put("_target", getTargetUrl(datasetIn)); return metadata; } - public String getSiteUrl() { - String hostUrl = System.getProperty("dataverse.siteUrl"); - if (hostUrl != null && !"".equals(hostUrl)) { - return hostUrl; - } - String hostName = System.getProperty("dataverse.fqdn"); - if (hostName == null) { - try { - hostName = InetAddress.getLocalHost().getCanonicalHostName(); - } catch (UnknownHostException e) { - return null; - } - } - hostUrl = "https://" + hostName; - return hostUrl; + private String getTargetUrl(Dataset datasetIn) { + return systemConfig.getDataverseSiteUrl() + Dataset.TARGET_URL + datasetIn.getGlobalId(); } - + private String getIdentifierFromDataset(Dataset dataset) { return dataset.getGlobalId(); } - public boolean publicizeIdentifier(Dataset studyIn) { - return updateIdentifierStatus(studyIn, "public"); + public boolean publicizeIdentifier(Dataset dataset) { + return updateIdentifierStatus(dataset, "public"); } private boolean updateIdentifierStatus(Dataset dataset, String statusIn) { String identifier = getIdentifierFromDataset(dataset); HashMap metadata = getUpdateMetadataFromDataset(dataset); metadata.put("_status", statusIn); + metadata.put("_target", getTargetUrl(dataset)); try { ezidService.setMetadata(identifier, metadata); return true; diff --git a/src/main/java/edu/harvard/iq/dataverse/DataCitation.java b/src/main/java/edu/harvard/iq/dataverse/DataCitation.java index 4ce1b3acc9b..75391638085 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataCitation.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataCitation.java @@ -24,21 +24,12 @@ public class DataCitation { private String authors; private String title; - private Date citationDate; + private String year; private GlobalId persistentId; private String version; private String UNF; private String distributors; - public DataCitation(String authors, String title, Date citationDate, GlobalId persistentId, String version, String UNF, String distributors) { - this.authors = authors; - this.title = title; - this.citationDate = citationDate; - this.persistentId = persistentId; - this.version = version; - this.UNF = UNF; - this.distributors = distributors; - } public DataCitation(DatasetVersion dsv) { // authors (or producer) @@ -47,9 +38,10 @@ public DataCitation(DatasetVersion dsv) { authors = dsv.getDatasetProducersString(); } - // citation date + // year + SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); if (!dsv.getDataset().isHarvested()) { - citationDate = dsv.getCitationDate(); + Date citationDate = dsv.getCitationDate(); if (citationDate == null) { if (dsv.getDataset().getPublicationDate() != null) { citationDate = dsv.getDataset().getPublicationDate(); @@ -57,14 +49,17 @@ public DataCitation(DatasetVersion dsv) { citationDate = new Date(); } } + + year = new SimpleDateFormat("yyyy").format(citationDate); + } else { try { - citationDate = new SimpleDateFormat("yyyy").parse(dsv.getDistributionDate()); + year = sdf.format(sdf.parse(dsv.getDistributionDate())); } catch (ParseException ex) { // ignore } } - + // title title = dsv.getTitle(); @@ -111,58 +106,37 @@ public String getAuthors() { return authors; } - public void setAuthors(String authors) { - this.authors = authors; - } public String getTitle() { return title; } - public void setTitle(String title) { - this.title = title; - } - public Date getCitationDate() { - return citationDate; + public String getYear() { + return year; } - public void setCitationDate(Date citationDate) { - this.citationDate = citationDate; - } public GlobalId getPersistentId() { return persistentId; } - public void setPersistentId(GlobalId persistentId) { - this.persistentId = persistentId; - } public String getVersion() { return version; } - public void setVersion(String version) { - this.version = version; - } public String getUNF() { return UNF; } - public void setUNF(String UNF) { - this.UNF = UNF; - } public String getDistributors() { return distributors; } - public void setDistributors(String distributors) { - this.distributors = distributors; - } - + @Override public String toString() { return toString(false); @@ -172,7 +146,7 @@ public String toString(boolean html) { // first add comma separated parts List citationList = new ArrayList<>(); citationList.add(formatString(authors, html)); - citationList.add(formatNonEmptyDate(citationDate,"yyyy")); + citationList.add(year); citationList.add(formatString(title, html, "\"")); citationList.add(formatURL(persistentId.toURL(), html)); citationList.add(formatString(distributors, html)); @@ -206,11 +180,7 @@ private String formatString(String value, boolean escapeHtml, String wrapper) { } return null; } - - private String formatNonEmptyDate(Date date, String format) { - return date == null ? null : new SimpleDateFormat(format).format(date); - } - + private String formatURL(URL value, boolean html) { if (value ==null) { return null; diff --git a/src/main/java/edu/harvard/iq/dataverse/Dataset.java b/src/main/java/edu/harvard/iq/dataverse/Dataset.java index 6b019ab9a4a..5787580802f 100644 --- a/src/main/java/edu/harvard/iq/dataverse/Dataset.java +++ b/src/main/java/edu/harvard/iq/dataverse/Dataset.java @@ -40,6 +40,8 @@ uniqueConstraints = @UniqueConstraint(columnNames = {"authority,protocol,identifier,doiseparator"})) public class Dataset extends DvObjectContainer { +// public static final String REDIRECT_URL = "/dataset.xhtml?persistentId="; + public static final String TARGET_URL = "/citation?persistentId="; private static final long serialVersionUID = 1L; @OneToMany(mappedBy = "owner", cascade = CascadeType.MERGE) diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java index c2e18cebef5..e4c44d36b5c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java @@ -1372,9 +1372,16 @@ public void setDisplayFileMetadata(List displayFileMetadata) { private boolean metadataExportEnabled; public String init() { + return init(true); + } + + public String initCitation() { + return init(false); + } + + private String init(boolean initFull) { //System.out.println("_YE_OLDE_QUERY_COUNTER_"); // for debug purposes - - String nonNullDefaultIfKeyNotFound = ""; + this.maxFileUploadSizeInBytes = systemConfig.getMaxFileUploadSize(); setDataverseSiteUrl(systemConfig.getDataverseSiteUrl()); /** @@ -1384,9 +1391,12 @@ public String init() { metadataExportEnabled = systemConfig.isDdiExportEnabled(); guestbookResponse = new GuestbookResponse(); + + String nonNullDefaultIfKeyNotFound = ""; protocol = settingsService.getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound); authority = settingsService.getValueForKey(SettingsServiceBean.Key.Authority, nonNullDefaultIfKeyNotFound); separator = settingsService.getValueForKey(SettingsServiceBean.Key.DoiSeparator, nonNullDefaultIfKeyNotFound); + if (dataset.getId() != null || versionId != null || persistentId != null) { // view mode for a dataset DatasetVersionServiceBean.RetrieveDatasetVersionResponse retrieveDatasetVersionResponse = null; @@ -1400,7 +1410,7 @@ public String init() { dataset = datasetService.findByGlobalId(persistentId); if (dataset == null) { logger.warning("No such dataset: "+persistentId); - return "/404.xhtml"; + return permissionsWrapper.notFound(); } logger.fine("retrived dataset, id="+dataset.getId()); @@ -1414,7 +1424,7 @@ public String init() { dataset = datasetService.find(dataset.getId()); if (dataset == null) { logger.warning("No such dataset: "+dataset); - return "/404.xhtml"; + return permissionsWrapper.notFound(); } //retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionById(dataset.getId(), version); retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(dataset.getVersions(), version); @@ -1429,7 +1439,7 @@ public String init() { } if (retrieveDatasetVersionResponse == null) { - return "/404.xhtml"; + return permissionsWrapper.notFound(); } @@ -1440,7 +1450,7 @@ public String init() { // Is the DatasetVersion or Dataset null? // if (workingVersion == null || this.dataset == null) { - return "/404.xhtml"; + return permissionsWrapper.notFound(); } // Is the Dataset harvested? @@ -1461,55 +1471,52 @@ public String init() { return originalSourceURL; } - return "/404.xhtml"; + return permissionsWrapper.notFound(); } - // If this DatasetVersion is unpublished and permission is doesn't have permissions: - // > Go to the Login page - // - - //if (!(workingVersion.isReleased() || workingVersion.isDeaccessioned()) && !permissionService.on(dataset).has(Permission.ViewUnpublishedDataset)) { + // Check permisisons if (!(workingVersion.isReleased() || workingVersion.isDeaccessioned()) && !this.canViewUnpublishedDataset()) { - if (!isSessionUserAuthenticated()) { - return "/loginpage.xhtml" + DataverseHeaderFragment.getRedirectPage(); - } else { - return "/403.xhtml"; //SEK need a new landing page if user is already logged in but lacks permission - } + return permissionsWrapper.notAuthorized(); } if (!retrieveDatasetVersionResponse.wasRequestedVersionRetrieved()) { //msg("checkit " + retrieveDatasetVersionResponse.getDifferentVersionMessage()); JsfHelper.addWarningMessage(retrieveDatasetVersionResponse.getDifferentVersionMessage());//JH.localize("dataset.message.metadataSuccess")); } + + // init the citation + displayCitation = dataset.getCitation(true, workingVersion); - //fileMetadatas = populateFileMetadatas(); - if (workingVersion.isDraft() && canUpdateDataset()) { - readOnly = false; - fileMetadatasSearch = workingVersion.getFileMetadatasSorted(); - } else { - // an attempt to retreive both the filemetadatas and datafiles early on, so that - // we don't have to do so later (possibly, many more times than necessary): - - datafileService.findFileMetadataOptimizedExperimental(dataset); - fileMetadatasSearch = workingVersion.getFileMetadatas(); - } + if (initFull) { + // init the files + //fileMetadatas = populateFileMetadatas(); + if (workingVersion.isDraft() && canUpdateDataset()) { + readOnly = false; + fileMetadatasSearch = workingVersion.getFileMetadatasSorted(); + } else { + // an attempt to retreive both the filemetadatas and datafiles early on, so that + // we don't have to do so later (possibly, many more times than necessary): + + datafileService.findFileMetadataOptimizedExperimental(dataset); + fileMetadatasSearch = workingVersion.getFileMetadatas(); + } - ownerId = dataset.getOwner().getId(); - datasetNextMajorVersion = this.dataset.getNextMajorVersionString(); - datasetNextMinorVersion = this.dataset.getNextMinorVersionString(); - datasetVersionUI = datasetVersionUI.initDatasetVersionUI(workingVersion, false); - updateDatasetFieldInputLevels(); - displayCitation = dataset.getCitation(true, workingVersion); - setExistReleasedVersion(resetExistRealeaseVersion()); + ownerId = dataset.getOwner().getId(); + datasetNextMajorVersion = this.dataset.getNextMajorVersionString(); + datasetNextMinorVersion = this.dataset.getNextMinorVersionString(); + datasetVersionUI = datasetVersionUI.initDatasetVersionUI(workingVersion, false); + updateDatasetFieldInputLevels(); + + setExistReleasedVersion(resetExistRealeaseVersion()); //moving setVersionTabList to tab change event - //setVersionTabList(resetVersionTabList()); - //setReleasedVersionTabList(resetReleasedVersionTabList()); - //SEK - lazymodel may be needed for datascroller in future release - // lazyModel = new LazyFileMetadataDataModel(workingVersion.getId(), datafileService ); - // populate MapLayerMetadata - this.loadMapLayerMetadataLookup(); // A DataFile may have a related MapLayerMetadata object - + //setVersionTabList(resetVersionTabList()); + //setReleasedVersionTabList(resetReleasedVersionTabList()); + //SEK - lazymodel may be needed for datascroller in future release + // lazyModel = new LazyFileMetadataDataModel(workingVersion.getId(), datafileService ); + // populate MapLayerMetadata + this.loadMapLayerMetadataLookup(); // A DataFile may have a related MapLayerMetadata object + } } else if (ownerId != null) { // create mode for a new child dataset readOnly = false; @@ -1521,13 +1528,9 @@ public String init() { dataset.setIdentifier(datasetService.generateIdentifierSequence(protocol, authority, separator)); if (dataset.getOwner() == null) { - return "/404.xhtml"; + return permissionsWrapper.notFound(); } else if (!permissionService.on(dataset.getOwner()).has(Permission.AddDataset)) { - if (!isSessionUserAuthenticated()) { - return "/loginpage.xhtml" + DataverseHeaderFragment.getRedirectPage(); - } else { - return "/403.xhtml"; //SEK need a new landing page if user is already logged in but lacks permission - } + return permissionsWrapper.notAuthorized(); } dataverseTemplates = dataverseService.find(ownerId).getTemplates(); @@ -1553,7 +1556,7 @@ public String init() { // FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Add New Dataset", " - Enter metadata to create the dataset's citation. You can add more metadata about this dataset after it's created.")); } else { - return "/404.xhtml"; + return permissionsWrapper.notFound(); } return null; @@ -2088,10 +2091,8 @@ public void refresh() { logger.fine("refreshing"); //dataset = datasetService.find(dataset.getId()); - dataset = null; - logger.fine("refreshing working version"); DatasetVersionServiceBean.RetrieveDatasetVersionResponse retrieveDatasetVersionResponse = null; @@ -3322,7 +3323,7 @@ public void downloadDatafileCitationBibtex(FileMetadata fileMetadata) { public void downloadCitationBibtex(FileMetadata fileMetadata) { - String bibFormatDowload = datasetService.createCitationBibtex(workingVersion, fileMetadata); + String bibFormatDowload = new BibtexCitation(workingVersion).toString(); FacesContext ctx = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse(); response.setContentType("application/download"); diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java index 6fb072f2903..7ff6faee598 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java @@ -265,35 +265,6 @@ public String createCitationRIS(DatasetVersion version, FileMetadata fileMetadat return retString; } - public String createCitationBibtex(DatasetVersion version) { - return createCitationBibtex(version, null); - } - - public String createCitationBibtex(DatasetVersion version, FileMetadata fileMetadata) { - String publisher = version.getRootDataverseNameforCitation(); - List authorList = version.getDatasetAuthors(); - List authorDisplayList = new ArrayList<>(); - - for (DatasetAuthor author : authorList) { - authorDisplayList.add(author.getName().getDisplayValue()); - } - - String retString = "@data{"; - retString += version.getDataset().getIdentifier() + "_" + version.getVersionYear() + "," + "\r\n"; - retString += "author = {"; - retString += String.join("; ", authorDisplayList); - retString += "}," + "\r\n"; - retString += "publisher = {" + publisher + "}," + "\r\n"; - retString += "title = {" + version.getTitle() + "}," + "\r\n"; - retString += "year = {" + version.getVersionYear() + "}," + "\r\n"; - retString += "doi = {" + version.getDataset().getAuthority() + - version.getDataset().getDoiSeparator() + - version.getDataset().getIdentifier() + "}," + "\r\n"; - retString += "url = {" + version.getDataset().getPersistentURL() + "}" + "\r\n"; - retString += "}"; - - return retString; - } private XMLOutputFactory xmlOutputFactory = null; diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetWidgetsPage.java b/src/main/java/edu/harvard/iq/dataverse/DatasetWidgetsPage.java new file mode 100644 index 00000000000..16be0504cd9 --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetWidgetsPage.java @@ -0,0 +1,60 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package edu.harvard.iq.dataverse; + +import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand; +import javax.ejb.EJB; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; + +/** + * + * @author skraffmi + */ +@ViewScoped +@Named("DatasetWidgetsPage") +public class DatasetWidgetsPage implements java.io.Serializable { + @EJB + DatasetServiceBean datasetService; + + private Long datasetId; + private Dataset dataset; + + @Inject + PermissionsWrapper permissionsWrapper; + + public String init() { + if (datasetId == null || datasetId.intValue() <= 0) { + return permissionsWrapper.notFound(); + } + dataset = datasetService.find(datasetId); + if (dataset == null) { + return permissionsWrapper.notFound(); + } + if (!permissionsWrapper.canIssueCommand(dataset, UpdateDatasetCommand.class)) { + return permissionsWrapper.notAuthorized(); + } + return null; + } + + public Long getDatasetId() { + return datasetId; + } + + public void setDatasetId(Long datasetId) { + this.datasetId = datasetId; + } + + public Dataset getDataset() { + return dataset; + } + + public void setDataset(Dataset dataset) { + this.dataset = dataset; + } + +} diff --git a/src/main/java/edu/harvard/iq/dataverse/Dataverse.java b/src/main/java/edu/harvard/iq/dataverse/Dataverse.java index 44ab7c59f7e..729681a8ad0 100644 --- a/src/main/java/edu/harvard/iq/dataverse/Dataverse.java +++ b/src/main/java/edu/harvard/iq/dataverse/Dataverse.java @@ -30,6 +30,7 @@ import javax.validation.constraints.Size; import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotEmpty; +import org.hibernate.validator.constraints.URL; /** * @@ -82,7 +83,7 @@ public enum DataverseType { @NotNull(message = "Please select a category for your dataverse.") @Column( nullable = false ) private DataverseType dataverseType; - + /** * When {@code true}, users are not granted permissions the got for parent * dataverses. @@ -700,5 +701,18 @@ public boolean isPermissionRoot() { public void setPermissionRoot(boolean permissionRoot) { this.permissionRoot = permissionRoot; } + + + + @URL + private String citationRedirectURL; + + public String getCitationRedirectURL() { + return citationRedirectURL; + } + + public void setCitationRedirectURL(String citationRedirectURL) { + this.citationRedirectURL = citationRedirectURL; + } } diff --git a/src/main/java/edu/harvard/iq/dataverse/DataverseHeaderFragment.java b/src/main/java/edu/harvard/iq/dataverse/DataverseHeaderFragment.java index 7c7331279da..0e3e9e6d2e9 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataverseHeaderFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataverseHeaderFragment.java @@ -58,6 +58,9 @@ public class DataverseHeaderFragment implements java.io.Serializable { @Inject DataverseSession dataverseSession; + + @Inject + NavigationWrapper navigationWrapper; @EJB UserNotificationServiceBean userNotificationService; @@ -75,6 +78,9 @@ public void setBreadcrumbs(List breadcrumbs) { } public void initBreadcrumbs(DvObject dvObject) { + if (dvObject == null) { + return; + } if (dvObject.getId() != null) { initBreadcrumbs(dvObject, null); } else { @@ -166,7 +172,7 @@ private TreeNode getDataverseNode(Dataverse dataverse, TreeNode root, boolean ex public String logout() { dataverseSession.setUser(null); - String redirectPage = getPageFromContext(); + String redirectPage = navigationWrapper.getPageFromContext(); try { redirectPage = URLDecoder.decode(redirectPage, "UTF-8"); } catch (UnsupportedEncodingException ex) { @@ -196,54 +202,14 @@ public boolean isSignupAllowed() { public String getSignupUrl(String loginRedirect) { String nonNullDefaultIfKeyNotFound = ""; String signUpUrl = settingsService.getValueForKey(SettingsServiceBean.Key.SignUpUrl, nonNullDefaultIfKeyNotFound); - return signUpUrl + (signUpUrl.indexOf("?") == -1 ? loginRedirect : loginRedirect.replace("?", "&")); + return signUpUrl + (!signUpUrl.contains("?") ? loginRedirect : loginRedirect.replace("?", "&")); } public String getLoginRedirectPage() { - return getRedirectPage(); + System.out.println("DEPRECATED call to getLoginRedirectPage method in DataverseHeaderfragment: " + navigationWrapper.getRedirectPage()); + return navigationWrapper.getRedirectPage(); } - // @todo consider creating a base bean, for now just make this static - public static String getRedirectPage() { - - String redirectPage = getPageFromContext(); - if (!StringUtils.isEmpty(redirectPage)) { - return "?redirectPage=" + redirectPage; - } - return ""; - } - - private static String getPageFromContext() { - try { - HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); - StringBuilder redirectPage = new StringBuilder(); - redirectPage.append(req.getServletPath()); - - // to regenerate the query string, we need to use the parameter map; however this can contain internal POST parameters - // that we don't want, so we filter through a list of paramters we do allow - // @todo verify what needs to be in this list of available parameters (for example do we want to repeat searches when you login? - List acceptableParameters = new ArrayList(); - acceptableParameters.addAll(Arrays.asList("id", "alias", "version", "q", "ownerId", "persistentId", "versionId", "datasetId", "selectedFileIds", "mode")); - - if (req.getParameterMap() != null) { - StringBuilder queryString = new StringBuilder(); - for (Map.Entry entry : ((Map) req.getParameterMap()).entrySet()) { - String name = entry.getKey(); - if (acceptableParameters.contains(name)) { - String value = entry.getValue()[0]; - queryString.append(queryString.length() == 0 ? "?" : "&").append(name).append("=").append(value); - } - } - redirectPage.append(queryString); - } - - return URLEncoder.encode(redirectPage.toString(), "UTF-8"); - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(DataverseHeaderFragment.class.getName()).log(Level.SEVERE, null, ex); - } - return ""; - } - public void addBreadcrumb (String url, String linkString){ breadcrumbs.add(new Breadcrumb(url, linkString)); } diff --git a/src/main/java/edu/harvard/iq/dataverse/DataversePage.java b/src/main/java/edu/harvard/iq/dataverse/DataversePage.java index 1b8b99740fe..cfb2fcc252a 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataversePage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataversePage.java @@ -104,6 +104,7 @@ public enum LinkMode { SettingsWrapper settingsWrapper; @EJB DataverseLinkingServiceBean linkingService; + @Inject PermissionsWrapper permissionsWrapper; private Dataverse dataverse = new Dataverse(); private EditMode editMode; @@ -291,16 +292,10 @@ public String init() { // check if dv exists and user has permission if (dataverse == null) { - return "/404.xhtml"; + return permissionsWrapper.notFound(); } if (!dataverse.isReleased() && !permissionService.on(dataverse).has(Permission.ViewUnpublishedDataverse)) { - System.out.print(" session.getUser().isAuthenticated() " + session.getUser().isAuthenticated()); - if (!session.getUser().isAuthenticated()){ - return "/loginpage.xhtml" + DataverseHeaderFragment.getRedirectPage(); - } else { - return "/403.xhtml"; //SEK need a new landing page if user is already logged in but lacks permission - } - + return permissionsWrapper.notAuthorized(); } ownerId = dataverse.getOwner() != null ? dataverse.getOwner().getId() : null; @@ -308,13 +303,9 @@ public String init() { editMode = EditMode.INFO; dataverse.setOwner(dataverseService.find(ownerId)); if (dataverse.getOwner() == null) { - return "/404.xhtml"; + return permissionsWrapper.notFound(); } else if (!permissionService.on(dataverse.getOwner()).has(Permission.AddDataverse)) { - if (!session.getUser().isAuthenticated()){ - return "/loginpage.xhtml" + DataverseHeaderFragment.getRedirectPage(); - } else { - return "/403.xhtml"; //SEK need a new landing page if user is already logged in but lacks permission - } + return permissionsWrapper.notAuthorized(); } // set defaults - contact e-mail and affiliation from user diff --git a/src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java b/src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java index 86c6ad5c8a2..a86374185e8 100644 --- a/src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java @@ -126,6 +126,7 @@ public enum FileEditMode { DataverseLinkingServiceBean dvLinkingService; @Inject DataverseRequestServiceBean dvRequestService; + @Inject PermissionsWrapper permissionsWrapper; private final DateFormat displayDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM); @@ -323,7 +324,7 @@ public String initCreateMode(String modeToken, DatasetVersion version, List()); initCustomQuestion(); } - } else if (ownerId != null && editMode.equals(GuestbookPage.EditMode.CREATE)) { + editMode = EditMode.METADATA; + } else if (ownerId != null && sourceId == null) { // create mode for a new template - dataverse = dataverseService.find(ownerId); guestbook = new Guestbook(); - guestbook.setDataverse(dataverse); + guestbook.setDataverse(dataverse); guestbook.setCustomQuestions(new ArrayList()); initCustomQuestion(); - } else if (ownerId != null && sourceId != null && editMode.equals(GuestbookPage.EditMode.CLONE)) { - // create mode for a new template - dataverse = dataverseService.find(ownerId); + editMode = EditMode.CREATE; + } else if (ownerId != null && sourceId != null ) { + // Clone mode for a new template from source + editMode = EditMode.CLONE; sourceGB = guestbookService.find(sourceId); guestbook = sourceGB.copyGuestbook(sourceGB, dataverse); String name = "Copy of " + sourceGB.getName(); @@ -157,6 +169,9 @@ public void init() { } else { throw new RuntimeException("On Guestook page without id or ownerid."); // improve error handling } + + return null; + } public String removeCustomQuestion(Long index){ diff --git a/src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java index 26795bd7f54..eeb815f09d0 100644 --- a/src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java @@ -227,8 +227,9 @@ private PublicKeyAuthenticationInfo getAuthInfo(String handlePrefix) { private String getRegistrationUrl(Dataset dataset) { String siteUrl = getSiteUrl(); - String targetUrl = siteUrl + "/dataset.xhtml?persistentId=hdl:" + dataset.getAuthority() - + "/" + dataset.getIdentifier(); + //String targetUrl = siteUrl + "/dataset.xhtml?persistentId=hdl:" + dataset.getAuthority() + String targetUrl = siteUrl + Dataset.TARGET_URL + "hdl:" + dataset.getAuthority() + + "/" + dataset.getIdentifier(); return targetUrl; } diff --git a/src/main/java/edu/harvard/iq/dataverse/ManageFilePermissionsPage.java b/src/main/java/edu/harvard/iq/dataverse/ManageFilePermissionsPage.java index 4c67c5b1342..201eb29a17e 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ManageFilePermissionsPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/ManageFilePermissionsPage.java @@ -70,6 +70,8 @@ public class ManageFilePermissionsPage implements java.io.Serializable { EjbDataverseEngine commandEngine; @Inject DataverseRequestServiceBean dvRequestService; + @Inject + PermissionsWrapper permissionsWrapper; @PersistenceContext(unitName = "VDCNet-ejbPU") EntityManager em; @@ -110,11 +112,11 @@ public String init() { // check if dvObject exists and user has permission if (dataset == null) { - return "/404.xhtml"; + return permissionsWrapper.notFound(); } if (!permissionService.on(dataset).has(Permission.ManageDatasetPermissions)) { - return "/loginpage.xhtml" + DataverseHeaderFragment.getRedirectPage(); + return permissionsWrapper.notAuthorized(); } initMaps(); diff --git a/src/main/java/edu/harvard/iq/dataverse/ManageGroupsPage.java b/src/main/java/edu/harvard/iq/dataverse/ManageGroupsPage.java index 9aaa060e4dc..1452f802cf6 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ManageGroupsPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/ManageGroupsPage.java @@ -65,6 +65,9 @@ public class ManageGroupsPage implements java.io.Serializable { GroupServiceBean groupService; @Inject DataverseRequestServiceBean dvRequestService; + + @Inject + PermissionsWrapper permissionsWrapper; @PersistenceContext(unitName = "VDCNet-ejbPU") EntityManager em; @@ -83,10 +86,21 @@ public class ManageGroupsPage implements java.io.Serializable { private Long dataverseId; private ExplicitGroup selectedGroup = null; - public void init() { + public String init() { setDataverse(dataverseService.find(getDataverseId())); - dvpage.setDataverse(getDataverse()); + Dataverse editDv = getDataverse(); + dvpage.setDataverse(editDv); + + if (editDv == null) { + return permissionsWrapper.notFound(); + } + Boolean hasPermissions = permissionsWrapper.canIssueCommand(editDv, CreateExplicitGroupCommand.class); + hasPermissions |= permissionsWrapper.canIssueCommand(editDv, DeleteExplicitGroupCommand.class); + hasPermissions |= permissionsWrapper.canIssueCommand(editDv, UpdateExplicitGroupCommand.class); + if (!hasPermissions) { + return permissionsWrapper.notAuthorized(); + } explicitGroups = new LinkedList<>(); List explicitGroupsForThisDataverse = @@ -95,6 +109,7 @@ public void init() { for (ExplicitGroup g : explicitGroupsForThisDataverse) { getExplicitGroups().add(g); } + return null; } diff --git a/src/main/java/edu/harvard/iq/dataverse/ManageGuestbooksPage.java b/src/main/java/edu/harvard/iq/dataverse/ManageGuestbooksPage.java index 3302b064a42..320a16e013c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ManageGuestbooksPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/ManageGuestbooksPage.java @@ -40,10 +40,10 @@ public class ManageGuestbooksPage implements java.io.Serializable { @EJB GuestbookResponseServiceBean guestbookResponseService; - + @EJB GuestbookServiceBean guestbookService; - + @EJB EjbDataverseEngine engineService; @@ -58,28 +58,35 @@ public class ManageGuestbooksPage implements java.io.Serializable { @Inject DataverseSession session; - + @Inject DataverseRequestServiceBean dvRequestService; + @Inject + PermissionsWrapper permissionsWrapper; + private List guestbooks; - private List responses; private Dataverse dataverse; private Long dataverseId; private boolean inheritGuestbooksValue; private boolean displayDownloadAll = false; - - private Guestbook selectedGuestbook = null; - public void init() { + public String init() { dataverse = dvService.find(dataverseId); - - Long totalResponses = guestbookResponseService.findCountAll(dataverseId); + + if (dataverse == null) { + return permissionsWrapper.notFound(); + } + if (!permissionsWrapper.canIssueCommand(dataverse, UpdateDataverseCommand.class)) { + return permissionsWrapper.notAuthorized(); + } + + Long totalResponses = guestbookResponseService.findCountAll(dataverseId); if(totalResponses.intValue() > 0){ displayDownloadAll = true; } - + dvpage.setDataverse(dataverse); guestbooks = new LinkedList<>(); @@ -104,8 +111,9 @@ public void init() { cg.setDataverse(dataverse); guestbooks.add(cg); } + return null; } - + public void downloadResponsesByDataverse(){ FacesContext ctx = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse(); @@ -115,14 +123,14 @@ public void downloadResponsesByDataverse(){ String converted = convertResponsesToCommaDelimited(guestbookResponseService.findArrayByDataverseId(dataverseId)); try { ServletOutputStream out = response.getOutputStream(); - out.write(converted.getBytes()); + out.write(converted.getBytes()); out.flush(); ctx.responseComplete(); } catch (Exception e) { } } - + public void downloadResponsesByDataverseAndGuestbook(){ FacesContext ctx = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse(); @@ -133,14 +141,14 @@ public void downloadResponsesByDataverseAndGuestbook(){ String converted = convertResponsesToCommaDelimited(guestbookResponseService.findArrayByDataverseIdAndGuestbookId(dataverseId, selectedGuestbook.getId())); try { ServletOutputStream out = response.getOutputStream(); - out.write(converted.getBytes()); + out.write(converted.getBytes()); out.flush(); ctx.responseComplete(); } catch (Exception e) { } } - + private String getFileName(){ return dataverse.getName() + "_GuestbookReponses.csv"; } @@ -148,7 +156,7 @@ private String getFileName(){ private final String SEPARATOR = ","; private final String END_OF_LINE = "\n"; - + private String convertResponsesToCommaDelimited(List guestbookResponses) { StringBuilder sb = new StringBuilder(); @@ -173,7 +181,7 @@ private String convertResponsesToCommaDelimited(List guestbookResponse sb.append(SEPARATOR); sb.append(array[8] == null ? "" : array[8]); if(array[9] != null){ - List responses = (List) array[9]; + List responses = (List) array[9]; for (Object[] response: responses){ sb.append(SEPARATOR); sb.append(response[0]); @@ -206,7 +214,7 @@ public void deleteGuestbook() { public void saveDataverse(ActionEvent e) { saveDataverse("", ""); } - + public String enableGuestbook(Guestbook selectedGuestbook) { selectedGuestbook.setEnabled(true); saveDataverse("dataset.manageGuestbooks.message.enableSuccess", "dataset.manageGuestbooks.message.enableFailure"); @@ -218,7 +226,7 @@ public String disableGuestbook(Guestbook selectedGuestbook) { saveDataverse("dataset.manageGuestbooks.message.disableSuccess", "dataset.manageGuestbooks.message.disableFailure"); return ""; } - + private void saveDataverse(String successMessage, String failureMessage) { if (successMessage.isEmpty()) { @@ -226,7 +234,7 @@ private void saveDataverse(String successMessage, String failureMessage) { } if (failureMessage.isEmpty()) { failureMessage = "dataset.manageGuestbooks.message.editFailure"; - } + } try { engineService.submit(new UpdateDataverseCommand(getDataverse(), null, null, dvRequestService.getDataverseRequest(), null)); JsfHelper.addSuccessMessage(JH.localize(successMessage)); @@ -243,7 +251,7 @@ public List getGuestbooks() { public void setGuestbooks(List guestbooks) { this.guestbooks = guestbooks; } - + public Dataverse getDataverse() { @@ -294,8 +302,8 @@ public void setDisplayDownloadAll(boolean displayDownloadAll) { public String updateGuestbooksRoot(javax.faces.event.AjaxBehaviorEvent event) throws javax.faces.event.AbortProcessingException { try { dataverse = engineService.submit( - new UpdateDataverseGuestbookRootCommand(!isInheritGuestbooksValue(), - dvRequestService.getDataverseRequest(), + new UpdateDataverseGuestbookRootCommand(!isInheritGuestbooksValue(), + dvRequestService.getDataverseRequest(), getDataverse())); init(); return ""; diff --git a/src/main/java/edu/harvard/iq/dataverse/ManagePermissionsPage.java b/src/main/java/edu/harvard/iq/dataverse/ManagePermissionsPage.java index b0125cce040..14a5b20d81f 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ManagePermissionsPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/ManagePermissionsPage.java @@ -71,6 +71,8 @@ public class ManagePermissionsPage implements java.io.Serializable { UserNotificationServiceBean userNotificationService; @Inject DataverseRequestServiceBean dvRequestService; + @Inject + PermissionsWrapper permissionsWrapper; @PersistenceContext(unitName = "VDCNet-ejbPU") @@ -100,13 +102,13 @@ public String init() { // check if dvObject exists and user has permission if (dvObject == null) { - return "/404.xhtml"; + 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 "/loginpage.xhtml" + DataverseHeaderFragment.getRedirectPage(); + return permissionsWrapper.notAuthorized(); } // initialize the configure settings diff --git a/src/main/java/edu/harvard/iq/dataverse/ManageTemplatesPage.java b/src/main/java/edu/harvard/iq/dataverse/ManageTemplatesPage.java index 77c407c9a04..de4a533705a 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ManageTemplatesPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/ManageTemplatesPage.java @@ -53,6 +53,9 @@ public class ManageTemplatesPage implements java.io.Serializable { @Inject DataverseRequestServiceBean dvRequestService; + + @Inject + PermissionsWrapper permissionsWrapper; private List