Fix dspace-api module per new code style

This commit is contained in:
Tim Donohue
2018-02-14 10:53:46 -06:00
parent 8ffc97f7f9
commit 8a48f782ea
1051 changed files with 53347 additions and 63373 deletions

View File

@@ -15,7 +15,10 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.*;
import org.dspace.content.DCDate;
import org.dspace.content.Item;
import org.dspace.content.MetadataSchema;
import org.dspace.content.MetadataValue;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.core.service.PluginService;
@@ -28,24 +31,26 @@ import org.springframework.beans.factory.annotation.Autowired;
* <p>
* Configuration properties: (with examples)
* {@code
* # DC metadata field to hold the user-supplied embargo terms
* embargo.field.terms = dc.embargo.terms
* # DC metadata field to hold computed "lift date" of embargo
* embargo.field.lift = dc.date.available
* # String to indicate indefinite (forever) embargo in terms
* embargo.terms.open = Indefinite
* # implementation of embargo setter plugin
* plugin.single.org.dspace.embargo.EmbargoSetter = edu.my.Setter
* # implementation of embargo lifter plugin
* plugin.single.org.dspace.embargo.EmbargoLifter = edu.my.Lifter
* # DC metadata field to hold the user-supplied embargo terms
* embargo.field.terms = dc.embargo.terms
* # DC metadata field to hold computed "lift date" of embargo
* embargo.field.lift = dc.date.available
* # String to indicate indefinite (forever) embargo in terms
* embargo.terms.open = Indefinite
* # implementation of embargo setter plugin
* plugin.single.org.dspace.embargo.EmbargoSetter = edu.my.Setter
* # implementation of embargo lifter plugin
* plugin.single.org.dspace.embargo.EmbargoLifter = edu.my.Lifter
* }
*
* @author Larry Stone
* @author Richard Rodgers
*/
public class EmbargoServiceImpl implements EmbargoService
{
public class EmbargoServiceImpl implements EmbargoService {
/** log4j category */
/**
* log4j category
*/
private final Logger log = Logger.getLogger(EmbargoServiceImpl.class);
// Metadata field components for user-supplied embargo terms
@@ -74,72 +79,65 @@ public class EmbargoServiceImpl implements EmbargoService
@Autowired(required = true)
protected PluginService pluginService;
protected EmbargoServiceImpl()
{
protected EmbargoServiceImpl() {
}
@Override
public void setEmbargo(Context context, Item item)
throws SQLException, AuthorizeException
{
throws SQLException, AuthorizeException {
// if lift is null, we might be restoring an item from an AIP
DCDate myLift = getEmbargoTermsAsDate(context, item);
if (myLift == null)
{
if ((myLift = recoverEmbargoDate(item)) == null)
{
return;
}
if (myLift == null) {
if ((myLift = recoverEmbargoDate(item)) == null) {
return;
}
}
String slift = myLift.toString();
try
{
try {
context.turnOffAuthorisationSystem();
itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY);
itemService.addMetadata(context, item, lift_schema, lift_element, lift_qualifier, null, slift);
log.info("Set embargo on Item "+item.getHandle()+", expires on: "+slift);
log.info("Set embargo on Item " + item.getHandle() + ", expires on: " + slift);
setter.setEmbargo(context, item);
itemService.update(context, item);
}
finally
{
} finally {
context.restoreAuthSystemState();
}
}
@Override
public DCDate getEmbargoTermsAsDate(Context context, Item item)
throws SQLException, AuthorizeException
{
throws SQLException, AuthorizeException {
List<MetadataValue> terms = itemService.getMetadata(item, terms_schema, terms_element,
terms_qualifier, Item.ANY);
terms_qualifier, Item.ANY);
DCDate result = null;
// Its poor form to blindly use an object that could be null...
if (terms == null)
if (terms == null) {
return null;
}
result = setter.parseTerms(context, item,
terms.size() > 0 ? terms.get(0).getValue() : null);
terms.size() > 0 ? terms.get(0).getValue() : null);
if (result == null)
if (result == null) {
return null;
}
// new DCDate(non-date String) means toDate() will return null
Date liftDate = result.toDate();
if (liftDate == null)
{
if (liftDate == null) {
throw new IllegalArgumentException(
"Embargo lift date is uninterpretable: "
+ result.toString());
"Embargo lift date is uninterpretable: "
+ result.toString());
}
/*
* NOTE: We do not check here for past dates as it can result in errors during AIP restoration.
* NOTE: We do not check here for past dates as it can result in errors during AIP restoration.
* Therefore, UIs should perform any such date validation on input. See DS-3348
*/
return result;
@@ -148,17 +146,17 @@ public class EmbargoServiceImpl implements EmbargoService
@Override
public void liftEmbargo(Context context, Item item)
throws SQLException, AuthorizeException, IOException
{
throws SQLException, AuthorizeException, IOException {
// new version of Embargo policies remain in place.
//lifter.liftEmbargo(context, item);
itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY);
// set the dc.date.available value to right now
itemService.clearMetadata(context, item, MetadataSchema.DC_SCHEMA, "date", "available", Item.ANY);
itemService.addMetadata(context, item, MetadataSchema.DC_SCHEMA, "date", "available", null, DCDate.getCurrent().toString());
itemService.addMetadata(context, item, MetadataSchema.DC_SCHEMA, "date", "available", null,
DCDate.getCurrent().toString());
log.info("Lifting embargo on Item "+item.getHandle());
log.info("Lifting embargo on Item " + item.getHandle());
itemService.update(context, item);
}
@@ -171,15 +169,14 @@ public class EmbargoServiceImpl implements EmbargoService
*
* @throws Exception on generic exception
*/
public void init() throws Exception
{
if (terms_schema == null)
{
public void init() throws Exception {
if (terms_schema == null) {
String terms = configurationService.getProperty("embargo.field.terms");
String lift = configurationService.getProperty("embargo.field.lift");
if (terms == null || lift == null)
{
throw new IllegalStateException("Missing one or more of the required DSpace configuration properties for EmbargoManager, check your configuration file.");
if (terms == null || lift == null) {
throw new IllegalStateException(
"Missing one or more of the required DSpace configuration properties for EmbargoManager, check " +
"your configuration file.");
}
terms_schema = getSchemaOf(terms);
terms_element = getElementOf(terms);
@@ -188,36 +185,31 @@ public class EmbargoServiceImpl implements EmbargoService
lift_element = getElementOf(lift);
lift_qualifier = getQualifierOf(lift);
setter = (EmbargoSetter)pluginService.getSinglePlugin(EmbargoSetter.class);
if (setter == null)
{
setter = (EmbargoSetter) pluginService.getSinglePlugin(EmbargoSetter.class);
if (setter == null) {
throw new IllegalStateException("The EmbargoSetter plugin was not defined in DSpace configuration.");
}
lifter = (EmbargoLifter)pluginService.getSinglePlugin(EmbargoLifter.class);
if (lifter == null)
{
lifter = (EmbargoLifter) pluginService.getSinglePlugin(EmbargoLifter.class);
if (lifter == null) {
throw new IllegalStateException("The EmbargoLifter plugin was not defined in DSpace configuration.");
}
}
}
// return the schema part of "schema.element.qualifier" metadata field spec
protected String getSchemaOf(String field)
{
protected String getSchemaOf(String field) {
String sa[] = field.split("\\.", 3);
return sa[0];
}
// return the element part of "schema.element.qualifier" metadata field spec, if any
protected String getElementOf(String field)
{
protected String getElementOf(String field) {
String sa[] = field.split("\\.", 3);
return sa.length > 1 ? sa[1] : null;
}
// return the qualifier part of "schema.element.qualifier" metadata field spec, if any
protected String getQualifierOf(String field)
{
protected String getQualifierOf(String field) {
String sa[] = field.split("\\.", 3);
return sa.length > 2 ? sa[2] : null;
}
@@ -227,12 +219,10 @@ public class EmbargoServiceImpl implements EmbargoService
protected DCDate recoverEmbargoDate(Item item) {
DCDate liftDate = null;
List<MetadataValue> lift = itemService.getMetadata(item, lift_schema, lift_element, lift_qualifier, Item.ANY);
if (lift.size() > 0)
{
if (lift.size() > 0) {
liftDate = new DCDate(lift.get(0).getValue());
// sanity check: do not allow an embargo lift date in the past.
if (liftDate.toDate().before(new Date()))
{
if (liftDate.toDate().before(new Date())) {
liftDate = null;
}
}
@@ -245,13 +235,13 @@ public class EmbargoServiceImpl implements EmbargoService
}
@Override
public List<MetadataValue> getLiftMetadata(Context context, Item item)
{
public List<MetadataValue> getLiftMetadata(Context context, Item item) {
return itemService.getMetadata(item, lift_schema, lift_element, lift_qualifier, Item.ANY);
}
@Override
public Iterator<Item> findItemsByLiftMetadata(Context context) throws SQLException, IOException, AuthorizeException {
public Iterator<Item> findItemsByLiftMetadata(Context context)
throws SQLException, IOException, AuthorizeException {
return itemService.findByMetadataField(context, lift_schema, lift_element, lift_qualifier, Item.ANY);
}
}