Merge branch 'DS-3740' of https://github.com/4Science/DSpace into DS-3740

This commit is contained in:
Luigi Andrea Pascarelli
2017-11-02 12:45:21 +01:00
9 changed files with 283 additions and 0 deletions

View File

@@ -172,6 +172,11 @@ public class WorkspaceItemServiceImpl implements WorkspaceItemService {
return workspaceItemDAO.findAll(context);
}
@Override
public List<WorkspaceItem> findAll(Context context, Integer limit, Integer offset) throws SQLException {
return workspaceItemDAO.findAll(context, limit, offset);
}
@Override
public void update(Context context, WorkspaceItem workspaceItem) throws SQLException, AuthorizeException {
// Authorisation is checked by the item.update() method below

View File

@@ -35,6 +35,8 @@ public interface WorkspaceItemDAO extends GenericDAO<WorkspaceItem> {
public List<WorkspaceItem> findAll(Context context) throws SQLException;
public List<WorkspaceItem> findAll(Context context, Integer limit, Integer offset) throws SQLException;
public List<WorkspaceItem> findWithSupervisedGroup(Context context) throws SQLException;
public List<WorkspaceItem> findBySupervisedGroupMember(Context context, EPerson ePerson) throws SQLException;

View File

@@ -72,6 +72,16 @@ public class WorkspaceItemDAOImpl extends AbstractHibernateDAO<WorkspaceItem> im
return list(criteria);
}
@Override
public List<WorkspaceItem> findAll(Context context, Integer limit, Integer offset) throws SQLException
{
Criteria criteria = createCriteria(context, WorkspaceItem.class);
criteria.addOrder(Order.asc("item"));
criteria.setFirstResult(offset);
criteria.setMaxResults(limit);
return list(criteria);
}
@Override
public List<WorkspaceItem> findWithSupervisedGroup(Context context) throws SQLException {
Criteria criteria = createCriteria(context, WorkspaceItem.class);

View File

@@ -126,6 +126,23 @@ public interface WorkspaceItemService extends InProgressSubmissionService<Worksp
public List<WorkspaceItem> findAll(Context context)
throws SQLException;
/**
* Get all workspace items in the whole system, paginated.
*
* @param context
* the context object
* @param limit
* limit
* @param offset
* offset
*
* @return a page of workspace items
* @throws SQLException
* if database error
*/
public List<WorkspaceItem> findAll(Context context, Integer limit, Integer offset) throws SQLException;
/**
* Delete the workspace item. The entry in workspaceitem, the unarchived
* item and its contents are all removed (multiple inclusion

View File

@@ -0,0 +1,56 @@
/**
* 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.app.rest.converter;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import org.dspace.app.rest.model.WorkspaceItemRest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* This is the converter from/to the WorkspaceItem in the DSpace API data model and the
* REST data model
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*
*/
@Component
public class WorkspaceItemConverter extends DSpaceConverter<org.dspace.content.WorkspaceItem, org.dspace.app.rest.model.WorkspaceItemRest> {
private static final Logger log = Logger.getLogger(WorkspaceItemConverter.class);
@Autowired
private EPersonConverter epersonConverter;
@Autowired
private ItemConverter itemConverter;
@Override
public WorkspaceItemRest fromModel(org.dspace.content.WorkspaceItem obj) {
WorkspaceItemRest witem = new WorkspaceItemRest();
witem.setId(obj.getID());
witem.setItem(itemConverter.convert(obj.getItem()));
try {
witem.setSubmitter(epersonConverter.convert(obj.getSubmitter()));
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
// 1. retrieve the submission definition
// 2. iterate over the submission section to allow to plugin additional info
return witem;
}
@Override
public org.dspace.content.WorkspaceItem toModel(WorkspaceItemRest obj) {
return null;
}
}

View File

@@ -23,6 +23,7 @@ public interface RestModel extends Serializable {
public static final String DISCOVER = "discover";
public static final String CONFIGURATION = "config";
public static final String INTEGRATION = "integration";
public static final String SUBMISSION = "submission";
@JsonIgnore
public String getCategory();

View File

@@ -0,0 +1,83 @@
/**
* 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.app.rest.model;
import java.util.Date;
import org.dspace.app.rest.RestResourceController;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* The WorkspaceItem REST Resource
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*
*/
public class WorkspaceItemRest extends BaseObjectRest<Integer> {
public static final String NAME = "workspaceitem";
public static final String CATEGORY = RestModel.SUBMISSION;
private Date lastModified = new Date();
@JsonIgnore
private ItemRest item;
@JsonIgnore
private SubmissionDefinitionRest submissionDefinition;
@JsonIgnore
private EPersonRest submitter;
@Override
public String getCategory() {
return CATEGORY;
}
@Override
public String getType() {
return NAME;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified){
this.lastModified = lastModified;
}
public ItemRest getItem() {
return item;
}
public void setItem(ItemRest item) {
this.item = item;
}
public SubmissionDefinitionRest getSubmissionDefinition() {
return submissionDefinition;
}
public void setSubmissionDefinition(SubmissionDefinitionRest submissionDefinition) {
this.submissionDefinition = submissionDefinition;
}
public EPersonRest getSubmitter() {
return submitter;
}
public void setSubmitter(EPersonRest submitter) {
this.submitter = submitter;
}
@Override
public Class getController() {
return RestResourceController.class;
}
}

View File

@@ -0,0 +1,26 @@
/**
* 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.app.rest.model.hateoas;
import org.dspace.app.rest.model.WorkspaceItemRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils;
/**
* WorkspaceItem Rest HAL Resource. The HAL Resource wraps the REST Resource
* adding support for the links and embedded resources
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*
*/
@RelNameDSpaceResource(WorkspaceItemRest.NAME)
public class WorkspaceItemResource extends DSpaceResource<WorkspaceItemRest> {
public WorkspaceItemResource(WorkspaceItemRest witem, Utils utils, String... rels) {
super(witem, utils, rels);
}
}

View File

@@ -0,0 +1,83 @@
/**
* 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.app.rest.repository;
import java.sql.SQLException;
import java.util.List;
import org.dspace.app.rest.converter.WorkspaceItemConverter;
import org.dspace.app.rest.model.WorkspaceItemRest;
import org.dspace.app.rest.model.hateoas.WorkspaceItemResource;
import org.dspace.content.WorkspaceItem;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
/**
* This is the repository responsible to manage WorkspaceItem Rest object
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*
*/
@Component(WorkspaceItemRest.CATEGORY + "." + WorkspaceItemRest.NAME)
public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceItemRest, Integer> {
@Autowired
WorkspaceItemService wis;
@Autowired
WorkspaceItemConverter converter;
public WorkspaceItemRestRepository() {
}
@Override
public WorkspaceItemRest findOne(Context context, Integer id) {
WorkspaceItem witem = null;
try {
witem = wis.find(context, id);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (witem == null) {
return null;
}
return converter.fromModel(witem);
}
@Override
public Page<WorkspaceItemRest> findAll(Context context, Pageable pageable) {
List<WorkspaceItem> witems = null;
int total = 0;
try {
total = wis.countTotal(context);
witems = wis.findAll(context, pageable.getPageSize(), pageable.getOffset());
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
Page<WorkspaceItemRest> page = new PageImpl<WorkspaceItem>(witems, pageable, total).map(converter);
return page;
}
@Override
public Class<WorkspaceItemRest> getDomainClass() {
return WorkspaceItemRest.class;
}
@Override
public WorkspaceItemResource wrapResource(WorkspaceItemRest witem, String... rels) {
return new WorkspaceItemResource(witem, utils, rels);
}
}