Support Metadata On All DSpaceObjects

This commit is contained in:
KevinVdV
2014-09-24 16:16:06 +02:00
parent ca090a8e8a
commit 87cd7145c9
63 changed files with 2721 additions and 1683 deletions

View File

@@ -57,9 +57,6 @@ public class Collection extends DSpaceObject
/** log4j category */
private static Logger log = Logger.getLogger(Collection.class);
/** Our context */
private Context ourContext;
/** The table row corresponding to this item */
private TableRow collectionRow;
@@ -75,9 +72,6 @@ public class Collection extends DSpaceObject
/** Flag set when data is modified, for events */
private boolean modified;
/** Flag set when metadata is modified, for events */
private boolean modifiedMetadata;
/**
* Groups corresponding to workflow steps - NOTE these start from one, so
* workflowGroups[0] corresponds to workflow_step_1.
@@ -108,7 +102,7 @@ public class Collection extends DSpaceObject
*/
Collection(Context context, TableRow row) throws SQLException
{
ourContext = context;
super(context);
collectionRow = row;
// Get the logo bitstream
@@ -150,7 +144,6 @@ public class Collection extends DSpaceObject
context.cache(this, row.getIntColumn("collection_id"));
modified = false;
modifiedMetadata = false;
clearDetails();
}
@@ -299,10 +292,26 @@ public class Collection extends DSpaceObject
* @return the collections in the system
* @throws SQLException
*/
public static Collection[] findAll(Context context) throws SQLException
{
TableRowIterator tri = DatabaseManager.queryTable(context, "collection",
"SELECT * FROM collection ORDER BY name");
public static Collection[] findAll(Context context) throws SQLException {
TableRowIterator tri = null;
try {
String query = "SELECT c.* FROM collection c " +
"LEFT JOIN metadatavalue m on (m.resource_id = c.collection_id and m.resource_type_id = ? and m.metadata_field_id = ?) ";
if(DatabaseManager.isOracle()){
query += " ORDER BY cast(m.text_value as varchar2(128))";
}else{
query += " ORDER BY m.text_value";
}
tri = DatabaseManager.query(context,
query,
Constants.COLLECTION,
MetadataField.findByElement(context, MetadataSchema.find(context, MetadataSchema.DC_SCHEMA).getSchemaID(), "title", null).getFieldID()
);
} catch (SQLException e) {
log.error("Find all Collections - ",e);
throw e;
}
List<Collection> collections = new ArrayList<Collection>();
@@ -351,9 +360,28 @@ public class Collection extends DSpaceObject
*/
public static Collection[] findAll(Context context, Integer limit, Integer offset) throws SQLException
{
TableRowIterator tri = DatabaseManager.queryTable(context, "collection",
"SELECT * FROM collection ORDER BY name limit ? offset ?", limit, offset);
TableRowIterator tri = null;
try{
String query = "SELECT c.* FROM collection c " +
"LEFT JOIN metadatavalue m on (m.resource_id = c.collection_id and m.resource_type_id = ? and m.metadata_field_id = ?) ";
if(DatabaseManager.isOracle()){
query += " ORDER BY cast(m.text_value as varchar2(128))";
}else{
query += " ORDER BY m.text_value";
}
query += " limit ? offset ?";
tri = DatabaseManager.query(context,
query,
Constants.COLLECTION,
MetadataField.findByElement(context, MetadataSchema.find(context, MetadataSchema.DC_SCHEMA).getSchemaID(), "title", null).getFieldID(),
limit,
offset
);
} catch (SQLException e) {
log.error("Find all Collections offset/limit - ",e);
throw e;
}
List<Collection> collections = new ArrayList<Collection>();
try
@@ -486,10 +514,12 @@ public class Collection extends DSpaceObject
* @exception IllegalArgumentException
* if the requested metadata field doesn't exist
*/
@Deprecated
public String getMetadata(String field)
{
String metadata = collectionRow.getStringColumn(field);
return (metadata == null) ? "" : metadata;
String[] MDValue = getMDValueByLegacyField(field);
String value = getMetadataFirstValue(MDValue[0], MDValue[1], MDValue[2], Item.ANY);
return value == null ? "" : value;
}
/**
@@ -504,10 +534,9 @@ public class Collection extends DSpaceObject
* if the requested metadata field doesn't exist
* @exception MissingResourceException
*/
public void setMetadata(String field, String value) throws MissingResourceException
{
if ((field.trim()).equals("name")
&& (value == null || value.trim().equals("")))
@Deprecated
public void setMetadata(String field, String value) throws MissingResourceException {
if ((field.trim()).equals("name") && (value == null || value.trim().equals("")))
{
try
{
@@ -519,6 +548,8 @@ public class Collection extends DSpaceObject
}
}
String[] MDValue = getMDValueByLegacyField(field);
/*
* Set metadata field to null if null
* and trim strings to eliminate excess
@@ -526,20 +557,21 @@ public class Collection extends DSpaceObject
*/
if(value == null)
{
collectionRow.setColumnNull(field);
clearMetadata(MDValue[0], MDValue[1], MDValue[2], Item.ANY);
modifiedMetadata = true;
}
else
{
collectionRow.setColumn(field, value.trim());
setMetadataSingleValue(MDValue[0], MDValue[1], MDValue[2], null, value);
}
modifiedMetadata = true;
addDetails(field);
}
public String getName()
{
return getMetadata("name");
String value = getMetadataFirstValue(MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
return value == null ? "" : value;
}
/**
@@ -893,8 +925,7 @@ public class Collection extends DSpaceObject
* @param license
* the license, or <code>null</code>
*/
public void setLicense(String license)
{
public void setLicense(String license) {
setMetadata("license",license);
}
@@ -1072,10 +1103,7 @@ public class Collection extends DSpaceObject
}
if (modifiedMetadata)
{
ourContext.addEvent(new Event(Event.MODIFY_METADATA,
Constants.COLLECTION, getID(), getDetails(),
getIdentifiers(ourContext)));
modifiedMetadata = false;
updateMetadata();
clearDetails();
}
}
@@ -1306,6 +1334,8 @@ public class Collection extends DSpaceObject
{
g.delete();
}
removeMetadataFromDatabase();
}
/**