Skip to content

Commit

Permalink
Merge pull request #2152 from Georgetown-University-Libraries/ds3707m
Browse files Browse the repository at this point in the history
DS-3707, DS-3715: Fixes to item level embargo/privacy in OAI-PMH (for master)
  • Loading branch information
tdonohue committed Aug 6, 2018
2 parents cbd5980 + 74f47de commit ea9efd7
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context
return itemDAO.findAll(context, true, true, true, since);
}

@Override
public Iterator<Item> findInArchiveOrWithdrawnNonDiscoverableModifiedSince(Context context, Date since)
throws SQLException {
return itemDAO.findAll(context, true, true, false, since);
}

@Override
public void updateLastModified(Context context, Item item) throws SQLException, AuthorizeException {
item.setLastModified(new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ public Iterator<Item> findAllByCollection(Context context, Collection collection
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since)
throws SQLException;

/**
* Get all Items installed or withdrawn, NON-discoverable, and modified since a Date.
* @param context context
* @param since earliest interesting last-modified date, or null for no date test.
* @return an iterator over the items in the collection.
* @throws SQLException if database error
*/
public Iterator<Item> findInArchiveOrWithdrawnNonDiscoverableModifiedSince(Context context, Date since)
throws SQLException;

/**
* Get all the items (including private and withdrawn) in this collection. The order is indeterminate.
*
Expand Down
118 changes: 118 additions & 0 deletions dspace-api/src/test/java/org/dspace/content/ItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,124 @@ public void testFindBySubmitter() throws Exception {
assertFalse("testFindBySubmitter 3", all.hasNext());
}

/**
* Test of findInArchiveOrWithdrawnDiscoverableModifiedSince method, of class Item.
*/
@Test
public void testFindInArchiveOrWithdrawnDiscoverableModifiedSince() throws Exception {
// Init item to be both withdrawn and discoverable
it.setWithdrawn(true);
it.setArchived(false);
it.setDiscoverable(true);
// Test 0: Using a future 'modified since' date, we should get non-null list, with no items
Iterator<Item> all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
DateUtils.addDays(it.getLastModified(),1));
assertThat("Returned list should not be null", all, notNullValue());
boolean added = false;
while (all.hasNext()) {
Item tmp = all.next();
if (tmp.equals(it)) {
added = true;
}
}
// Test 1: we should NOT find our item in this list
assertFalse("List should not contain item when passing a date newer than item last-modified date", added);
// Test 2: Using a past 'modified since' date, we should get a non-null list containing our item
all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
DateUtils.addDays(it.getLastModified(),-1));
assertThat("Returned list should not be null", all, notNullValue());
added = false;
while (all.hasNext()) {
Item tmp = all.next();
if (tmp.equals(it)) {
added = true;
}
}
// Test 3: we should find our item in this list
assertTrue("List should contain item when passing a date older than item last-modified date", added);
// Repeat Tests 2, 3 with withdrawn = false and archived = true as this should result in same behaviour
it.setWithdrawn(false);
it.setArchived(true);
// Test 4: Using a past 'modified since' date, we should get a non-null list containing our item
all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
DateUtils.addDays(it.getLastModified(),-1));
assertThat("Returned list should not be null", all, notNullValue());
added = false;
while (all.hasNext()) {
Item tmp = all.next();
if (tmp.equals(it)) {
added = true;
}
}
// Test 5: We should find our item in this list
assertTrue("List should contain item when passing a date older than item last-modified date", added);
// Test 6: Make sure non-discoverable items are not returned, regardless of archived/withdrawn state
it.setDiscoverable(false);
all = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(context,
DateUtils.addDays(it.getLastModified(),-1));
assertThat("Returned list should not be null", all, notNullValue());
added = false;
while (all.hasNext()) {
Item tmp = all.next();
if (tmp.equals(it)) {
added = true;
}
}
// Test 7: We should not find our item in this list
assertFalse("List should not contain non-discoverable items", added);
}
/**
* Test of findInArchiveOrWithdrawnNonDiscoverableModifiedSince method, of class Item.
*/
@Test
public void testFindInArchiveOrWithdrawnNonDiscoverableModifiedSince() throws Exception {
// Init item to be both withdrawn and discoverable
it.setWithdrawn(true);
it.setArchived(false);
it.setDiscoverable(false);
// Test 0: Using a future 'modified since' date, we should get non-null list, with no items
Iterator<Item> all = itemService.findInArchiveOrWithdrawnNonDiscoverableModifiedSince(context,
DateUtils.addDays(it.getLastModified(),1));
assertThat("Returned list should not be null", all, notNullValue());
boolean added = false;
while (all.hasNext()) {
Item tmp = all.next();
if (tmp.equals(it)) {
added = true;
}
}
// Test 1: We should NOT find our item in this list
assertFalse("List should not contain item when passing a date newer than item last-modified date", added);
// Test 2: Using a past 'modified since' date, we should get a non-null list containing our item
all = itemService.findInArchiveOrWithdrawnNonDiscoverableModifiedSince(context,
DateUtils.addDays(it.getLastModified(),-1));
assertThat("Returned list should not be null", all, notNullValue());
added = false;
while (all.hasNext()) {
Item tmp = all.next();
if (tmp.equals(it)) {
added = true;
}
}
// Test 3: We should find our item in this list
assertTrue("List should contain item when passing a date older than item last-modified date", added);
// Repeat Tests 2, 3 with discoverable = true
it.setDiscoverable(true);
// Test 4: Now we should still get a non-null list with NO items since item is discoverable
all = itemService.findInArchiveOrWithdrawnNonDiscoverableModifiedSince(context,
DateUtils.addDays(it.getLastModified(),-1));
assertThat("Returned list should not be null", all, notNullValue());
added = false;
while (all.hasNext()) {
Item tmp = all.next();
if (tmp.equals(it)) {
added = true;
}
}
// Test 5: We should NOT find our item in this list
assertFalse("List should not contain discoverable items", added);
}

/**
* Test of getID method, of class Item.
*/
Expand Down

0 comments on commit ea9efd7

Please sign in to comment.