Project

General

Profile

« Previous | Next » 

Revision 6911

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

View differences:

src/edu/ucsb/nceas/metacat/dataone/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
src/edu/ucsb/nceas/metacat/admin/upgrade/GenerateSystemMetadata.java
26 26
 */
27 27

  
28 28

  
29
import java.security.NoSuchAlgorithmException;
30
import java.sql.SQLException;
31 29
import java.util.List;
32 30

  
33 31
import org.apache.commons.logging.Log;
34 32
import org.apache.commons.logging.LogFactory;
35
import org.dataone.service.exceptions.InvalidRequest;
36
import org.dataone.service.exceptions.InvalidSystemMetadata;
37
import org.dataone.service.exceptions.InvalidToken;
38
import org.dataone.service.exceptions.NotAuthorized;
39
import org.dataone.service.exceptions.NotFound;
40
import org.dataone.service.exceptions.NotImplemented;
41
import org.dataone.service.exceptions.ServiceFailure;
42
import org.dataone.service.types.v1.SystemMetadata;
43 33

  
44 34
import edu.emory.mathcs.backport.java.util.Collections;
45
import edu.ucsb.nceas.metacat.AccessionNumberException;
46 35
import edu.ucsb.nceas.metacat.DBUtil;
47
import edu.ucsb.nceas.metacat.IdentifierManager;
48
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
49 36
import edu.ucsb.nceas.metacat.admin.AdminException;
50 37
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
51 38
import edu.ucsb.nceas.metacat.properties.PropertyService;
52
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
53 39
import edu.ucsb.nceas.utilities.SortedProperties;
54 40

  
55 41
public class GenerateSystemMetadata implements UpgradeUtilityInterface {
......
69 55
            Collections.sort(idList);
70 56

  
71 57
            // generate based on this list
72
			generateSystemMetadata(idList, includeOre, downloadData);
58
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
73 59
		} catch (Exception e) {
74 60
			String msg = "Problem generating missing system metadata: " + e.getMessage();
75 61
			log.error(msg, e);
......
79 65
    	return success;
80 66
    }
81 67
    
82
    /**
83
     * Generate SystemMetadata for any object in the object store that does
84
     * not already have it.  SystemMetadata documents themselves, are, of course,
85
     * exempt.  This is a utility method for migration of existing object 
86
     * stores to DataONE where SystemMetadata is required for all objects.
87
     * @param idList
88
     * @param includeOre
89
     * @param downloadData
90
     * @throws ServiceFailure
91
     * @throws McdbDocNotFoundException
92
     * @throws PropertyNotFoundException
93
     * @throws InvalidToken
94
     * @throws NotAuthorized
95
     * @throws NotFound
96
     * @throws NotImplemented
97
     * @throws InvalidRequest
98
     * @throws NoSuchAlgorithmException
99
     * @throws AccessionNumberException
100
     * @throws SQLException
101
     */
102
    public void generateSystemMetadata(List<String> idList, boolean includeOre, boolean downloadData) 
103
    throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized, 
104
    NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException 
105
    {
106
        
107
        for (String localId : idList) { 
108
            //for each id, add a system metadata doc
109
        	try {
110
        		log.debug("generating system metadata for " + localId);
111
        		generateSystemMetadata(localId, includeOre, downloadData);
112
        	} catch (Exception e) {
113
				log.error("Error generating system metadata for: " + localId, e);
114
			}
115
        }
116
        log.info("done generating system metadata");
117
    }
118
    
119

  
120
    /**
121
     * Generate SystemMetadata for a particular object with identifier localId.
122
     * This is a utility method for migration of existing objects 
123
     * to DataONE where SystemMetadata is required for all objects.
124
     * @param localId
125
     * @param includeOre
126
     * @param downloadData
127
     * @throws ServiceFailure
128
     * @throws McdbDocNotFoundException
129
     * @throws PropertyNotFoundException
130
     * @throws InvalidToken
131
     * @throws NotAuthorized
132
     * @throws NotFound
133
     * @throws NotImplemented
134
     * @throws InvalidRequest
135
     * @throws NoSuchAlgorithmException
136
     * @throws AccessionNumberException
137
     * @throws SQLException
138
     * @throws InvalidSystemMetadata
139
     */
140
    protected void generateSystemMetadata(String localId, boolean includeOre, boolean downloadData) 
141
    throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized,
142
    NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException, InvalidSystemMetadata 
143
    {
144
    	log.debug("generateSystemMetadata() called.");
145
    	log.debug("Creating SystemMetadata for localId " + localId);
146
        SystemMetadata sm = null;
147

  
148
        //generate required system metadata fields from the document
149
        try {
150
        	sm = SystemMetadataFactory.createSystemMetadata(localId, includeOre, downloadData);
151
        } catch (Exception e1) {
152
        	e1.printStackTrace();
153
        	ServiceFailure sf = new ServiceFailure("00","Exception in generateSystemMetadata: " +
154
        			e1.getMessage());
155
        	sf.setStackTrace(e1.getStackTrace());
156
        	throw sf;
157
        }
158
        
159
        //insert the systemmetadata object or just update it as needed
160
        boolean exists = IdentifierManager.getInstance().systemMetadataExists(sm.getIdentifier().getValue());
161
        if (!exists) {
162
        	IdentifierManager.getInstance().createSystemMetadata(sm);
163
            log.info("Generated SystemMetadata for " + localId);
164
        } else {
165
        	IdentifierManager.getInstance().updateSystemMetadata(sm);
166
            log.info("Updated SystemMetadata for " + localId);
167
        }
168
    }
169
    
170
    
171 68
    public static void main(String [] ags){
172 69

  
173 70
        try {

Also available in: Unified diff