Revision 5366
Added by berkley over 14 years ago
test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java | ||
---|---|---|
130 | 130 |
Date d5 = new Date(); |
131 | 131 |
Identifier id5 = createDoc(token, getTestDoc(), of1); |
132 | 132 |
SystemMetadata sm5 = getSystemMetadata(token, id5); |
133 |
|
|
133 |
|
|
134 |
Date d6 = new Date(); |
|
135 |
|
|
134 | 136 |
//now get the objects for specific time ranges and test that it returns |
135 | 137 |
//the correct objects |
136 | 138 |
|
137 | 139 |
//should return sm1 and sm2 |
138 |
ObjectList list1 = cs.listObjects(token, d1, d2, null);
|
|
140 |
ObjectList list1 = cs.listObjects(token, d1, d3, null);
|
|
139 | 141 |
assertTrue(list1.sizeObjectInfoList() == 2); |
140 |
ObjectInfo oi1 = list1.getObjectInfo(0); |
|
141 |
assertTrue(oi1.getIdentifier().getValue().equals(id1.getValue())); |
|
142 |
ObjectInfo oi2 = list1.getObjectInfo(1); |
|
143 |
assertTrue(oi2.getIdentifier().getValue().equals(id2.getValue())); |
|
142 |
assertTrue(idInObjectList(id1, list1)); |
|
143 |
assertTrue(idInObjectList(id2, list1)); |
|
144 | 144 |
|
145 | 145 |
//should only return sm1 |
146 |
ObjectList list2 = cs.listObjects(token, d1, d2, of1);
|
|
146 |
ObjectList list2 = cs.listObjects(token, d1, d3, of1);
|
|
147 | 147 |
assertTrue(list2.sizeObjectInfoList() == 1); |
148 |
ObjectInfo oi3 = list2.getObjectInfo(0); |
|
149 |
assertTrue(oi3.getIdentifier().getValue().equals(id1.getValue())); |
|
148 |
assertTrue(idInObjectList(id1, list2)); |
|
150 | 149 |
|
151 | 150 |
//should return sm1-sm4 |
152 |
ObjectList list3 = cs.listObjects(token, d1, d4, null);
|
|
151 |
ObjectList list3 = cs.listObjects(token, d1, d5, null);
|
|
153 | 152 |
assertTrue(list3.sizeObjectInfoList() == 4); |
154 | 153 |
ObjectInfo oi4 = list3.getObjectInfo(0); |
155 |
assertTrue(oi4.getIdentifier().getValue().equals(id1.getValue())); |
|
156 |
ObjectInfo oi5 = list3.getObjectInfo(1); |
|
157 |
assertTrue(oi5.getIdentifier().getValue().equals(id2.getValue())); |
|
158 |
ObjectInfo oi6 = list3.getObjectInfo(2); |
|
159 |
assertTrue(oi6.getIdentifier().getValue().equals(id3.getValue())); |
|
160 |
ObjectInfo oi7 = list3.getObjectInfo(3); |
|
161 |
assertTrue(oi7.getIdentifier().getValue().equals(id4.getValue())); |
|
154 |
assertTrue(idInObjectList(id1, list3)); |
|
155 |
assertTrue(idInObjectList(id2, list3)); |
|
156 |
assertTrue(idInObjectList(id3, list3)); |
|
157 |
assertTrue(idInObjectList(id4, list3)); |
|
162 | 158 |
|
163 | 159 |
//should only return sm2 and sm4 |
164 |
ObjectList list4 = cs.listObjects(token, d1, d2, of2);
|
|
160 |
ObjectList list4 = cs.listObjects(token, d1, d5, of2);
|
|
165 | 161 |
assertTrue(list4.sizeObjectInfoList() == 2); |
166 |
ObjectInfo oi8 = list4.getObjectInfo(0); |
|
167 |
assertTrue(oi8.getIdentifier().getValue().equals(id2.getValue())); |
|
168 |
ObjectInfo oi9 = list4.getObjectInfo(1); |
|
169 |
assertTrue(oi9.getIdentifier().getValue().equals(id4.getValue())); |
|
162 |
assertTrue(idInObjectList(id2, list4)); |
|
163 |
assertTrue(idInObjectList(id4, list4)); |
|
170 | 164 |
|
171 | 165 |
//should return all |
172 |
ObjectList list5 = cs.listObjects(token, d1, d5, null);
|
|
166 |
ObjectList list5 = cs.listObjects(token, d1, d6, null);
|
|
173 | 167 |
assertTrue(list5.sizeObjectInfoList() == 5); |
168 |
assertTrue(idInObjectList(id1, list5)); |
|
169 |
assertTrue(idInObjectList(id2, list5)); |
|
170 |
assertTrue(idInObjectList(id3, list5)); |
|
171 |
assertTrue(idInObjectList(id4, list5)); |
|
172 |
assertTrue(idInObjectList(id5, list5)); |
|
173 |
|
|
174 | 174 |
//should return 1, 3, 5 |
175 |
ObjectList list6 = cs.listObjects(token, d1, d2, of1); |
|
176 |
assertTrue(list5.sizeObjectInfoList() == 3); |
|
175 |
ObjectList list6 = cs.listObjects(token, d1, d6, of1); |
|
176 |
assertTrue(list6.sizeObjectInfoList() == 3); |
|
177 |
assertTrue(idInObjectList(id1, list6)); |
|
178 |
assertTrue(idInObjectList(id3, list6)); |
|
179 |
assertTrue(idInObjectList(id5, list6)); |
|
177 | 180 |
|
178 |
|
|
179 | 181 |
} |
180 | 182 |
catch(Exception e) |
181 | 183 |
{ |
... | ... | |
184 | 186 |
} |
185 | 187 |
} |
186 | 188 |
|
189 |
private boolean idInObjectList(Identifier id, ObjectList list) |
|
190 |
{ |
|
191 |
for(int i=0; i<list.sizeObjectInfoList(); i++) |
|
192 |
{ |
|
193 |
ObjectInfo oi = list.getObjectInfo(i); |
|
194 |
if(id.getValue().equals(oi.getIdentifier().getValue())) |
|
195 |
return true; |
|
196 |
} |
|
197 |
return false; |
|
198 |
} |
|
199 |
|
|
187 | 200 |
/** |
188 | 201 |
* public Identifier update(AuthToken token, Identifier guid, |
189 | 202 |
* InputStream object, Identifier obsoletedGuid, SystemMetadata sysmeta) |
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
31 | 31 |
import java.io.OutputStream; |
32 | 32 |
import java.io.PrintWriter; |
33 | 33 |
import java.sql.SQLException; |
34 |
import java.util.Date; |
|
35 |
import java.util.Enumeration; |
|
36 |
import java.util.Hashtable; |
|
37 |
import java.util.Timer; |
|
38 |
import java.util.List; |
|
34 |
import java.util.*; |
|
39 | 35 |
import java.text.DateFormat; |
40 | 36 |
|
41 | 37 |
import javax.servlet.ServletContext; |
... | ... | |
356 | 352 |
"identifier", "objectFormat", "dateSysMetadataModified", "checksum"}); |
357 | 353 |
params.put("anyfield", new String[] {"%"}); |
358 | 354 |
|
359 |
System.out.println("listing objects"); |
|
360 | 355 |
MetacatResultSet rs = handler.query(metacatUrl, params, sessionData.getUserName(), |
361 | 356 |
sessionData.getGroupNames(), sessionData.getId()); |
362 | 357 |
List docs = rs.getDocuments(); |
... | ... | |
370 | 365 |
{ //make sure the objectFormat is the one specified |
371 | 366 |
continue; |
372 | 367 |
} |
373 |
Date dateSysMetadataModified = DateFormat.getDateTimeInstance().parse(d.getField("dateSysMetadataModified"));
|
|
368 |
Date dateSysMetadataModified = parseDate(d.getField("dateSysMetadataModified"));
|
|
374 | 369 |
int startDateComparison = 0; |
375 | 370 |
int endDateComparison = 0; |
376 | 371 |
if(startTime != null) |
... | ... | |
399 | 394 |
id.setValue(d.getField("identifier")); |
400 | 395 |
info.setIdentifier(id); |
401 | 396 |
info.setObjectFormat(returnedObjectFormat); |
402 |
info.setSize(new Long(d.getField("size")).longValue()); |
|
397 |
info.setSize(new Long(d.getField("size").trim()).longValue());
|
|
403 | 398 |
//add the ObjectInfo to the ObjectList |
404 | 399 |
ol.addObjectInfo(info); |
405 | 400 |
|
... | ... | |
599 | 594 |
throw new NotFound("1000", e.getMessage()); |
600 | 595 |
} |
601 | 596 |
} |
597 |
|
|
598 |
/** |
|
599 |
* parse the date in the systemMetadata |
|
600 |
* @param s |
|
601 |
* @return |
|
602 |
* @throws Exception |
|
603 |
*/ |
|
604 |
private Date parseDate(String s) |
|
605 |
throws Exception |
|
606 |
{ |
|
607 |
Date d = null; |
|
608 |
int tIndex = s.indexOf("T"); |
|
609 |
int zIndex = s.indexOf("Z"); |
|
610 |
if(tIndex != -1 && zIndex != -1) |
|
611 |
{ //parse a date that looks like 2010-05-18T21:12:54.362Z |
|
612 |
//System.out.println("original date: " + s); |
|
613 |
|
|
614 |
String date = s.substring(0, tIndex); |
|
615 |
String year = date.substring(0, date.indexOf("-")); |
|
616 |
String month = date.substring(date.indexOf("-") + 1, date.lastIndexOf("-")); |
|
617 |
String day = date.substring(date.lastIndexOf("-") + 1, date.length()); |
|
618 |
/*System.out.println("date: " + "year: " + new Integer(year).intValue() + |
|
619 |
" month: " + new Integer(month).intValue() + " day: " + |
|
620 |
new Integer(day).intValue()); |
|
621 |
*/ |
|
622 |
String time = s.substring(tIndex + 1, zIndex); |
|
623 |
String hour = time.substring(0, time.indexOf(":")); |
|
624 |
String minute = time.substring(time.indexOf(":") + 1, time.lastIndexOf(":")); |
|
625 |
String seconds = "00"; |
|
626 |
String milliseconds = "00"; |
|
627 |
if(time.indexOf(".") != -1) |
|
628 |
{ |
|
629 |
seconds = time.substring(time.lastIndexOf(":") + 1, time.indexOf(".")); |
|
630 |
milliseconds = time.substring(time.indexOf(".") + 1, time.length()); |
|
631 |
} |
|
632 |
/*System.out.println("time: " + "hour: " + new Integer(hour).intValue() + |
|
633 |
" minute: " + new Integer(minute).intValue() + " seconds: " + |
|
634 |
new Integer(seconds).intValue() + " milli: " + |
|
635 |
new Integer(milliseconds).intValue());*/ |
|
636 |
|
|
637 |
//d = DateFormat.getDateTimeInstance().parse(date + " " + time); |
|
638 |
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT-0")); |
|
639 |
c.set(new Integer(year).intValue(), new Integer(month).intValue() - 1, |
|
640 |
new Integer(day).intValue(), new Integer(hour).intValue(), |
|
641 |
new Integer(minute).intValue(), new Integer(seconds).intValue()); |
|
642 |
c.set(Calendar.MILLISECOND, new Integer(milliseconds).intValue()); |
|
643 |
d = new Date(c.getTimeInMillis()); |
|
644 |
//System.out.println("d: " + d); |
|
645 |
return d; |
|
646 |
} |
|
647 |
else |
|
648 |
{ //if it's not in the expected format, try the formatter |
|
649 |
return DateFormat.getDateTimeInstance().parse(s); |
|
650 |
} |
|
651 |
} |
|
602 | 652 |
|
603 | 653 |
/* |
604 | 654 |
* Look up the information on the session using the token provided in |
Also available in: Unified diff
finished the crud part of listObjects. need to implement it in the rest interface now.