Skip to content

Commit

Permalink
Enhancing the PR for DS-1990.
Browse files Browse the repository at this point in the history
Adds a cache to the Identifier array in the DSpaceObject class.
Renames the method from lookupIdentifiers into getIdentifiers.
  • Loading branch information
pnbecker committed Aug 28, 2014
1 parent 446c7ef commit 3fdc76c
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 67 deletions.
12 changes: 6 additions & 6 deletions dspace-api/src/main/java/org/dspace/content/Bitstream.java
Expand Up @@ -212,7 +212,7 @@ static Bitstream create(Context context, InputStream is)
bitstream.setFormat(null);

context.addEvent(new Event(Event.CREATE, Constants.BITSTREAM,
bitstreamID, null, bitstream.lookupIdentifiers(context)));
bitstreamID, null, bitstream.getIdentifiers(context)));

return bitstream;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ static Bitstream register(Context context,
bitstream.setFormat(null);

context.addEvent(new Event(Event.CREATE, Constants.BITSTREAM,
bitstreamID, "REGISTER", bitstream.lookupIdentifiers(context)));
bitstreamID, "REGISTER", bitstream.getIdentifiers(context)));

return bitstream;
}
Expand Down Expand Up @@ -509,14 +509,14 @@ public void update() throws SQLException, AuthorizeException
if (modified)
{
bContext.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM,
getID(), null, lookupIdentifiers(bContext)));
getID(), null, getIdentifiers(bContext)));
modified = false;
}
if (modifiedMetadata)
{
bContext.addEvent(new Event(Event.MODIFY_METADATA,
Constants.BITSTREAM, getID(), getDetails(),
lookupIdentifiers(bContext)));
getIdentifiers(bContext)));
modifiedMetadata = false;
clearDetails();
}
Expand Down Expand Up @@ -544,7 +544,7 @@ void delete() throws SQLException
"bitstream_id=" + getID()));

bContext.addEvent(new Event(Event.DELETE, Constants.BITSTREAM, getID(),
String.valueOf(getSequenceID()), lookupIdentifiers(bContext)));
String.valueOf(getSequenceID()), getIdentifiers(bContext)));

// Remove from cache
bContext.removeCached(this, getID());
Expand Down Expand Up @@ -751,6 +751,6 @@ public void updateLastModified()
{
//Also fire a modified event since the bitstream HAS been modified
bContext.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM, getID(),
null, lookupIdentifiers(bContext)));
null, getIdentifiers(bContext)));
}
}
10 changes: 5 additions & 5 deletions dspace-api/src/main/java/org/dspace/content/Bundle.java
Expand Up @@ -448,7 +448,7 @@ public void addBitstream(Bitstream b) throws SQLException,

ourContext.addEvent(new Event(Event.ADD, Constants.BUNDLE, getID(),
Constants.BITSTREAM, b.getID(), String.valueOf(b.getSequenceID()),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));

// copy authorization policies from bundle to bitstream
// FIXME: multiple inclusion is affected by this...
Expand Down Expand Up @@ -553,7 +553,7 @@ public void removeBitstream(Bitstream b) throws AuthorizeException,

ourContext.addEvent(new Event(Event.REMOVE, Constants.BUNDLE, getID(),
Constants.BITSTREAM, b.getID(), String.valueOf(b.getSequenceID()),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));

//Ensure that the last modified from the item is triggered !
Item owningItem = (Item) getParentObject();
Expand Down Expand Up @@ -614,13 +614,13 @@ public void update() throws SQLException, AuthorizeException
if (modified)
{
ourContext.addEvent(new Event(Event.MODIFY, Constants.BUNDLE, getID(),
null, lookupIdentifiers(ourContext)));
null, getIdentifiers(ourContext)));
modified = false;
}
if (modifiedMetadata)
{
ourContext.addEvent(new Event(Event.MODIFY_METADATA, Constants.BUNDLE,
getID(), null, lookupIdentifiers(ourContext)));
getID(), null, getIdentifiers(ourContext)));
modifiedMetadata = false;
}

Expand All @@ -638,7 +638,7 @@ void delete() throws SQLException, AuthorizeException, IOException
+ getID()));

ourContext.addEvent(new Event(Event.DELETE, Constants.BUNDLE, getID(),
getName(), lookupIdentifiers(ourContext)));
getName(), getIdentifiers(ourContext)));

// Remove from cache
ourContext.removeCached(this, getID());
Expand Down
16 changes: 8 additions & 8 deletions dspace-api/src/main/java/org/dspace/content/Collection.java
Expand Up @@ -280,7 +280,7 @@ static Collection create(Context context, String handle) throws SQLException,
myPolicy.update();

context.addEvent(new Event(Event.CREATE, Constants.COLLECTION,
c.getID(), c.handle, c.lookupIdentifiers(context)));
c.getID(), c.handle, c.getIdentifiers(context)));

log.info(LogManager.getHeader(context, "create_collection",
"collection_id=" + row.getIntColumn("collection_id"))
Expand Down Expand Up @@ -971,7 +971,7 @@ public void removeTemplateItem() throws SQLException, AuthorizeException,
}

ourContext.addEvent(new Event(Event.MODIFY, Constants.COLLECTION,
getID(), "remove_template_item", lookupIdentifiers(ourContext)));
getID(), "remove_template_item", getIdentifiers(ourContext)));
}

/**
Expand Down Expand Up @@ -1003,7 +1003,7 @@ public void addItem(Item item) throws SQLException, AuthorizeException

ourContext.addEvent(new Event(Event.ADD, Constants.COLLECTION, getID(),
Constants.ITEM, item.getID(), item.getHandle(),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));
}

/**
Expand Down Expand Up @@ -1043,7 +1043,7 @@ public void removeItem(Item item) throws SQLException, AuthorizeException,

ourContext.addEvent(new Event(Event.REMOVE, Constants.COLLECTION,
getID(), Constants.ITEM, item.getID(), item.getHandle(),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));
}

/**
Expand All @@ -1067,14 +1067,14 @@ public void update() throws SQLException, AuthorizeException
if (modified)
{
ourContext.addEvent(new Event(Event.MODIFY, Constants.COLLECTION,
getID(), null, lookupIdentifiers(ourContext)));
getID(), null, getIdentifiers(ourContext)));
modified = false;
}
if (modifiedMetadata)
{
ourContext.addEvent(new Event(Event.MODIFY_METADATA,
Constants.COLLECTION, getID(), getDetails(),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));
modifiedMetadata = false;
clearDetails();
}
Expand Down Expand Up @@ -1141,7 +1141,7 @@ void delete() throws SQLException, AuthorizeException, IOException
"collection_id=" + getID()));

ourContext.addEvent(new Event(Event.DELETE, Constants.COLLECTION,
getID(), getHandle(), lookupIdentifiers(ourContext)));
getID(), getHandle(), getIdentifiers(ourContext)));

// Remove from cache
ourContext.removeCached(this, getID());
Expand Down Expand Up @@ -1577,6 +1577,6 @@ public void updateLastModified()
{
//Also fire a modified event since the collection HAS been modified
ourContext.addEvent(new Event(Event.MODIFY, Constants.COLLECTION,
getID(), null, lookupIdentifiers(ourContext)));
getID(), null, getIdentifiers(ourContext)));
}
}
22 changes: 11 additions & 11 deletions dspace-api/src/main/java/org/dspace/content/Community.java
Expand Up @@ -233,14 +233,14 @@ public static Community create(Community parent, Context context, String handle)
myPolicy.update();

context.addEvent(new Event(Event.CREATE, Constants.COMMUNITY, c.getID(),
c.handle, c.lookupIdentifiers(context)));
c.handle, c.getIdentifiers(context)));

// if creating a top-level Community, simulate an ADD event at the Site.
if (parent == null)
{
context.addEvent(new Event(Event.ADD, Constants.SITE, Site.SITE_ID,
Constants.COMMUNITY, c.getID(), c.handle,
c.lookupIdentifiers(context)));
c.getIdentifiers(context)));
}

log.info(LogManager.getHeader(context, "create_community",
Expand Down Expand Up @@ -531,14 +531,14 @@ public void update() throws SQLException, AuthorizeException
if (modified)
{
ourContext.addEvent(new Event(Event.MODIFY, Constants.COMMUNITY,
getID(), null, lookupIdentifiers(ourContext)));
getID(), null, getIdentifiers(ourContext)));
modified = false;
}
if (modifiedMetadata)
{
ourContext.addEvent(new Event(Event.MODIFY_METADATA,
Constants.COMMUNITY, getID(), getDetails(),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));
modifiedMetadata = false;
clearDetails();
}
Expand Down Expand Up @@ -911,7 +911,7 @@ public void addCollection(Collection c) throws SQLException,

ourContext.addEvent(new Event(Event.ADD, Constants.COMMUNITY,
getID(), Constants.COLLECTION, c.getID(), c.getHandle(),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));

DatabaseManager.insert(ourContext, mappingRow);
}
Expand Down Expand Up @@ -988,7 +988,7 @@ public void addSubcommunity(Community c) throws SQLException,

ourContext.addEvent(new Event(Event.ADD, Constants.COMMUNITY,
getID(), Constants.COMMUNITY, c.getID(), c.getHandle(),
lookupIdentifiers(ourContext)));
getIdentifiers(ourContext)));

DatabaseManager.insert(ourContext, mappingRow);
}
Expand Down Expand Up @@ -1026,7 +1026,7 @@ public void removeCollection(Collection c) throws SQLException,
// Capture ID & Handle of Collection we are removing, so we can trigger events later
int removedId = c.getID();
String removedHandle = c.getHandle();
String[] removedIdentifiers = c.lookupIdentifiers(ourContext);
String[] removedIdentifiers = c.getIdentifiers(ourContext);

// How many parent(s) does this collection have?
TableRow trow = DatabaseManager.querySingle(ourContext,
Expand Down Expand Up @@ -1087,7 +1087,7 @@ public void removeSubcommunity(Community c) throws SQLException,
// Capture ID & Handle of Community we are removing, so we can trigger events later
int removedId = c.getID();
String removedHandle = c.getHandle();
String[] removedIdentifiers = c.lookupIdentifiers(ourContext);
String[] removedIdentifiers = c.getIdentifiers(ourContext);

// How many parent(s) does this subcommunity have?
TableRow trow = DatabaseManager.querySingle(ourContext,
Expand Down Expand Up @@ -1158,7 +1158,7 @@ public void delete() throws SQLException, AuthorizeException, IOException

// Since this is a top level Community, simulate a REMOVE event at the Site.
ourContext.addEvent(new Event(Event.REMOVE, Constants.SITE, Site.SITE_ID,
Constants.COMMUNITY, getID(), getHandle(), lookupIdentifiers(ourContext)));
Constants.COMMUNITY, getID(), getHandle(), getIdentifiers(ourContext)));
} else {
// This is a subcommunity, so let the parent remove it
// NOTE: this essentially just logs event and calls "rawDelete()"
Expand All @@ -1182,7 +1182,7 @@ private void rawDelete() throws SQLException, AuthorizeException, IOException
// Capture ID & Handle of object we are removing, so we can trigger events later
int deletedId = getID();
String deletedHandle = getHandle();
String[] deletedIdentifiers = lookupIdentifiers(ourContext);
String[] deletedIdentifiers = getIdentifiers(ourContext);

// Remove Community object from cache
ourContext.removeCached(this, getID());
Expand Down Expand Up @@ -1401,6 +1401,6 @@ public void updateLastModified()
{
//Also fire a modified event since the community HAS been modified
ourContext.addEvent(new Event(Event.MODIFY, Constants.COMMUNITY,
getID(), null, lookupIdentifiers(ourContext)));
getID(), null, getIdentifiers(ourContext)));
}
}
56 changes: 42 additions & 14 deletions dspace-api/src/main/java/org/dspace/content/DSpaceObject.java
Expand Up @@ -29,6 +29,8 @@ public abstract class DSpaceObject
// accumulate information to add to "detail" element of content Event,
// e.g. to document metadata fields touched, etc.
private StringBuffer eventDetails = null;

private String[] identifiers = null;

/**
* Reset the cache of event details.
Expand Down Expand Up @@ -109,26 +111,52 @@ public String getTypeText()
* Tries to lookup all Identifiers of this DSpaceObject.
* @return An array containing all found identifiers or an array with a length of 0.
*/
public String[] lookupIdentifiers(Context context)
public String[] getIdentifiers(Context context)
{
String[] identifiers = new String[0];
IdentifierService identifierService =
new DSpace().getSingletonService(IdentifierService.class);

if (identifierService != null)
if (identifiers == null)
{
return identifierService.lookup(context, this);
log.debug("This DSO's identifiers cache is empty, looking for identifiers...");
identifiers = new String[0];

IdentifierService identifierService =
new DSpace().getSingletonService(IdentifierService.class);

if (identifierService != null)
{
identifiers = identifierService.lookup(context, this);
} else {
log.warn("No IdentifierService found, will return an array containing "
+ "the Handle only.");
if (getHandle() != null)
{
identifiers = new String[] { HandleManager.getCanonicalForm(getHandle()) };
}
}
}

log.warn("No IdentifierService found, will return an array containing "
+ "the Handle only.");

if (getHandle() != null)

if (log.isDebugEnabled())
{
return new String[] { HandleManager.getCanonicalForm(getHandle()) };
StringBuilder dbgMsg = new StringBuilder();
for (String id : identifiers)
{
if (dbgMsg.capacity() == 0)
{
dbgMsg.append("This DSO's Identifiers are: ");
} else {
dbgMsg.append(", ");
}
dbgMsg.append(id);
}
dbgMsg.append(".");
log.debug(dbgMsg.toString());
}

return new String[0];
return identifiers;
}

public void resetIdentifiersCache()
{
identifiers = null;
}

/**
Expand Down
Expand Up @@ -224,7 +224,7 @@ private static Item finishItem(Context c, Item item, InProgressSubmission is)

// Notify interested parties of newly archived Item
c.addEvent(new Event(Event.INSTALL, Constants.ITEM, item.getID(),
item.getHandle(), item.lookupIdentifiers(c)));
item.getHandle(), item.getIdentifiers(c)));

// remove in-progress submission
is.deleteWrapper();
Expand Down

0 comments on commit 3fdc76c

Please sign in to comment.