Project

General

Profile

« Previous | Next » 

Revision 5320

Refactored metacat to use dataone-service-api-0.3.0 jar file, with the new JIBX generated types and serialization. Included JIBX runtime jar in metacat to handle serialization and deserialization of SystemMetadata objects. Removed the old API jar file.

View differences:

src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
22 22
 */
23 23
package edu.ucsb.nceas.metacat.restservice;
24 24

  
25
import java.io.BufferedReader;
26
import java.io.File;
27
import java.io.FileNotFoundException;
28
import java.io.FileOutputStream;
29 25
import java.io.IOException;
30 26
import java.io.InputStream;
31 27
import java.io.OutputStream;
......
54 50
import org.dataone.service.exceptions.ServiceFailure;
55 51
import org.dataone.service.exceptions.UnsupportedType;
56 52
import org.dataone.service.types.AuthToken;
57
import org.dataone.service.types.IdentifierType;
53
import org.dataone.service.types.Identifier;
58 54
import org.dataone.service.types.SystemMetadata;
59
import org.exolab.castor.jdo.conf.DataSource;
55
import org.jibx.runtime.BindingDirectory;
56
import org.jibx.runtime.IBindingFactory;
57
import org.jibx.runtime.IUnmarshallingContext;
58
import org.jibx.runtime.JiBXException;
60 59

  
61 60
import edu.ucsb.nceas.metacat.DBUtil;
62 61
import edu.ucsb.nceas.metacat.IdentifierManager;
......
470 469
        OutputStream out = null;
471 470
        try {
472 471
            out = response.getOutputStream();
473
            InputStream data = cs.get(token, new IdentifierType(guid));
472
            Identifier id = new Identifier();
473
            id.setValue(guid);
474
            InputStream data = cs.get(token, id);
474 475
            IOUtils.copyLarge(data, response.getOutputStream());
475 476
        } catch (BaseException e) {
476 477
                serializeException(e, out);
......
604 605
                    }
605 606
                }
606 607

  
608
                // TODO: access control!
607 609
                //if (username != null && !username.equals("public")) {
608 610
                if (username != null) {
609 611

  
610 612
                    logMetacat.debug("Commence creation...");
611 613
                    AuthToken token = null;
612
                    SystemMetadata m = new SystemMetadata(sysmeta);
613
                    logMetacat.debug(m.serialize(SystemMetadata.FMT_XML));
614
                    //IOUtils.copy(object, System.out);
615
//                    byte[] b = new byte[2048];
616
//                    int len = object.read(b);
617
//                    logMetacat.debug("Read " + len + " bytes from object: " + new String(b));
614
                    IBindingFactory bfact =
615
                        BindingDirectory.getFactory(SystemMetadata.class);
616
                    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
617
                    SystemMetadata m = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
618

  
618 619
                    CrudService cs = new CrudService(servletContext, request, response);
619
                    cs.create(token, new IdentifierType(guid), object, m);
620
                    Identifier id = new Identifier();
621
                    id.setValue(guid);
622
                    cs.create(token, id, object, m);
620 623

  
621 624
                } else {
622 625
                    logMetacat.debug("Unauthorized to create.");
......
649 652
        } catch (IOException e) {
650 653
            ServiceFailure sf = new ServiceFailure(1000, e.getMessage());
651 654
            serializeException(sf, out);
655
        } catch (JiBXException e) {
656
            e.printStackTrace(System.out);
657
            InvalidSystemMetadata ism = new InvalidSystemMetadata(1080, e.getMessage());
658
            serializeException(ism, out);
652 659
        }
653 660
    }
654 661

  
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
54 54
import org.dataone.service.types.AuthToken;
55 55
import org.dataone.service.types.Checksum;
56 56
import org.dataone.service.types.DescribeResponse;
57
import org.dataone.service.types.IdentifierType;
57
import org.dataone.service.types.Identifier;
58 58
import org.dataone.service.types.LogRecordSet;
59 59
import org.dataone.service.types.SystemMetadata;
60 60

  
......
173 173
        return sessionData;
174 174
    }
175 175
    
176
    public IdentifierType create(AuthToken token, IdentifierType guid, 
176
    public Identifier create(AuthToken token, Identifier guid, 
177 177
            InputStream object, SystemMetadata sysmeta) throws InvalidToken, 
178 178
            ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, 
179 179
            InsufficientResources, InvalidSystemMetadata, NotImplemented {
......
185 185
        String[] groups = null;
186 186

  
187 187
        // verify that guid == SystemMetadata.getIdentifier()
188
        logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getIdentifier() + "|" + sysmeta.getIdentifier().getIdentifier());
188
        logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
189 189
//        if (!guid.getIdentifier().equals(sysmeta.getIdentifier().getIdentifier())) {
190 190
//            throw new InvalidSystemMetadata(1180, 
191 191
//                "GUID in method call does not match GUID in system metadata.");
......
194 194
        logMetacat.debug("Checking if identifier exists...");
195 195
        // Check that the identifier does not already exist
196 196
        IdentifierManager im = IdentifierManager.getInstance();
197
        if (im.identifierExists(guid.getIdentifier())) {
197
        if (im.identifierExists(guid.getValue())) {
198 198
            throw new IdentifierNotUnique(1120, 
199 199
                "GUID is already in use by an existing object.");
200 200
        }
201 201

  
202 202
        // generate guid/localId pair for object
203 203
        logMetacat.debug("Generating a guid/localId mapping");
204
        String localId = im.generateLocalId(guid.getIdentifier(), 1);
204
        String localId = im.generateLocalId(guid.getValue(), 1);
205 205

  
206 206
        // TODO: generate guid/localId pair for sysmeta
207 207
        // TODO: update system metadata fields
......
285 285
        return guid;
286 286
    }
287 287

  
288
    public IdentifierType delete(AuthToken token, IdentifierType guid)
288
    public Identifier delete(AuthToken token, Identifier guid)
289 289
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
290 290
            NotImplemented {
291 291
        throw new NotImplemented(1000, "This method not yet implemented.");
292 292
    }
293 293

  
294
    public DescribeResponse describe(AuthToken token, IdentifierType guid)
294
    public DescribeResponse describe(AuthToken token, Identifier guid)
295 295
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
296 296
            NotImplemented {
297 297
        throw new NotImplemented(1000, "This method not yet implemented.");
298 298
    }
299 299
    
300
    public InputStream get(AuthToken token, IdentifierType guid)
300
    public InputStream get(AuthToken token, Identifier guid)
301 301
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
302 302
            NotImplemented {
303 303
        
......
308 308
        // Look up the localId for this global identifier
309 309
        IdentifierManager im = IdentifierManager.getInstance();
310 310
        try {
311
            final String localId = im.getLocalId(guid.getIdentifier());
311
            final String localId = im.getLocalId(guid.getValue());
312 312

  
313 313
            final InputStreamFromOutputStream<String> objectStream = 
314 314
                new InputStreamFromOutputStream<String>() {
......
392 392
*/
393 393
    }
394 394

  
395
    public Checksum getChecksum(AuthToken token, IdentifierType guid)
395
    public Checksum getChecksum(AuthToken token, Identifier guid)
396 396
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
397 397
            InvalidRequest, NotImplemented {
398 398
        throw new NotImplemented(1000, "This method not yet implemented.");
399 399
    }
400 400

  
401
    public Checksum getChecksum(AuthToken token, IdentifierType guid, 
401
    public Checksum getChecksum(AuthToken token, Identifier guid, 
402 402
            String checksumAlgorithm) throws InvalidToken, ServiceFailure, 
403 403
            NotAuthorized, NotFound, InvalidRequest, NotImplemented {
404 404
        throw new NotImplemented(1000, "This method not yet implemented.");
......
410 410
        throw new NotImplemented(1000, "This method not yet implemented.");
411 411
    }
412 412

  
413
    public SystemMetadata getSystemMetadata(AuthToken token, IdentifierType guid)
413
    public SystemMetadata getSystemMetadata(AuthToken token, Identifier guid)
414 414
            throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
415 415
            InvalidRequest, NotImplemented {
416 416
        
......
424 424
        throw new NotImplemented(1000, "This method not yet implemented.");
425 425
    }
426 426

  
427
    public IdentifierType update(AuthToken token, IdentifierType guid, 
428
            InputStream object, IdentifierType obsoletedGuid, SystemMetadata sysmeta) 
427
    public Identifier update(AuthToken token, Identifier guid, 
428
            InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) 
429 429
            throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
430 430
            UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, 
431 431
            NotImplemented {
build.xml
1554 1554
         sibling of the current build directory. Requires maven2 to
1555 1555
         be installed and on the path. -->
1556 1556
    <target name="dataone-service" if="d1.available">
1557
        <property name="d1.jar" value="dataone-service-api-0.1.0.jar"/>
1557
        <property name="d1.jar" value="dataone-service-api-0.3.0.jar"/>
1558 1558

  
1559 1559
        <artifact:mvn pom="${d1.dir}/pom.xml" fork="true"
1560 1560
                      mavenHome="${maven.home}">

Also available in: Unified diff