forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated comments * added new databased entity preview content * not works: map fileinfo to preview content * get data from database if it exists * create preview content from file info * Failing tests - temp commit * changed name varchar length * added _ to sql script names
- Loading branch information
1 parent
514c145
commit 35e3587
Showing
25 changed files
with
1,241 additions
and
5 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
dspace-api/src/main/java/org/dspace/content/PreviewContent.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,155 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.content; | ||
|
||
import java.util.Hashtable; | ||
import java.util.Map; | ||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.JoinTable; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.MapKeyColumn; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.SequenceGenerator; | ||
import javax.persistence.Table; | ||
|
||
import org.dspace.core.Context; | ||
import org.dspace.core.ReloadableEntity; | ||
|
||
/** | ||
* Database entity representation of the previewcontent table. | ||
* It is not possible to create entity from FileInfo class (without modifications) | ||
* so we created PreviewContent (which serves as an entity for FileInfo) | ||
* with corresponding database table previewcontent. | ||
* | ||
* @author Michaela Paurikova (dspace at dataquest.sk) | ||
*/ | ||
@Entity | ||
@Table(name = "previewcontent") | ||
public class PreviewContent implements ReloadableEntity<Integer> { | ||
|
||
@Id | ||
@Column(name = "previewcontent_id") | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "previewcontent_previewcontent_id_seq") | ||
@SequenceGenerator(name = "previewcontent_previewcontent_id_seq", | ||
sequenceName = "previewcontent_previewcontent_id_seq", allocationSize = 1) | ||
private Integer id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST}) | ||
@JoinColumn(name = "bitstream_id") | ||
private Bitstream bitstream; | ||
|
||
@Column(name = "name") | ||
public String name; | ||
|
||
@Column(name = "content") | ||
public String content; | ||
|
||
@Column(name = "isDirectory") | ||
public boolean isDirectory; | ||
|
||
@Column(name = "size") | ||
public String size; | ||
|
||
@OneToMany(cascade = CascadeType.ALL) | ||
@JoinTable( | ||
name = "preview2preview", | ||
joinColumns = @JoinColumn(name = "parent_id"), | ||
inverseJoinColumns = @JoinColumn(name = "child_id") | ||
) | ||
@MapKeyColumn(name = "name") | ||
public Map<String, PreviewContent> sub = new Hashtable<>(); | ||
|
||
/** | ||
* Protected constructor. | ||
*/ | ||
protected PreviewContent() {} | ||
|
||
/** | ||
* Protected constructor, create object using: | ||
* {@link org.dspace.content.service.PreviewContentService#create(Context, PreviewContent)} | ||
*/ | ||
protected PreviewContent(PreviewContent previewContent) { | ||
this.bitstream = previewContent.getBitstream(); | ||
this.name = previewContent.getName(); | ||
this.content = previewContent.getContent(); | ||
this.isDirectory = previewContent.isDirectory(); | ||
this.size = previewContent.getSize(); | ||
this.sub = previewContent.getSubPreviewContents(); | ||
} | ||
|
||
/** | ||
* Protected constructor, create object using: | ||
* {@link org.dspace.content.service.PreviewContentService#create(Context, Bitstream, String, String, boolean, | ||
* String, Map<String, PreviewContent>)} | ||
*/ | ||
protected PreviewContent(Bitstream bitstream, String name, String content, boolean isDirectory, String size, | ||
Map<String, PreviewContent> subPreviewContents) { | ||
this.bitstream = bitstream; | ||
this.name = name; | ||
this.content = content; | ||
this.isDirectory = isDirectory; | ||
this.size = size; | ||
this.sub = subPreviewContents; | ||
} | ||
|
||
@Override | ||
public Integer getID() { | ||
return id; | ||
} | ||
|
||
public Bitstream getBitstream() { | ||
return bitstream; | ||
} | ||
|
||
public void setBitstream(Bitstream bitstream) { | ||
this.bitstream = bitstream; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
public boolean isDirectory() { | ||
return isDirectory; | ||
} | ||
|
||
public void setDirectory(boolean directory) { | ||
isDirectory = directory; | ||
} | ||
|
||
public String getSize() { | ||
return size; | ||
} | ||
|
||
public void setSize(String size) { | ||
this.size = size; | ||
} | ||
|
||
public Map<String, PreviewContent> getSubPreviewContents() { | ||
return sub; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
dspace-api/src/main/java/org/dspace/content/PreviewContentServiceImpl.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,90 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.content; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import org.dspace.authorize.AuthorizeException; | ||
import org.dspace.authorize.service.AuthorizeService; | ||
import org.dspace.content.dao.PreviewContentDAO; | ||
import org.dspace.content.service.PreviewContentService; | ||
import org.dspace.core.Context; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Service implementation for the PreviewContent object. | ||
* | ||
* @author Michaela Paurikova (dspace at dataquest.sk) | ||
*/ | ||
public class PreviewContentServiceImpl implements PreviewContentService { | ||
|
||
/** | ||
* logger | ||
*/ | ||
private static final Logger log = LoggerFactory.getLogger(PreviewContentServiceImpl.class); | ||
|
||
|
||
@Autowired | ||
PreviewContentDAO previewContentDAO; | ||
@Autowired(required = true) | ||
AuthorizeService authorizeService; | ||
|
||
@Override | ||
public PreviewContent create(Context context, Bitstream bitstream, String name, String content, | ||
boolean isDirectory, String size, Map<String, PreviewContent> subPreviewContents) | ||
throws SQLException { | ||
//no authorization required! | ||
// Create a table row | ||
PreviewContent previewContent = previewContentDAO.create(context, new PreviewContent(bitstream, name, content, | ||
isDirectory, size, subPreviewContents)); | ||
log.info("Created new preview content of ID = {}", previewContent.getID()); | ||
return previewContent; | ||
} | ||
|
||
@Override | ||
public PreviewContent create(Context context, PreviewContent previewContent) throws SQLException { | ||
//no authorization required! | ||
PreviewContent newPreviewContent = previewContentDAO.create(context, new PreviewContent(previewContent)); | ||
log.info("Created new preview content of ID = {}", newPreviewContent.getID()); | ||
return newPreviewContent; | ||
} | ||
|
||
@Override | ||
public void delete(Context context, PreviewContent previewContent) throws SQLException, AuthorizeException { | ||
if (!authorizeService.isAdmin(context)) { | ||
throw new AuthorizeException( | ||
"You must be an admin to delete an CLARIN Content Preview"); | ||
} | ||
previewContentDAO.delete(context, previewContent); | ||
} | ||
|
||
@Override | ||
public PreviewContent find(Context context, int valueId) throws SQLException { | ||
return previewContentDAO.findByID(context, PreviewContent.class, valueId); | ||
} | ||
|
||
@Override | ||
public List<PreviewContent> findByBitstream(Context context, UUID bitstreamId) throws SQLException { | ||
return previewContentDAO.findByBitstream(context, bitstreamId); | ||
} | ||
|
||
@Override | ||
public List<PreviewContent> findRootByBitstream(Context context, UUID bitstreamId) throws SQLException { | ||
return previewContentDAO.findRootByBitstream(context, bitstreamId); | ||
} | ||
|
||
@Override | ||
public List<PreviewContent> findAll(Context context) throws SQLException { | ||
return previewContentDAO.findAll(context, PreviewContent.class); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
dspace-api/src/main/java/org/dspace/content/dao/PreviewContentDAO.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,44 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.content.dao; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.dspace.content.PreviewContent; | ||
import org.dspace.core.Context; | ||
import org.dspace.core.GenericDAO; | ||
|
||
/** | ||
* Database Access Object interface class for the PreviewContent object. | ||
* This class should only be accessed from a single service and should never be exposed outside of the API | ||
* | ||
* @author Michaela Paurikova (dspace at dataquest.sk) | ||
*/ | ||
public interface PreviewContentDAO extends GenericDAO<PreviewContent> { | ||
/** | ||
* Find all preview content based on ID of bitstream the preview content is added to. | ||
* | ||
* @param context DSpace context | ||
* @param bitstreamId The bitstream ID | ||
* @return List of found preview content | ||
* @throws SQLException If a database error occurs | ||
*/ | ||
List<PreviewContent> findByBitstream(Context context, UUID bitstreamId) throws SQLException; | ||
|
||
/** | ||
* Find all preview content based on bitstream that are the root directory. | ||
* | ||
* @param context DSpace context | ||
* @param bitstreamId The bitstream ID | ||
* @return List of found preview content | ||
* @throws SQLException If a database error occurs | ||
*/ | ||
List<PreviewContent> findRootByBitstream(Context context, UUID bitstreamId) throws SQLException; | ||
} |
55 changes: 55 additions & 0 deletions
55
dspace-api/src/main/java/org/dspace/content/dao/impl/PreviewContentDAOImpl.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,55 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.content.dao.impl; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import javax.persistence.Query; | ||
|
||
import org.dspace.content.PreviewContent; | ||
import org.dspace.content.dao.PreviewContentDAO; | ||
import org.dspace.core.AbstractHibernateDAO; | ||
import org.dspace.core.Context; | ||
|
||
/** | ||
* Hibernate implementation of the Database Access Object interface class for the PreviewContent object. | ||
* This class should never be accessed directly. | ||
* | ||
* @author Michaela Paurikova (dspace at dataquest.sk) | ||
*/ | ||
public class PreviewContentDAOImpl extends AbstractHibernateDAO<PreviewContent> implements PreviewContentDAO { | ||
|
||
protected PreviewContentDAOImpl() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public List<PreviewContent> findByBitstream(Context context, UUID bitstreamId) throws SQLException { | ||
Query query = createQuery(context, "SELECT pc FROM " + PreviewContent.class.getSimpleName() + | ||
" as pc join pc.bitstream as b WHERE b.id = :bitstream_id"); | ||
query.setParameter("bitstream_id", bitstreamId); | ||
query.setHint("org.hibernate.cacheable", Boolean.TRUE); | ||
return findMany(context, query); | ||
} | ||
|
||
@Override | ||
public List<PreviewContent> findRootByBitstream(Context context, UUID bitstreamId) throws SQLException { | ||
// select only data from the previewcontent table whose ID is not a child in the preview2preview table | ||
Query query = createQuery(context, | ||
"SELECT pc FROM " + PreviewContent.class.getSimpleName() + " pc " + | ||
"JOIN pc.bitstream b " + | ||
"WHERE b.id = :bitstream_id " + | ||
"AND pc.id NOT IN (SELECT child.id FROM " + PreviewContent.class.getSimpleName() + " parent " + | ||
"JOIN parent.sub child)" | ||
); | ||
query.setParameter("bitstream_id", bitstreamId); | ||
query.setHint("org.hibernate.cacheable", Boolean.TRUE); | ||
return findMany(context, query); | ||
} | ||
} |
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
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.