forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IQSS#3118 from IQSS/2469-widgets
2469 widgets
- Loading branch information
Showing
62 changed files
with
1,920 additions
and
1,071 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE dataverse ADD COLUMN citationRedirectURL character varying(255); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/edu/harvard/iq/dataverse/BibtexCitation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String> 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(); | ||
} | ||
|
||
} | ||
|
93 changes: 93 additions & 0 deletions
93
src/main/java/edu/harvard/iq/dataverse/CitationServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <code>GET</code> and <code>POST</code> | ||
* 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); | ||
} | ||
|
||
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> | ||
/** | ||
* Handles the HTTP <code>GET</code> 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 <code>POST</code> 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."; | ||
}// </editor-fold> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.