72 |
72 |
import javax.xml.parsers.ParserConfigurationException;
|
73 |
73 |
import javax.xml.xpath.XPathExpressionException;
|
74 |
74 |
|
|
75 |
import org.apache.commons.io.IOUtils;
|
75 |
76 |
import org.apache.commons.io.input.XmlStreamReader;
|
76 |
77 |
import org.apache.log4j.Logger;
|
77 |
78 |
import org.dataone.client.ObjectFormatCache;
|
... | ... | |
1014 |
1015 |
* @throws ClassNotFoundException
|
1015 |
1016 |
* @throws IOException
|
1016 |
1017 |
*/
|
1017 |
|
public InputStream read(String docid)
|
|
1018 |
public static InputStream read(String docid)
|
1018 |
1019 |
throws ParseLSIDException,
|
1019 |
1020 |
PropertyNotFoundException, McdbException, SQLException,
|
1020 |
1021 |
ClassNotFoundException, IOException
|
... | ... | |
1128 |
1129 |
*
|
1129 |
1130 |
* @return fileInputStream The file to read as a FileInputStream
|
1130 |
1131 |
*/
|
1131 |
|
private FileInputStream readFromFilesystem(String filename)
|
|
1132 |
private static FileInputStream readFromFilesystem(String filename)
|
1132 |
1133 |
throws FileNotFoundException {
|
1133 |
1134 |
|
1134 |
1135 |
logMetacat.debug("MetacatHandler.readFromFilesystem() called.");
|
... | ... | |
1870 |
1871 |
// handle inserts
|
1871 |
1872 |
try {
|
1872 |
1873 |
// create the system metadata
|
1873 |
|
sysMeta = createSystemMetadata(newdocid, user, groups);
|
|
1874 |
sysMeta = createSystemMetadata(newdocid);
|
1874 |
1875 |
|
1875 |
1876 |
// save it to the map
|
1876 |
1877 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
|
... | ... | |
3014 |
3015 |
username, groupnames);
|
3015 |
3016 |
|
3016 |
3017 |
// generate system metadata about the doc
|
3017 |
|
SystemMetadata sm = createSystemMetadata(docid, username, groupnames);
|
|
3018 |
SystemMetadata sm = createSystemMetadata(docid);
|
3018 |
3019 |
|
3019 |
3020 |
// manage it in the store
|
3020 |
3021 |
HazelcastService.getInstance().getSystemMetadataMap().put(sm.getIdentifier(), sm);
|
... | ... | |
3523 |
3524 |
*
|
3524 |
3525 |
* @return sysMeta The system metadata object created
|
3525 |
3526 |
*/
|
3526 |
|
public SystemMetadata createSystemMetadata(String localId,
|
3527 |
|
String username, String[] groups)
|
|
3527 |
public static SystemMetadata createSystemMetadata(String localId)
|
3528 |
3528 |
throws McdbException, McdbDocNotFoundException, SQLException,
|
3529 |
3529 |
IOException, AccessionNumberException, ClassNotFoundException,
|
3530 |
3530 |
InsufficientKarmaException, ParseLSIDException, PropertyNotFoundException,
|
... | ... | |
3532 |
3532 |
{
|
3533 |
3533 |
logMetacat.debug("MetacatHandler.createSystemMetadata() called.");
|
3534 |
3534 |
logMetacat.debug("provided localId: " + localId);
|
3535 |
|
logMetacat.debug("provided username: " + username);
|
3536 |
3535 |
|
3537 |
3536 |
// create system metadata for the document
|
3538 |
3537 |
SystemMetadata sysMeta = new SystemMetadata();
|
... | ... | |
3562 |
3561 |
// get the data or metadata object
|
3563 |
3562 |
InputStream inputStream;
|
3564 |
3563 |
try {
|
3565 |
|
inputStream = this.read(localId);
|
|
3564 |
inputStream = read(localId);
|
3566 |
3565 |
} catch ( ParseLSIDException ple ) {
|
3567 |
3566 |
logMetacat.debug("There was a problem parsing the LSID from " +
|
3568 |
3567 |
localId + ". The error message was: " + ple.getMessage());
|
... | ... | |
3682 |
3681 |
logMetacat.debug("There was not an existing system metadata " + "document for " + dataDocLocalId);
|
3683 |
3682 |
try {
|
3684 |
3683 |
logMetacat.debug("Creating a system metadata " + "document for " + dataDocLocalId);
|
3685 |
|
dataSysMeta = this.createSystemMetadata(dataDocLocalId, username, groups);
|
|
3684 |
dataSysMeta = createSystemMetadata(dataDocLocalId);
|
3686 |
3685 |
|
3687 |
3686 |
// now look it up again
|
3688 |
3687 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev);
|
... | ... | |
3760 |
3759 |
|
3761 |
3760 |
|
3762 |
3761 |
//create the checksum
|
3763 |
|
inputStream = this.read(localId);
|
|
3762 |
inputStream = read(localId);
|
3764 |
3763 |
String algorithm = "MD5";
|
3765 |
3764 |
Checksum checksum = ChecksumUtil.checksum(inputStream, algorithm);
|
3766 |
3765 |
sysMeta.setChecksum(checksum);
|
3767 |
3766 |
|
3768 |
3767 |
//set the size
|
3769 |
|
inputStream = this.read(localId);
|
|
3768 |
inputStream = read(localId);
|
3770 |
3769 |
String sizeStr = new Long(sizeOfStream(inputStream)).toString();
|
3771 |
3770 |
sysMeta.setSize(new BigInteger(sizeStr));
|
3772 |
3771 |
|
3773 |
|
|
3774 |
3772 |
//submitter
|
3775 |
3773 |
Subject subject = new Subject();
|
3776 |
3774 |
subject.setValue((String) docInfo.get("user_owner"));
|
... | ... | |
3812 |
3810 |
* @return size The size in bytes of the input stream as a long
|
3813 |
3811 |
* @throws IOException
|
3814 |
3812 |
*/
|
3815 |
|
private long sizeOfStream(InputStream is)
|
|
3813 |
private static long sizeOfStream(InputStream is)
|
3816 |
3814 |
throws IOException {
|
3817 |
3815 |
|
3818 |
3816 |
long size = 0;
|
simplify SystemMetadata generation -- will be done during Metacat upgrade for D1 features/support.