Revision 5428
Added by berkley over 14 years ago
test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java | ||
---|---|---|
53 | 53 |
import edu.ucsb.nceas.metacat.service.SessionService; |
54 | 54 |
import edu.ucsb.nceas.metacat.util.SessionData; |
55 | 55 |
|
56 |
import com.gc.iotools.stream.is.InputStreamFromOutputStream; |
|
57 |
|
|
56 | 58 |
/** |
57 | 59 |
* A JUnit test for testing the dataone CrudService class |
58 | 60 |
*/ |
... | ... | |
87 | 89 |
public static Test suite() |
88 | 90 |
{ |
89 | 91 |
TestSuite suite = new TestSuite(); |
90 |
/*suite.addTest(new CrudServiceTest("initialize"));
|
|
92 |
suite.addTest(new CrudServiceTest("initialize")); |
|
91 | 93 |
suite.addTest(new CrudServiceTest("testSingletonAccessor")); |
92 | 94 |
suite.addTest(new CrudServiceTest("testCreateAndGet")); |
93 | 95 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata")); |
94 |
suite.addTest(new CrudServiceTest("testUpdate"));*/
|
|
96 |
suite.addTest(new CrudServiceTest("testUpdate")); |
|
95 | 97 |
suite.addTest(new CrudServiceTest("testListObjects")); |
96 |
/*suite.addTest(new CrudServiceTest("testAccessControl"));
|
|
98 |
suite.addTest(new CrudServiceTest("testAccessControl")); |
|
97 | 99 |
suite.addTest(new CrudServiceTest("testGenerateMissingSystemMetadata")); |
98 | 100 |
suite.addTest(new CrudServiceTest("testGetLogRecords")); |
99 | 101 |
suite.addTest(new CrudServiceTest("testChecksumError")); |
100 |
suite.addTest(new CrudServiceTest("testPublicAccess"));*/
|
|
102 |
suite.addTest(new CrudServiceTest("testPublicAccess")); |
|
101 | 103 |
return suite; |
102 | 104 |
} |
103 | 105 |
|
... | ... | |
156 | 158 |
{ |
157 | 159 |
AuthToken publicToken = new AuthToken("public"); |
158 | 160 |
data = cs.get(publicToken, id); |
161 |
data.read(); |
|
162 |
|
|
159 | 163 |
fail("should have thrown an exception"); |
160 | 164 |
} |
161 | 165 |
catch(Exception e) |
162 | 166 |
{ |
163 |
data.close(); |
|
164 |
|
|
167 |
/*System.out.println("%%%%%%%%%%%%%%%%%%%%%%%getting result"); |
|
168 |
Object o = ((InputStreamFromOutputStream)data).getResult(); |
|
169 |
System.out.println("result: " + o); |
|
170 |
System.out.println("exception thrown!"); |
|
171 |
System.out.println("exception thrown: " + e.getClass().getName());*/ |
|
165 | 172 |
} |
173 |
|
|
174 |
|
|
175 |
|
|
166 | 176 |
makeDocPublic(token, id, true); |
167 | 177 |
token = new AuthToken("public"); |
168 | 178 |
data = cs.get(token, id); |
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java | ||
---|---|---|
32 | 32 |
import javax.servlet.http.HttpServletRequest; |
33 | 33 |
import javax.servlet.http.HttpServletResponse; |
34 | 34 |
import java.text.DateFormat; |
35 |
import java.text.ParseException; |
|
35 | 36 |
import java.text.ParsePosition; |
36 | 37 |
import java.text.SimpleDateFormat; |
37 | 38 |
|
... | ... | |
212 | 213 |
private static final String FUNCTION_NAME_UPDATE = "update"; |
213 | 214 |
private static final String FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA = "generatemissingsystemmetadata"; |
214 | 215 |
|
215 |
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
|
216 |
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
|
216 | 217 |
|
217 | 218 |
private ServletContext servletContext; |
218 | 219 |
private Logger logMetacat; |
... | ... | |
690 | 691 |
{ |
691 | 692 |
try |
692 | 693 |
{ |
693 |
startTime = dateFormat.parse(value[0]); |
|
694 |
//startTime = dateFormat.parse(value[0]); |
|
695 |
startTime = parseDateAndConvertToGMT(value[0]); |
|
694 | 696 |
} |
695 | 697 |
catch(Exception e) |
696 | 698 |
{ //if we can't parse it, just don't use the startTime param |
... | ... | |
702 | 704 |
{ |
703 | 705 |
try |
704 | 706 |
{ |
705 |
endTime = dateFormat.parse(value[0]); |
|
707 |
//endTime = dateFormat.parse(value[0]); |
|
708 |
endTime = parseDateAndConvertToGMT(value[0]); |
|
706 | 709 |
} |
707 | 710 |
catch(Exception e) |
708 | 711 |
{ //if we can't parse it, just don't use the endTime param |
... | ... | |
770 | 773 |
serializeException(sf, out); |
771 | 774 |
} |
772 | 775 |
} |
776 |
|
|
777 |
/** |
|
778 |
* parse a date and return it in GMT if it ends with a 'Z' |
|
779 |
* @param date |
|
780 |
* @return |
|
781 |
* @throws ParseException |
|
782 |
*/ |
|
783 |
private Date parseDateAndConvertToGMT(String date) throws ParseException |
|
784 |
{ |
|
785 |
System.out.println("Parsing date " + date); |
|
786 |
Date d = dateFormat.parse(date); |
|
787 |
|
|
788 |
if(date.endsWith("Z")) |
|
789 |
{ |
|
790 |
Calendar lTime = Calendar.getInstance(); |
|
791 |
lTime.setTime(d); |
|
792 |
Calendar zTime = Calendar.getInstance(TimeZone.getTimeZone("GMT-0")); |
|
793 |
zTime.set(Calendar.MONTH, lTime.get(Calendar.MONTH)); |
|
794 |
zTime.set(Calendar.DATE, lTime.get(Calendar.DATE)); |
|
795 |
zTime.set(Calendar.YEAR, lTime.get(Calendar.YEAR)); |
|
796 |
zTime.set(Calendar.HOUR, lTime.get(Calendar.HOUR)); |
|
797 |
zTime.set(Calendar.MINUTE, lTime.get(Calendar.MINUTE)); |
|
798 |
zTime.set(Calendar.SECOND, lTime.get(Calendar.SECOND)); |
|
799 |
|
|
800 |
System.out.println("date parsed to " + zTime.getTime()); |
|
801 |
return zTime.getTime(); |
|
802 |
} |
|
803 |
|
|
804 |
System.out.println("date parsed, but not converted. returned as " + d); |
|
805 |
return d; |
|
806 |
} |
|
773 | 807 |
|
774 | 808 |
/** |
775 | 809 |
* Implements REST version of DataONE CRUD API --> getSystemMetadata |
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
99 | 99 |
|
100 | 100 |
private String metacatUrl; |
101 | 101 |
|
102 |
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
|
|
102 |
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
|
|
103 | 103 |
|
104 | 104 |
/** |
105 | 105 |
* singleton accessor |
... | ... | |
532 | 532 |
dateSMM = dateSMM.substring(0, dateSMM.indexOf(".")) + 'Z'; |
533 | 533 |
} |
534 | 534 |
//System.out.println("dateSMM: " + dateSMM); |
535 |
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT-0")); |
|
536 |
dateSysMetadataModified = dateFormat.parse(dateSMM); |
|
537 |
//System.out.println("dateSysMetadataModified: " + dateSysMetadataModified); |
|
538 |
|
|
539 |
//dateSysMetadataModified = getDateInTimeZone(dateSysMetadataModified, TimeZone.getDefault().getID()); |
|
540 |
//System.out.println("dateSysMetadataModified after convertion to default timezone: " + dateSysMetadataModified); |
|
535 |
//dateFormat.setTimeZone(TimeZone.getTimeZone("GMT-0")); |
|
536 |
try |
|
537 |
{ //the format we want |
|
538 |
dateSysMetadataModified = dateFormat.parse(dateSMM); |
|
539 |
} |
|
540 |
catch(java.text.ParseException pe) |
|
541 |
{ //try another legacy format |
|
542 |
DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); |
|
543 |
dateFormat2.setTimeZone(TimeZone.getTimeZone("GMT-0")); |
|
544 |
dateSysMetadataModified = dateFormat2.parse(dateSMM); |
|
545 |
} |
|
541 | 546 |
} |
547 |
|
|
542 | 548 |
/*System.out.println("docid: " + d.docid); |
543 | 549 |
System.out.println("dateSysMetadataModified: " + dateSysMetadataModified); |
544 | 550 |
System.out.println("startTime: " + startTime); |
... | ... | |
599 | 605 |
|
600 | 606 |
docs = docCopy; |
601 | 607 |
totalAfterQuery = docs.size(); |
602 |
System.out.println("total after subquery: " + totalAfterQuery); |
|
608 |
//System.out.println("total after subquery: " + totalAfterQuery);
|
|
603 | 609 |
|
604 | 610 |
//make sure we don't run over the end |
605 | 611 |
int end = start + count; |
... | ... | |
669 | 675 |
EventLog.getInstance().log(metacatUrl, |
670 | 676 |
username, null, "read"); |
671 | 677 |
logCrud.info("listObjects"); |
672 |
//System.out.println("ol.size: " + ol.sizeObjectInfoList()); |
|
673 | 678 |
ol.setCount(count); |
674 | 679 |
ol.setStart(start); |
675 | 680 |
ol.setTotal(totalAfterQuery); |
676 |
System.out.println("returning " + ol.sizeObjectInfoList() + " items in the object list"); |
|
677 | 681 |
return ol; |
678 | 682 |
} |
679 | 683 |
|
... | ... | |
771 | 775 |
return "Completed"; |
772 | 776 |
} |
773 | 777 |
}; |
774 |
System.out.println("1"); |
|
775 | 778 |
String username = sessionData.getUserName(); |
776 | 779 |
EventLog.getInstance().log(metacatUrl, |
777 | 780 |
username, im.getLocalId(guid.getValue()), "read"); |
... | ... | |
1267 | 1270 |
System.out.println("****inserting new system metadata with modified date " + sysmeta.getDateSysMetadataModified()); |
1268 | 1271 |
|
1269 | 1272 |
String xml = new String(serializeSystemMetadata(sysmeta).toByteArray()); |
1273 |
//System.out.println("sysmeta: " + xml); |
|
1270 | 1274 |
String localId = insertDocument(xml, sysMetaGuid, sessionData); |
1271 | 1275 |
System.out.println("sysmeta inserted with localId " + localId); |
1272 | 1276 |
//insert the system metadata doc id into the identifiers table to |
... | ... | |
1590 | 1594 |
} |
1591 | 1595 |
catch(Exception e) |
1592 | 1596 |
{ |
1593 |
System.out.println("couldn't parse a date: " + e.getMessage()); |
|
1597 |
System.out.println("POSSIBLE ERROR: couldn't parse a date: " + e.getMessage());
|
|
1594 | 1598 |
Date dateCreated = new Date(); |
1595 | 1599 |
sm.setDateUploaded(dateCreated); |
1596 | 1600 |
Date dateUpdated = new Date(); |
Also available in: Unified diff
updated for date format that supports time zones correctly.