mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 04:23:13 +00:00
Support Metadata On All DSpaceObjects
This commit is contained in:
@@ -41,8 +41,6 @@ public class Bitstream extends DSpaceObject
|
||||
/** log4j logger */
|
||||
private static Logger log = Logger.getLogger(Bitstream.class);
|
||||
|
||||
/** Our context */
|
||||
private Context bContext;
|
||||
|
||||
/** The row in the table representing this bitstream */
|
||||
private TableRow bRow;
|
||||
@@ -53,9 +51,6 @@ public class Bitstream extends DSpaceObject
|
||||
/** Flag set when data is modified, for events */
|
||||
private boolean modified;
|
||||
|
||||
/** Flag set when metadata is modified, for events */
|
||||
private boolean modifiedMetadata;
|
||||
|
||||
/**
|
||||
* Private constructor for creating a Bitstream object based on the contents
|
||||
* of a DB table row.
|
||||
@@ -68,7 +63,7 @@ public class Bitstream extends DSpaceObject
|
||||
*/
|
||||
Bitstream(Context context, TableRow row) throws SQLException
|
||||
{
|
||||
bContext = context;
|
||||
super(context);
|
||||
bRow = row;
|
||||
|
||||
// Get the bitstream format
|
||||
@@ -91,7 +86,6 @@ public class Bitstream extends DSpaceObject
|
||||
context.cache(this, row.getIntColumn("bitstream_id"));
|
||||
|
||||
modified = false;
|
||||
modifiedMetadata = false;
|
||||
clearDetails();
|
||||
}
|
||||
|
||||
@@ -298,9 +292,8 @@ public class Bitstream extends DSpaceObject
|
||||
*
|
||||
* @return the name of the bitstream
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return bRow.getStringColumn("name");
|
||||
public String getName(){
|
||||
return getMetadataFirstValue(MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,11 +302,8 @@ public class Bitstream extends DSpaceObject
|
||||
* @param n
|
||||
* the new name of the bitstream
|
||||
*/
|
||||
public void setName(String n)
|
||||
{
|
||||
bRow.setColumn("name", n);
|
||||
modifiedMetadata = true;
|
||||
addDetails("Name");
|
||||
public void setName(String n) {
|
||||
setMetadataSingleValue(MetadataSchema.DC_SCHEMA, "title", null, null, n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,7 +315,7 @@ public class Bitstream extends DSpaceObject
|
||||
*/
|
||||
public String getSource()
|
||||
{
|
||||
return bRow.getStringColumn("source");
|
||||
return getMetadataFirstValue(MetadataSchema.DC_SCHEMA, "source", null, Item.ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,11 +324,8 @@ public class Bitstream extends DSpaceObject
|
||||
* @param n
|
||||
* the new source of the bitstream
|
||||
*/
|
||||
public void setSource(String n)
|
||||
{
|
||||
bRow.setColumn("source", n);
|
||||
modifiedMetadata = true;
|
||||
addDetails("Source");
|
||||
public void setSource(String n) {
|
||||
setMetadataSingleValue(MetadataSchema.DC_SCHEMA, "source", null, null, n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,7 +336,7 @@ public class Bitstream extends DSpaceObject
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return bRow.getStringColumn("description");
|
||||
return getMetadataFirstValue(MetadataSchema.DC_SCHEMA, "description", null, Item.ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -358,11 +345,8 @@ public class Bitstream extends DSpaceObject
|
||||
* @param n
|
||||
* the new description of the bitstream
|
||||
*/
|
||||
public void setDescription(String n)
|
||||
{
|
||||
bRow.setColumn("description", n);
|
||||
modifiedMetadata = true;
|
||||
addDetails("Description");
|
||||
public void setDescription(String n) {
|
||||
setMetadataSingleValue(MetadataSchema.DC_SCHEMA, "description", null, null, n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,14 +387,9 @@ public class Bitstream extends DSpaceObject
|
||||
* the user's description of the format
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void setUserFormatDescription(String desc) throws SQLException
|
||||
{
|
||||
// FIXME: Would be better if this didn't throw an SQLException,
|
||||
// but we need to find the unknown format!
|
||||
public void setUserFormatDescription(String desc) throws SQLException {
|
||||
setFormat(null);
|
||||
bRow.setColumn("user_format_description", desc);
|
||||
modifiedMetadata = true;
|
||||
addDetails("UserFormatDescription");
|
||||
setMetadataSingleValue(MetadataSchema.DC_SCHEMA, "format", null, null, desc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,7 +400,7 @@ public class Bitstream extends DSpaceObject
|
||||
*/
|
||||
public String getUserFormatDescription()
|
||||
{
|
||||
return bRow.getStringColumn("user_format_description");
|
||||
return getMetadataFirstValue(MetadataSchema.DC_SCHEMA, "format", null, Item.ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +414,7 @@ public class Bitstream extends DSpaceObject
|
||||
if (bitstreamFormat.getShortDescription().equals("Unknown"))
|
||||
{
|
||||
// Get user description if there is one
|
||||
String desc = bRow.getStringColumn("user_format_description");
|
||||
String desc = getUserFormatDescription();
|
||||
|
||||
if (desc == null)
|
||||
{
|
||||
@@ -476,7 +455,7 @@ public class Bitstream extends DSpaceObject
|
||||
if (f == null)
|
||||
{
|
||||
// Use "Unknown" format
|
||||
bitstreamFormat = BitstreamFormat.findUnknown(bContext);
|
||||
bitstreamFormat = BitstreamFormat.findUnknown(ourContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -484,7 +463,7 @@ public class Bitstream extends DSpaceObject
|
||||
}
|
||||
|
||||
// Remove user type description
|
||||
bRow.setColumnNull("user_format_description");
|
||||
clearMetadata(MetadataSchema.DC_SCHEMA,"format",null, Item.ANY);
|
||||
|
||||
// Update the ID in the table row
|
||||
bRow.setColumn("bitstream_format_id", bitstreamFormat.getID());
|
||||
@@ -501,27 +480,24 @@ public class Bitstream extends DSpaceObject
|
||||
public void update() throws SQLException, AuthorizeException
|
||||
{
|
||||
// Check authorisation
|
||||
AuthorizeManager.authorizeAction(bContext, this, Constants.WRITE);
|
||||
AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE);
|
||||
|
||||
log.info(LogManager.getHeader(bContext, "update_bitstream",
|
||||
log.info(LogManager.getHeader(ourContext, "update_bitstream",
|
||||
"bitstream_id=" + getID()));
|
||||
|
||||
DatabaseManager.update(ourContext, bRow);
|
||||
|
||||
if (modified)
|
||||
{
|
||||
bContext.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM,
|
||||
getID(), null, getIdentifiers(bContext)));
|
||||
ourContext.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM, getID(), null, getIdentifiers(ourContext)));
|
||||
modified = false;
|
||||
}
|
||||
if (modifiedMetadata)
|
||||
{
|
||||
bContext.addEvent(new Event(Event.MODIFY_METADATA,
|
||||
Constants.BITSTREAM, getID(), getDetails(),
|
||||
getIdentifiers(bContext)));
|
||||
modifiedMetadata = false;
|
||||
updateMetadata();
|
||||
clearDetails();
|
||||
}
|
||||
|
||||
DatabaseManager.update(bContext, bRow);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,28 +511,30 @@ public class Bitstream extends DSpaceObject
|
||||
|
||||
// changed to a check on remove
|
||||
// Check authorisation
|
||||
//AuthorizeManager.authorizeAction(bContext, this, Constants.DELETE);
|
||||
log.info(LogManager.getHeader(bContext, "delete_bitstream",
|
||||
//AuthorizeManager.authorizeAction(ourContext, this, Constants.DELETE);
|
||||
log.info(LogManager.getHeader(ourContext, "delete_bitstream",
|
||||
"bitstream_id=" + getID()));
|
||||
|
||||
bContext.addEvent(new Event(Event.DELETE, Constants.BITSTREAM, getID(),
|
||||
String.valueOf(getSequenceID()), getIdentifiers(bContext)));
|
||||
ourContext.addEvent(new Event(Event.DELETE, Constants.BITSTREAM, getID(),
|
||||
String.valueOf(getSequenceID()), getIdentifiers(ourContext)));
|
||||
|
||||
// Remove from cache
|
||||
bContext.removeCached(this, getID());
|
||||
ourContext.removeCached(this, getID());
|
||||
|
||||
// Remove policies
|
||||
AuthorizeManager.removeAllPolicies(bContext, this);
|
||||
AuthorizeManager.removeAllPolicies(ourContext, this);
|
||||
|
||||
// Remove references to primary bitstreams in bundle
|
||||
String query = "update bundle set primary_bitstream_id = ";
|
||||
query += (oracle ? "''" : "Null") + " where primary_bitstream_id = ? ";
|
||||
DatabaseManager.updateQuery(bContext,
|
||||
DatabaseManager.updateQuery(ourContext,
|
||||
query, bRow.getIntColumn("bitstream_id"));
|
||||
|
||||
// Remove bitstream itself
|
||||
BitstreamStorageManager.delete(bContext, bRow
|
||||
BitstreamStorageManager.delete(ourContext, bRow
|
||||
.getIntColumn("bitstream_id"));
|
||||
|
||||
removeMetadataFromDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -568,7 +546,7 @@ public class Bitstream extends DSpaceObject
|
||||
boolean isDeleted() throws SQLException
|
||||
{
|
||||
String query = "select count(*) as mycount from Bitstream where deleted = '1' and bitstream_id = ? ";
|
||||
TableRowIterator tri = DatabaseManager.query(bContext, query, bRow.getIntColumn("bitstream_id"));
|
||||
TableRowIterator tri = DatabaseManager.query(ourContext, query, bRow.getIntColumn("bitstream_id"));
|
||||
long count = 0;
|
||||
|
||||
try
|
||||
@@ -600,9 +578,9 @@ public class Bitstream extends DSpaceObject
|
||||
AuthorizeException
|
||||
{
|
||||
// Maybe should return AuthorizeException??
|
||||
AuthorizeManager.authorizeAction(bContext, this, Constants.READ);
|
||||
AuthorizeManager.authorizeAction(ourContext, this, Constants.READ);
|
||||
|
||||
return BitstreamStorageManager.retrieve(bContext, bRow
|
||||
return BitstreamStorageManager.retrieve(ourContext, bRow
|
||||
.getIntColumn("bitstream_id"));
|
||||
}
|
||||
|
||||
@@ -615,11 +593,11 @@ public class Bitstream extends DSpaceObject
|
||||
public Bundle[] getBundles() throws SQLException
|
||||
{
|
||||
// Get the bundle table rows
|
||||
TableRowIterator tri = DatabaseManager.queryTable(bContext, "bundle",
|
||||
"SELECT bundle.* FROM bundle, bundle2bitstream WHERE " +
|
||||
"bundle.bundle_id=bundle2bitstream.bundle_id AND " +
|
||||
"bundle2bitstream.bitstream_id= ? ",
|
||||
bRow.getIntColumn("bitstream_id"));
|
||||
TableRowIterator tri = DatabaseManager.queryTable(ourContext, "bundle",
|
||||
"SELECT bundle.* FROM bundle, bundle2bitstream WHERE " +
|
||||
"bundle.bundle_id=bundle2bitstream.bundle_id AND " +
|
||||
"bundle2bitstream.bitstream_id= ? ",
|
||||
bRow.getIntColumn("bitstream_id"));
|
||||
|
||||
// Build a list of Bundle objects
|
||||
List<Bundle> bundles = new ArrayList<Bundle>();
|
||||
@@ -630,7 +608,7 @@ public class Bitstream extends DSpaceObject
|
||||
TableRow r = tri.next();
|
||||
|
||||
// First check the cache
|
||||
Bundle fromCache = (Bundle) bContext.fromCache(Bundle.class, r
|
||||
Bundle fromCache = (Bundle) ourContext.fromCache(Bundle.class, r
|
||||
.getIntColumn("bundle_id"));
|
||||
|
||||
if (fromCache != null)
|
||||
@@ -639,7 +617,7 @@ public class Bitstream extends DSpaceObject
|
||||
}
|
||||
else
|
||||
{
|
||||
bundles.add(new Bundle(bContext, r));
|
||||
bundles.add(new Bundle(ourContext, r));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -716,23 +694,23 @@ public class Bitstream extends DSpaceObject
|
||||
else
|
||||
{
|
||||
// is the bitstream a logo for a community or a collection?
|
||||
TableRow qResult = DatabaseManager.querySingle(bContext,
|
||||
TableRow qResult = DatabaseManager.querySingle(ourContext,
|
||||
"SELECT collection_id FROM collection " +
|
||||
"WHERE logo_bitstream_id = ?",getID());
|
||||
if (qResult != null)
|
||||
{
|
||||
return Collection.find(bContext,qResult.getIntColumn("collection_id"));
|
||||
return Collection.find(ourContext,qResult.getIntColumn("collection_id"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// is the bitstream related to a community?
|
||||
qResult = DatabaseManager.querySingle(bContext,
|
||||
qResult = DatabaseManager.querySingle(ourContext,
|
||||
"SELECT community_id FROM community " +
|
||||
"WHERE logo_bitstream_id = ?",getID());
|
||||
|
||||
if (qResult != null)
|
||||
{
|
||||
return Community.find(bContext,qResult.getIntColumn("community_id"));
|
||||
return Community.find(ourContext,qResult.getIntColumn("community_id"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -746,7 +724,6 @@ public class Bitstream extends DSpaceObject
|
||||
public void updateLastModified()
|
||||
{
|
||||
//Also fire a modified event since the bitstream HAS been modified
|
||||
bContext.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM, getID(),
|
||||
null, getIdentifiers(bContext)));
|
||||
ourContext.addEvent(new Event(Event.MODIFY, Constants.BITSTREAM, getID(), null, getIdentifiers(ourContext)));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user