[CST-12108] improve code

This commit is contained in:
Mykhaylo Boychuk
2024-01-23 00:36:00 +01:00
parent 2ea401caf1
commit 96ee4304cc
2 changed files with 15 additions and 10 deletions

View File

@@ -14,10 +14,8 @@ import java.util.Date;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.QAEvent; import org.dspace.content.QAEvent;
import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.qaevent.service.QAEventService; import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO; import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
@@ -39,14 +37,14 @@ public class ReinstateCorrectionType implements CorrectionType, InitializingBean
@Autowired @Autowired
private QAEventService qaEventService; private QAEventService qaEventService;
@Autowired
private AuthorizeService authorizeService;
@Override @Override
public boolean isAllowed(Context context, Item targetItem) throws SQLException, AuthorizeException { public boolean isAllowed(Context context, Item targetItem) throws SQLException {
authorizeService.authorizeAction(context, targetItem, Constants.READ); if (!targetItem.isWithdrawn()) {
return false;
}
long tot = qaEventService.countSourcesByTarget(context, targetItem.getID()); long tot = qaEventService.countSourcesByTarget(context, targetItem.getID());
return tot == 0 && targetItem.isWithdrawn(); return tot == 0;
} }
@Override @Override

View File

@@ -43,10 +43,17 @@ public class WithdrawnCorrectionType implements CorrectionType, InitializingBean
private AuthorizeService authorizeService; private AuthorizeService authorizeService;
@Override @Override
public boolean isAllowed(Context context, Item targetItem) throws AuthorizeException, SQLException { public boolean isAllowed(Context context, Item targetItem) throws SQLException {
authorizeService.authorizeAction(context, targetItem, READ); 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()); long tot = qaEventService.countSourcesByTarget(context, targetItem.getID());
return tot == 0 && targetItem.isArchived() && !targetItem.isWithdrawn(); return tot == 0;
} }
@Override @Override