Revision 6384
Added by Chris Jones over 12 years ago
MetacatHandler.java | ||
---|---|---|
41 | 41 |
import java.io.StringReader; |
42 | 42 |
import java.io.UnsupportedEncodingException; |
43 | 43 |
import java.io.Writer; |
44 |
import java.math.BigInteger; |
|
44 | 45 |
import java.net.MalformedURLException; |
45 | 46 |
import java.net.URL; |
46 | 47 |
import java.security.NoSuchAlgorithmException; |
... | ... | |
81 | 82 |
import org.dataone.service.types.v1.Identifier; |
82 | 83 |
import org.dataone.service.types.v1.NodeReference; |
83 | 84 |
import org.dataone.service.types.v1.ObjectFormat; |
85 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
|
84 | 86 |
import org.dataone.service.types.v1.Subject; |
85 | 87 |
import org.dataone.service.types.v1.SystemMetadata; |
86 | 88 |
import org.dataone.service.types.v1.util.ChecksumUtil; |
... | ... | |
3575 | 3577 |
Hashtable<String, Object> docInfo = IdentifierManager.getInstance().getDocumentInfo(localId); |
3576 | 3578 |
//set the default object format |
3577 | 3579 |
String doctype = (String) docInfo.get("doctype"); |
3578 |
ObjectFormat format = null;
|
|
3580 |
ObjectFormatIdentifier fmtid = null;
|
|
3579 | 3581 |
|
3580 | 3582 |
// set the object format, fall back to defaults |
3581 | 3583 |
try { |
3582 |
format = ObjectFormatCache.getInstance().getFormat(doctype);
|
|
3584 |
fmtid = ObjectFormatCache.getInstance().getFormat(doctype).getFmtid();
|
|
3583 | 3585 |
|
3584 | 3586 |
} catch (NotFound nfe) { |
3585 | 3587 |
|
3586 | 3588 |
try { |
3587 | 3589 |
// format is not registered, use default |
3588 | 3590 |
if (doctype.trim().equals("BIN")) { |
3589 |
format = ObjectFormatCache.getInstance().getFormat("application/octet-stream"); |
|
3591 |
fmtid = ObjectFormatCache.getInstance().getFormat( |
|
3592 |
"application/octet-stream").getFmtid(); |
|
3590 | 3593 |
|
3591 | 3594 |
} else { |
3592 |
format = ObjectFormatCache.getInstance().getFormat("text/plain");
|
|
3595 |
fmtid = ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid();
|
|
3593 | 3596 |
} |
3594 | 3597 |
|
3595 | 3598 |
} catch (NotFound nf) { |
... | ... | |
3600 | 3603 |
|
3601 | 3604 |
} |
3602 | 3605 |
|
3603 |
sysMeta.setObjectFormat(format);
|
|
3604 |
logMetacat.debug("The ObjectFormat for " + localId + " is " + format.toString());
|
|
3606 |
sysMeta.setFmtid(fmtid);
|
|
3607 |
logMetacat.debug("The ObjectFormat for " + localId + " is " + fmtid.getValue());
|
|
3605 | 3608 |
|
3606 | 3609 |
// further parse EML documents to get data object format, |
3607 | 3610 |
// describes and describedBy information |
3608 |
if ( format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.0") ||
|
|
3609 |
format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.1") ||
|
|
3610 |
format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.0") ||
|
|
3611 |
format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.1") ) {
|
|
3611 |
if ( fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.0").getFmtid() ||
|
|
3612 |
fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.1").getFmtid() ||
|
|
3613 |
fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.0").getFmtid() ||
|
|
3614 |
fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.1").getFmtid() ) {
|
|
3612 | 3615 |
|
3613 | 3616 |
try { |
3614 | 3617 |
|
... | ... | |
3668 | 3671 |
|
3669 | 3672 |
// set object format |
3670 | 3673 |
logMetacat.debug("Updating system metadata for " + dataGuid.getValue() + " to " + dataDocMimeType); |
3671 |
ObjectFormat f = ObjectFormatCache.getInstance().getFormat(dataDocMimeType); |
|
3672 |
if (f == null) { |
|
3673 |
f = ObjectFormatCache.getInstance().getFormat("application/octet-stream"); |
|
3674 |
try { |
|
3675 |
ObjectFormatIdentifier fmt = |
|
3676 |
ObjectFormatCache.getInstance().getFormat(dataDocMimeType).getFmtid(); |
|
3677 |
dataSysMeta.setFmtid(fmt); |
|
3678 |
|
|
3679 |
} catch (NotFound nfe) { |
|
3680 |
logMetacat.debug("Couldn't find format identifier for: " + |
|
3681 |
dataDocMimeType + ". Setting it to application/octet-stream."); |
|
3682 |
ObjectFormatIdentifier newFmtid = new ObjectFormatIdentifier(); |
|
3683 |
newFmtid.setValue("application/octet-stream"); |
|
3684 |
|
|
3674 | 3685 |
} |
3675 |
dataSysMeta.setObjectFormat(f); |
|
3676 | 3686 |
|
3677 | 3687 |
// update the values |
3678 | 3688 |
IdentifierManager.getInstance().updateSystemMetadata(dataSysMeta); |
... | ... | |
3735 | 3745 |
|
3736 | 3746 |
//set the size |
3737 | 3747 |
inputStream = this.read(localId); |
3738 |
sysMeta.setSize(sizeOfStream(inputStream)); |
|
3748 |
String sizeStr = new Long(sizeOfStream(inputStream)).toString(); |
|
3749 |
sysMeta.setSize(new BigInteger(sizeStr)); |
|
3739 | 3750 |
|
3751 |
|
|
3740 | 3752 |
//submitter |
3741 | 3753 |
Subject subject = new Subject(); |
3742 | 3754 |
subject.setValue((String) docInfo.get("user_owner")); |
Also available in: Unified diff
Update classes to use the DataONE 0.6.4 schema and types. Major changes involve using BigInteger vs long in SystemMetadata.size, and using ObjectFormatIdentifier rather than Object format.