mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 14:33:09 +00:00
DS-3578 Endpoints to retrieve EPerson and Groups
implemented pagination in the eperson and group service
This commit is contained in:
@@ -143,6 +143,11 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EPerson> findAll(Context context, int sortField) throws SQLException {
|
public List<EPerson> findAll(Context context, int sortField) throws SQLException {
|
||||||
|
return findAll(context, sortField, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<EPerson> findAll(Context context, int sortField, int pageSize, int offset) throws SQLException {
|
||||||
String sortColumn = null;
|
String sortColumn = null;
|
||||||
MetadataField metadataFieldSort = null;
|
MetadataField metadataFieldSort = null;
|
||||||
switch (sortField)
|
switch (sortField)
|
||||||
@@ -165,7 +170,7 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
|||||||
default:
|
default:
|
||||||
metadataFieldSort = metadataFieldService.findByElement(context, "eperson", "lastname", null);
|
metadataFieldSort = metadataFieldService.findByElement(context, "eperson", "lastname", null);
|
||||||
}
|
}
|
||||||
return ePersonDAO.findAll(context, metadataFieldSort, sortColumn);
|
return ePersonDAO.findAll(context, metadataFieldSort, sortColumn, pageSize, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -278,14 +278,20 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
|
|||||||
throw new UnsupportedOperationException("You can only find all groups sorted by name with this method");
|
throw new UnsupportedOperationException("You can only find all groups sorted by name with this method");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Group> findAll(Context context, List<MetadataField> metadataSortFields) throws SQLException
|
public List<Group> findAll(Context context, List<MetadataField> metadataSortFields) throws SQLException
|
||||||
|
{
|
||||||
|
return findAll(context, metadataSortFields, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Group> findAll(Context context, List<MetadataField> metadataSortFields, int pageSize, int offset) throws SQLException
|
||||||
{
|
{
|
||||||
if (CollectionUtils.isEmpty(metadataSortFields)) {
|
if (CollectionUtils.isEmpty(metadataSortFields)) {
|
||||||
return groupDAO.findAll(context);
|
return groupDAO.findAll(context, pageSize, offset);
|
||||||
} else {
|
} else {
|
||||||
return groupDAO.findAll(context, metadataSortFields);
|
return groupDAO.findAll(context, metadataSortFields, pageSize, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ public interface EPersonDAO extends DSpaceObjectDAO<EPerson>, DSpaceObjectLegacy
|
|||||||
|
|
||||||
public List<EPerson> findNotActiveSince(Context context, Date date) throws SQLException;
|
public List<EPerson> findNotActiveSince(Context context, Date date) throws SQLException;
|
||||||
|
|
||||||
public List<EPerson> findAll(Context context, MetadataField metadataFieldSort, String sortColumn) throws SQLException;
|
public List<EPerson> findAll(Context context, MetadataField metadataFieldSort, String sortColumn, int pageSize, int offset) throws SQLException;
|
||||||
|
|
||||||
public List<EPerson> findAllSubscribers(Context context) throws SQLException;
|
public List<EPerson> findAllSubscribers(Context context) throws SQLException;
|
||||||
|
|
||||||
|
@@ -42,19 +42,27 @@ public interface GroupDAO extends DSpaceObjectDAO<Group>, DSpaceObjectLegacySupp
|
|||||||
* Find all groups ordered by the specified metadata fields ascending
|
* Find all groups ordered by the specified metadata fields ascending
|
||||||
* @param context The DSpace context
|
* @param context The DSpace context
|
||||||
* @param sortMetadataFields The metadata fields to sort on
|
* @param sortMetadataFields The metadata fields to sort on
|
||||||
|
* @param pageSize
|
||||||
|
* how many results return
|
||||||
|
* @param offset
|
||||||
|
* the position of the first result to return
|
||||||
* @return A list of all groups, ordered by metadata fields
|
* @return A list of all groups, ordered by metadata fields
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
*/
|
*/
|
||||||
List<Group> findAll(Context context, List<MetadataField> sortMetadataFields) throws SQLException;
|
List<Group> findAll(Context context, List<MetadataField> metadataSortFields, int pageSize, int offset) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all groups ordered by name ascending
|
* Find all groups ordered by name ascending
|
||||||
* @param context The DSpace context
|
* @param context The DSpace context
|
||||||
|
* @param pageSize
|
||||||
|
* how many results return
|
||||||
|
* @param offset
|
||||||
|
* the position of the first result to return
|
||||||
* @return A list of all groups, ordered by name
|
* @return A list of all groups, ordered by name
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
*/
|
*/
|
||||||
List<Group> findAll(Context context) throws SQLException;
|
List<Group> findAll(Context context, int pageSize, int offset) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all groups that the given ePerson belongs to
|
* Find all groups that the given ePerson belongs to
|
||||||
* @param context The DSpace context
|
* @param context The DSpace context
|
||||||
|
@@ -83,7 +83,7 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EPerson> findAll(Context context, MetadataField metadataSortField, String sortField) throws SQLException {
|
public List<EPerson> findAll(Context context, MetadataField metadataSortField, String sortField, int pageSize, int offset) throws SQLException {
|
||||||
String queryString = "SELECT " + EPerson.class.getSimpleName().toLowerCase() + " FROM EPerson as " + EPerson.class.getSimpleName().toLowerCase();
|
String queryString = "SELECT " + EPerson.class.getSimpleName().toLowerCase() + " FROM EPerson as " + EPerson.class.getSimpleName().toLowerCase();
|
||||||
|
|
||||||
List<MetadataField> sortFields = ListUtils.EMPTY_LIST;
|
List<MetadataField> sortFields = ListUtils.EMPTY_LIST;
|
||||||
@@ -92,7 +92,7 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
|||||||
sortFields = Collections.singletonList(metadataSortField);
|
sortFields = Collections.singletonList(metadataSortField);
|
||||||
}
|
}
|
||||||
|
|
||||||
Query query = getSearchQuery(context, queryString, null, ListUtils.EMPTY_LIST, sortFields, sortField);
|
Query query = getSearchQuery(context, queryString, null, ListUtils.EMPTY_LIST, sortFields, sortField, pageSize, offset);
|
||||||
return list(query);
|
return list(query);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -132,6 +132,10 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Query getSearchQuery(Context context, String queryString, String queryParam, List<MetadataField> queryFields, List<MetadataField> sortFields, String sortField) throws SQLException {
|
protected Query getSearchQuery(Context context, String queryString, String queryParam, List<MetadataField> queryFields, List<MetadataField> sortFields, String sortField) throws SQLException {
|
||||||
|
return getSearchQuery(context, queryString, queryParam, queryFields, sortFields, sortField, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Query getSearchQuery(Context context, String queryString, String queryParam, List<MetadataField> queryFields, List<MetadataField> sortFields, String sortField, int pageSize, int offset) throws SQLException {
|
||||||
|
|
||||||
StringBuilder queryBuilder = new StringBuilder();
|
StringBuilder queryBuilder = new StringBuilder();
|
||||||
queryBuilder.append(queryString);
|
queryBuilder.append(queryString);
|
||||||
@@ -150,6 +154,12 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
Query query = createQuery(context, queryBuilder.toString());
|
Query query = createQuery(context, queryBuilder.toString());
|
||||||
|
if (pageSize > 0) {
|
||||||
|
query.setMaxResults(pageSize);
|
||||||
|
}
|
||||||
|
if (offset > 0) {
|
||||||
|
query.setFirstResult(offset);
|
||||||
|
}
|
||||||
if(StringUtils.isNotBlank(queryParam)) {
|
if(StringUtils.isNotBlank(queryParam)) {
|
||||||
query.setParameter("queryParam", "%"+queryParam.toLowerCase()+"%");
|
query.setParameter("queryParam", "%"+queryParam.toLowerCase()+"%");
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Group> findAll(Context context, List<MetadataField> sortMetadataFields) throws SQLException
|
public List<Group> findAll(Context context, List<MetadataField> sortMetadataFields, int pageSize, int offset) throws SQLException
|
||||||
{
|
{
|
||||||
StringBuilder queryBuilder = new StringBuilder();
|
StringBuilder queryBuilder = new StringBuilder();
|
||||||
String groupTableName = "g";
|
String groupTableName = "g";
|
||||||
@@ -64,16 +64,33 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
|||||||
addMetadataSortQuery(queryBuilder, sortMetadataFields, null);
|
addMetadataSortQuery(queryBuilder, sortMetadataFields, null);
|
||||||
|
|
||||||
Query query = createQuery(context, queryBuilder.toString());
|
Query query = createQuery(context, queryBuilder.toString());
|
||||||
|
if (pageSize > 0) {
|
||||||
|
query.setMaxResults(pageSize);
|
||||||
|
}
|
||||||
|
if (offset > 0) {
|
||||||
|
query.setFirstResult(offset);
|
||||||
|
}
|
||||||
for (MetadataField sortField : sortMetadataFields) {
|
for (MetadataField sortField : sortMetadataFields) {
|
||||||
query.setParameter(sortField.toString(), sortField.getID());
|
query.setParameter(sortField.toString(), sortField.getID());
|
||||||
}
|
}
|
||||||
return list(query);
|
return list(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public List<Group> findAll(Context context) throws SQLException {
|
||||||
|
// return findAll()
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Group> findAll(Context context) throws SQLException {
|
public List<Group> findAll(Context context, int pageSize, int offset) throws SQLException {
|
||||||
Query query = createQuery(context,
|
Query query = createQuery(context,
|
||||||
"SELECT g FROM Group g ORDER BY g.name ASC");
|
"SELECT g FROM Group g ORDER BY g.name ASC");
|
||||||
|
if (pageSize > 0) {
|
||||||
|
query.setMaxResults(pageSize);
|
||||||
|
}
|
||||||
|
if (offset > 0) {
|
||||||
|
query.setFirstResult(offset);
|
||||||
|
}
|
||||||
query.setCacheable(true);
|
query.setCacheable(true);
|
||||||
|
|
||||||
return list(query);
|
return list(query);
|
||||||
|
@@ -124,7 +124,7 @@ public interface EPersonService extends DSpaceObjectService<EPerson>, DSpaceObje
|
|||||||
throws SQLException;
|
throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all the epeople that match a particular query
|
* @deprecated use the paginated method. Find all the epeople in a specific order
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>ID</code></li>
|
* <li><code>ID</code></li>
|
||||||
* <li><code>LASTNAME</code></li>
|
* <li><code>LASTNAME</code></li>
|
||||||
@@ -136,12 +136,37 @@ public interface EPersonService extends DSpaceObjectService<EPerson>, DSpaceObje
|
|||||||
* The relevant DSpace Context.
|
* The relevant DSpace Context.
|
||||||
* @param sortField
|
* @param sortField
|
||||||
* which field to sort EPersons by
|
* which field to sort EPersons by
|
||||||
* @return array of EPerson objects
|
* @return list of EPerson objects
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* An exception that provides information on a database access error or other errors.
|
* An exception that provides information on a database access error or other errors.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public List<EPerson> findAll(Context context, int sortField)
|
public List<EPerson> findAll(Context context, int sortField)
|
||||||
throws SQLException;
|
throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all the epeople in a specific order
|
||||||
|
* <ul>
|
||||||
|
* <li><code>ID</code></li>
|
||||||
|
* <li><code>LASTNAME</code></li>
|
||||||
|
* <li><code>EMAIL</code></li>
|
||||||
|
* <li><code>NETID</code></li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* The relevant DSpace Context.
|
||||||
|
* @param sortField
|
||||||
|
* which field to sort EPersons by
|
||||||
|
* @param pageSize
|
||||||
|
* how many results return
|
||||||
|
* @param offset
|
||||||
|
* the position of the first result to return
|
||||||
|
* @return list of EPerson objects
|
||||||
|
* @throws SQLException
|
||||||
|
* An exception that provides information on a database access error or other errors.
|
||||||
|
*/
|
||||||
|
public List<EPerson> findAll(Context context, int sortField, int pageSize, int offset)
|
||||||
|
throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new eperson
|
* Create a new eperson
|
||||||
|
@@ -188,13 +188,28 @@ public interface GroupService extends DSpaceObjectService<Group>, DSpaceObjectLe
|
|||||||
* The relevant DSpace Context.
|
* The relevant DSpace Context.
|
||||||
* @param metadataSortFields
|
* @param metadataSortFields
|
||||||
* metadata fields to sort by, leave empty to sort by Name
|
* metadata fields to sort by, leave empty to sort by Name
|
||||||
|
* @param pageSize
|
||||||
|
* how many results return
|
||||||
|
* @param offset
|
||||||
|
* the position of the first result to return
|
||||||
|
* @return List of all groups in the site
|
||||||
|
* @throws SQLException if error
|
||||||
|
*/
|
||||||
|
public List<Group> findAll(Context context, List<MetadataField> metadataSortFields, int pageSize, int offset) throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Please use {@code findAll(Context context, List<MetadataField> metadataFieldsSort, int pageSize, int offset)} instead
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* The relevant DSpace Context.
|
||||||
|
* @param metadataSortFields
|
||||||
|
* metadata fields to sort by, leave empty to sort by Name
|
||||||
*
|
*
|
||||||
* @return List of all groups in the site
|
* @return List of all groups in the site
|
||||||
* @throws SQLException if error
|
* @throws SQLException if error
|
||||||
*/
|
*/
|
||||||
public List<Group> findAll(Context context, List<MetadataField> metadataSortFields) throws SQLException;
|
public List<Group> findAll(Context context, List<MetadataField> metadataSortFields) throws SQLException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DEPRECATED: Please use {@code findAll(Context context, List<MetadataField> metadataFieldsSort)} instead
|
* DEPRECATED: Please use {@code findAll(Context context, List<MetadataField> metadataFieldsSort)} instead
|
||||||
* @param context DSpace context
|
* @param context DSpace context
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* 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.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.app.rest.model.EPersonGroupRest;
|
||||||
|
import org.dspace.app.rest.model.EPersonRest;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.eperson.Group;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the converter from/to the EPerson in the DSpace API data model and the
|
||||||
|
* REST data model
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class EPersonConverter extends DSpaceObjectConverter<EPerson, org.dspace.app.rest.model.EPersonRest> {
|
||||||
|
@Autowired(required = true)
|
||||||
|
private EPersonGroupConverter epersonGroupConverter;
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(EPersonConverter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EPersonRest fromModel(EPerson obj) {
|
||||||
|
EPersonRest eperson = super.fromModel(obj);
|
||||||
|
eperson.setLastActive(obj.getLastActive());
|
||||||
|
eperson.setNetid(obj.getNetid());
|
||||||
|
eperson.setCanLogIn(obj.canLogIn());
|
||||||
|
eperson.setRequireCertificate(obj.getRequireCertificate());
|
||||||
|
eperson.setSelfRegistered(obj.getSelfRegistered());
|
||||||
|
eperson.setEmail(obj.getEmail());
|
||||||
|
List<EPersonGroupRest> groups = new ArrayList<EPersonGroupRest>();
|
||||||
|
for (Group g : obj.getGroups()) {
|
||||||
|
groups.add(epersonGroupConverter.convert(g));
|
||||||
|
}
|
||||||
|
eperson.setGroups(groups);
|
||||||
|
return eperson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EPerson toModel(EPersonRest obj) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EPersonRest newInstance() {
|
||||||
|
return new EPersonRest();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* 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.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.app.rest.model.EPersonGroupRest;
|
||||||
|
import org.dspace.eperson.Group;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the converter from/to the EPerson Group in the DSpace API data model
|
||||||
|
* and the REST data model
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class EPersonGroupConverter extends DSpaceObjectConverter<Group, org.dspace.app.rest.model.EPersonGroupRest> {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(EPersonGroupConverter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EPersonGroupRest fromModel(Group obj) {
|
||||||
|
EPersonGroupRest epersongroup = super.fromModel(obj);
|
||||||
|
epersongroup.setPermanent(obj.isPermanent());
|
||||||
|
List<EPersonGroupRest> groups = new ArrayList<EPersonGroupRest>();
|
||||||
|
for (Group g : obj.getMemberGroups()) {
|
||||||
|
groups.add(convert(g));
|
||||||
|
}
|
||||||
|
epersongroup.setGroups(groups);
|
||||||
|
|
||||||
|
return epersongroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Group toModel(EPersonGroupRest obj) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EPersonGroupRest newInstance() {
|
||||||
|
return new EPersonGroupRest();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* 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.List;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.RestResourceController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The EPerson Group REST Resource
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EPersonGroupRest extends DSpaceObjectRest {
|
||||||
|
public static final String NAME = "epersongroup";
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private boolean permanent;
|
||||||
|
|
||||||
|
// FIXME this should be annotated with @JsonIgnore but right now only simple
|
||||||
|
// rest resource can be embedded not list, see
|
||||||
|
// https://jira.duraspace.org/browse/DS-3483
|
||||||
|
private List<EPersonGroupRest> groups;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermanent() {
|
||||||
|
return permanent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermanent(boolean permanent) {
|
||||||
|
this.permanent = permanent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EPersonGroupRest> getGroups() {
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroups(List<EPersonGroupRest> groups) {
|
||||||
|
this.groups = groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
|
public Class getController() {
|
||||||
|
return RestResourceController.class;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.util.List;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.RestResourceController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The EPerson REST Resource
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EPersonRest extends DSpaceObjectRest {
|
||||||
|
public static final String NAME = "eperson";
|
||||||
|
|
||||||
|
private String netid;
|
||||||
|
|
||||||
|
private Date lastActive;
|
||||||
|
|
||||||
|
private boolean canLogIn;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private boolean requireCertificate = false;
|
||||||
|
|
||||||
|
private boolean selfRegistered = false;
|
||||||
|
|
||||||
|
// FIXME this should be annotated with @JsonIgnore but right now only simple
|
||||||
|
// rest resource can be embedded not list, see
|
||||||
|
// https://jira.duraspace.org/browse/DS-3483
|
||||||
|
private List<EPersonGroupRest> groups;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetid() {
|
||||||
|
return netid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNetid(String netid) {
|
||||||
|
this.netid = netid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastActive() {
|
||||||
|
return lastActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastActive(Date lastActive) {
|
||||||
|
this.lastActive = lastActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCanLogIn() {
|
||||||
|
return canLogIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanLogIn(boolean canLogIn) {
|
||||||
|
this.canLogIn = canLogIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRequireCertificate() {
|
||||||
|
return requireCertificate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequireCertificate(boolean requireCertificate) {
|
||||||
|
this.requireCertificate = requireCertificate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelfRegistered() {
|
||||||
|
return selfRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelfRegistered(boolean selfRegistered) {
|
||||||
|
this.selfRegistered = selfRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EPersonGroupRest> getGroups() {
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroups(List<EPersonGroupRest> groups) {
|
||||||
|
this.groups = groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
|
public Class getController() {
|
||||||
|
return RestResourceController.class;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* 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.EPersonGroupRest;
|
||||||
|
import org.dspace.app.rest.utils.Utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EPerson 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(EPersonGroupRest.NAME)
|
||||||
|
public class EPersonGroupResource extends DSpaceResource<EPersonGroupRest> {
|
||||||
|
public EPersonGroupResource(EPersonGroupRest group, Utils utils, String... rels) {
|
||||||
|
super(group, utils, rels);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* 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.EPersonRest;
|
||||||
|
import org.dspace.app.rest.utils.Utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EPerson 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(EPersonRest.NAME)
|
||||||
|
public class EPersonResource extends DSpaceResource<EPersonRest> {
|
||||||
|
public EPersonResource(EPersonRest eperson, Utils utils, String... rels) {
|
||||||
|
super(eperson, utils, rels);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.util.UUID;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.converter.EPersonGroupConverter;
|
||||||
|
import org.dspace.app.rest.model.EPersonGroupRest;
|
||||||
|
import org.dspace.app.rest.model.hateoas.EPersonGroupResource;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.eperson.Group;
|
||||||
|
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||||
|
import org.dspace.eperson.service.GroupService;
|
||||||
|
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 EPerson Rest object
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component(EPersonGroupRest.NAME)
|
||||||
|
public class EPersonGroupRestRepository extends DSpaceRestRepository<EPersonGroupRest, UUID> {
|
||||||
|
GroupService gs = EPersonServiceFactory.getInstance().getGroupService();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
EPersonGroupConverter converter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EPersonGroupRest findOne(Context context, UUID id) {
|
||||||
|
Group group = null;
|
||||||
|
try {
|
||||||
|
group = gs.find(context, id);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (group == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return converter.fromModel(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<EPersonGroupRest> findAll(Context context, Pageable pageable) {
|
||||||
|
List<Group> groups = null;
|
||||||
|
int total = 0;
|
||||||
|
try {
|
||||||
|
total = gs.countTotal(context);
|
||||||
|
groups = gs.findAll(context, null, pageable.getPageSize(), pageable.getOffset());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
Page<EPersonGroupRest> page = new PageImpl<Group>(groups, pageable, total).map(converter);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<EPersonGroupRest> getDomainClass() {
|
||||||
|
return EPersonGroupRest.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EPersonGroupResource wrapResource(EPersonGroupRest eperson, String... rels) {
|
||||||
|
return new EPersonGroupResource(eperson, utils, rels);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.util.UUID;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.converter.EPersonConverter;
|
||||||
|
import org.dspace.app.rest.model.EPersonRest;
|
||||||
|
import org.dspace.app.rest.model.hateoas.EPersonResource;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||||
|
import org.dspace.eperson.service.EPersonService;
|
||||||
|
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 EPerson Rest object
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component(EPersonRest.NAME)
|
||||||
|
public class EPersonRestRepository extends DSpaceRestRepository<EPersonRest, UUID> {
|
||||||
|
EPersonService es = EPersonServiceFactory.getInstance().getEPersonService();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
EPersonConverter converter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EPersonRest findOne(Context context, UUID id) {
|
||||||
|
EPerson eperson = null;
|
||||||
|
try {
|
||||||
|
eperson = es.find(context, id);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (eperson == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return converter.fromModel(eperson);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<EPersonRest> findAll(Context context, Pageable pageable) {
|
||||||
|
List<EPerson> epersons = null;
|
||||||
|
int total = 0;
|
||||||
|
try {
|
||||||
|
total = es.countTotal(context);
|
||||||
|
epersons = es.findAll(context, EPerson.ID, pageable.getPageSize(), pageable.getOffset());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
Page<EPersonRest> page = new PageImpl<EPerson>(epersons, pageable, total).map(converter);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<EPersonRest> getDomainClass() {
|
||||||
|
return EPersonRest.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EPersonResource wrapResource(EPersonRest eperson, String... rels) {
|
||||||
|
return new EPersonResource(eperson, utils, rels);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user