Revision 6911
Added by ben leinfelder over 12 years ago
SystemMetadataFactory.java | ||
---|---|---|
51 | 51 |
import org.dataone.client.ObjectFormatCache; |
52 | 52 |
import org.dataone.ore.ResourceMapFactory; |
53 | 53 |
import org.dataone.service.exceptions.BaseException; |
54 |
import org.dataone.service.exceptions.InvalidRequest; |
|
55 |
import org.dataone.service.exceptions.InvalidSystemMetadata; |
|
56 |
import org.dataone.service.exceptions.InvalidToken; |
|
57 |
import org.dataone.service.exceptions.NotAuthorized; |
|
54 | 58 |
import org.dataone.service.exceptions.NotFound; |
59 |
import org.dataone.service.exceptions.NotImplemented; |
|
60 |
import org.dataone.service.exceptions.ServiceFailure; |
|
55 | 61 |
import org.dataone.service.types.v1.AccessPolicy; |
56 | 62 |
import org.dataone.service.types.v1.Checksum; |
57 | 63 |
import org.dataone.service.types.v1.Identifier; |
... | ... | |
288 | 294 |
SystemMetadata obsoletesSysMeta = IdentifierManager.getInstance().getSystemMetadata(obsoletes.getValue()); |
289 | 295 |
if (obsoletesSysMeta != null) { |
290 | 296 |
obsoletesSysMeta.setObsoletedBy(identifier); |
291 |
obsoletesSysMeta.setArchived(true);
|
|
292 |
HazelcastService.getInstance().getSystemMetadataMap().put(obsoletes, obsoletesSysMeta);
|
|
297 |
obsoletesSysMeta.setArchived(true);
|
|
298 |
HazelcastService.getInstance().getSystemMetadataMap().put(obsoletes, obsoletesSysMeta);
|
|
293 | 299 |
} |
294 | 300 |
} |
295 | 301 |
|
... | ... | |
604 | 610 |
} |
605 | 611 |
|
606 | 612 |
/** |
613 |
* Generate SystemMetadata for any object in the object store that does |
|
614 |
* not already have it. SystemMetadata documents themselves, are, of course, |
|
615 |
* exempt. This is a utility method for migration of existing object |
|
616 |
* stores to DataONE where SystemMetadata is required for all objects. |
|
617 |
* @param idList |
|
618 |
* @param includeOre |
|
619 |
* @param downloadData |
|
620 |
* @throws ServiceFailure |
|
621 |
* @throws McdbDocNotFoundException |
|
622 |
* @throws PropertyNotFoundException |
|
623 |
* @throws InvalidToken |
|
624 |
* @throws NotAuthorized |
|
625 |
* @throws NotFound |
|
626 |
* @throws NotImplemented |
|
627 |
* @throws InvalidRequest |
|
628 |
* @throws NoSuchAlgorithmException |
|
629 |
* @throws AccessionNumberException |
|
630 |
* @throws SQLException |
|
631 |
*/ |
|
632 |
public static void generateSystemMetadata(List<String> idList, boolean includeOre, boolean downloadData) |
|
633 |
throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized, |
|
634 |
NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException |
|
635 |
{ |
|
636 |
|
|
637 |
for (String localId : idList) { |
|
638 |
//for each id, add a system metadata doc |
|
639 |
try { |
|
640 |
logMetacat.debug("generating system metadata for " + localId); |
|
641 |
generateSystemMetadata(localId, includeOre, downloadData); |
|
642 |
} catch (Exception e) { |
|
643 |
logMetacat.error("Error generating system metadata for: " + localId, e); |
|
644 |
} |
|
645 |
} |
|
646 |
logMetacat.info("done generating system metadata"); |
|
647 |
} |
|
648 |
|
|
649 |
|
|
650 |
/** |
|
651 |
* Generate SystemMetadata for a particular object with identifier localId. |
|
652 |
* This is a utility method for migration of existing objects |
|
653 |
* to DataONE where SystemMetadata is required for all objects. |
|
654 |
* @param localId |
|
655 |
* @param includeOre |
|
656 |
* @param downloadData |
|
657 |
* @throws ServiceFailure |
|
658 |
* @throws McdbDocNotFoundException |
|
659 |
* @throws PropertyNotFoundException |
|
660 |
* @throws InvalidToken |
|
661 |
* @throws NotAuthorized |
|
662 |
* @throws NotFound |
|
663 |
* @throws NotImplemented |
|
664 |
* @throws InvalidRequest |
|
665 |
* @throws NoSuchAlgorithmException |
|
666 |
* @throws AccessionNumberException |
|
667 |
* @throws SQLException |
|
668 |
* @throws InvalidSystemMetadata |
|
669 |
*/ |
|
670 |
protected static void generateSystemMetadata(String localId, boolean includeOre, boolean downloadData) |
|
671 |
throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized, |
|
672 |
NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException, InvalidSystemMetadata |
|
673 |
{ |
|
674 |
logMetacat.debug("generateSystemMetadata() called."); |
|
675 |
logMetacat.debug("Creating SystemMetadata for localId " + localId); |
|
676 |
SystemMetadata sm = null; |
|
677 |
|
|
678 |
//generate required system metadata fields from the document |
|
679 |
try { |
|
680 |
sm = SystemMetadataFactory.createSystemMetadata(localId, includeOre, downloadData); |
|
681 |
} catch (Exception e1) { |
|
682 |
e1.printStackTrace(); |
|
683 |
ServiceFailure sf = new ServiceFailure("00","Exception in generateSystemMetadata: " + |
|
684 |
e1.getMessage()); |
|
685 |
sf.setStackTrace(e1.getStackTrace()); |
|
686 |
throw sf; |
|
687 |
} |
|
688 |
|
|
689 |
//insert the systemmetadata object or just update it as needed |
|
690 |
boolean exists = IdentifierManager.getInstance().systemMetadataExists(sm.getIdentifier().getValue()); |
|
691 |
if (!exists) { |
|
692 |
IdentifierManager.getInstance().createSystemMetadata(sm); |
|
693 |
logMetacat.info("Generated SystemMetadata for " + localId); |
|
694 |
} else { |
|
695 |
IdentifierManager.getInstance().updateSystemMetadata(sm); |
|
696 |
logMetacat.info("Updated SystemMetadata for " + localId); |
|
697 |
} |
|
698 |
} |
|
699 |
|
|
700 |
/** |
|
607 | 701 |
* Determines if we already have registered an ORE map for this package |
608 | 702 |
* @param guid of the EML/packaging object |
609 | 703 |
* @return true if there is an ORE map for the given package |
Also available in: Unified diff
refactor generate system meta loop to the factory class -- to be reused in sysmeta and ORE generation
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5522