Project

General

Profile

« Previous | Next » 

Revision 6469

use d1_common_java's date serialization utility for parsing parameters

View differences:

src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
72 72
import org.dataone.service.types.v1.Permission;
73 73
import org.dataone.service.types.v1.Subject;
74 74
import org.dataone.service.types.v1.SystemMetadata;
75
import org.dataone.service.util.DateTimeMarshaller;
75 76
import org.dataone.service.util.TypeMarshaller;
76 77
import org.jibx.runtime.JiBXException;
77 78

  
......
600 601
        try {
601 602
        	String fromDateS = params.get("fromDate")[0];
602 603
            logMetacat.debug("param fromDateS: " + fromDateS);
603
            fromDate = parseDateAndConvertToGMT(fromDateS);
604
            fromDate = DateTimeMarshaller.deserializeDateToUTC(fromDateS);
604 605
        } catch (Exception e) {
605 606
        	logMetacat.warn("Could not parse fromDate: " + e.getMessage());
606 607
        }
607 608
        try {
608 609
        	String toDateS = params.get("toDate")[0];
609 610
            logMetacat.debug("param toDateS: " + toDateS);
610
            toDate = parseDateAndConvertToGMT(toDateS);
611
            toDate = DateTimeMarshaller.deserializeDateToUTC(toDateS);
611 612
        } catch (Exception e) {
612 613
        	logMetacat.warn("Could not parse toDate: " + e.getMessage());
613 614
		}
......
712 713
                    try
713 714
                    {
714 715
                      //startTime = dateFormat.parse(value[0]);
715
                        startTime = parseDateAndConvertToGMT(value[0]);
716
                    	startTime = DateTimeMarshaller.deserializeDateToUTC(value[0]);
717
                        //startTime = parseDateAndConvertToGMT(value[0]);
716 718
                    }
717 719
                    catch(Exception e)
718 720
                    {  //if we can't parse it, just don't use the startTime param
......
725 727
                    try
726 728
                    {
727 729
                      //endTime = dateFormat.parse(value[0]);
728
                        endTime = parseDateAndConvertToGMT(value[0]);
730
                    	endTime = DateTimeMarshaller.deserializeDateToUTC(value[0]);
731
                        //endTime = parseDateAndConvertToGMT(value[0]);
729 732
                    }
730 733
                    catch(Exception e)
731 734
                    {  //if we can't parse it, just don't use the endTime param
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
62 62
import org.dataone.service.types.v1.Permission;
63 63
import org.dataone.service.types.v1.Subject;
64 64
import org.dataone.service.types.v1.SystemMetadata;
65
import org.dataone.service.util.DateTimeMarshaller;
65 66
import org.dataone.service.util.TypeMarshaller;
66 67
import org.jibx.runtime.JiBXException;
67 68

  
......
376 377
        try {
377 378
        	String fromDateS = params.get("fromDate")[0];
378 379
            logMetacat.debug("param fromDateS: " + fromDateS);
379
            fromDate = parseDateAndConvertToGMT(fromDateS);
380
            fromDate = DateTimeMarshaller.deserializeDateToUTC(fromDateS);
380 381
        } catch (Exception e) {
381 382
        	logMetacat.warn("Could not parse fromDate: " + e.getMessage());
382 383
        }
383 384
        try {
384 385
        	String toDateS = params.get("toDate")[0];
385 386
            logMetacat.debug("param toDateS: " + toDateS);
386
            toDate = parseDateAndConvertToGMT(toDateS);
387
            toDate = DateTimeMarshaller.deserializeDateToUTC(toDateS);
387 388
        } catch (Exception e) {
388 389
        	logMetacat.warn("Could not parse toDate: " + e.getMessage());
389 390
		}
src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java
99 99
     */
100 100
    protected static final String FUNCTION_NAME_INSERT = "insert";
101 101
    protected static final String FUNCTION_NAME_UPDATE = "update";
102

  
103
    protected static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
104 102
    
105 103
    protected ServletContext servletContext;
106 104
    protected Logger logMetacat;
......
314 312
            params.put(name, value);
315 313
        }
316 314
    }
317

  
315
   
318 316
    /**
319
     * parse a date and return it in GMT if it ends with a 'Z'
320
     * @param date
321
     * @return
322
     * @throws ParseException
323
     */
324
    protected Date parseDateAndConvertToGMT(String date) throws ParseException
325
    {
326
        try
327
        {   //the format we want
328
            return dateFormat.parse(date);
329
        }
330
        catch(java.text.ParseException pe)
331
        {   //try another legacy format
332
            DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
333
            dateFormat2.setTimeZone(TimeZone.getTimeZone("GMT-0"));
334
            return dateFormat2.parse(date);
335
        }    
336
    }
337

  
338
        
339
    /**
340 317
     * locate the boundary marker for an MMP
341 318
     * @param is
342 319
     * @return

Also available in: Unified diff