mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 22:43:12 +00:00
DS-3533 Simplify and normalize code
This commit is contained in:
@@ -153,9 +153,9 @@ public class RestResourceController implements InitializingBean {
|
|||||||
*
|
*
|
||||||
* Note that the regular expression in the request mapping accept a number as identifier;
|
* Note that the regular expression in the request mapping accept a number as identifier;
|
||||||
*
|
*
|
||||||
* Please see {@link RestResourceController#findOne(String, String, String, String)} for findOne with string as
|
* Please see {@link RestResourceController#findOne(String, String, String)} for findOne with string as
|
||||||
* identifier
|
* identifier
|
||||||
* and see {@link RestResourceController#findOne(String, String, UUID, String)} for uuid as identifier
|
* and see {@link RestResourceController#findOne(String, String, UUID)} for uuid as identifier
|
||||||
*
|
*
|
||||||
* @param apiCategory
|
* @param apiCategory
|
||||||
* @param model
|
* @param model
|
||||||
@@ -185,9 +185,9 @@ public class RestResourceController implements InitializingBean {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Please see {@link RestResourceController#findOne(String, String, Integer, String)} for findOne with number as
|
* Please see {@link RestResourceController#findOne(String, String, Integer)} for findOne with number as
|
||||||
* identifier
|
* identifier
|
||||||
* and see {@link RestResourceController#findOne(String, String, UUID, String)} for uuid as identifier
|
* and see {@link RestResourceController#findOne(String, String, UUID)} for uuid as identifier
|
||||||
*
|
*
|
||||||
* @param apiCategory
|
* @param apiCategory
|
||||||
* @param model
|
* @param model
|
||||||
@@ -206,9 +206,9 @@ public class RestResourceController implements InitializingBean {
|
|||||||
*
|
*
|
||||||
* Note that the regular expression in the request mapping accept a UUID as identifier;
|
* Note that the regular expression in the request mapping accept a UUID as identifier;
|
||||||
*
|
*
|
||||||
* Please see {@link RestResourceController#findOne(String, String, Integer, String)} for findOne with number as
|
* Please see {@link RestResourceController#findOne(String, String, Integer)} for findOne with number as
|
||||||
* identifier
|
* identifier
|
||||||
* and see {@link RestResourceController#findOne(String, String, String, String)} for string as identifier
|
* and see {@link RestResourceController#findOne(String, String, String)} for string as identifier
|
||||||
*
|
*
|
||||||
* @param apiCategory
|
* @param apiCategory
|
||||||
* @param model
|
* @param model
|
||||||
|
@@ -29,6 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.hateoas.Resource;
|
import org.springframework.hateoas.Resource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -89,6 +92,25 @@ public class ConverterService {
|
|||||||
return restObject;
|
return restObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a list of model objects to a page of rest objects using the given {@link Projection}.
|
||||||
|
*
|
||||||
|
* @param modelObjects
|
||||||
|
* @param pageable
|
||||||
|
* @param total
|
||||||
|
* @param projection
|
||||||
|
* @param <T>
|
||||||
|
* @param <D>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public <T, D> Page<T> toRestPage(List<D> modelObjects, Pageable pageable, long total, Projection projection) {
|
||||||
|
return new PageImpl<>(modelObjects, pageable, total).map((object) -> toRest(object, projection));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T, D> Page<T> toRestPage(Page<D> modelObjects, Projection projection) {
|
||||||
|
return modelObjects.map((object) -> toRest(object, projection));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the converter supporting the given class as input.
|
* Gets the converter supporting the given class as input.
|
||||||
*
|
*
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.repository;
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.converter.ConverterService;
|
||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -26,6 +27,9 @@ public abstract class AbstractDSpaceRestRepository {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected Utils utils;
|
protected Utils utils;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected ConverterService converter;
|
||||||
|
|
||||||
protected RequestService requestService = new DSpace().getRequestService();
|
protected RequestService requestService = new DSpace().getRequestService();
|
||||||
|
|
||||||
protected Context obtainContext() {
|
protected Context obtainContext() {
|
||||||
|
@@ -42,22 +42,21 @@ public class AuthorityRestRepository extends DSpaceRestRepository<AuthorityRest,
|
|||||||
@Override
|
@Override
|
||||||
public AuthorityRest findOne(Context context, String name) {
|
public AuthorityRest findOne(Context context, String name) {
|
||||||
ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(name);
|
ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(name);
|
||||||
AuthorityRest result = authorityUtils.convertAuthority(source, name, utils.obtainProjection());
|
return authorityUtils.convertAuthority(source, name, utils.obtainProjection());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
@Override
|
@Override
|
||||||
public Page<AuthorityRest> findAll(Context context, Pageable pageable) {
|
public Page<AuthorityRest> findAll(Context context, Pageable pageable) {
|
||||||
Set<String> authoritiesName = cas.getChoiceAuthoritiesNames();
|
Set<String> authoritiesName = cas.getChoiceAuthoritiesNames();
|
||||||
List<AuthorityRest> results = new ArrayList<AuthorityRest>();
|
List<AuthorityRest> results = new ArrayList<>();
|
||||||
Projection projection = utils.obtainProjection(true);
|
Projection projection = utils.obtainProjection(true);
|
||||||
for (String authorityName : authoritiesName) {
|
for (String authorityName : authoritiesName) {
|
||||||
ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(authorityName);
|
ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(authorityName);
|
||||||
AuthorityRest result = authorityUtils.convertAuthority(source, authorityName, projection);
|
AuthorityRest result = authorityUtils.convertAuthority(source, authorityName, projection);
|
||||||
results.add(result);
|
results.add(result);
|
||||||
}
|
}
|
||||||
return new PageImpl<AuthorityRest>(results, pageable, results.size());
|
return new PageImpl<>(results, pageable, results.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -15,7 +15,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.BitstreamFormatRest;
|
import org.dspace.app.rest.model.BitstreamFormatRest;
|
||||||
@@ -43,14 +42,6 @@ public class BitstreamFormatRestRepository extends DSpaceRestRepository<Bitstrea
|
|||||||
@Autowired
|
@Autowired
|
||||||
BitstreamFormatService bitstreamFormatService;
|
BitstreamFormatService bitstreamFormatService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
|
|
||||||
public BitstreamFormatRestRepository() {
|
|
||||||
System.out.println("Repository initialized by Spring");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BitstreamFormatRest findOne(Context context, Integer id) {
|
public BitstreamFormatRest findOne(Context context, Integer id) {
|
||||||
BitstreamFormat bit = null;
|
BitstreamFormat bit = null;
|
||||||
@@ -67,16 +58,12 @@ public class BitstreamFormatRestRepository extends DSpaceRestRepository<Bitstrea
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<BitstreamFormatRest> findAll(Context context, Pageable pageable) {
|
public Page<BitstreamFormatRest> findAll(Context context, Pageable pageable) {
|
||||||
List<BitstreamFormat> bit = null;
|
|
||||||
try {
|
try {
|
||||||
bit = bitstreamFormatService.findAll(context);
|
List<BitstreamFormat> bit = bitstreamFormatService.findAll(context);
|
||||||
|
return converter.toRestPage(utils.getPage(bit, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<BitstreamFormatRest> page = utils.getPage(bit, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -14,7 +14,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dspace.app.rest.converter.BrowseEntryConverter;
|
import org.dspace.app.rest.converter.BrowseEntryConverter;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.BrowseEntryRest;
|
import org.dspace.app.rest.model.BrowseEntryRest;
|
||||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
import org.dspace.app.rest.projection.Projection;
|
||||||
@@ -45,9 +44,6 @@ import org.springframework.stereotype.Component;
|
|||||||
public class BrowseEntryLinkRepository extends AbstractDSpaceRestRepository
|
public class BrowseEntryLinkRepository extends AbstractDSpaceRestRepository
|
||||||
implements LinkRestRepository {
|
implements LinkRestRepository {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
BrowseEntryConverter browseEntryConverter;
|
BrowseEntryConverter browseEntryConverter;
|
||||||
|
|
||||||
|
@@ -7,18 +7,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.repository;
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.browse.BrowseException;
|
import org.dspace.browse.BrowseException;
|
||||||
import org.dspace.browse.BrowseIndex;
|
import org.dspace.browse.BrowseIndex;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -30,9 +26,6 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component(BrowseIndexRest.CATEGORY + "." + BrowseIndexRest.NAME)
|
@Component(BrowseIndexRest.CATEGORY + "." + BrowseIndexRest.NAME)
|
||||||
public class BrowseIndexRestRepository extends DSpaceRestRepository<BrowseIndexRest, String> {
|
public class BrowseIndexRestRepository extends DSpaceRestRepository<BrowseIndexRest, String> {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BrowseIndexRest findOne(Context context, String name) {
|
public BrowseIndexRest findOne(Context context, String name) {
|
||||||
BrowseIndexRest bi = null;
|
BrowseIndexRest bi = null;
|
||||||
@@ -50,22 +43,12 @@ public class BrowseIndexRestRepository extends DSpaceRestRepository<BrowseIndexR
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<BrowseIndexRest> findAll(Context context, Pageable pageable) {
|
public Page<BrowseIndexRest> findAll(Context context, Pageable pageable) {
|
||||||
List<BrowseIndexRest> it = null;
|
|
||||||
List<BrowseIndex> indexesList = new ArrayList<BrowseIndex>();
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
BrowseIndex[] indexes = BrowseIndex.getBrowseIndices();
|
List<BrowseIndex> indexes = Arrays.asList(BrowseIndex.getBrowseIndices());
|
||||||
total = indexes.length;
|
return converter.toRestPage(indexes, pageable, indexes.size(), utils.obtainProjection(true));
|
||||||
for (BrowseIndex bix : indexes) {
|
|
||||||
indexesList.add(bix);
|
|
||||||
}
|
|
||||||
} catch (BrowseException e) {
|
} catch (BrowseException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<BrowseIndexRest> page = new PageImpl<>(indexesList, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -14,7 +14,6 @@ import java.util.List;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||||
import org.dspace.app.rest.model.ItemRest;
|
import org.dspace.app.rest.model.ItemRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
import org.dspace.app.rest.projection.Projection;
|
||||||
@@ -31,7 +30,6 @@ import org.dspace.sort.SortException;
|
|||||||
import org.dspace.sort.SortOption;
|
import org.dspace.sort.SortOption;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -47,8 +45,6 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component(BrowseIndexRest.CATEGORY + "." + BrowseIndexRest.NAME + "." + BrowseIndexRest.ITEMS)
|
@Component(BrowseIndexRest.CATEGORY + "." + BrowseIndexRest.NAME + "." + BrowseIndexRest.ITEMS)
|
||||||
public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository
|
public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository
|
||||||
implements LinkRestRepository {
|
implements LinkRestRepository {
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ScopeResolver scopeResolver;
|
ScopeResolver scopeResolver;
|
||||||
@@ -153,9 +149,7 @@ public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository
|
|||||||
tmpResult.add((Item) bb);
|
tmpResult.add((Item) bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
Page<ItemRest> page = new PageImpl<Item>(tmpResult, pageResultInfo, binfo.getTotal())
|
return converter.toRestPage(tmpResult, pageResultInfo, binfo.getTotal(), projection);
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,7 +18,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
||||||
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
@@ -69,9 +68,6 @@ public class ClaimedTaskRestRepository extends DSpaceRestRepository<ClaimedTaskR
|
|||||||
@Autowired
|
@Autowired
|
||||||
ClaimedTaskService claimedTaskService;
|
ClaimedTaskService claimedTaskService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
XmlWorkflowService workflowService;
|
XmlWorkflowService workflowService;
|
||||||
|
|
||||||
@@ -100,7 +96,6 @@ public class ClaimedTaskRestRepository extends DSpaceRestRepository<ClaimedTaskR
|
|||||||
public Page<ClaimedTaskRest> findByUser(@Parameter(value = "uuid", required = true) UUID userID,
|
public Page<ClaimedTaskRest> findByUser(@Parameter(value = "uuid", required = true) UUID userID,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
//FIXME this should be secured with annotation but they are currently ignored by search methods
|
//FIXME this should be secured with annotation but they are currently ignored by search methods
|
||||||
List<ClaimedTask> tasks = null;
|
|
||||||
try {
|
try {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
EPerson currentUser = context.getCurrentUser();
|
EPerson currentUser = context.getCurrentUser();
|
||||||
@@ -111,16 +106,14 @@ public class ClaimedTaskRestRepository extends DSpaceRestRepository<ClaimedTaskR
|
|||||||
}
|
}
|
||||||
if (authorizeService.isAdmin(context) || userID.equals(currentUser.getID())) {
|
if (authorizeService.isAdmin(context) || userID.equals(currentUser.getID())) {
|
||||||
EPerson ep = epersonService.find(context, userID);
|
EPerson ep = epersonService.find(context, userID);
|
||||||
tasks = claimedTaskService.findByEperson(context, ep);
|
List<ClaimedTask> tasks = claimedTaskService.findByEperson(context, ep);
|
||||||
|
return converter.toRestPage(utils.getPage(tasks, pageable), utils.obtainProjection(true));
|
||||||
} else {
|
} else {
|
||||||
throw new RESTAuthorizationException("Only administrators can search for claimed tasks of other users");
|
throw new RESTAuthorizationException("Only administrators can search for claimed tasks of other users");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Page<ClaimedTaskRest> page = utils.getPage(tasks, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, utils.obtainProjection()));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,7 +9,6 @@ package org.dspace.app.rest.repository;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
@@ -19,7 +18,6 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
@@ -38,7 +36,6 @@ import org.dspace.core.Constants;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -58,9 +55,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
|||||||
@Autowired
|
@Autowired
|
||||||
CommunityService communityService;
|
CommunityService communityService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CollectionRestEqualityUtils collectionRestEqualityUtils;
|
CollectionRestEqualityUtils collectionRestEqualityUtils;
|
||||||
|
|
||||||
@@ -86,65 +80,42 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<CollectionRest> findAll(Context context, Pageable pageable) {
|
public Page<CollectionRest> findAll(Context context, Pageable pageable) {
|
||||||
List<Collection> it = null;
|
|
||||||
List<Collection> collections = new ArrayList<Collection>();
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
total = cs.countTotal(context);
|
long total = cs.countTotal(context);
|
||||||
it = cs.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
List<Collection> collections = cs.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
||||||
for (Collection c : it) {
|
return converter.toRestPage(collections, pageable, total, utils.obtainProjection(true));
|
||||||
collections.add(c);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<CollectionRest> page = new PageImpl<>(collections, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SearchRestMethod(name = "findAuthorizedByCommunity")
|
@SearchRestMethod(name = "findAuthorizedByCommunity")
|
||||||
public Page<CollectionRest> findAuthorizedByCommunity(
|
public Page<CollectionRest> findAuthorizedByCommunity(
|
||||||
@Parameter(value = "uuid", required = true) UUID communityUuid, Pageable pageable) {
|
@Parameter(value = "uuid", required = true) UUID communityUuid, Pageable pageable) {
|
||||||
Context context = obtainContext();
|
|
||||||
List<Collection> it = null;
|
|
||||||
List<Collection> collections = new ArrayList<Collection>();
|
|
||||||
try {
|
try {
|
||||||
|
Context context = obtainContext();
|
||||||
Community com = communityService.find(context, communityUuid);
|
Community com = communityService.find(context, communityUuid);
|
||||||
if (com == null) {
|
if (com == null) {
|
||||||
throw new ResourceNotFoundException(
|
throw new ResourceNotFoundException(
|
||||||
CommunityRest.CATEGORY + "." + CommunityRest.NAME + " with id: " + communityUuid
|
CommunityRest.CATEGORY + "." + CommunityRest.NAME + " with id: " + communityUuid
|
||||||
+ " not found");
|
+ " not found");
|
||||||
}
|
}
|
||||||
it = cs.findAuthorized(context, com, Constants.ADD);
|
List<Collection> collections = cs.findAuthorized(context, com, Constants.ADD);
|
||||||
for (Collection c : it) {
|
return converter.toRestPage(utils.getPage(collections, pageable), utils.obtainProjection(true));
|
||||||
collections.add(c);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Page<CollectionRest> page = utils.getPage(collections, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, utils.obtainProjection()));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SearchRestMethod(name = "findAuthorized")
|
@SearchRestMethod(name = "findAuthorized")
|
||||||
public Page<CollectionRest> findAuthorized(Pageable pageable) {
|
public Page<CollectionRest> findAuthorized(Pageable pageable) {
|
||||||
Context context = obtainContext();
|
|
||||||
List<Collection> it = null;
|
|
||||||
List<Collection> collections = new ArrayList<Collection>();
|
|
||||||
try {
|
try {
|
||||||
it = cs.findAuthorizedOptimized(context, Constants.ADD);
|
Context context = obtainContext();
|
||||||
for (Collection c : it) {
|
List<Collection> collections = cs.findAuthorizedOptimized(context, Constants.ADD);
|
||||||
collections.add(c);
|
return converter.toRestPage(utils.getPage(collections, pageable), utils.obtainProjection(true));
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Page<CollectionRest> page = utils.getPage(collections, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, utils.obtainProjection()));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,7 +9,6 @@ package org.dspace.app.rest.repository;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
@@ -33,7 +32,6 @@ import org.dspace.content.service.CommunityService;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -138,37 +136,25 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<CommunityRest> findAll(Context context, Pageable pageable) {
|
public Page<CommunityRest> findAll(Context context, Pageable pageable) {
|
||||||
List<Community> it = null;
|
|
||||||
List<Community> communities = new ArrayList<Community>();
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
total = cs.countTotal(context);
|
long total = cs.countTotal(context);
|
||||||
it = cs.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
List<Community> communities = cs.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
||||||
for (Community c : it) {
|
return converter.toRestPage(communities, pageable, total, utils.obtainProjection(true));
|
||||||
communities.add(c);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<CommunityRest> page = new PageImpl<>(communities, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add methods in dspace api to support pagination of top level
|
// TODO: Add methods in dspace api to support pagination of top level
|
||||||
// communities
|
// communities
|
||||||
@SearchRestMethod(name = "top")
|
@SearchRestMethod(name = "top")
|
||||||
public Page<CommunityRest> findAllTop(Pageable pageable) {
|
public Page<CommunityRest> findAllTop(Pageable pageable) {
|
||||||
List<Community> topCommunities = null;
|
|
||||||
try {
|
try {
|
||||||
topCommunities = cs.findAllTop(obtainContext());
|
List<Community> communities = cs.findAllTop(obtainContext());
|
||||||
|
return converter.toRestPage(utils.getPage(communities, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Page<CommunityRest> page = utils.getPage(topCommunities, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, utils.obtainProjection()));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add method in dspace api to support direct query for subcommunities
|
// TODO: add method in dspace api to support direct query for subcommunities
|
||||||
@@ -177,20 +163,17 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
|
|||||||
public Page<CommunityRest> findSubCommunities(@Parameter(value = "parent", required = true) UUID parentCommunity,
|
public Page<CommunityRest> findSubCommunities(@Parameter(value = "parent", required = true) UUID parentCommunity,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
List<Community> subCommunities = new ArrayList<Community>();
|
|
||||||
try {
|
try {
|
||||||
Community community = cs.find(context, parentCommunity);
|
Community community = cs.find(context, parentCommunity);
|
||||||
if (community == null) {
|
if (community == null) {
|
||||||
throw new ResourceNotFoundException(
|
throw new ResourceNotFoundException(
|
||||||
CommunityRest.CATEGORY + "." + CommunityRest.NAME + " with id: " + parentCommunity + " not found");
|
CommunityRest.CATEGORY + "." + CommunityRest.NAME + " with id: " + parentCommunity + " not found");
|
||||||
}
|
}
|
||||||
subCommunities = community.getSubcommunities();
|
List<Community> subCommunities = community.getSubcommunities();
|
||||||
|
return converter.toRestPage(utils.getPage(subCommunities, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Page<CommunityRest> page = utils.getPage(subCommunities, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, utils.obtainProjection()));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,6 @@ package org.dspace.app.rest.repository;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.converter.MetadataConverter;
|
import org.dspace.app.rest.converter.MetadataConverter;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.DSpaceObjectRest;
|
import org.dspace.app.rest.model.DSpaceObjectRest;
|
||||||
@@ -38,9 +37,6 @@ public abstract class DSpaceObjectRestRepository<M extends DSpaceObject, R exten
|
|||||||
@Autowired
|
@Autowired
|
||||||
MetadataConverter metadataConverter;
|
MetadataConverter metadataConverter;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
DSpaceObjectRestRepository(DSpaceObjectService<M> dsoService,
|
DSpaceObjectRestRepository(DSpaceObjectService<M> dsoService,
|
||||||
DSpaceObjectPatch<R> dsoPatch) {
|
DSpaceObjectPatch<R> dsoPatch) {
|
||||||
this.dsoService = dsoService;
|
this.dsoService = dsoService;
|
||||||
|
@@ -18,7 +18,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.EPersonRest;
|
import org.dspace.app.rest.model.EPersonRest;
|
||||||
import org.dspace.app.rest.model.patch.Patch;
|
import org.dspace.app.rest.model.patch.Patch;
|
||||||
@@ -31,7 +30,6 @@ import org.dspace.eperson.EPerson;
|
|||||||
import org.dspace.eperson.service.EPersonService;
|
import org.dspace.eperson.service.EPersonService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -112,22 +110,13 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
|
|||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@PreAuthorize("hasAuthority('ADMIN')")
|
||||||
public Page<EPersonRest> findAll(Context context, Pageable pageable) {
|
public Page<EPersonRest> findAll(Context context, Pageable pageable) {
|
||||||
List<EPerson> epersons = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
if (!authorizeService.isAdmin(context)) {
|
long total = es.countTotal(context);
|
||||||
throw new RESTAuthorizationException(
|
List<EPerson> epersons = es.findAll(context, EPerson.EMAIL, pageable.getPageSize(), pageable.getOffset());
|
||||||
"The EPerson collection endpoint is reserved to system administrators");
|
return converter.toRestPage(epersons, pageable, total, utils.obtainProjection(true));
|
||||||
}
|
|
||||||
total = es.countTotal(context);
|
|
||||||
epersons = es.findAll(context, EPerson.EMAIL, pageable.getPageSize(), pageable.getOffset());
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<EPersonRest> page = new PageImpl<>(epersons, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,18 +132,15 @@ public class EPersonRestRepository extends DSpaceObjectRestRepository<EPerson, E
|
|||||||
@SearchRestMethod(name = "byName")
|
@SearchRestMethod(name = "byName")
|
||||||
public Page<EPersonRest> findByName(@Parameter(value = "q", required = true) String q,
|
public Page<EPersonRest> findByName(@Parameter(value = "q", required = true) String q,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
List<EPerson> epersons = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
epersons = es.search(context, q, pageable.getOffset(), pageable.getOffset() + pageable.getPageSize());
|
long total = es.searchResultCount(context, q);
|
||||||
total = es.searchResultCount(context, q);
|
List<EPerson> epersons = es.search(context, q, pageable.getOffset(),
|
||||||
|
pageable.getOffset() + pageable.getPageSize());
|
||||||
|
return converter.toRestPage(epersons, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Page<EPersonRest> page = new PageImpl<>(epersons, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, utils.obtainProjection()));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -10,9 +10,7 @@ package org.dspace.app.rest.repository;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.EntityTypeRest;
|
import org.dspace.app.rest.model.EntityTypeRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.content.EntityType;
|
import org.dspace.content.EntityType;
|
||||||
import org.dspace.content.service.EntityTypeService;
|
import org.dspace.content.service.EntityTypeService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -31,9 +29,6 @@ public class EntityTypeRestRepository extends DSpaceRestRepository<EntityTypeRes
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EntityTypeService entityTypeService;
|
private EntityTypeService entityTypeService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConverterService converter;
|
|
||||||
|
|
||||||
public EntityTypeRest findOne(Context context, Integer integer) {
|
public EntityTypeRest findOne(Context context, Integer integer) {
|
||||||
try {
|
try {
|
||||||
EntityType entityType = entityTypeService.find(context, integer);
|
EntityType entityType = entityTypeService.find(context, integer);
|
||||||
@@ -47,16 +42,12 @@ public class EntityTypeRestRepository extends DSpaceRestRepository<EntityTypeRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Page<EntityTypeRest> findAll(Context context, Pageable pageable) {
|
public Page<EntityTypeRest> findAll(Context context, Pageable pageable) {
|
||||||
List<EntityType> entityTypeList = null;
|
|
||||||
try {
|
try {
|
||||||
entityTypeList = entityTypeService.findAll(context);
|
List<EntityType> entityTypes = entityTypeService.findAll(context);
|
||||||
|
return converter.toRestPage(utils.getPage(entityTypes, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<EntityTypeRest> page = utils.getPage(entityTypeList, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<EntityTypeRest> getDomainClass() {
|
public Class<EntityTypeRest> getDomainClass() {
|
||||||
|
@@ -27,7 +27,6 @@ import org.dspace.eperson.Group;
|
|||||||
import org.dspace.eperson.service.GroupService;
|
import org.dspace.eperson.service.GroupService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -97,18 +96,13 @@ public class GroupRestRepository extends DSpaceObjectRestRepository<Group, Group
|
|||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@PreAuthorize("hasAuthority('ADMIN')")
|
||||||
@Override
|
@Override
|
||||||
public Page<GroupRest> findAll(Context context, Pageable pageable) {
|
public Page<GroupRest> findAll(Context context, Pageable pageable) {
|
||||||
List<Group> groups = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
total = gs.countTotal(context);
|
long total = gs.countTotal(context);
|
||||||
groups = gs.findAll(context, null, pageable.getPageSize(), pageable.getOffset());
|
List<Group> groups = gs.findAll(context, null, pageable.getPageSize(), pageable.getOffset());
|
||||||
|
return converter.toRestPage(groups, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<GroupRest> page = new PageImpl<Group>(groups, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -17,7 +17,6 @@ import javax.servlet.ServletInputStream;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.converter.HarvestedCollectionConverter;
|
import org.dspace.app.rest.converter.HarvestedCollectionConverter;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.HarvestTypeEnum;
|
import org.dspace.app.rest.model.HarvestTypeEnum;
|
||||||
@@ -46,9 +45,6 @@ public class HarvestedCollectionRestRepository extends AbstractDSpaceRestReposit
|
|||||||
@Autowired
|
@Autowired
|
||||||
HarvestedCollectionConverter harvestedCollectionConverter;
|
HarvestedCollectionConverter harvestedCollectionConverter;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
public HarvestedCollectionRest findOne(Collection collection) throws SQLException {
|
public HarvestedCollectionRest findOne(Collection collection) throws SQLException {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
|
|
||||||
|
@@ -13,7 +13,6 @@ import java.util.UUID;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.ItemRest;
|
import org.dspace.app.rest.model.ItemRest;
|
||||||
import org.dspace.app.rest.model.RelationshipRest;
|
import org.dspace.app.rest.model.RelationshipRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
import org.dspace.app.rest.projection.Projection;
|
||||||
@@ -24,7 +23,6 @@ import org.dspace.content.service.RelationshipService;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -42,9 +40,6 @@ public class ItemRelationshipLinkRepository extends AbstractDSpaceRestRepository
|
|||||||
@Autowired
|
@Autowired
|
||||||
ItemService itemService;
|
ItemService itemService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
//@PreAuthorize("hasPermission(#itemId, 'ITEM', 'READ')")
|
//@PreAuthorize("hasPermission(#itemId, 'ITEM', 'READ')")
|
||||||
public Page<RelationshipRest> getItemRelationships(@Nullable HttpServletRequest request,
|
public Page<RelationshipRest> getItemRelationships(@Nullable HttpServletRequest request,
|
||||||
UUID itemId,
|
UUID itemId,
|
||||||
@@ -61,8 +56,7 @@ public class ItemRelationshipLinkRepository extends AbstractDSpaceRestRepository
|
|||||||
Integer offset = pageable == null ? null : pageable.getOffset();
|
Integer offset = pageable == null ? null : pageable.getOffset();
|
||||||
int total = relationshipService.countByItem(context, item);
|
int total = relationshipService.countByItem(context, item);
|
||||||
List<Relationship> relationships = relationshipService.findByItem(context, item, limit, offset);
|
List<Relationship> relationships = relationshipService.findByItem(context, item, limit, offset);
|
||||||
return new PageImpl<>(relationships, pageable, total)
|
return converter.toRestPage(relationships, pageable, total, projection);
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,6 @@ import org.dspace.core.Context;
|
|||||||
import org.dspace.util.UUIDUtils;
|
import org.dspace.util.UUIDUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -100,21 +99,17 @@ public class ItemRestRepository extends DSpaceObjectRestRepository<Item, ItemRes
|
|||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@PreAuthorize("hasAuthority('ADMIN')")
|
||||||
public Page<ItemRest> findAll(Context context, Pageable pageable) {
|
public Page<ItemRest> findAll(Context context, Pageable pageable) {
|
||||||
Iterator<Item> it = null;
|
|
||||||
List<Item> items = new ArrayList<Item>();
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
total = is.countTotal(context);
|
long total = is.countTotal(context);
|
||||||
it = is.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
Iterator<Item> it = is.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
||||||
|
List<Item> items = new ArrayList<>();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Item i = it.next();
|
items.add(it.next());
|
||||||
items.add(i);
|
|
||||||
}
|
}
|
||||||
|
return converter.toRestPage(items, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
return new PageImpl<>(items, pageable, total).map((object) -> converter.toRest(object, projection));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.MetadataFieldRest;
|
import org.dspace.app.rest.model.MetadataFieldRest;
|
||||||
@@ -54,12 +53,6 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
|
|||||||
@Autowired
|
@Autowired
|
||||||
MetadataSchemaService metadataSchemaService;
|
MetadataSchemaService metadataSchemaService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
public MetadataFieldRestRepository() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetadataFieldRest findOne(Context context, Integer id) {
|
public MetadataFieldRest findOne(Context context, Integer id) {
|
||||||
MetadataField metadataField = null;
|
MetadataField metadataField = null;
|
||||||
@@ -76,36 +69,28 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<MetadataFieldRest> findAll(Context context, Pageable pageable) {
|
public Page<MetadataFieldRest> findAll(Context context, Pageable pageable) {
|
||||||
List<MetadataField> metadataField = null;
|
|
||||||
try {
|
try {
|
||||||
metadataField = metadataFieldService.findAll(context);
|
List<MetadataField> metadataFields = metadataFieldService.findAll(context);
|
||||||
|
return converter.toRestPage(utils.getPage(metadataFields, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<MetadataFieldRest> page = utils.getPage(metadataField, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SearchRestMethod(name = "bySchema")
|
@SearchRestMethod(name = "bySchema")
|
||||||
public Page<MetadataFieldRest> findBySchema(@Parameter(value = "schema", required = true) String schemaName,
|
public Page<MetadataFieldRest> findBySchema(@Parameter(value = "schema", required = true) String schemaName,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
Context context = obtainContext();
|
|
||||||
List<MetadataField> metadataFields = null;
|
|
||||||
try {
|
try {
|
||||||
|
Context context = obtainContext();
|
||||||
MetadataSchema schema = metadataSchemaService.find(context, schemaName);
|
MetadataSchema schema = metadataSchemaService.find(context, schemaName);
|
||||||
if (schema == null) {
|
if (schema == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
metadataFields = metadataFieldService.findAllInSchema(context, schema);
|
List<MetadataField> metadataFields = metadataFieldService.findAllInSchema(context, schema);
|
||||||
|
return converter.toRestPage(utils.getPage(metadataFields, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<MetadataFieldRest> page = utils.getPage(metadataFields, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,7 +18,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.MetadataSchemaRest;
|
import org.dspace.app.rest.model.MetadataSchemaRest;
|
||||||
@@ -46,12 +45,6 @@ public class MetadataSchemaRestRepository extends DSpaceRestRepository<MetadataS
|
|||||||
@Autowired
|
@Autowired
|
||||||
MetadataSchemaService metadataSchemaService;
|
MetadataSchemaService metadataSchemaService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
public MetadataSchemaRestRepository() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetadataSchemaRest findOne(Context context, Integer id) {
|
public MetadataSchemaRest findOne(Context context, Integer id) {
|
||||||
MetadataSchema metadataSchema = null;
|
MetadataSchema metadataSchema = null;
|
||||||
@@ -68,16 +61,12 @@ public class MetadataSchemaRestRepository extends DSpaceRestRepository<MetadataS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<MetadataSchemaRest> findAll(Context context, Pageable pageable) {
|
public Page<MetadataSchemaRest> findAll(Context context, Pageable pageable) {
|
||||||
List<MetadataSchema> metadataSchema = null;
|
|
||||||
try {
|
try {
|
||||||
metadataSchema = metadataSchemaService.findAll(context);
|
List<MetadataSchema> metadataSchemas = metadataSchemaService.findAll(context);
|
||||||
|
return converter.toRestPage(utils.getPage(metadataSchemas, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<MetadataSchemaRest> page = utils.getPage(metadataSchema, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -17,11 +17,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.PoolTaskRest;
|
import org.dspace.app.rest.model.PoolTaskRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.service.AuthorizeService;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
@@ -65,9 +63,6 @@ public class PoolTaskRestRepository extends DSpaceRestRepository<PoolTaskRest, I
|
|||||||
@Autowired
|
@Autowired
|
||||||
PoolTaskService poolTaskService;
|
PoolTaskService poolTaskService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
XmlWorkflowService workflowService;
|
XmlWorkflowService workflowService;
|
||||||
|
|
||||||
@@ -94,7 +89,6 @@ public class PoolTaskRestRepository extends DSpaceRestRepository<PoolTaskRest, I
|
|||||||
|
|
||||||
@SearchRestMethod(name = "findByUser")
|
@SearchRestMethod(name = "findByUser")
|
||||||
public Page<PoolTaskRest> findByUser(@Parameter(value = "uuid") UUID userID, Pageable pageable) {
|
public Page<PoolTaskRest> findByUser(@Parameter(value = "uuid") UUID userID, Pageable pageable) {
|
||||||
List<PoolTask> tasks = null;
|
|
||||||
try {
|
try {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
//FIXME this should be secured with annotation but they are currently ignored by search methods
|
//FIXME this should be secured with annotation but they are currently ignored by search methods
|
||||||
@@ -106,7 +100,8 @@ public class PoolTaskRestRepository extends DSpaceRestRepository<PoolTaskRest, I
|
|||||||
}
|
}
|
||||||
if (authorizeService.isAdmin(context) || userID.equals(currentUser.getID())) {
|
if (authorizeService.isAdmin(context) || userID.equals(currentUser.getID())) {
|
||||||
EPerson ep = epersonService.find(context, userID);
|
EPerson ep = epersonService.find(context, userID);
|
||||||
tasks = poolTaskService.findByEperson(context, ep);
|
List<PoolTask> tasks = poolTaskService.findByEperson(context, ep);
|
||||||
|
return converter.toRestPage(utils.getPage(tasks, pageable), utils.obtainProjection(true));
|
||||||
} else {
|
} else {
|
||||||
throw new RESTAuthorizationException("Only administrators can search for pool tasks of other users");
|
throw new RESTAuthorizationException("Only administrators can search for pool tasks of other users");
|
||||||
}
|
}
|
||||||
@@ -115,10 +110,6 @@ public class PoolTaskRestRepository extends DSpaceRestRepository<PoolTaskRest, I
|
|||||||
} catch (SQLException | IOException e) {
|
} catch (SQLException | IOException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<PoolTaskRest> page = utils.getPage(tasks, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,7 +9,6 @@ package org.dspace.app.rest.repository;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -20,7 +19,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.RelationshipRest;
|
import org.dspace.app.rest.model.RelationshipRest;
|
||||||
@@ -39,7 +37,6 @@ import org.dspace.core.Context;
|
|||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
@@ -53,7 +50,6 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
|
|||||||
|
|
||||||
private static final Logger log = Logger.getLogger(RelationshipRestRepository.class);
|
private static final Logger log = Logger.getLogger(RelationshipRestRepository.class);
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ItemService itemService;
|
private ItemService itemService;
|
||||||
|
|
||||||
@@ -63,9 +59,6 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RelationshipTypeService relationshipTypeService;
|
private RelationshipTypeService relationshipTypeService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AuthorizeService authorizeService;
|
private AuthorizeService authorizeService;
|
||||||
|
|
||||||
@@ -80,19 +73,14 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<RelationshipRest> findAll(Context context, Pageable pageable) {
|
public Page<RelationshipRest> findAll(Context context, Pageable pageable) {
|
||||||
int total = 0;
|
|
||||||
List<Relationship> relationships = new ArrayList<>();
|
|
||||||
try {
|
try {
|
||||||
total = relationshipService.countTotal(context);
|
long total = relationshipService.countTotal(context);
|
||||||
relationships = relationshipService.findAll(context,
|
List<Relationship> relationships = relationshipService.findAll(context,
|
||||||
pageable.getPageSize(), pageable.getOffset());
|
pageable.getPageSize(), pageable.getOffset());
|
||||||
|
return converter.toRestPage(relationships, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<RelationshipRest> page = new PageImpl<>(relationships, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -343,10 +331,6 @@ public class RelationshipRestRepository extends DSpaceRestRepository<Relationshi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Projection projection = utils.obtainProjection(true);
|
return converter.toRestPage(relationships, pageable, total, utils.obtainProjection(true));
|
||||||
Page<RelationshipRest> page = new PageImpl<>(relationships, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,9 +10,7 @@ package org.dspace.app.rest.repository;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.RelationshipTypeRest;
|
import org.dspace.app.rest.model.RelationshipTypeRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.content.RelationshipType;
|
import org.dspace.content.RelationshipType;
|
||||||
import org.dspace.content.service.RelationshipTypeService;
|
import org.dspace.content.service.RelationshipTypeService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -30,9 +28,6 @@ public class RelationshipTypeRestRepository extends DSpaceRestRepository<Relatio
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RelationshipTypeService relationshipTypeService;
|
private RelationshipTypeService relationshipTypeService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConverterService converter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RelationshipTypeRest findOne(Context context, Integer integer) {
|
public RelationshipTypeRest findOne(Context context, Integer integer) {
|
||||||
try {
|
try {
|
||||||
@@ -44,16 +39,12 @@ public class RelationshipTypeRestRepository extends DSpaceRestRepository<Relatio
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<RelationshipTypeRest> findAll(Context context, Pageable pageable) {
|
public Page<RelationshipTypeRest> findAll(Context context, Pageable pageable) {
|
||||||
List<RelationshipType> relationshipTypeList = null;
|
|
||||||
try {
|
try {
|
||||||
relationshipTypeList = relationshipTypeService.findAll(context);
|
List<RelationshipType> relationshipTypes = relationshipTypeService.findAll(context);
|
||||||
|
return converter.toRestPage(utils.getPage(relationshipTypes, pageable), utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<RelationshipTypeRest> page = utils.getPage(relationshipTypeList, pageable)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,10 +9,8 @@ package org.dspace.app.rest.repository;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
||||||
import org.dspace.app.rest.model.ResourcePolicyRest;
|
import org.dspace.app.rest.model.ResourcePolicyRest;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
|
||||||
import org.dspace.authorize.ResourcePolicy;
|
import org.dspace.authorize.ResourcePolicy;
|
||||||
import org.dspace.authorize.service.ResourcePolicyService;
|
import org.dspace.authorize.service.ResourcePolicyService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -33,12 +31,6 @@ public class ResourcePolicyRestRepository extends DSpaceRestRepository<ResourceP
|
|||||||
@Autowired
|
@Autowired
|
||||||
ResourcePolicyService resourcePolicyService;
|
ResourcePolicyService resourcePolicyService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
Utils utils;
|
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
@Override
|
@Override
|
||||||
public ResourcePolicyRest findOne(Context context, Integer id) {
|
public ResourcePolicyRest findOne(Context context, Integer id) {
|
||||||
|
@@ -8,14 +8,13 @@
|
|||||||
package org.dspace.app.rest.repository;
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.app.rest.model.SiteRest;
|
import org.dspace.app.rest.model.SiteRest;
|
||||||
import org.dspace.app.rest.model.patch.Patch;
|
import org.dspace.app.rest.model.patch.Patch;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
|
import org.dspace.app.rest.repository.patch.DSpaceObjectPatch;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.Site;
|
import org.dspace.content.Site;
|
||||||
@@ -23,7 +22,6 @@ import org.dspace.content.service.SiteService;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -61,17 +59,12 @@ public class SiteRestRepository extends DSpaceObjectRestRepository<Site, SiteRes
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<SiteRest> findAll(Context context, Pageable pageable) {
|
public Page<SiteRest> findAll(Context context, Pageable pageable) {
|
||||||
List<Site> sites = new ArrayList<Site>();
|
|
||||||
int total = 1;
|
|
||||||
try {
|
try {
|
||||||
sites.add(sitesv.findSite(context));
|
List<Site> sites = Arrays.asList(sitesv.findSite(context));
|
||||||
|
return converter.toRestPage(sites, pageable, 1L, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<SiteRest> page = new PageImpl<Site>(sites, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -13,7 +13,6 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component(StatisticsSupportRest.CATEGORY + "." + StatisticsSupportRest.NAME)
|
@Component(StatisticsSupportRest.CATEGORY + "." + StatisticsSupportRest.NAME)
|
||||||
public class StatisticsRestRepository extends AbstractDSpaceRestRepository {
|
public class StatisticsRestRepository extends AbstractDSpaceRestRepository {
|
||||||
|
|
||||||
|
|
||||||
public StatisticsSupportRest getStatisticsSupport() {
|
public StatisticsSupportRest getStatisticsSupport() {
|
||||||
return new StatisticsSupportRest();
|
return new StatisticsSupportRest();
|
||||||
}
|
}
|
||||||
|
@@ -13,9 +13,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.SubmissionDefinitionRest;
|
import org.dspace.app.rest.model.SubmissionDefinitionRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.app.util.SubmissionConfig;
|
import org.dspace.app.util.SubmissionConfig;
|
||||||
import org.dspace.app.util.SubmissionConfigReader;
|
import org.dspace.app.util.SubmissionConfigReader;
|
||||||
import org.dspace.app.util.SubmissionConfigReaderException;
|
import org.dspace.app.util.SubmissionConfigReaderException;
|
||||||
@@ -23,9 +21,7 @@ import org.dspace.content.Collection;
|
|||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.CollectionService;
|
import org.dspace.content.service.CollectionService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -41,9 +37,6 @@ public class SubmissionDefinitionRestRepository extends DSpaceRestRepository<Sub
|
|||||||
|
|
||||||
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConverterService converter;
|
|
||||||
|
|
||||||
public SubmissionDefinitionRestRepository() throws SubmissionConfigReaderException {
|
public SubmissionDefinitionRestRepository() throws SubmissionConfigReaderException {
|
||||||
submissionConfigReader = new SubmissionConfigReader();
|
submissionConfigReader = new SubmissionConfigReader();
|
||||||
}
|
}
|
||||||
@@ -64,10 +57,7 @@ public class SubmissionDefinitionRestRepository extends DSpaceRestRepository<Sub
|
|||||||
int total = submissionConfigReader.countSubmissionConfigs();
|
int total = submissionConfigReader.countSubmissionConfigs();
|
||||||
List<SubmissionConfig> subConfs = submissionConfigReader.getAllSubmissionConfigs(
|
List<SubmissionConfig> subConfs = submissionConfigReader.getAllSubmissionConfigs(
|
||||||
pageable.getPageSize(), pageable.getOffset());
|
pageable.getPageSize(), pageable.getOffset());
|
||||||
Projection projection = utils.obtainProjection(true);
|
return converter.toRestPage(subConfs, pageable, total, utils.obtainProjection(true));
|
||||||
Page<SubmissionDefinitionRest> page = new PageImpl<>(subConfs, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
@@ -7,19 +7,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.repository;
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.SubmissionFormRest;
|
import org.dspace.app.rest.model.SubmissionFormRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.app.util.DCInputSet;
|
import org.dspace.app.util.DCInputSet;
|
||||||
import org.dspace.app.util.DCInputsReader;
|
import org.dspace.app.util.DCInputsReader;
|
||||||
import org.dspace.app.util.DCInputsReaderException;
|
import org.dspace.app.util.DCInputsReaderException;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -35,9 +30,6 @@ public class SubmissionFormRestRepository extends DSpaceRestRepository<Submissio
|
|||||||
|
|
||||||
private DCInputsReader inputReader;
|
private DCInputsReader inputReader;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConverterService converter;
|
|
||||||
|
|
||||||
public SubmissionFormRestRepository() throws DCInputsReaderException {
|
public SubmissionFormRestRepository() throws DCInputsReaderException {
|
||||||
inputReader = new DCInputsReader();
|
inputReader = new DCInputsReader();
|
||||||
}
|
}
|
||||||
@@ -60,17 +52,13 @@ public class SubmissionFormRestRepository extends DSpaceRestRepository<Submissio
|
|||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
@Override
|
@Override
|
||||||
public Page<SubmissionFormRest> findAll(Context context, Pageable pageable) {
|
public Page<SubmissionFormRest> findAll(Context context, Pageable pageable) {
|
||||||
List<DCInputSet> subConfs = new ArrayList<DCInputSet>();
|
|
||||||
int total = inputReader.countInputs();
|
|
||||||
try {
|
try {
|
||||||
subConfs = inputReader.getAllInputs(pageable.getPageSize(), pageable.getOffset());
|
long total = inputReader.countInputs();
|
||||||
|
List<DCInputSet> subConfs = inputReader.getAllInputs(pageable.getPageSize(), pageable.getOffset());
|
||||||
|
return converter.toRestPage(subConfs, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (DCInputsReaderException e) {
|
} catch (DCInputsReaderException e) {
|
||||||
throw new IllegalStateException(e.getMessage(), e);
|
throw new IllegalStateException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<SubmissionFormRest> page = new PageImpl<>(subConfs, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,18 +10,14 @@ package org.dspace.app.rest.repository;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.SubmissionDefinitionRest;
|
import org.dspace.app.rest.model.SubmissionDefinitionRest;
|
||||||
import org.dspace.app.rest.model.SubmissionSectionRest;
|
import org.dspace.app.rest.model.SubmissionSectionRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.app.util.SubmissionConfig;
|
import org.dspace.app.util.SubmissionConfig;
|
||||||
import org.dspace.app.util.SubmissionConfigReader;
|
import org.dspace.app.util.SubmissionConfigReader;
|
||||||
import org.dspace.app.util.SubmissionConfigReaderException;
|
import org.dspace.app.util.SubmissionConfigReaderException;
|
||||||
import org.dspace.app.util.SubmissionStepConfig;
|
import org.dspace.app.util.SubmissionStepConfig;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -36,9 +32,6 @@ public class SubmissionPanelRestRepository extends DSpaceRestRepository<Submissi
|
|||||||
|
|
||||||
private SubmissionConfigReader submissionConfigReader;
|
private SubmissionConfigReader submissionConfigReader;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConverterService converter;
|
|
||||||
|
|
||||||
public SubmissionPanelRestRepository() throws SubmissionConfigReaderException {
|
public SubmissionPanelRestRepository() throws SubmissionConfigReaderException {
|
||||||
submissionConfigReader = new SubmissionConfigReader();
|
submissionConfigReader = new SubmissionConfigReader();
|
||||||
}
|
}
|
||||||
@@ -58,9 +51,9 @@ public class SubmissionPanelRestRepository extends DSpaceRestRepository<Submissi
|
|||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
@Override
|
@Override
|
||||||
public Page<SubmissionSectionRest> findAll(Context context, Pageable pageable) {
|
public Page<SubmissionSectionRest> findAll(Context context, Pageable pageable) {
|
||||||
List<SubmissionConfig> subConfs = new ArrayList<SubmissionConfig>();
|
List<SubmissionConfig> subConfs = submissionConfigReader.getAllSubmissionConfigs(
|
||||||
subConfs = submissionConfigReader.getAllSubmissionConfigs(pageable.getPageSize(), pageable.getOffset());
|
pageable.getPageSize(), pageable.getOffset());
|
||||||
int total = 0;
|
long total = 0;
|
||||||
List<SubmissionStepConfig> stepConfs = new ArrayList<>();
|
List<SubmissionStepConfig> stepConfs = new ArrayList<>();
|
||||||
for (SubmissionConfig config : subConfs) {
|
for (SubmissionConfig config : subConfs) {
|
||||||
total = +config.getNumberOfSteps();
|
total = +config.getNumberOfSteps();
|
||||||
@@ -69,10 +62,7 @@ public class SubmissionPanelRestRepository extends DSpaceRestRepository<Submissi
|
|||||||
stepConfs.add(step);
|
stepConfs.add(step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
return converter.toRestPage(stepConfs, pageable, total, utils.obtainProjection(true));
|
||||||
Page<SubmissionSectionRest> page = new PageImpl<>(stepConfs, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -12,7 +12,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.model.AccessConditionOptionRest;
|
import org.dspace.app.rest.model.AccessConditionOptionRest;
|
||||||
import org.dspace.app.rest.model.SubmissionUploadRest;
|
import org.dspace.app.rest.model.SubmissionUploadRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
import org.dspace.app.rest.projection.Projection;
|
||||||
@@ -58,9 +57,6 @@ public class SubmissionUploadRestRepository extends DSpaceRestRepository<Submiss
|
|||||||
@Autowired
|
@Autowired
|
||||||
GroupService groupService;
|
GroupService groupService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
DateMathParser dateMathParser = new DateMathParser();
|
DateMathParser dateMathParser = new DateMathParser();
|
||||||
|
|
||||||
public SubmissionUploadRestRepository() throws SubmissionConfigReaderException {
|
public SubmissionUploadRestRepository() throws SubmissionConfigReaderException {
|
||||||
|
@@ -17,7 +17,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
@@ -47,7 +46,6 @@ import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
|||||||
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
|
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -69,27 +67,29 @@ public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowIte
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
XmlWorkflowItemService wis;
|
XmlWorkflowItemService wis;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ItemService itemService;
|
ItemService itemService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
BitstreamService bitstreamService;
|
BitstreamService bitstreamService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
BitstreamFormatService bitstreamFormatService;
|
BitstreamFormatService bitstreamFormatService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ConfigurationService configurationService;
|
ConfigurationService configurationService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
SubmissionService submissionService;
|
SubmissionService submissionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
EPersonServiceImpl epersonService;
|
EPersonServiceImpl epersonService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WorkflowService<XmlWorkflowItem> wfs;
|
WorkflowService<XmlWorkflowItem> wfs;
|
||||||
|
|
||||||
private SubmissionConfigReader submissionConfigReader;
|
private final SubmissionConfigReader submissionConfigReader;
|
||||||
|
|
||||||
public WorkflowItemRestRepository() throws SubmissionConfigReaderException {
|
public WorkflowItemRestRepository() throws SubmissionConfigReaderException {
|
||||||
submissionConfigReader = new SubmissionConfigReader();
|
submissionConfigReader = new SubmissionConfigReader();
|
||||||
@@ -113,37 +113,28 @@ public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowIte
|
|||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@PreAuthorize("hasAuthority('ADMIN')")
|
||||||
public Page<WorkflowItemRest> findAll(Context context, Pageable pageable) {
|
public Page<WorkflowItemRest> findAll(Context context, Pageable pageable) {
|
||||||
List<XmlWorkflowItem> witems = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
total = wis.countAll(context);
|
long total = wis.countAll(context);
|
||||||
witems = wis.findAll(context, pageable.getPageNumber(), pageable.getPageSize());
|
List<XmlWorkflowItem> witems = wis.findAll(context, pageable.getPageNumber(), pageable.getPageSize());
|
||||||
|
return converter.toRestPage(witems, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<WorkflowItemRest> page = new PageImpl<>(witems, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SearchRestMethod(name = "findBySubmitter")
|
@SearchRestMethod(name = "findBySubmitter")
|
||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@PreAuthorize("hasAuthority('ADMIN')")
|
||||||
public Page<WorkflowItemRest> findBySubmitter(@Parameter(value = "uuid") UUID submitterID, Pageable pageable) {
|
public Page<WorkflowItemRest> findBySubmitter(@Parameter(value = "uuid") UUID submitterID, Pageable pageable) {
|
||||||
List<XmlWorkflowItem> witems = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
EPerson ep = epersonService.find(context, submitterID);
|
EPerson ep = epersonService.find(context, submitterID);
|
||||||
witems = wis.findBySubmitter(context, ep, pageable.getPageNumber(), pageable.getPageSize());
|
long total = wis.countBySubmitter(context, ep);
|
||||||
total = wis.countBySubmitter(context, ep);
|
List<XmlWorkflowItem> witems = wis.findBySubmitter(context, ep, pageable.getPageNumber(),
|
||||||
|
pageable.getPageSize());
|
||||||
|
return converter.toRestPage(witems, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<WorkflowItemRest> page = new PageImpl<>(witems, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -24,7 +24,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.rest.Parameter;
|
import org.dspace.app.rest.Parameter;
|
||||||
import org.dspace.app.rest.SearchRestMethod;
|
import org.dspace.app.rest.SearchRestMethod;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
|
||||||
import org.dspace.app.rest.converter.WorkspaceItemConverter;
|
import org.dspace.app.rest.converter.WorkspaceItemConverter;
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.model.ErrorRest;
|
import org.dspace.app.rest.model.ErrorRest;
|
||||||
@@ -63,7 +62,6 @@ import org.dspace.submit.lookup.SubmissionLookupService;
|
|||||||
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.json.patch.PatchException;
|
import org.springframework.data.rest.webmvc.json.patch.PatchException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -83,22 +81,25 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WorkspaceItemService wis;
|
WorkspaceItemService wis;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ItemService itemService;
|
ItemService itemService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
BitstreamService bitstreamService;
|
BitstreamService bitstreamService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
BitstreamFormatService bitstreamFormatService;
|
BitstreamFormatService bitstreamFormatService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ConfigurationService configurationService;
|
ConfigurationService configurationService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WorkspaceItemConverter workspaceItemConverter;
|
WorkspaceItemConverter workspaceItemConverter;
|
||||||
@Autowired
|
|
||||||
ConverterService converter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
SubmissionService submissionService;
|
SubmissionService submissionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
EPersonServiceImpl epersonService;
|
EPersonServiceImpl epersonService;
|
||||||
|
|
||||||
@@ -132,38 +133,28 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
//TODO @PreAuthorize("hasAuthority('ADMIN')")
|
//TODO @PreAuthorize("hasAuthority('ADMIN')")
|
||||||
@Override
|
@Override
|
||||||
public Page<WorkspaceItemRest> findAll(Context context, Pageable pageable) {
|
public Page<WorkspaceItemRest> findAll(Context context, Pageable pageable) {
|
||||||
List<WorkspaceItem> witems = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
total = wis.countTotal(context);
|
long total = wis.countTotal(context);
|
||||||
witems = wis.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
List<WorkspaceItem> witems = wis.findAll(context, pageable.getPageSize(), pageable.getOffset());
|
||||||
|
return converter.toRestPage(witems, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<WorkspaceItemRest> page = new PageImpl<>(witems, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO @PreAuthorize("hasPermission(#submitterID, 'EPERSON', 'READ')")
|
//TODO @PreAuthorize("hasPermission(#submitterID, 'EPERSON', 'READ')")
|
||||||
@SearchRestMethod(name = "findBySubmitter")
|
@SearchRestMethod(name = "findBySubmitter")
|
||||||
public Page<WorkspaceItemRest> findBySubmitter(@Parameter(value = "uuid", required = true) UUID submitterID,
|
public Page<WorkspaceItemRest> findBySubmitter(@Parameter(value = "uuid", required = true) UUID submitterID,
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
List<WorkspaceItem> witems = null;
|
|
||||||
int total = 0;
|
|
||||||
try {
|
try {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
EPerson ep = epersonService.find(context, submitterID);
|
EPerson ep = epersonService.find(context, submitterID);
|
||||||
witems = wis.findByEPerson(context, ep, pageable.getPageSize(), pageable.getOffset());
|
long total = wis.countByEPerson(context, ep);
|
||||||
total = wis.countByEPerson(context, ep);
|
List<WorkspaceItem> witems = wis.findByEPerson(context, ep, pageable.getPageSize(), pageable.getOffset());
|
||||||
|
return converter.toRestPage(witems, pageable, total, utils.obtainProjection(true));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
Projection projection = utils.obtainProjection(true);
|
|
||||||
Page<WorkspaceItemRest> page = new PageImpl<>(witems, pageable, total)
|
|
||||||
.map((object) -> converter.toRest(object, projection));
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -203,7 +194,6 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
+ " Therefore it cannot be used by the Configurable Submission as the " +
|
+ " Therefore it cannot be used by the Configurable Submission as the " +
|
||||||
"<processing-class>!");
|
"<processing-class>!");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@@ -436,6 +436,8 @@ public class Utils {
|
|||||||
return obtainProjection(false);
|
return obtainProjection(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds embeds or links for all class-level LinkRel annotations for which embeds or links are allowed.
|
* Adds embeds or links for all class-level LinkRel annotations for which embeds or links are allowed.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user