forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'DSpace:main' into main
- Loading branch information
Showing
57 changed files
with
3,436 additions
and
796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
dspace-api/src/main/java/org/dspace/correctiontype/CorrectionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
141 changes: 141 additions & 0 deletions
141
dspace-api/src/main/java/org/dspace/correctiontype/ReinstateCorrectionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.