Revision 8760
Added by Lauren Walker over 10 years ago
src/edu/ucsb/nceas/metacat/admin/upgrade/UpdateDOI.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import java.util.Collections; |
28 | 28 |
import java.util.List; |
29 |
import java.util.ArrayList; |
|
29 | 30 |
|
30 | 31 |
import org.apache.commons.logging.Log; |
31 | 32 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
44 | 45 |
|
45 | 46 |
/** |
46 | 47 |
* Updates existing DOI registrations for EML versions |
47 |
* @author leinfelder |
|
48 |
* @author leinfelder, walker
|
|
48 | 49 |
* |
49 | 50 |
*/ |
50 | 51 |
public class UpdateDOI implements UpgradeUtilityInterface { |
... | ... | |
61 | 62 |
this.serverLocation = serverLocation; |
62 | 63 |
} |
63 | 64 |
|
65 |
/** |
|
66 |
* Update the registration of a list of DOIs |
|
67 |
* @param identifiers - DOIs to update |
|
68 |
*/ |
|
64 | 69 |
private void updateDOIRegistration(List<String> identifiers) { |
65 | 70 |
for (String pid: identifiers) { |
66 | 71 |
try { |
67 |
|
|
68 |
String docid = DocumentUtil.getDocIdFromAccessionNumber(pid); |
|
69 |
int rev = DocumentUtil.getRevisionFromAccessionNumber(pid); |
|
70 |
String guid = IdentifierManager.getInstance().getGUID(docid, rev); |
|
72 |
//Create an identifier and retrieve the SystemMetadata for this guid |
|
71 | 73 |
Identifier identifier = new Identifier(); |
72 |
identifier.setValue(guid); |
|
73 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
74 |
identifier.setValue(pid); |
|
75 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(identifier); |
|
76 |
|
|
77 |
//Update the registration |
|
74 | 78 |
DOIService.getInstance().registerDOI(sysMeta); |
75 | 79 |
} catch (Exception e) { |
76 | 80 |
// what to do? nothing |
... | ... | |
81 | 85 |
} |
82 | 86 |
} |
83 | 87 |
|
88 |
/** |
|
89 |
* Update the DOI registration of all ids in this server with EML formatIds |
|
90 |
*/ |
|
84 | 91 |
public boolean upgrade() throws AdminException { |
85 | 92 |
boolean success = true; |
86 | 93 |
|
... | ... | |
115 | 122 |
return success; |
116 | 123 |
} |
117 | 124 |
|
125 |
/** |
|
126 |
* Update the registration of all DOIs with the specified guids in this server |
|
127 |
* @param ids - a List of DOIs to update |
|
128 |
*/ |
|
129 |
public boolean upgradeById(List<String> ids) throws AdminException { |
|
130 |
boolean success = true; |
|
131 |
|
|
132 |
try{ |
|
133 |
updateDOIRegistration(ids); |
|
134 |
} catch (Exception e) { |
|
135 |
String msg = "Problem updating DOIs: " + e.getMessage(); |
|
136 |
log.error(msg, e); |
|
137 |
success = false; |
|
138 |
throw new AdminException(msg); |
|
139 |
} |
|
140 |
return success; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Update the registration of all DOIs in this server with the specified formatId |
|
145 |
* @param formatIds - a List of formatIDs used to filter DOI selection |
|
146 |
*/ |
|
147 |
public boolean upgradeByFormatId(List<String> formatIds) throws AdminException { |
|
148 |
boolean success = true; |
|
149 |
List<String> idList = new ArrayList<String>(); |
|
150 |
|
|
151 |
try{ |
|
152 |
for (String formatId: formatIds) { |
|
153 |
//Get all the docids with this formatId |
|
154 |
List<String> docids = DBUtil.getAllDocidsByType(formatId, true, serverLocation); |
|
155 |
|
|
156 |
//get the guids for each docid and add to our list |
|
157 |
for(String id: docids){ |
|
158 |
String docid = DocumentUtil.getDocIdFromAccessionNumber(id); |
|
159 |
int rev = DocumentUtil.getRevisionFromAccessionNumber(id); |
|
160 |
String guid = IdentifierManager.getInstance().getGUID(docid, rev); |
|
161 |
idList.add(guid); |
|
162 |
} |
|
163 |
|
|
164 |
//Update the registration for all these guids |
|
165 |
Collections.sort(idList); |
|
166 |
updateDOIRegistration(idList); |
|
167 |
} |
|
168 |
} catch (Exception e) { |
|
169 |
String msg = "Problem updating DOIs: " + e.getMessage(); |
|
170 |
log.error(msg, e); |
|
171 |
success = false; |
|
172 |
throw new AdminException(msg); |
|
173 |
} |
|
174 |
return success; |
|
175 |
} |
|
176 |
|
|
118 | 177 |
} |
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
420 | 420 |
String serverid = ((String[]) params.get("serverid"))[0]; |
421 | 421 |
serverLocation = Integer.parseInt(serverid); |
422 | 422 |
udoi.setServerLocation(serverLocation ); |
423 |
udoi.upgrade(); |
|
424 |
out.write("Generated ORE maps for server " + serverid); |
|
423 |
|
|
424 |
//Get the list of IDs, if any were given |
|
425 |
String ids = ((String[]) params.get("ids"))[0]; |
|
425 | 426 |
|
427 |
//Get the formatId, if one was given |
|
428 |
String formatIds = ((String[]) params.get("formatIds"))[0]; |
|
429 |
|
|
430 |
//Allow DOI's to be updated by both ID and formatId |
|
431 |
if((ids.length() > 0) || (formatIds.length() > 0)){ |
|
432 |
//If at least one ID was given, update their DOI registrations |
|
433 |
if(ids.length() > 0){ |
|
434 |
String delimeter = " "; |
|
435 |
String[] idArray = ids.split(delimeter); |
|
436 |
List<String> idList = Arrays.asList(idArray); |
|
437 |
udoi.upgradeById(idList); |
|
438 |
} |
|
439 |
|
|
440 |
//If at least one formatId was given, update the DOI registrations |
|
441 |
if(formatIds.length() > 0){ |
|
442 |
String delimeter = " "; |
|
443 |
String[] formatIdArray = formatIds.split(delimeter); |
|
444 |
List<String> formatIdList = Arrays.asList(formatIdArray); |
|
445 |
udoi.upgradeByFormatId(formatIdList); |
|
446 |
} |
|
447 |
} |
|
448 |
else{ |
|
449 |
udoi.upgrade(); |
|
450 |
} |
|
451 |
out.write("Updated DOI's for server " + serverid); |
|
452 |
|
|
426 | 453 |
} else if (subaction.equals("removeinvalidreplicas")) { |
427 | 454 |
RemoveInvalidReplicas rir = new RemoveInvalidReplicas(); |
428 | 455 |
int serverLocation = -1; |
... | ... | |
526 | 553 |
out.write("<input name='configureType' type='hidden' value='replication'/>"); |
527 | 554 |
out.write("<input name='action' type='hidden' value='servercontrol'/>"); |
528 | 555 |
out.write("<input name='subaction' type='hidden' value='updatedoi'/>"); |
556 |
out.write("<label>Update by ID:</label>"); |
|
557 |
out.write("<textarea name='ids'></textarea>"); |
|
558 |
out.write("<label>Update by formatId:</label>"); |
|
559 |
out.write("<textarea name='formatIds'></textarea>"); |
|
529 | 560 |
out.write("<input type='submit' value='Update DOIs'/>"); |
530 | 561 |
out.write("</form></td>"); |
531 | 562 |
|
Also available in: Unified diff
Add admin service to update DOI registrations by specifying a list of formatIds or DOIs, or update all.