Skip to content

Commit

Permalink
[Ticket 2124] Slow response times
Browse files Browse the repository at this point in the history
  • Loading branch information
YanaDePauw authored and Atmire-Kristof committed Apr 29, 2024
1 parent 502028f commit 4703934
Show file tree
Hide file tree
Showing 13 changed files with 854 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ public class DeleteFeature implements AuthorizationFeature {
@Override
public boolean isAuthorized(Context context, BaseObjectRest object) throws SQLException {
if (object instanceof BaseObjectRest) {
DSpaceObject dSpaceObject = (DSpaceObject) utils.getDSpaceAPIObjectFromRest(context, object);

if (object.getType().equals(WorkspaceItemRest.NAME)) {
object = ((WorkspaceItemRest)object).getItem();
WorkspaceItem workspaceItem = (WorkspaceItem) utils.getDSpaceAPIObjectFromRest(context, object);
dSpaceObject = workspaceItem.getItem();
}

DSpaceObject dSpaceObject = (DSpaceObject) utils.getDSpaceAPIObjectFromRest(context, object);
DSpaceObject parentObject = getParentObject(context, dSpaceObject);

switch (object.getType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ protected void fillFromModel(T obj, R witem, Projection projection) {
submitter = obj.getSubmitter();

witem.setId(obj.getID());
witem.setCollection(collection != null ? converter.toRest(collection, projection) : null);
witem.setItem(converter.toRest(item, projection));
if (submitter != null) {
witem.setSubmitter(converter.toRest(submitter, projection));
}
// witem.setCollection(collection != null ? converter.toRest(collection, projection) : null);
// witem.setItem(converter.toRest(item, projection));
// if (submitter != null) {
// witem.setSubmitter(converter.toRest(submitter, projection));
// }

// 1. retrieve the submission definition
// 2. iterate over the submission section to allow to plugin additional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@
*/
public abstract class AInprogressSubmissionRest extends BaseObjectRest<Integer> {


private Date lastModified = new Date();
private Map<String, Serializable> sections;
@JsonIgnore
private CollectionRest collection;
@JsonIgnore
private ItemRest item;
@JsonIgnore
private SubmissionDefinitionRest submissionDefinition;
@JsonIgnore
private EPersonRest submitter;

public Date getLastModified() {
return lastModified;
Expand All @@ -41,14 +36,6 @@ public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}

public ItemRest getItem() {
return item;
}

public void setItem(ItemRest item) {
this.item = item;
}

public SubmissionDefinitionRest getSubmissionDefinition() {
return submissionDefinition;
}
Expand All @@ -57,14 +44,6 @@ public void setSubmissionDefinition(SubmissionDefinitionRest submissionDefinitio
this.submissionDefinition = submissionDefinition;
}

public EPersonRest getSubmitter() {
return submitter;
}

public void setSubmitter(EPersonRest submitter) {
this.submitter = submitter;
}

public Map<String, Serializable> getSections() {
if (sections == null) {
sections = new HashMap<String, Serializable>();
Expand All @@ -76,12 +55,6 @@ public void setSections(Map<String, Serializable> sections) {
this.sections = sections;
}

public CollectionRest getCollection() {
return collection;
}

public void setCollection(CollectionRest collection) {
this.collection = collection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@
* @author Andrea Bollini (andrea.bollini at 4science.it)
*/
@LinksRest(links = {
@LinkRest(
name = WorkflowItemRest.STEP,
method = "getStep"
)
@LinkRest(
name = WorkflowItemRest.STEP,
method = "getStep"
),
@LinkRest(
name = WorkflowItemRest.SUBMITTER,
method = "getWorkflowItemSubmitter"
),
@LinkRest(
name = WorkflowItemRest.ITEM,
method = "getWorkflowItemItem"
),
@LinkRest(
name = WorkflowItemRest.COLLECTION,
method = "getWorkflowItemCollection"
)
})
public class WorkflowItemRest extends AInprogressSubmissionRest {
public static final String NAME = "workflowitem";
Expand All @@ -27,6 +39,11 @@ public class WorkflowItemRest extends AInprogressSubmissionRest {

public static final String STEP = "step";

public static final String SUBMITTER = "submitter";
public static final String ITEM = "item";
public static final String COLLECTION = "collection";


@Override
public String getCategory() {
return CATEGORY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
@LinkRest(
name = WorkspaceItemRest.SUPERVISION_ORDERS,
method = "getSupervisionOrders"
),
@LinkRest(
name = WorkspaceItemRest.SUBMITTER,
method = "getWorkspaceItemSubmitter"
),
@LinkRest(
name = WorkspaceItemRest.ITEM,
method = "getWorkspaceItemItem"
),
@LinkRest(
name = WorkspaceItemRest.COLLECTION,
method = "getWorkspaceItemCollection"
)
})
public class WorkspaceItemRest extends AInprogressSubmissionRest {
Expand All @@ -26,6 +38,9 @@ public class WorkspaceItemRest extends AInprogressSubmissionRest {
public static final String CATEGORY = RestAddressableModel.SUBMISSION;

public static final String SUPERVISION_ORDERS = "supervisionOrders";
public static final String SUBMITTER = "submitter";
public static final String ITEM = "item";
public static final String COLLECTION = "collection";

@Override
public String getCategory() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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 javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;

import org.dspace.app.rest.model.CollectionRest;
import org.dspace.app.rest.model.WorkflowItemRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.core.Context;
import org.dspace.workflow.WorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;

/**
* Link repository for "collection" subresource of a workflow item.
*/
@Component(WorkflowItemRest.CATEGORY + "." + WorkflowItemRest.NAME + "." + WorkflowItemRest.COLLECTION)
public class WorkflowItemCollectionLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository {

@Autowired
XmlWorkflowItemService wis;

/**
* Retrieve the item for a workflow collection.
*
* @param request - The current request
* @param id - The workflow item ID for which to retrieve the collection
* @param optionalPageable - optional pageable object
* @param projection - the current projection
* @return the item for the workflow collection
*/
@PreAuthorize("hasPermission(#id, 'WORKFLOWITEM', 'READ')")
public CollectionRest getWorkflowItemCollection(@Nullable HttpServletRequest request, Integer id,
@Nullable Pageable optionalPageable, Projection projection) {
try {
Context context = obtainContext();
WorkflowItem witem = wis.find(context, id);
if (witem == null) {
throw new ResourceNotFoundException("No such workflow item: " + id);
}

return converter.toRest(witem.getCollection(), projection);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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 javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;

import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.model.WorkflowItemRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.core.Context;
import org.dspace.workflow.WorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;

/**
* Link repository for "item" subresource of a workflow item.
*/
@Component(WorkflowItemRest.CATEGORY + "." + WorkflowItemRest.NAME + "." + WorkflowItemRest.ITEM)
public class WorkflowItemItemLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository {

@Autowired
XmlWorkflowItemService wis;

/**
* Retrieve the item for a workflow item.
*
* @param request - The current request
* @param id - The workflow item ID for which to retrieve the item
* @param optionalPageable - optional pageable object
* @param projection - the current projection
* @return the item for the workflow item
*/
@PreAuthorize("hasPermission(#id, 'WORKFLOWITEM', 'READ')")
public ItemRest getWorkflowItemItem(@Nullable HttpServletRequest request, Integer id,
@Nullable Pageable optionalPageable, Projection projection) {
try {
Context context = obtainContext();
WorkflowItem witem = wis.find(context, id);
if (witem == null) {
throw new ResourceNotFoundException("No such workflow item: " + id);
}

return converter.toRest(witem.getItem(), projection);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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 javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;

import org.dspace.app.rest.model.EPersonRest;
import org.dspace.app.rest.model.WorkflowItemRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.core.Context;
import org.dspace.workflow.WorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;

/**
* Link repository for "submitter" subresource of a workflow item.
*/
@Component(WorkflowItemRest.CATEGORY + "." + WorkflowItemRest.NAME + "." + WorkflowItemRest.SUBMITTER)
public class WorkflowItemSubmitterLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository {

@Autowired
XmlWorkflowItemService wis;

/**
* Retrieve the submitter for a workflow item.
*
* @param request - The current request
* @param id - The workflow item ID for which to retrieve the submitter
* @param optionalPageable - optional pageable object
* @param projection - the current projection
* @return the submitter for the workflow item
*/
@PreAuthorize("hasPermission(#id, 'WORKFLOWITEM', 'READ')")
public EPersonRest getWorkflowItemSubmitter(@Nullable HttpServletRequest request, Integer id,
@Nullable Pageable optionalPageable, Projection projection) {
try {
Context context = obtainContext();
WorkflowItem witem = wis.find(context, id);
if (witem == null) {
throw new ResourceNotFoundException("No such workflow item: " + id);
}

return converter.toRest(witem.getSubmitter(), projection);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 4703934

Please sign in to comment.