diff --git a/src/main/java/edu/harvard/iq/dataverse/DataCiteRESTfullClient.java b/src/main/java/edu/harvard/iq/dataverse/DataCiteRESTfullClient.java index a8ddc3b06e9..f4af6d436f2 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataCiteRESTfullClient.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataCiteRESTfullClient.java @@ -176,6 +176,8 @@ public boolean testDOIExists(String doi) { * @return */ public String postMetadata(String metadata) { + System.out.println("postMetadata url: " + this.url + "/metadata"); + HttpPost httpPost = new HttpPost(this.url + "/metadata"); httpPost.setHeader("Content-Type", "application/xml;charset=UTF-8"); try { diff --git a/src/main/java/edu/harvard/iq/dataverse/FileDownload.java b/src/main/java/edu/harvard/iq/dataverse/FileDownload.java new file mode 100644 index 00000000000..8463a8278c0 --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/FileDownload.java @@ -0,0 +1,165 @@ +/* + * 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.io.Serializable; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; +import javax.persistence.CascadeType; +import javax.persistence.OneToOne; +import javax.persistence.MapsId; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import java.util.Date; + + +/** + * + * @author marina + */ +@Entity +public class FileDownload implements Serializable { + + @Id + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + @MapsId + private GuestbookResponse guestbookResponse; + + @Temporal(value = TemporalType.TIMESTAMP) + private Date downloadTimestamp; + + /* + Transient Values carry non-written information + that will assist in the download process + - selected file ids is a comma delimited list that contains the file ids for multiple download + - fileFormat tells the download api which format a subsettable file should be downloaded as + */ + + @Transient + private String selectedFileIds; + + @Transient + private String fileFormat; + + + /** + * Possible values for downloadType include "Download", "Subset", + * "WorldMap", or the displayName of an ExternalTool. + * + * TODO: Types like "Download" and "Subset" and probably "WorldMap" should + * be defined once as constants (likely an enum) rather than having these + * strings duplicated in various places when setDownloadtype() is called. + * (Some day it would be nice to convert WorldMap into an ExternalTool but + * it's not worth the effort at this time.) + */ + private String downloadtype; + private String sessionId; + + public FileDownload(){ + + } + + public FileDownload(FileDownload source){ + this.setDownloadTimestamp(source.getDownloadTimestamp()); + this.setDownloadtype(source.getDownloadtype()); + this.setFileFormat(source.getFileFormat()); + this.setGuestbookResponse(source.getGuestbookResponse()); + this.setSelectedFileIds(source.getSelectedFileIds()); + this.setSessionId(source.getSessionId()); + } + + public String getFileFormat() { + return fileFormat; + } + + //for download + public void setFileFormat(String downloadFormat) { + this.fileFormat = downloadFormat; + } + + public String getDownloadtype() { + return downloadtype; + } + + public void setDownloadtype(String downloadtype) { + this.downloadtype = downloadtype; + } + + public String getSessionId() { + return sessionId; + } + + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } + + public String getSelectedFileIds() { + return selectedFileIds; + } + + public void setSelectedFileIds(String selectedFileIds) { + this.selectedFileIds = selectedFileIds; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getDownloadTimestamp(){ + return this.downloadTimestamp; + } + + public void setDownloadTimestamp(Date downloadTimestamp){ + this.downloadTimestamp = downloadTimestamp; + } + + + public void setGuestbookResponse(GuestbookResponse gbr){ + this.guestbookResponse = gbr; + } + + public GuestbookResponse getGuestbookResponse(){ + return this.guestbookResponse; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof FileDownload)) { + return false; + } + FileDownload other = (FileDownload) object; + if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "edu.harvard.iq.dataverse.FileDownload[ id=" + id + " ]"; + } + + +} diff --git a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java index 19f55dc241a..2d358dc9b0d 100644 --- a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java +++ b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java @@ -1,3 +1,4 @@ + /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates @@ -24,16 +25,13 @@ @Index(columnList = "datafile_id"), @Index(columnList = "dataset_id") }) -@NamedQueries( - @NamedQuery(name = "GuestbookResponse.findByAuthenticatedUserId", - query = "SELECT gbr FROM GuestbookResponse gbr WHERE gbr.authenticatedUser.id=:authenticatedUserId") -) + public class GuestbookResponse implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - + @ManyToOne @JoinColumn(nullable=false) private Guestbook guestbook; @@ -54,27 +52,18 @@ public class GuestbookResponse implements Serializable { @JoinColumn(nullable=true) private AuthenticatedUser authenticatedUser; + @OneToOne(cascade=CascadeType.ALL,mappedBy="guestbookResponse",fetch = FetchType.LAZY, optional = false) + private FileDownload fileDownload; + @OneToMany(mappedBy="guestbookResponse",cascade={CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST},orphanRemoval=true) @OrderBy ("id") private List customQuestionResponses; - private String name; private String email; private String institution; private String position; - /** - * Possible values for downloadType include "Download", "Subset", - * "WorldMap", or the displayName of an ExternalTool. - * - * TODO: Types like "Download" and "Subset" and probably "WorldMap" should - * be defined once as constants (likely an enum) rather than having these - * strings duplicated in various places when setDownloadtype() is called. - * (Some day it would be nice to convert WorldMap into an ExternalTool but - * it's not worth the effort at this time.) - */ - private String downloadtype; - private String sessionId; + @Temporal(value = TemporalType.TIMESTAMP) private Date responseTime; @@ -82,17 +71,9 @@ public class GuestbookResponse implements Serializable { /* Transient Values carry non-written information that will assist in the download process - - selected file ids is a comma delimited list that contains the file ids for multiple download - - fileFormat tells the download api which format a subsettable file should be downloaded as - writeResponse is set to false when dataset version is draft. */ - - @Transient - private String selectedFileIds; - - @Transient - private String fileFormat; - + @Transient private boolean writeResponse = true; @@ -112,23 +93,22 @@ public void setWriteResponse(boolean writeResponse) { this.writeResponse = writeResponse; } - public String getSelectedFileIds() { - return selectedFileIds; + public String getSelectedFileIds(){ + return this.fileDownload.getSelectedFileIds(); } - + public void setSelectedFileIds(String selectedFileIds) { - this.selectedFileIds = selectedFileIds; + this.fileDownload.setSelectedFileIds(selectedFileIds); } - public String getFileFormat() { - return fileFormat; + return this.fileDownload.getFileFormat(); } public void setFileFormat(String downloadFormat) { - this.fileFormat = downloadFormat; + this.fileDownload.setFileFormat(downloadFormat); } - + public ExternalTool getExternalTool() { return externalTool; } @@ -138,7 +118,10 @@ public void setExternalTool(ExternalTool externalTool) { } public GuestbookResponse(){ - + if(this.getFileDownload() == null){ + this.fileDownload = new FileDownload(); + this.fileDownload.setGuestbookResponse(this); + } } public GuestbookResponse(GuestbookResponse source){ @@ -151,7 +134,7 @@ public GuestbookResponse(GuestbookResponse source){ this.setDataset(source.getDataset()); this.setDatasetVersion(source.getDatasetVersion()); this.setAuthenticatedUser(source.getAuthenticatedUser()); - this.setSessionId(source.getSessionId()); + List customQuestionResponses = new ArrayList<>(); if (!source.getCustomQuestionResponses().isEmpty()){ for (CustomQuestionResponse customQuestionResponse : source.getCustomQuestionResponses() ){ @@ -164,6 +147,7 @@ public GuestbookResponse(GuestbookResponse source){ } this.setCustomQuestionResponses(customQuestionResponses); this.setGuestbook(source.getGuestbook()); + this.setFileDownload(source.getFileDownload()); } @@ -221,6 +205,7 @@ public Date getResponseTime() { public void setResponseTime(Date responseTime) { this.responseTime = responseTime; + this.getFileDownload().setDownloadTimestamp(responseTime); } public String getResponseDate() { @@ -240,6 +225,15 @@ public void setCustomQuestionResponses(List customQuesti this.customQuestionResponses = customQuestionResponses; } + public FileDownload getFileDownload(){ + return fileDownload; + } + + public void setFileDownload(FileDownload fDownload){ + this.fileDownload = fDownload; + } + + public Dataset getDataset() { return dataset; } @@ -273,19 +267,21 @@ public void setAuthenticatedUser(AuthenticatedUser authenticatedUser) { } public String getDownloadtype() { - return downloadtype; + return this.fileDownload.getDownloadtype(); } public void setDownloadtype(String downloadtype) { - this.downloadtype = downloadtype; + this.fileDownload.setDownloadtype(downloadtype); + } public String getSessionId() { - return sessionId; + return this.fileDownload.getSessionId(); } public void setSessionId(String sessionId) { - this.sessionId = sessionId; + + this.fileDownload.setSessionId(sessionId); } @Override diff --git a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java index 79bdce62359..dd41c92ffbd 100644 --- a/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/GuestbookResponseServiceBean.java @@ -46,14 +46,15 @@ public class GuestbookResponseServiceBean { // the collected data, in CSV format, from the manage-guestbooks and // guestbook-results pages. (for entire dataverses, and for the individual // guestbooks within dataverses, respectively). -- L.A. - private static final String BASE_QUERY_STRING_FOR_DOWNLOAD_AS_CSV = "select r.id, g.name, v.value, r.responsetime, r.downloadtype," + private static final String BASE_QUERY_STRING_FOR_DOWNLOAD_AS_CSV = "select r.id, g.name, v.value, r.responsetime, f.downloadtype," + " m.label, r.dataFile_id, r.name, r.email, r.institution, r.position " - + "from guestbookresponse r, datasetfieldvalue v, filemetadata m, dvobject o, guestbook g " + + "from guestbookresponse r, filedownload f, datasetfieldvalue v, filemetadata m, dvobject o, guestbook g " + "where " + " v.datasetfield_id = (select id from datasetfield f where datasetfieldtype_id = 1 " + " and datasetversion_id = (select max(id) from datasetversion where dataset_id =r.dataset_id )) " + " and m.datasetversion_id = (select max(datasetversion_id) from filemetadata where datafile_id =r.datafile_id ) " + " and m.datafile_id = r.datafile_id " + + " and r.id = f.guestbookresponse_id " + " and r.dataset_id = o.id " + " and r.guestbook_id = g.id "; @@ -61,13 +62,14 @@ public class GuestbookResponseServiceBean { // on the guestbook-results.xhtml page (the info we show on the page is // less detailed than what we let the users download as CSV files, so this // query has fewer fields than the one above). -- L.A. - private static final String BASE_QUERY_STRING_FOR_PAGE_DISPLAY = "select r.id, v.value, r.responsetime, r.downloadtype, m.label, r.name " - + "from guestbookresponse r, datasetfieldvalue v, filemetadata m , dvobject o " + private static final String BASE_QUERY_STRING_FOR_PAGE_DISPLAY = "select r.id, v.value, r.responsetime, f.downloadtype, m.label, r.name " + + "from guestbookresponse r, filedownload f, datasetfieldvalue v, filemetadata m , dvobject o " + "where " + " v.datasetfield_id = (select id from datasetfield f where datasetfieldtype_id = 1 " + " and datasetversion_id = (select max(id) from datasetversion where dataset_id =r.dataset_id )) " + " and m.datasetversion_id = (select max(datasetversion_id) from filemetadata where datafile_id =r.datafile_id ) " + " and m.datafile_id = r.datafile_id " + + " and r.id = f.guestbookresponse_id " + " and r.dataset_id = o.id "; // And a custom query for retrieving *all* the custom question responses, for @@ -730,7 +732,7 @@ private void setUserDefaultResponses(GuestbookResponse guestbookResponse, Datave } else{ user = sessionUser; } - + if (user != null) { guestbookResponse.setEmail(getUserEMail(user)); guestbookResponse.setName(getUserName(user)); @@ -749,6 +751,7 @@ private void setUserDefaultResponses(GuestbookResponse guestbookResponse, Datave private void setUserDefaultResponses(GuestbookResponse guestbookResponse, DataverseSession session) { User user = session.getUser(); + if (user != null) { guestbookResponse.setEmail(getUserEMail(user)); guestbookResponse.setName(getUserName(user)); diff --git a/src/main/resources/db/migration/V4.14.0.2__2043-split-gbr-table.sql b/src/main/resources/db/migration/V4.14.0.2__2043-split-gbr-table.sql new file mode 100644 index 00000000000..b161a093497 --- /dev/null +++ b/src/main/resources/db/migration/V4.14.0.2__2043-split-gbr-table.sql @@ -0,0 +1,4 @@ +begin; +insert into filedownload(GUESTBOOKRESPONSE_ID,DOWNLOADTYPE,DOWNLOADTIMESTAMP,SESSIONID) select ID, DOWNLOADTYPE,RESPONSETIME,SESSIONID from guestbookresponse; +alter table guestbookresponse drop column DOWNLOADTYPE, drop column SESSIONID; +commit;