Revision 7843
Added by ben leinfelder almost 11 years ago
MetacatHandler.java | ||
---|---|---|
52 | 52 |
import java.util.HashMap; |
53 | 53 |
import java.util.Hashtable; |
54 | 54 |
import java.util.Iterator; |
55 |
import java.util.List; |
|
55 | 56 |
import java.util.Map; |
56 | 57 |
import java.util.Timer; |
57 | 58 |
import java.util.Vector; |
... | ... | |
66 | 67 |
|
67 | 68 |
import org.apache.commons.io.input.XmlStreamReader; |
68 | 69 |
import org.apache.log4j.Logger; |
70 |
import org.dataone.service.types.v1.Identifier; |
|
69 | 71 |
import org.dataone.service.types.v1.SystemMetadata; |
70 | 72 |
import org.ecoinformatics.eml.EMLParser; |
71 | 73 |
|
... | ... | |
2587 | 2589 |
} |
2588 | 2590 |
|
2589 | 2591 |
/** |
2592 |
* Rebuild the index for one or more documents. If the "pid" parameter is |
|
2593 |
* provided, rebuild for just that one document (or list of documents). If |
|
2594 |
* not, then rebuild the index for all documents in the systemMetadata table. |
|
2595 |
* |
|
2596 |
* @param params |
|
2597 |
* the parameters from the web request |
|
2598 |
* @param request |
|
2599 |
* the http request object for getting request details |
|
2600 |
* @param response |
|
2601 |
* the http response object for writing output |
|
2602 |
* @param username |
|
2603 |
* the username of the authenticated user |
|
2604 |
*/ |
|
2605 |
protected void handleReindexAction(Hashtable<String, String[]> params, |
|
2606 |
HttpServletRequest request, HttpServletResponse response, |
|
2607 |
String username, String[] groups) { |
|
2608 |
Logger logMetacat = Logger.getLogger(MetacatHandler.class); |
|
2609 |
|
|
2610 |
// Get all of the parameters in the correct formats |
|
2611 |
String[] pid = params.get("pid"); |
|
2612 |
|
|
2613 |
// Rebuild the indices for appropriate documents |
|
2614 |
try { |
|
2615 |
response.setContentType("text/xml"); |
|
2616 |
PrintWriter out = response.getWriter(); |
|
2617 |
|
|
2618 |
// Check that the user is authenticated as an administrator account |
|
2619 |
if (!AuthUtil.isAdministrator(username, groups)) { |
|
2620 |
out.print("<error>"); |
|
2621 |
out.print("The user \"" + username + |
|
2622 |
"\" is not authorized for this action."); |
|
2623 |
out.print("</error>"); |
|
2624 |
return; |
|
2625 |
} |
|
2626 |
|
|
2627 |
// Process the documents |
|
2628 |
StringBuffer results = new StringBuffer(); |
|
2629 |
if (pid == null || pid.length == 0) { |
|
2630 |
// Process all of the documents |
|
2631 |
logMetacat.info("queueing doc index for all documents"); |
|
2632 |
try { |
|
2633 |
List<String> allIdentifiers = IdentifierManager.getInstance().getAllSystemMetadataGUIDs(); |
|
2634 |
Iterator<String> it = allIdentifiers.iterator(); |
|
2635 |
results.append("<success>"); |
|
2636 |
while (it.hasNext()) { |
|
2637 |
String id = it.next(); |
|
2638 |
Identifier identifier = new Identifier(); |
|
2639 |
identifier.setValue(id); |
|
2640 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(identifier); |
|
2641 |
HazelcastService.getInstance().getIndexQueue().add(sysMeta); |
|
2642 |
results.append("<pid>" + id + "</pid>\n"); |
|
2643 |
logMetacat.debug("queued SystemMetadata for index on pid: " + id); |
|
2644 |
} |
|
2645 |
results.append("</success>"); |
|
2646 |
|
|
2647 |
logMetacat.info("done queueing index for all documents"); |
|
2648 |
} catch (Exception e) { |
|
2649 |
// report the error |
|
2650 |
results = new StringBuffer(); |
|
2651 |
results.append("<error>"); |
|
2652 |
results.append(e.getMessage()); |
|
2653 |
results.append("</error>"); |
|
2654 |
} |
|
2655 |
} else { |
|
2656 |
results.append("<success>\n"); |
|
2657 |
// Only process the requested documents |
|
2658 |
for (int i = 0; i < pid.length; i++) { |
|
2659 |
String id = pid[i]; |
|
2660 |
logMetacat.info("queueing doc index for pid " + id); |
|
2661 |
Identifier identifier = new Identifier(); |
|
2662 |
identifier.setValue(id); |
|
2663 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(identifier); |
|
2664 |
HazelcastService.getInstance().getIndexQueue().add(sysMeta); |
|
2665 |
results.append("<pid>" + id + "</pid>\n"); |
|
2666 |
logMetacat.info("done queueing doc index for pid " + id); |
|
2667 |
} |
|
2668 |
results.append("</success>"); |
|
2669 |
} |
|
2670 |
out.print(results.toString()); |
|
2671 |
out.close(); |
|
2672 |
} catch (IOException e) { |
|
2673 |
logMetacat.error("MetacatHandler.handleBuildIndexAction - " + |
|
2674 |
"Could not open http response for writing: " + |
|
2675 |
e.getMessage()); |
|
2676 |
e.printStackTrace(); |
|
2677 |
} catch (MetacatUtilException ue) { |
|
2678 |
logMetacat.error("MetacatHandler.handleBuildIndexAction - " + |
|
2679 |
"Could not determine if user is administrator: " + |
|
2680 |
ue.getMessage()); |
|
2681 |
ue.printStackTrace(); |
|
2682 |
} |
|
2683 |
} |
|
2684 |
|
|
2685 |
/** |
|
2590 | 2686 |
* Build the index for one document by reading the document and |
2591 | 2687 |
* calling its buildIndex() method. |
2592 | 2688 |
* |
Also available in: Unified diff
add Metacat servlet action to force the reindexing of one or more or all pids in the system. https://projects.ecoinformatics.org/ecoinfo/issues/5945