Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: leinfelder $'
7
 *     '$Date: 2011-06-07 12:08:45 -0700 (Tue, 07 Jun 2011) $'
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 */
23
package edu.ucsb.nceas.metacat.dataone;
24

    
25
import java.io.InputStream;
26
import java.util.Date;
27

    
28
import org.apache.log4j.Logger;
29
import org.dataone.service.cn.CNCore;
30
import org.dataone.service.exceptions.IdentifierNotUnique;
31
import org.dataone.service.exceptions.InsufficientResources;
32
import org.dataone.service.exceptions.InvalidRequest;
33
import org.dataone.service.exceptions.InvalidSystemMetadata;
34
import org.dataone.service.exceptions.InvalidToken;
35
import org.dataone.service.exceptions.NotAuthorized;
36
import org.dataone.service.exceptions.NotFound;
37
import org.dataone.service.exceptions.NotImplemented;
38
import org.dataone.service.exceptions.ServiceFailure;
39
import org.dataone.service.exceptions.UnsupportedType;
40
import org.dataone.service.types.Event;
41
import org.dataone.service.types.Identifier;
42
import org.dataone.service.types.Log;
43
import org.dataone.service.types.NodeList;
44
import org.dataone.service.types.ObjectFormat;
45
import org.dataone.service.types.ObjectFormatIdentifier;
46
import org.dataone.service.types.ObjectFormatList;
47
import org.dataone.service.types.Session;
48
import org.dataone.service.types.SystemMetadata;
49

    
50
import edu.ucsb.nceas.metacat.EventLog;
51
import edu.ucsb.nceas.metacat.IdentifierManager;
52
import edu.ucsb.nceas.metacat.replication.ForceReplicationSystemMetadataHandler;
53

    
54
/**
55
 * 
56
 * Implements DataONE CNCore services for Metacat. 
57
 * 
58
 * @author leinfelder
59
 */
60
public class CNCoreImpl implements CNCore
61
{
62
    private static CNCoreImpl instance = null;
63

    
64
    private Logger logMetacat = null;
65
        
66
    /**
67
     * singleton accessor
68
     */
69
    public static CNCoreImpl getInstance() 
70
    {
71
      if (instance == null) {
72
        instance = new CNCoreImpl();
73
      }
74
      
75
      return instance;
76
    }
77
    
78
    /**
79
     * Constructor, private for singleton access
80
     */
81
    private CNCoreImpl() {
82
        logMetacat = Logger.getLogger(CNCoreImpl.class);
83
        
84
    }
85
    
86
    /**
87
     * register System Metadata without data/metadata object
88
     */
89
    @Override
90
    public boolean registerSystemMetaData(Session session, Identifier guid,
91
            SystemMetadata sysmeta) throws NotImplemented, NotAuthorized,
92
            ServiceFailure, InvalidRequest {
93
        logMetacat.debug("Starting CrudService.create()...");
94
        
95
        // TODO: control who can call this?
96
        if (session == null) {
97
            //TODO: many of the thrown exceptions do not use the correct error codes
98
            //check these against the docs and correct them
99
            throw new NotAuthorized("4861", "No Session - could not authorize to registration." +
100
                    "  If you are not logged in, please do so and retry the request.");
101
        }
102
        
103
        // verify that guid == SystemMetadata.getIdentifier()
104
        logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
105
        if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
106
            throw new InvalidRequest("4863", 
107
                "GUID in method call (" + guid.getValue() + ") does not match GUID in system metadata (" +
108
                sysmeta.getIdentifier().getValue() + ").");
109
        }
110

    
111
        logMetacat.debug("Checking if identifier exists...");
112
        // Check that the identifier does not already exist
113
        IdentifierManager im = IdentifierManager.getInstance();
114
        if (im.identifierExists(guid.getValue())) {
115
            throw new InvalidRequest("4863", 
116
                "GUID is already in use by an existing object.");
117
        }
118

    
119
        // insert the system metadata into the object store
120
        logMetacat.debug("Starting to insert SystemMetadata...");
121
        sysmeta.setDateSysMetadataModified(new Date());
122
        try {
123
			IdentifierManager.getInstance().createSystemMetadata(sysmeta);
124
			IdentifierManager.getInstance().updateSystemMetadata(sysmeta);
125
			// force replication of this record
126
			ForceReplicationSystemMetadataHandler forceReplication = new ForceReplicationSystemMetadataHandler(guid.getValue(), null);
127
		} catch (Exception e) {
128
            throw new ServiceFailure("4862", "Error inserting system metadata: " + e.getClass() + ": " + e.getMessage());
129
		}
130
        
131
        logMetacat.debug("Returning from registerSystemMetadata");
132
        EventLog.getInstance().log(null, session.getSubject().getValue(), guid.getValue(), "registerSystemMetadata");
133
        return true;
134
    }
135

    
136

    
137
  @Override
138
  public Log getLogRecords(Session arg0, Date arg1, Date arg2,
139
    Event arg3) throws InvalidToken, InvalidRequest, ServiceFailure,
140
    NotAuthorized, NotImplemented {
141
  	  // TODO Auto-generated method stub
142
  	  return null;
143
    }
144
   @Override
145
	 public ObjectFormat getFormat(ObjectFormatIdentifier arg0) 
146
	   throws InvalidRequest, ServiceFailure, NotFound, InsufficientResources, 
147
	   NotImplemented {
148
		 // TODO Auto-generated method stub
149
		 return null;
150
	}
151

    
152
	@Override
153
	public NodeList listNodes() throws NotImplemented, ServiceFailure {
154
		// TODO Auto-generated method stub
155
		return null;
156
	}
157

    
158
	@Override
159
  public ObjectFormatList listFormats() throws InvalidRequest, ServiceFailure,
160
    NotFound, InsufficientResources, NotImplemented {
161
	  // TODO Auto-generated method stub
162
	  return null;
163
  }
164

    
165
	@Override
166
	public Identifier create(Session arg0, Identifier arg1, InputStream arg2,
167
			SystemMetadata arg3) throws InvalidToken, ServiceFailure,
168
			NotAuthorized, IdentifierNotUnique, UnsupportedType,
169
			InsufficientResources, InvalidSystemMetadata, NotImplemented,
170
			InvalidRequest {
171
		// TODO Auto-generated method stub
172
		return null;
173
	}
174

    
175
	@Override
176
	public Identifier reserveIdentifier(Session arg0, Identifier arg1,
177
			String arg2, String arg3) throws InvalidToken, ServiceFailure,
178
			NotAuthorized, IdentifierNotUnique, NotImplemented, InvalidRequest {
179
		// TODO Auto-generated method stub
180
		return null;
181
	}
182

    
183
}
184

    
(1-1/5)