Revision 6911
Added by ben leinfelder over 12 years ago
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
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