Skip to content

Commit

Permalink
Merge branch 'DSpace:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
msevigny authored Feb 28, 2024
2 parents 2d26e56 + ff30259 commit aa236f0
Show file tree
Hide file tree
Showing 57 changed files with 3,436 additions and 796 deletions.
10 changes: 6 additions & 4 deletions dspace-api/src/main/java/org/dspace/content/QAEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Date;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.OpenaireMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.dspace.util.RawJsonDeserializer;
Expand All @@ -29,7 +30,8 @@ public class QAEvent {
public static final String REJECTED = "rejected";
public static final String DISCARDED = "discarded";

public static final String OPENAIRE_SOURCE = "openaire";
public static final String OPENAIRE_SOURCE = "OpenAIRE";
public static final String DSPACE_USERS_SOURCE = "DSpaceUsers";

private String source;

Expand Down Expand Up @@ -62,8 +64,7 @@ public class QAEvent {

private String status = "PENDING";

public QAEvent() {
}
public QAEvent() {}

public QAEvent(String source, String originalId, String target, String title,
String topic, double trust, String message, Date lastUpdate) {
Expand All @@ -81,7 +82,6 @@ public QAEvent(String source, String originalId, String target, String title,
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}

}

public String getOriginalId() {
Expand Down Expand Up @@ -205,6 +205,8 @@ public Class<? extends QAMessageDTO> getMessageDtoClass() {
switch (getSource()) {
case OPENAIRE_SOURCE:
return OpenaireMessageDTO.class;
case DSPACE_USERS_SOURCE:
return CorrectionTypeMessageDTO.class;
default:
throw new IllegalArgumentException("Unknown event's source: " + getSource());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.correctiontype;

import java.sql.SQLException;

import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.core.Context;
import org.dspace.qaevent.service.dto.QAMessageDTO;

/**
* Interface class that model the CorrectionType.
*
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.com)
*/
public interface CorrectionType {

/**
* Retrieves the unique identifier associated to the CorrectionType.
*/
public String getId();

/**
* Retrieves the topic associated with the to the CorrectionType.
*/
public String getTopic();

/**
* Checks whether the CorrectionType required related item.
*/
public boolean isRequiredRelatedItem();

/**
* Checks whether target item is allowed for current CorrectionType
*
* @param context Current DSpace session
* @param targetItem Target item
* @throws AuthorizeException if authorize error
* @throws SQLException if there's a database problem
*/
public boolean isAllowed(Context context, Item targetItem) throws AuthorizeException, SQLException;

/**
* Checks whether target item and related item are allowed for current CorrectionType
*
* @param context Current DSpace session
* @param targetItem Target item
* @param relatedItem Related item
* @throws AuthorizeException if authorize error
* @throws SQLException if there's a database problem
*/
public boolean isAllowed(Context context, Item targetItem, Item relatedItem) throws AuthorizeException,SQLException;

/**
* Creates a QAEvent for a specific target item.
*
* @param context Current DSpace session
* @param targetItem Target item
* @param reason Reason
* @return QAEvent
*/
public QAEvent createCorrection(Context context, Item targetItem, QAMessageDTO reason);

/**
* Creates a QAEvent for a target item and related item.
* @param context Current DSpace session
* @param targetItem Target item
* @param relatedItem Related item
* @param reason Reason
* @return QAEvent
*/
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem, QAMessageDTO reason);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* 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.correctiontype;

import static org.dspace.content.QAEvent.DSPACE_USERS_SOURCE;
import static org.dspace.correctiontype.WithdrawnCorrectionType.WITHDRAWAL_REINSTATE_GROUP;

import java.sql.SQLException;
import java.util.Date;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.StringUtils;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.core.Context;
import org.dspace.eperson.Group;
import org.dspace.eperson.service.GroupService;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Implementation class for {@link CorrectionType}
* that will reinstate target item if it's withdrawn.
*
* @author Mykhaylo Boychuk ([email protected])
*/
public class ReinstateCorrectionType implements CorrectionType, InitializingBean {

private String id;
private String topic;
private String creationForm;

@Autowired
private GroupService groupService;
@Autowired
private QAEventService qaEventService;
@Autowired
private AuthorizeService authorizeService;
@Autowired
private ConfigurationService configurationService;

@Override
public boolean isAllowed(Context context, Item targetItem) throws SQLException {
if (!targetItem.isWithdrawn()) {
return false;
}
boolean isAdmin = authorizeService.isAdmin(context);
if (!currentUserIsMemberOfwithdrawalReinstateGroup(context) && !isAdmin) {
return false;
}
long tot = qaEventService.countSourcesByTarget(context, targetItem.getID());
return tot == 0;
}

private boolean currentUserIsMemberOfwithdrawalReinstateGroup(Context context) throws SQLException {
String groupName = configurationService.getProperty(WITHDRAWAL_REINSTATE_GROUP);
if (StringUtils.isBlank(groupName)) {
return false;
}
Group withdrawalReinstateGroup = groupService.findByName(context, groupName);
return withdrawalReinstateGroup != null && groupService.isMember(context, withdrawalReinstateGroup);
}

@Override
public boolean isAllowed(Context context, Item targetItem, Item relatedItem) throws AuthorizeException,
SQLException {
return isAllowed(context, targetItem);
}

@Override
public QAEvent createCorrection(Context context, Item targetItem, QAMessageDTO reason) {
ObjectNode reasonJson = createReasonJson(reason);
QAEvent qaEvent = new QAEvent(DSPACE_USERS_SOURCE,
context.getCurrentUser().getID().toString(),
targetItem.getID().toString(),
targetItem.getName(),
this.getTopic(),
1.0,
reasonJson.toString(),
new Date()
);

qaEventService.store(context, qaEvent);
return qaEvent;
}

private ObjectNode createReasonJson(QAMessageDTO reason) {
CorrectionTypeMessageDTO mesasge = (CorrectionTypeMessageDTO) reason;
ObjectNode jsonNode = new ObjectMapper().createObjectNode();
jsonNode.put("reason", mesasge.getReason());
return jsonNode;
}

@Override
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem, QAMessageDTO reason) {
return this.createCorrection(context, targetItem, reason);
}

@Override
public boolean isRequiredRelatedItem() {
return false;
}

@Override
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@Override
public String getTopic() {
return topic;
}

public void setTopic(String topic) {
this.topic = topic;
}

@Override
public void afterPropertiesSet() throws Exception {}

public void setCreationForm(String creationForm) {
this.creationForm = creationForm;
}

}
Loading

0 comments on commit aa236f0

Please sign in to comment.