Revision 5286
Added by Matt Jones about 14 years ago
DocumentUtil.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import java.io.PrintWriter; |
30 | 30 |
import java.sql.SQLException; |
31 |
import java.util.Calendar; |
|
32 |
import java.util.Date; |
|
33 |
import java.util.GregorianCalendar; |
|
31 | 34 |
import java.util.Hashtable; |
35 |
import java.util.SimpleTimeZone; |
|
32 | 36 |
import java.util.Stack; |
37 |
import java.util.TimeZone; |
|
33 | 38 |
import java.util.Vector; |
34 | 39 |
|
35 | 40 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
60 | 65 |
|
61 | 66 |
private static Logger logMetacat = Logger.getLogger(DocumentUtil.class); |
62 | 67 |
private static char separator = '.'; |
63 |
|
|
68 |
private static String prefix = "autogen"; |
|
69 |
|
|
64 | 70 |
static { |
65 | 71 |
try { |
66 |
separator = PropertyService.getProperty("document.accNumSeparator").charAt(0); |
|
72 |
separator = PropertyService.getProperty("document.accNumSeparator").charAt(0);
|
|
67 | 73 |
} catch (PropertyNotFoundException pnfe) { |
68 |
logMetacat.error("DocumentUtil() - Could not retrieve account number separator. "
|
|
74 |
logMetacat.error("DocumentUtil() - Could not retrieve accession number separator. "
|
|
69 | 75 |
+ "Separator set to '.' : " + pnfe.getMessage()); |
70 | 76 |
} |
77 |
try { |
|
78 |
prefix = PropertyService.getProperty("document.accNumPrefix"); |
|
79 |
} catch (PropertyNotFoundException pnfe) { |
|
80 |
logMetacat.error("DocumentUtil() - Could not retrieve accession number prefix. " |
|
81 |
+ "Prefix set to " + prefix + ": " + pnfe.getMessage()); |
|
82 |
} |
|
71 | 83 |
} |
72 | 84 |
|
73 | 85 |
/** |
... | ... | |
486 | 498 |
|
487 | 499 |
out.write(result); |
488 | 500 |
} |
501 |
|
|
502 |
/** |
|
503 |
* Create a unique docid for use in inserts and updates using the default |
|
504 |
* prefix from the document.accNumPrefix property. Does not include the |
|
505 |
* 'revision' part of the id if revision is '0', otherwise sets the |
|
506 |
* revision number to 'revision'. |
|
507 |
* |
|
508 |
* @param idPrefix the prefix to be used to construct the scope portion of the docid |
|
509 |
* @param revision the integer revision to use for this docid |
|
510 |
* @return a String docid based on the current date and time |
|
511 |
*/ |
|
512 |
public static String generateDocumentId(int revision) { |
|
513 |
return generateDocumentId(prefix, revision); |
|
514 |
} |
|
515 |
|
|
516 |
/** |
|
517 |
* Create a unique docid for use in inserts and updates using the prefix |
|
518 |
* that is provided. Does not include the 'revision' part of the id if |
|
519 |
* revision is '0', otherwise sets the revision number to 'revision'. |
|
520 |
* |
|
521 |
* @param idPrefix the prefix to be used to construct the scope portion of the docid |
|
522 |
* @param revision the integer revision to use for this docid |
|
523 |
* @return a String docid based on the current date and time |
|
524 |
*/ |
|
525 |
public static String generateDocumentId(String idPrefix, int revision) |
|
526 |
{ |
|
527 |
StringBuffer docid = new StringBuffer(idPrefix); |
|
528 |
docid.append("."); |
|
489 | 529 |
|
530 |
// Create a calendar to get the date formatted properly |
|
531 |
String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); |
|
532 |
SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); |
|
533 |
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); |
|
534 |
pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); |
|
535 |
Calendar calendar = new GregorianCalendar(pdt); |
|
536 |
Date trialTime = new Date(); |
|
537 |
calendar.setTime(trialTime); |
|
538 |
docid.append(calendar.get(Calendar.YEAR)); |
|
539 |
docid.append(calendar.get(Calendar.DAY_OF_YEAR)); |
|
540 |
docid.append(calendar.get(Calendar.HOUR_OF_DAY)); |
|
541 |
docid.append(calendar.get(Calendar.MINUTE)); |
|
542 |
docid.append(calendar.get(Calendar.SECOND)); |
|
543 |
docid.append(calendar.get(Calendar.MILLISECOND)); |
|
544 |
|
|
545 |
if (revision > 0) { |
|
546 |
docid.append(".").append(revision); |
|
547 |
} |
|
548 |
return docid.toString(); |
|
549 |
} |
|
490 | 550 |
} |
Also available in: Unified diff
Added support to ResourceHandler to allow the putObject method to use
arbitrary guid strings as input. These strings are examined, and if they
match the Metacat docid format (scope.id.rev), they are used directly. If
the id is a string in another format, a new localId is generated based on
the current time. Either way, a mapping is made into the identifier table
to relate the original guid to the new localId. Modified DocumentUtil to
generate the ids, and MCTest case to use this new utility method (to stay DRY).
Tests were updated to expect these global identifiers in the putObject
method.