Skip to content

Commit

Permalink
Issue #1257: Added the DataverseRequest object, wrapping the datavers…
Browse files Browse the repository at this point in the history
…e user and some request metadata.
  • Loading branch information
michbarsinai committed Aug 10, 2015
1 parent 06bb98e commit c10cbd9
Show file tree
Hide file tree
Showing 118 changed files with 911 additions and 742 deletions.
46 changes: 24 additions & 22 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,18 @@ public enum DisplayMode {
@EJB
DatasetLinkingServiceBean dsLinkingService;
@Inject
DataverseRequestServiceBean dvRequestService;
@Inject
DatasetVersionUI datasetVersionUI;

private static final DateFormat displayDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
private final DateFormat displayDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);

private Dataset dataset = new Dataset();
private EditMode editMode;
private Long ownerId;
private Long versionId;
private int selectedTabIndex;
private List<DataFile> newFiles = new ArrayList();
private final List<DataFile> newFiles = new ArrayList();
private DatasetVersion workingVersion;
private int releaseRadio = 1;
private int deaccessionRadio = 0;
Expand Down Expand Up @@ -179,8 +181,8 @@ public enum DisplayMode {


// Used to store results of permissions checks
private Map<String, Boolean> datasetPermissionMap = new HashMap<>(); // { Permission human_name : Boolean }
private Map<Long, Boolean> fileDownloadPermissionMap = new HashMap<>(); // { FileMetadata.id : Boolean }
private final Map<String, Boolean> datasetPermissionMap = new HashMap<>(); // { Permission human_name : Boolean }
private final Map<Long, Boolean> fileDownloadPermissionMap = new HashMap<>(); // { FileMetadata.id : Boolean }

private DataFile selectedDownloadFile;

Expand Down Expand Up @@ -1151,14 +1153,14 @@ public String saveGuestbookResponse(String type) {
try {
if (this.guestbookResponse != null) {
if (!type.equals("multiple")) {
cmd = new CreateGuestbookResponseCommand(session.getUser(), this.guestbookResponse, dataset);
cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), this.guestbookResponse, dataset);
commandEngine.submit(cmd);
} else {
for (FileMetadata fmd : this.selectedFiles) {
DataFile df = fmd.getDataFile();
if (df != null) {
this.guestbookResponse.setDataFile(df);
cmd = new CreateGuestbookResponseCommand(session.getUser(), this.guestbookResponse, dataset);
cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), this.guestbookResponse, dataset);
commandEngine.submit(cmd);
}
}
Expand Down Expand Up @@ -1235,7 +1237,7 @@ private void callDownloadServlet( String downloadType, Long fileId){
if (downloadType != null && downloadType.equals("tab")){
fileDownloadUrl = "/api/access/datafile/" + this.selectedDownloadFile.getId()+ "?format=tab";
}
logger.fine("Returning file download url: " + fileDownloadUrl);
logger.fine("Returning file download url: " + fileDownloadUrl);
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(fileDownloadUrl);
} catch (IOException ex) {
Expand Down Expand Up @@ -1353,7 +1355,7 @@ public String sendBackToContributor() {
workingVersion = dataset.getEditVersion();
workingVersion.setInReview(false);
try {
cmd = new UpdateDatasetCommand(dataset, session.getUser());
cmd = new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest());
dataset = commandEngine.submit(cmd);
} catch (CommandException ex) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Dataset Submission Failed", " - " + ex.toString()));
Expand All @@ -1379,7 +1381,7 @@ public String submitDataset() {
workingVersion = dataset.getEditVersion();
workingVersion.setInReview(true);
try {
cmd = new UpdateDatasetCommand(dataset, session.getUser());
cmd = new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest());
dataset = commandEngine.submit(cmd);
} catch (CommandException ex) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Dataset Submission Failed", " - " + ex.toString()));
Expand Down Expand Up @@ -1407,7 +1409,7 @@ public String releaseDataset() {

private void releaseParentDV(){
if (session.getUser() instanceof AuthenticatedUser) {
PublishDataverseCommand cmd = new PublishDataverseCommand((AuthenticatedUser) session.getUser(), dataset.getOwner());
PublishDataverseCommand cmd = new PublishDataverseCommand(dvRequestService.getDataverseRequest(), dataset.getOwner());
try {
commandEngine.submit(cmd);
JsfHelper.addSuccessMessage(JH.localize("dataverse.publish.success"));
Expand All @@ -1430,13 +1432,13 @@ public String deaccessionVersions() {
if (selectedDeaccessionVersions == null) {
for (DatasetVersion dv : this.dataset.getVersions()) {
if (dv.isReleased()) {
cmd = new DeaccessionDatasetVersionCommand(session.getUser(), setDatasetVersionDeaccessionReasonAndURL(dv), true);
cmd = new DeaccessionDatasetVersionCommand(dvRequestService.getDataverseRequest(), setDatasetVersionDeaccessionReasonAndURL(dv), true);
DatasetVersion datasetv = commandEngine.submit(cmd);
}
}
} else {
for (DatasetVersion dv : selectedDeaccessionVersions) {
cmd = new DeaccessionDatasetVersionCommand(session.getUser(), setDatasetVersionDeaccessionReasonAndURL(dv), false);
cmd = new DeaccessionDatasetVersionCommand(dvRequestService.getDataverseRequest(), setDatasetVersionDeaccessionReasonAndURL(dv), false);
DatasetVersion datasetv = commandEngine.submit(cmd);
}
}
Expand Down Expand Up @@ -1490,9 +1492,9 @@ private String releaseDataset(boolean minor) {
if (session.getUser() instanceof AuthenticatedUser) {
try {
if (editMode == EditMode.CREATE) {
cmd = new PublishDatasetCommand(dataset, (AuthenticatedUser) session.getUser(), minor);
cmd = new PublishDatasetCommand(dataset, dvRequestService.getDataverseRequest(), minor);
} else {
cmd = new PublishDatasetCommand(dataset, (AuthenticatedUser) session.getUser(), minor);
cmd = new PublishDatasetCommand(dataset, dvRequestService.getDataverseRequest(), minor);
}
dataset = commandEngine.submit(cmd);
JsfHelper.addSuccessMessage(JH.localize("dataset.message.publishSuccess"));
Expand All @@ -1519,7 +1521,7 @@ private String releaseDataset(boolean minor) {
public String registerDataset() {
Command<Dataset> cmd;
try {
cmd = new UpdateDatasetCommand(dataset, session.getUser());
cmd = new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest());
dataset = commandEngine.submit(cmd);
} catch (CommandException ex) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Dataset Registration Failed", " - " + ex.toString()));
Expand Down Expand Up @@ -1569,7 +1571,7 @@ public String deleteDataset() {

Command cmd;
try {
cmd = new DestroyDatasetCommand(dataset, session.getUser());
cmd = new DestroyDatasetCommand(dataset, dvRequestService.getDataverseRequest());
commandEngine.submit(cmd);
/* - need to figure out what to do
Update notification in Delete Dataset Method
Expand All @@ -1587,7 +1589,7 @@ public String deleteDataset() {
public String deleteDatasetVersion() {
Command cmd;
try {
cmd = new DeleteDatasetVersionCommand(session.getUser(), dataset);
cmd = new DeleteDatasetVersionCommand(dvRequestService.getDataverseRequest(), dataset);
commandEngine.submit(cmd);
JsfHelper.addSuccessMessage(JH.localize("datasetVersion.message.deleteSuccess"));
} catch (CommandException ex) {
Expand Down Expand Up @@ -1627,7 +1629,7 @@ public String saveLinkedDataset() {
return "";
}
linkingDataverse = dataverseService.find(linkingDataverseId);
LinkDatasetCommand cmd = new LinkDatasetCommand(session.getUser(), linkingDataverse, dataset);
LinkDatasetCommand cmd = new LinkDatasetCommand(dvRequestService.getDataverseRequest(), linkingDataverse, dataset);
try {
commandEngine.submit(cmd);
//JsfHelper.addFlashMessage(JH.localize("dataset.message.linkSuccess") + linkingDataverse.getDisplayName());
Expand Down Expand Up @@ -1829,17 +1831,17 @@ public String save() {
workingVersion.setLicense(DatasetVersion.License.CC0);
if ( selectedTemplate != null ) {
if ( session.getUser().isAuthenticated() ) {
cmd = new CreateDatasetCommand(dataset, (AuthenticatedUser) session.getUser(), false, null, selectedTemplate);
cmd = new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest(), false, null, selectedTemplate);
} else {
JH.addMessage(FacesMessage.SEVERITY_FATAL, JH.localize("dataset.create.authenticatedUsersOnly"));
return null;
}
} else {
cmd = new CreateDatasetCommand(dataset, session.getUser());
cmd = new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest());
}

} else {
cmd = new UpdateDatasetCommand(dataset, session.getUser(), filesToBeDeleted);
cmd = new UpdateDatasetCommand(dataset, dvRequestService.getDataverseRequest(), filesToBeDeleted);
}
dataset = commandEngine.submit(cmd);
if (editMode == EditMode.CREATE) {
Expand Down Expand Up @@ -2361,7 +2363,7 @@ private void createSilentGuestbookEntry(FileMetadata fileMetadata, String format
Command cmd;
try {
if (this.guestbookResponse != null) {
cmd = new CreateGuestbookResponseCommand(session.getUser(), guestbookResponse, dataset);
cmd = new CreateGuestbookResponseCommand(dvRequestService.getDataverseRequest(), guestbookResponse, dataset);
commandEngine.submit(cmd);
}
} catch (CommandException ex) {
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/edu/harvard/iq/dataverse/DataversePage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.UserNotification.Type;
import edu.harvard.iq.dataverse.authorization.DataverseRole;
import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.authorization.users.User;
Expand Down Expand Up @@ -35,7 +34,6 @@
import javax.inject.Named;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
Expand Down Expand Up @@ -98,7 +96,8 @@ public enum LinkMode {
@EJB DataverseRoleServiceBean dataverseRoleServiceBean;
@Inject
SearchIncludeFragment searchIncludeFragment;

@Inject
DataverseRequestServiceBean dvRequestService;
@EJB
DataverseLinkingServiceBean linkingService;

Expand Down Expand Up @@ -614,17 +613,17 @@ public String save() {
if (session.getUser().isAuthenticated()) {
dataverse.setOwner(ownerId != null ? dataverseService.find(ownerId) : null);
create = Boolean.TRUE;
cmd = new CreateDataverseCommand(dataverse, (AuthenticatedUser) session.getUser(), facets.getTarget(), listDFTIL);
cmd = new CreateDataverseCommand(dataverse, dvRequestService.getDataverseRequest(), facets.getTarget(), listDFTIL);
} else {
JH.addMessage(FacesMessage.SEVERITY_FATAL, BundleUtil.getStringFromBundle("dataverse.create.authenticatedUsersOnly"));
return null;
}
} else {
create = Boolean.FALSE;
if (editMode != null && editMode.equals(editMode.FEATURED)) {
cmd = new UpdateDataverseCommand(dataverse, null, featuredDataverses.getTarget(), session.getUser(), null);
if (editMode != null && editMode.equals(EditMode.FEATURED)) {
cmd = new UpdateDataverseCommand(dataverse, null, featuredDataverses.getTarget(), dvRequestService.getDataverseRequest(), null);
} else {
cmd = new UpdateDataverseCommand(dataverse, facets.getTarget(), null, session.getUser(), listDFTIL);
cmd = new UpdateDataverseCommand(dataverse, facets.getTarget(), null, dvRequestService.getDataverseRequest(), listDFTIL);
}
}

Expand All @@ -636,8 +635,8 @@ public String save() {
}
}

String message = "";
if (editMode != null && editMode.equals(editMode.FEATURED)) {
String message;
if (editMode != null && editMode.equals(EditMode.FEATURED)) {
message = "The featured dataverses for this dataverse have been updated.";
} else {
message = (create) ? BundleUtil.getStringFromBundle("dataverse.create.success", Arrays.asList(systemConfig.getGuidesBaseUrl(), systemConfig.getVersion())) : BundleUtil.getStringFromBundle("dataverse.update.success");
Expand Down Expand Up @@ -743,13 +742,13 @@ public String saveLinkedDataverse() {

linkingDataverse = dataverseService.find(linkingDataverseId);

LinkDataverseCommand cmd = new LinkDataverseCommand(session.getUser(), linkingDataverse, dataverse);
LinkDataverseCommand cmd = new LinkDataverseCommand(dvRequestService.getDataverseRequest(), linkingDataverse, dataverse);
//LinkDvObjectCommand cmd = new LinkDvObjectCommand (session.getUser(), linkingDataverse, dataverse);
try {
commandEngine.submit(cmd);
} catch (CommandException ex) {
String msg = "Unable to link " + dataverse.getDisplayName() + " to " + linkingDataverse.getDisplayName() + ". An internal error occurred.";
logger.severe(msg + " " + ex);
logger.log(Level.SEVERE, "{0} {1}", new Object[]{msg, ex});
JsfHelper.addErrorMessage(msg);
return "/dataverse.xhtml?alias=" + dataverse.getAlias() + "&faces-redirect=true";
}
Expand Down Expand Up @@ -779,7 +778,7 @@ public String saveLinkedDataverse() {
arguments.add(linkingDataverse.getDisplayName());
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataverse.linked.internalerror", arguments));
String msg = dataverse.getDisplayName() + " has been successfully linked to " + linkingDataverse.getDisplayName() + " but contents will not appear until an internal error has been fixed.";
logger.severe(msg + " " + ex);
logger.log(Level.SEVERE, "{0} {1}", new Object[]{msg, ex});
//JsfHelper.addErrorMessage(msg);
return "/dataverse.xhtml?alias=" + dataverse.getAlias() + "&faces-redirect=true";
}
Expand Down Expand Up @@ -849,7 +848,7 @@ public String saveSavedSearch() {
savedSearch.getSavedSearchFilterQueries().add(ssfq);
}
}
CreateSavedSearchCommand cmd = new CreateSavedSearchCommand(session.getUser(), linkingDataverse, savedSearch);
CreateSavedSearchCommand cmd = new CreateSavedSearchCommand(dvRequestService.getDataverseRequest(), linkingDataverse, savedSearch);
try {
commandEngine.submit(cmd);

Expand Down Expand Up @@ -878,7 +877,7 @@ private AuthenticatedUser getAuthenticatedUser() {

public String releaseDataverse() {
if (session.getUser() instanceof AuthenticatedUser) {
PublishDataverseCommand cmd = new PublishDataverseCommand((AuthenticatedUser) session.getUser(), dataverse);
PublishDataverseCommand cmd = new PublishDataverseCommand(dvRequestService.getDataverseRequest(), dataverse);
try {
commandEngine.submit(cmd);
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("dataverse.publish.success"));
Expand All @@ -896,7 +895,7 @@ public String releaseDataverse() {
}

public String deleteDataverse() {
DeleteDataverseCommand cmd = new DeleteDataverseCommand(session.getUser(), dataverse);
DeleteDataverseCommand cmd = new DeleteDataverseCommand(dvRequestService.getDataverseRequest(), dataverse);
try {
commandEngine.submit(cmd);
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("dataverse.delete.success"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;

/**
* The service bean to go to when one needs the current {@link DataverseRequest}.
* @author michael
*/
@Named
@RequestScoped
public class DataverseRequestServiceBean {

@Inject
DataverseSession dataverseSessionSvc;

@Context
HttpServletRequest httpRequest;

private DataverseRequest dataverseRequest;

@PostConstruct
protected void setup() {
dataverseRequest = new DataverseRequest(dataverseSessionSvc.getUser(), httpRequest);
}

public DataverseRequest getDataverseRequest() {
return dataverseRequest;
}

}
14 changes: 4 additions & 10 deletions src/main/java/edu/harvard/iq/dataverse/DataverseSession.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUserServiceBean;
import edu.harvard.iq.dataverse.PermissionServiceBean.PermissionQuery;
import edu.harvard.iq.dataverse.PermissionServiceBean.StaticPermissionQuery;
import edu.harvard.iq.dataverse.actionlogging.ActionLogRecord;
import edu.harvard.iq.dataverse.actionlogging.ActionLogServiceBean;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.authorization.users.GuestUser;
import edu.harvard.iq.dataverse.authorization.users.User;
import edu.harvard.iq.dataverse.authorization.users.UserRequestMetadata;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

/**
*
Expand All @@ -36,12 +33,9 @@ public class DataverseSession implements Serializable{

public User getUser() {
if ( user == null ) {
user = new GuestUser();
}

if (FacesContext.getCurrentInstance() != null) {
user.setRequestMetadata( new UserRequestMetadata((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()) );
user = GuestUser.get();
}

return user;
}

Expand All @@ -53,7 +47,7 @@ public void setUser(AuthenticatedUser aUser) {
this.user = aUser;
}

public PermissionQuery on( Dataverse d ) {
public StaticPermissionQuery on( Dataverse d ) {
return permissionsService.userOn(user, d);
}

Expand Down
Loading

0 comments on commit c10cbd9

Please sign in to comment.