/*
 */
package org.datadryad.api;

import java.sql.SQLException;
import org.dspace.content.Collection;
import org.dspace.content.DCValue;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.doi.DOI;
import org.dspace.handle.HandleManager;
import org.dspace.identifier.DOIIdentifierProvider;

/**
 *
 * @author Dan Leehr <dan.leehr@nescent.org>
 */
public abstract class DryadObject {
    private static final String PUBLICATION_NAME_SCHEMA = "prism";
    private static final String PUBLICATION_NAME_ELEMENT = "publicationName";
    private static final String PUBLICATION_NAME_QUALIFIER = Item.ANY;

    protected WorkspaceItem workspaceItem;
    protected DryadObject(WorkspaceItem workspaceItem) {
        this.workspaceItem = workspaceItem;
    }
    protected static Collection collectionFromHandle(Context context, String handle) throws SQLException {
        DSpaceObject object = HandleManager.resolveToObject(context, handle);
        if(object.getType() == Constants.COLLECTION) {
            return (Collection)object;
        } else {
            return null;
        }
    }

    public WorkspaceItem getWorkspaceItem() {
        return workspaceItem;
    }

    public Item getItem() {
        if(workspaceItem != null) {
            return workspaceItem.getItem();
        }
        return null;
    }

    public String getIdentifier() {
        return DOIIdentifierProvider.getDoiValue(getItem());
    }

    public void setPublicationName(String publicationName) {
        getItem().clearMetadata(PUBLICATION_NAME_SCHEMA, PUBLICATION_NAME_ELEMENT, PUBLICATION_NAME_QUALIFIER, null);
        getItem().addMetadata(PUBLICATION_NAME_SCHEMA, PUBLICATION_NAME_ELEMENT, PUBLICATION_NAME_QUALIFIER, null, publicationName);
    }

}

@@ -44,15 +44,123 @@
 ava.
-sql.SQL
+io.IOException;%0Aimport java.sql.SQLException;%0Aimport org.apache.log4j.Logger;%0Aimport org.dspace.authorize.Authorize
 Exce
@@ -208,43 +208,8 @@
 on;%0A
-import org.dspace.content.DCValue;%0A
 impo
@@ -321,53 +321,8 @@
 em;%0A
-import org.dspace.core.ConfigurationManager;%0A
 impo
@@ -387,35 +387,8 @@
 xt;%0A
-import org.dspace.doi.DOI;%0A
 impo
@@ -778,16 +778,81 @@
 R = 
-Item.ANY
+null;%0A    private static Logger log = Logger.getLogger(DryadObject.class)
 ;%0A%0A 
@@ -1729,16 +1729,36 @@
 ionName)
+ throws SQLException
  %7B%0A     
@@ -1870,16 +1870,16 @@
  null);%0A
-
         
@@ -1999,21 +1999,306 @@
 ationName);%0A
+        try %7B%0A            getWorkspaceItem().update();%0A        %7D catch (AuthorizeException ex) %7B%0A            log.error(%22Authorize exception setting publication name%22, ex);%0A        %7D catch (IOException ex) %7B%0A            log.error(%22IO exception setting publication name%22, ex);%0A        %7D%0A
     %7D%0A%0A%7D%0A

Call Update after setting publicationName