Skip to content

Commit

Permalink
Added: persisting featured items in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Dec 26, 2024
1 parent 0744c30 commit 2c96f21
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package edu.harvard.iq.dataverse;

import jakarta.ejb.Stateless;
import jakarta.inject.Named;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

import java.io.Serializable;

@Stateless
@Named
public class DataverseFeaturedItemServiceBean implements Serializable {

@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;

public DataverseFeaturedItem save(DataverseFeaturedItem dataverseFeaturedItem) {
if (dataverseFeaturedItem.getId() == null) {
em.persist(dataverseFeaturedItem);
return dataverseFeaturedItem;
} else {
return em.merge(dataverseFeaturedItem);
}
}
}
10 changes: 9 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/EjbDataverseEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ public class EjbDataverseEngine {
ConfirmEmailServiceBean confirmEmailService;

@EJB
StorageUseServiceBean storageUseService;
StorageUseServiceBean storageUseService;

@EJB
DataverseFeaturedItemServiceBean dataverseFeaturedItemServiceBean;

@EJB
EjbDataverseEngineInner innerEngine;
Expand Down Expand Up @@ -522,6 +525,11 @@ public DatasetFieldServiceBean dsField() {
return dsField;
}

@Override
public DataverseFeaturedItemServiceBean dataverseFeaturedItems() {
return dataverseFeaturedItemServiceBean;
}

@Override
public StorageUseServiceBean storageUse() {
return storageUseService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package edu.harvard.iq.dataverse.api.dto;

import org.glassfish.jersey.media.multipart.FormDataContentDisposition;

import java.io.InputStream;

public class NewDataverseFeaturedItemDTO {
private String content;
private int displayOrder;
private InputStream fileInputStream;
private String imageFileName;

public static NewDataverseFeaturedItemDTO fromFormData(String content,
int order,
InputStream fileInputStream,
FormDataContentDisposition contentDispositionHeader) {
NewDataverseFeaturedItemDTO newDataverseFeaturedItemDTO = new NewDataverseFeaturedItemDTO();
newDataverseFeaturedItemDTO.content = content;
newDataverseFeaturedItemDTO.displayOrder = order;
newDataverseFeaturedItemDTO.fileInputStream = fileInputStream;
newDataverseFeaturedItemDTO.imageFileName = contentDispositionHeader.getFileName();
return newDataverseFeaturedItemDTO;
}

public String getContent() {
return content;
}

public int getDisplayOrder() {
return displayOrder;
}

public InputStream getFileInputStream() {
return fileInputStream;
}

public String getImageFileName() {
return imageFileName;
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
package edu.harvard.iq.dataverse.engine.command;

import edu.harvard.iq.dataverse.DataFileServiceBean;
import edu.harvard.iq.dataverse.DatasetFieldServiceBean;
import edu.harvard.iq.dataverse.DatasetLinkingServiceBean;
import edu.harvard.iq.dataverse.DatasetServiceBean;
import edu.harvard.iq.dataverse.DatasetVersionServiceBean;
import edu.harvard.iq.dataverse.DataverseFacetServiceBean;
import edu.harvard.iq.dataverse.DataverseFieldTypeInputLevelServiceBean;
import edu.harvard.iq.dataverse.DataverseLinkingServiceBean;
import edu.harvard.iq.dataverse.DataverseRoleServiceBean;
import edu.harvard.iq.dataverse.DataverseServiceBean;
import edu.harvard.iq.dataverse.*;
import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUserServiceBean;
import edu.harvard.iq.dataverse.DvObjectServiceBean;
import edu.harvard.iq.dataverse.FeaturedDataverseServiceBean;
import edu.harvard.iq.dataverse.FileDownloadServiceBean;
import edu.harvard.iq.dataverse.GuestbookResponseServiceBean;
import edu.harvard.iq.dataverse.GuestbookServiceBean;
import edu.harvard.iq.dataverse.MetadataBlockServiceBean;
import edu.harvard.iq.dataverse.search.IndexServiceBean;
import edu.harvard.iq.dataverse.PermissionServiceBean;
import edu.harvard.iq.dataverse.RoleAssigneeServiceBean;
import edu.harvard.iq.dataverse.search.SearchServiceBean;
import edu.harvard.iq.dataverse.TemplateServiceBean;
import edu.harvard.iq.dataverse.UserNotificationServiceBean;
import edu.harvard.iq.dataverse.actionlogging.ActionLogServiceBean;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.groups.GroupServiceBean;
Expand Down Expand Up @@ -152,4 +133,6 @@ public interface CommandContext {
public void addCommand(Command command);

public DatasetFieldServiceBean dsField();

public DataverseFeaturedItemServiceBean dataverseFeaturedItems();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DataverseFeaturedItem execute(CommandContext ctxt) throws CommandExceptio
featuredItem.setContent(newDataverseFeaturedItemDTO.getContent());
featuredItem.setDisplayOrder(newDataverseFeaturedItemDTO.getDisplayOrder());
featuredItem.setDataverse(dataverse);
return featuredItem;
return ctxt.dataverseFeaturedItems().save(featuredItem);
}

private void setImageIfAvailable(DataverseFeaturedItem featuredItem) throws IllegalCommandException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ public StorageUseServiceBean storageUse() {
return null;
}

@Override
public DataverseFeaturedItemServiceBean dataverseFeaturedItems() {
return null;
}

@Override
public void beginCommandSequence() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
Expand Down

0 comments on commit 2c96f21

Please sign in to comment.