Skip to content

Commit

Permalink
[CST-12108] improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
Micheleboychuk committed Jan 22, 2024
1 parent 2ea401c commit 96ee430
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

import com.google.gson.Gson;
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.Constants;
import org.dspace.core.Context;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
Expand All @@ -39,14 +37,14 @@ public class ReinstateCorrectionType implements CorrectionType, InitializingBean

@Autowired
private QAEventService qaEventService;
@Autowired
private AuthorizeService authorizeService;

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ public class WithdrawnCorrectionType implements CorrectionType, InitializingBean
private AuthorizeService authorizeService;

@Override
public boolean isAllowed(Context context, Item targetItem) throws AuthorizeException, SQLException {
authorizeService.authorizeAction(context, targetItem, READ);
public boolean isAllowed(Context context, Item targetItem) throws SQLException {
if (targetItem.isWithdrawn() || !targetItem.isArchived()) {
return false;
}
try {
authorizeService.authorizeAction(context, targetItem, READ);
} catch (AuthorizeException e) {
return false;
}
long tot = qaEventService.countSourcesByTarget(context, targetItem.getID());
return tot == 0 && targetItem.isArchived() && !targetItem.isWithdrawn();
return tot == 0;
}

@Override
Expand Down

0 comments on commit 96ee430

Please sign in to comment.