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

2043 split gbr table #5863

Merged
merged 24 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fae6439
Merge pull request #1 from IQSS/develop
mdmADA May 14, 2019
01633ec
Added @OneToOne relationship to FileDownload.
mdmADA May 14, 2019
b91687e
Added @OneToOne relationship to FileDownload.
mdmADA May 15, 2019
d0dee89
postMetadata causing problems
mdmADA May 17, 2019
c3874f9
Changes to GuestbookResponse interface implementation to call FileDow…
mdmADA May 17, 2019
2bc6fa6
Setting up one-to-one relationship between FileDownload and Guestbook…
mdmADA May 17, 2019
9f6834c
Fixed getId() and setId()
mdmADA May 17, 2019
c69f783
Fixing possible null FileDownload
mdmADA May 17, 2019
07f9642
Fixing downloadTimestamp
mdmADA May 17, 2019
f37b46c
Fixing downloadTimestamp
mdmADA May 20, 2019
65ffdcc
Not sure why 'Guest' not written to GuestbookResponse when Guest user…
mdmADA May 20, 2019
acdd7c9
Testing out different onetoone mapping scheme.
mdmADA May 20, 2019
b0992e7
Cleaning up OneToOne code.
mdmADA May 20, 2019
3214701
Cleaning up OneToOne code.
mdmADA May 20, 2019
0f71cc0
Cleaning up OneToOne code.
mdmADA May 21, 2019
b8d1fbd
Merge pull request #3 from IQSS/develop
mdmADA May 21, 2019
54a204e
Adding update sql script related to splitting guestbookresponse table…
mdmADA May 23, 2019
f643aff
Merge pull request #4 from IQSS/develop
mdmADA May 23, 2019
fd36230
Rename V4.14.0.1__2043-split-gbr-table.sql to V4.14.0.2__2043-split-g…
mdmADA Jun 7, 2019
c8d27a9
Merge pull request #5 from IQSS/develop
mdmADA Jun 7, 2019
f4b5dd4
Update V4.14.0.2__2043-split-gbr-table.sql
mdmADA Jun 18, 2019
beb88dc
Merge pull request #6 from IQSS/develop
mdmADA Jun 18, 2019
2b164af
Modify the BASE_QUERY_STRING_FOR_DOWNLOAD_AS_CSV and BASE_QUERY_STRIN…
mdmADA Jun 20, 2019
4d82505
Merge origin/2043-split-gb-table into 2043-split-gb-table
mdmADA Jun 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
165 changes: 165 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/FileDownload.java
Original file line number Diff line number Diff line change
@@ -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 + " ]";
}


}
78 changes: 37 additions & 41 deletions src/main/java/edu/harvard/iq/dataverse/GuestbookResponse.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
Expand All @@ -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;
Expand All @@ -54,45 +52,28 @@ 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<CustomQuestionResponse> 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;

/*
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;

Expand All @@ -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;
}
Expand All @@ -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){
Expand All @@ -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 <CustomQuestionResponse> customQuestionResponses = new ArrayList<>();
if (!source.getCustomQuestionResponses().isEmpty()){
for (CustomQuestionResponse customQuestionResponse : source.getCustomQuestionResponses() ){
Expand All @@ -164,6 +147,7 @@ public GuestbookResponse(GuestbookResponse source){
}
this.setCustomQuestionResponses(customQuestionResponses);
this.setGuestbook(source.getGuestbook());
this.setFileDownload(source.getFileDownload());
}


Expand Down Expand Up @@ -221,6 +205,7 @@ public Date getResponseTime() {

public void setResponseTime(Date responseTime) {
this.responseTime = responseTime;
this.getFileDownload().setDownloadTimestamp(responseTime);
}

public String getResponseDate() {
Expand All @@ -240,6 +225,15 @@ public void setCustomQuestionResponses(List<CustomQuestionResponse> customQuesti
this.customQuestionResponses = customQuestionResponses;
}

public FileDownload getFileDownload(){
return fileDownload;
}

public void setFileDownload(FileDownload fDownload){
this.fileDownload = fDownload;
}


public Dataset getDataset() {
return dataset;
}
Expand Down Expand Up @@ -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
Expand Down
Loading