DefaultAccessStatusHelper: getEmbargoFromItem return null embargo if status than embargo

This commit is contained in:
Agustina Martinez
2023-09-20 16:26:14 +01:00
parent f1add5fe24
commit e05e73a112
4 changed files with 15 additions and 10 deletions

View File

@@ -22,6 +22,7 @@ public interface AccessStatusHelper {
*
* @param context the DSpace context
* @param item the item
* @param threshold the embargo threshold date
* @return an access status value
* @throws SQLException An exception that provides information on a database access error or other errors.
*/
@@ -33,8 +34,9 @@ public interface AccessStatusHelper {
*
* @param context the DSpace context
* @param item the item to check for embargo information
* @param threshold the embargo threshold date
* @return an embargo date
* @throws SQLException An exception that provides information on a database access error or other errors.
*/
public String getEmbargoFromItem(Context context, Item item) throws SQLException;
public String getEmbargoFromItem(Context context, Item item, Date threshold) throws SQLException;
}

View File

@@ -70,6 +70,6 @@ public class AccessStatusServiceImpl implements AccessStatusService {
@Override
public String getEmbargoFromItem(Context context, Item item) throws SQLException {
return helper.getEmbargoFromItem(context, item);
return helper.getEmbargoFromItem(context, item, forever_date);
}
}

View File

@@ -173,11 +173,14 @@ public class DefaultAccessStatusHelper implements AccessStatusHelper {
* @return an access status value
*/
@Override
public String getEmbargoFromItem(Context context, Item item)
public String getEmbargoFromItem(Context context, Item item, Date threshold)
throws SQLException {
Date embargoedDate;
Date embargoDate;
if (item == null) {
// If Item status is not "embargo" then return a null embargo date.
String accessStatus = getAccessStatusFromItem(context, item, threshold);
if (item == null || !accessStatus.equals(EMBARGO)) {
return null;
}
// Consider only the original bundles.
@@ -202,9 +205,9 @@ public class DefaultAccessStatusHelper implements AccessStatusHelper {
return null;
}
embargoedDate = this.retrieveShortestEmbargo(context, bitstream);
embargoDate = this.retrieveShortestEmbargo(context, bitstream);
return embargoedDate != null ? embargoedDate.toString() : null;
return embargoDate != null ? embargoDate.toString() : null;
}
/**

View File

@@ -274,7 +274,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
context.restoreAuthSystemState();
String status = helper.getAccessStatusFromItem(context, itemWithEmbargo, threshold);
assertThat("testWithEmbargo 0", status, equalTo(DefaultAccessStatusHelper.EMBARGO));
String embargoDate = helper.getEmbargoFromItem(context, itemWithEmbargo);
String embargoDate = helper.getEmbargoFromItem(context, itemWithEmbargo, threshold);
assertThat("testWithEmbargo 1", embargoDate, equalTo(policy.getStartDate().toString()));
}
@@ -393,7 +393,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
context.restoreAuthSystemState();
String status = helper.getAccessStatusFromItem(context, itemWithPrimaryAndMultipleBitstreams, threshold);
assertThat("testWithPrimaryAndMultipleBitstreams 0", status, equalTo(DefaultAccessStatusHelper.EMBARGO));
String embargoDate = helper.getEmbargoFromItem(context, itemWithPrimaryAndMultipleBitstreams);
String embargoDate = helper.getEmbargoFromItem(context, itemWithPrimaryAndMultipleBitstreams, threshold);
assertThat("testWithPrimaryAndMultipleBitstreams 1", embargoDate, equalTo(policy.getStartDate().toString()));
}
@@ -424,7 +424,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
context.restoreAuthSystemState();
String status = helper.getAccessStatusFromItem(context, itemWithoutPrimaryAndMultipleBitstreams, threshold);
assertThat("testWithNoPrimaryAndMultipleBitstreams 0", status, equalTo(DefaultAccessStatusHelper.OPEN_ACCESS));
String embargoDate = helper.getEmbargoFromItem(context, itemWithEmbargo);
String embargoDate = helper.getEmbargoFromItem(context, itemWithEmbargo, threshold);
assertThat("testWithNoPrimaryAndMultipleBitstreams 1", embargoDate, equalTo(null));
}