mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
CST-12105 first draft of api endpoint
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.ldn.model;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonPropertyOrder(value = {
|
||||
"itemuuid",
|
||||
"endorsements",
|
||||
"ingests",
|
||||
"reviews"
|
||||
})
|
||||
|
||||
/**
|
||||
* item requests of LDN messages of type
|
||||
*
|
||||
* "Offer", "coar-notify:EndorsementAction"
|
||||
* "Offer", "coar-notify:IngestAction"
|
||||
* "Offer", "coar-notify:ReviewAction"
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science dot it)
|
||||
*/
|
||||
public class ItemRequests extends Base {
|
||||
|
||||
private ItemRequest endorsements;
|
||||
private ItemRequest ingests;
|
||||
private ItemRequest reviews;
|
||||
private UUID itemUuid;
|
||||
|
||||
public ItemRequests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemRequest getEndorsements() {
|
||||
return endorsements;
|
||||
}
|
||||
|
||||
public void setEndorsements(ItemRequest endorsements) {
|
||||
this.endorsements = endorsements;
|
||||
}
|
||||
|
||||
public ItemRequest getIngests() {
|
||||
return ingests;
|
||||
}
|
||||
|
||||
public void setIngests(ItemRequest ingests) {
|
||||
this.ingests = ingests;
|
||||
}
|
||||
|
||||
public ItemRequest getReviews() {
|
||||
return reviews;
|
||||
}
|
||||
|
||||
public void setReviews(ItemRequest reviews) {
|
||||
this.reviews = reviews;
|
||||
}
|
||||
|
||||
public UUID getItemUuid() {
|
||||
return itemUuid;
|
||||
}
|
||||
|
||||
public void setItemUuid(UUID itemUuid) {
|
||||
this.itemUuid = itemUuid;
|
||||
}
|
||||
|
||||
public class ItemRequest {
|
||||
Integer count;
|
||||
Boolean accepted;
|
||||
Boolean rejected;
|
||||
Boolean tentative;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,9 +9,11 @@ package org.dspace.app.ldn.service;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.ldn.LDNMessageEntity;
|
||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||
import org.dspace.app.ldn.model.ItemRequests;
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
import org.dspace.app.ldn.model.Service;
|
||||
import org.dspace.core.Context;
|
||||
@@ -106,4 +108,14 @@ public interface LDNMessageService {
|
||||
* @throws SQLException if something goes wrong
|
||||
*/
|
||||
public NotifyServiceEntity findNotifyService(Context context, Service service) throws SQLException;
|
||||
|
||||
/**
|
||||
* find the ldn messages of Requests by item uuid
|
||||
*
|
||||
* @param context the context
|
||||
* @param itemId the item uuid
|
||||
* @return the item requests object
|
||||
* @throws SQLException If something goes wrong in the database
|
||||
*/
|
||||
public ItemRequests findRequestsByItemUUID(Context context, UUID itemId) throws SQLException;
|
||||
}
|
||||
|
@@ -26,6 +26,8 @@ import org.dspace.app.ldn.LDNRouter;
|
||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||
import org.dspace.app.ldn.dao.LDNMessageDao;
|
||||
import org.dspace.app.ldn.dao.NotifyServiceDao;
|
||||
import org.dspace.app.ldn.model.ItemRequests;
|
||||
import org.dspace.app.ldn.model.ItemRequests.ItemRequest;
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
import org.dspace.app.ldn.model.Service;
|
||||
import org.dspace.app.ldn.processor.LDNProcessor;
|
||||
@@ -268,4 +270,14 @@ public class LDNMessageServiceImpl implements LDNMessageService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemRequests findRequestsByItemUUID(Context context, UUID itemId) throws SQLException {
|
||||
ItemRequests result = new ItemRequests();
|
||||
result.setItemUuid(itemId);
|
||||
ItemRequest ingests = result.getIngests();
|
||||
result.setIngests(ingests);
|
||||
/* TODO SEARCH FOR LDN MESSAGES */
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.ldn.model.ItemRequests;
|
||||
import org.dspace.app.rest.model.LDNItemRequestsRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This is the converter from/to the ItemRequests in the DSpace API data model and
|
||||
* the REST data model
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*/
|
||||
@Component
|
||||
public class LDNItemRequestsConverter implements DSpaceConverter<ItemRequests, LDNItemRequestsRest> {
|
||||
|
||||
@Override
|
||||
public LDNItemRequestsRest convert(ItemRequests modelObject, Projection projection) {
|
||||
LDNItemRequestsRest result = new LDNItemRequestsRest();
|
||||
result.setItemuuid(modelObject.getItemUuid());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ItemRequests> getModelClass() {
|
||||
return ItemRequests.class;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.dspace.app.rest.RestResourceController;
|
||||
|
||||
/**
|
||||
* Rest entity for LDN requests targeting items
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science dot it)
|
||||
*/
|
||||
@JsonPropertyOrder(value = {
|
||||
"itemuuid",
|
||||
"endorsements",
|
||||
"ingests",
|
||||
"reviews"
|
||||
})
|
||||
public class LDNItemRequestsRest extends BaseObjectRest<Integer> {
|
||||
public static final String CATEGORY = RestAddressableModel.LDN;
|
||||
public static final String NAME = "ldnitemservice";
|
||||
public static final String GET_ITEM_REQUESTS = "getItemRequests";
|
||||
|
||||
private ItemRequest endorsements;
|
||||
private ItemRequest ingests;
|
||||
private ItemRequest reviews;
|
||||
private UUID itemuuid;
|
||||
|
||||
public LDNItemRequestsRest() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ItemRequest getEndorsements() {
|
||||
return endorsements;
|
||||
}
|
||||
|
||||
public void setEndorsements(ItemRequest endorsements) {
|
||||
this.endorsements = endorsements;
|
||||
}
|
||||
|
||||
public ItemRequest getIngests() {
|
||||
return ingests;
|
||||
}
|
||||
|
||||
public void setIngests(ItemRequest ingests) {
|
||||
this.ingests = ingests;
|
||||
}
|
||||
|
||||
public ItemRequest getReviews() {
|
||||
return reviews;
|
||||
}
|
||||
|
||||
public void setReviews(ItemRequest reviews) {
|
||||
this.reviews = reviews;
|
||||
}
|
||||
|
||||
public UUID getItemuuid() {
|
||||
return itemuuid;
|
||||
}
|
||||
|
||||
public void setItemuuid(UUID itemuuid) {
|
||||
this.itemuuid = itemuuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return CATEGORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
public Class getController() {
|
||||
return RestResourceController.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ItemRequest {
|
||||
Integer count;
|
||||
Boolean accepted;
|
||||
Boolean rejected;
|
||||
Boolean tentative;
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.ldn.model.ItemRequests;
|
||||
import org.dspace.app.ldn.service.LDNMessageService;
|
||||
import org.dspace.app.rest.Parameter;
|
||||
import org.dspace.app.rest.SearchRestMethod;
|
||||
import org.dspace.app.rest.model.LDNItemRequestsRest;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Rest Repository for LDN requests targeting items
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science dot it)
|
||||
*/
|
||||
@Component(LDNItemRequestsRest.CATEGORY + "." + LDNItemRequestsRest.NAME)
|
||||
public class LDNItemRequestsRestRepository extends DSpaceRestRepository<LDNItemRequestsRest, String> {
|
||||
|
||||
private static final Logger log = LogManager.getLogger(LDNItemRequestsRestRepository.class);
|
||||
|
||||
@Autowired
|
||||
private LDNMessageService ldnMessageService;
|
||||
|
||||
@SearchRestMethod(name = LDNItemRequestsRest.GET_ITEM_REQUESTS)
|
||||
//@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||
public LDNItemRequestsRest findItemRequests(
|
||||
@Parameter(value = "itemuuid", required = true) UUID itemUuid) {
|
||||
|
||||
log.info("START findItemRequests looking for requests for item " + itemUuid);
|
||||
Context context = obtainContext();
|
||||
ItemRequests resultRequests = new ItemRequests();
|
||||
try {
|
||||
resultRequests = ldnMessageService.findRequestsByItemUUID(context, itemUuid);
|
||||
} catch (SQLException e) {
|
||||
log.error(e);
|
||||
}
|
||||
log.info("END findItemRequests");
|
||||
return converter.toRest(resultRequests, utils.obtainProjection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LDNItemRequestsRest findOne(Context context, String id) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<LDNItemRequestsRest> findAll(Context context, Pageable pageable) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<LDNItemRequestsRest> getDomainClass() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user