2598 |
2598 |
/**
|
2599 |
2599 |
* Rebuild the index for one or more documents. If the "pid" parameter is
|
2600 |
2600 |
* provided, rebuild for just that one document (or list of documents). If
|
2601 |
|
* not, then rebuild the index for all documents in the systemMetadata table.
|
|
2601 |
* not, an error message will be returned.
|
2602 |
2602 |
*
|
2603 |
2603 |
* @param params
|
2604 |
2604 |
* the parameters from the web request
|
... | ... | |
2616 |
2616 |
|
2617 |
2617 |
// Get all of the parameters in the correct formats
|
2618 |
2618 |
String[] pid = params.get("pid");
|
2619 |
|
|
|
2619 |
PrintWriter out = null;
|
|
2620 |
// Process the documents
|
|
2621 |
StringBuffer results = new StringBuffer();
|
2620 |
2622 |
// Rebuild the indices for appropriate documents
|
2621 |
2623 |
try {
|
2622 |
2624 |
response.setContentType("text/xml");
|
2623 |
|
PrintWriter out = response.getWriter();
|
|
2625 |
out = response.getWriter();
|
2624 |
2626 |
|
2625 |
2627 |
// Check that the user is authenticated as an administrator account
|
2626 |
2628 |
if (!AuthUtil.isAdministrator(username, groups)) {
|
... | ... | |
2628 |
2630 |
out.print("The user \"" + username +
|
2629 |
2631 |
"\" is not authorized for this action.");
|
2630 |
2632 |
out.print("</error>");
|
|
2633 |
out.close();
|
2631 |
2634 |
return;
|
2632 |
2635 |
}
|
2633 |
2636 |
|
2634 |
|
// Process the documents
|
2635 |
|
StringBuffer results = new StringBuffer();
|
|
2637 |
|
2636 |
2638 |
if (pid == null || pid.length == 0) {
|
2637 |
|
// Process all of the documents
|
2638 |
|
logMetacat.info("queueing doc index for all documents");
|
2639 |
|
try {
|
2640 |
|
List<String> allIdentifiers = IdentifierManager.getInstance().getAllSystemMetadataGUIDs();
|
2641 |
|
Iterator<String> it = allIdentifiers.iterator();
|
2642 |
|
results.append("<success>");
|
2643 |
|
while (it.hasNext()) {
|
2644 |
|
String id = it.next();
|
2645 |
|
Identifier identifier = new Identifier();
|
2646 |
|
identifier.setValue(id);
|
2647 |
|
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(identifier);
|
2648 |
|
HazelcastService.getInstance().getIndexQueue().add(sysMeta);
|
2649 |
|
results.append("<pid>" + id + "</pid>\n");
|
2650 |
|
logMetacat.debug("queued SystemMetadata for index on pid: " + id);
|
2651 |
|
}
|
2652 |
|
results.append("</success>");
|
2653 |
|
|
2654 |
|
logMetacat.info("done queueing index for all documents");
|
2655 |
|
} catch (Exception e) {
|
2656 |
|
// report the error
|
2657 |
|
results = new StringBuffer();
|
2658 |
|
results.append("<error>");
|
2659 |
|
results.append(e.getMessage());
|
2660 |
|
results.append("</error>");
|
2661 |
|
}
|
|
2639 |
//report the error
|
|
2640 |
results = new StringBuffer();
|
|
2641 |
results.append("<error>");
|
|
2642 |
results.append("The parameter - pid is missing. Please check your parameter list.");
|
|
2643 |
results.append("</error>");
|
2662 |
2644 |
} else {
|
2663 |
|
results.append("<success>\n");
|
|
2645 |
Vector<String> successList = new Vector<String>();
|
|
2646 |
Vector<String> failedList = new Vector<String>();
|
|
2647 |
|
2664 |
2648 |
// Only process the requested documents
|
2665 |
2649 |
for (int i = 0; i < pid.length; i++) {
|
2666 |
2650 |
String id = pid[i];
|
... | ... | |
2668 |
2652 |
Identifier identifier = new Identifier();
|
2669 |
2653 |
identifier.setValue(id);
|
2670 |
2654 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(identifier);
|
2671 |
|
HazelcastService.getInstance().getIndexQueue().add(sysMeta);
|
2672 |
|
results.append("<pid>" + id + "</pid>\n");
|
2673 |
|
logMetacat.info("done queueing doc index for pid " + id);
|
|
2655 |
if(sysMeta == null) {
|
|
2656 |
failedList.add(id);
|
|
2657 |
logMetacat.info("no system metadata was found for pid " + id);
|
|
2658 |
} else {
|
|
2659 |
HazelcastService.getInstance().getIndexQueue().add(sysMeta);
|
|
2660 |
successList.add(id);
|
|
2661 |
logMetacat.info("done queueing doc index for pid " + id);
|
|
2662 |
}
|
2674 |
2663 |
}
|
2675 |
|
results.append("</success>");
|
|
2664 |
results.append("<results>\n");
|
|
2665 |
if(successList.size() >0) {
|
|
2666 |
results.append("<success>\n");
|
|
2667 |
for(String id : successList) {
|
|
2668 |
results.append("<pid>" + id + "</pid>\n");
|
|
2669 |
}
|
|
2670 |
results.append("</success>");
|
|
2671 |
}
|
|
2672 |
|
|
2673 |
if(failedList.size()>0) {
|
|
2674 |
results.append("<error>\n");
|
|
2675 |
for(String id : failedList) {
|
|
2676 |
results.append("<pid>" + id + "</pid>\n");
|
|
2677 |
}
|
|
2678 |
results.append("</error>");
|
|
2679 |
}
|
|
2680 |
results.append("</results>\n");
|
2676 |
2681 |
}
|
2677 |
|
out.print(results.toString());
|
2678 |
|
out.close();
|
2679 |
2682 |
} catch (IOException e) {
|
2680 |
2683 |
logMetacat.error("MetacatHandler.handleBuildIndexAction - " +
|
2681 |
2684 |
"Could not open http response for writing: " +
|
... | ... | |
2686 |
2689 |
"Could not determine if user is administrator: " +
|
2687 |
2690 |
ue.getMessage());
|
2688 |
2691 |
ue.printStackTrace();
|
|
2692 |
} finally {
|
|
2693 |
if(out != null) {
|
|
2694 |
out.print(results.toString());
|
|
2695 |
out.close();
|
|
2696 |
}
|
2689 |
2697 |
}
|
2690 |
2698 |
}
|
2691 |
2699 |
|
|
2700 |
|
2692 |
2701 |
/**
|
|
2702 |
*Rebuild the index for all documents in the systemMetadata table.
|
|
2703 |
*
|
|
2704 |
* @param params
|
|
2705 |
* the parameters from the web request
|
|
2706 |
* @param request
|
|
2707 |
* the http request object for getting request details
|
|
2708 |
* @param response
|
|
2709 |
* the http response object for writing output
|
|
2710 |
* @param username
|
|
2711 |
* the username of the authenticated user
|
|
2712 |
*/
|
|
2713 |
protected void handleReindexAllAction(Hashtable<String, String[]> params,
|
|
2714 |
HttpServletRequest request, HttpServletResponse response,
|
|
2715 |
String username, String[] groups) {
|
|
2716 |
Logger logMetacat = Logger.getLogger(MetacatHandler.class);
|
|
2717 |
|
|
2718 |
|
|
2719 |
|
|
2720 |
// Rebuild the indices for all documents which are in the systemmetadata table
|
|
2721 |
PrintWriter out = null;
|
|
2722 |
// Process the documents
|
|
2723 |
StringBuffer results = new StringBuffer();
|
|
2724 |
try {
|
|
2725 |
response.setContentType("text/xml");
|
|
2726 |
out = response.getWriter();
|
|
2727 |
|
|
2728 |
// Check that the user is authenticated as an administrator account
|
|
2729 |
if (!AuthUtil.isAdministrator(username, groups)) {
|
|
2730 |
out.print("<error>");
|
|
2731 |
out.print("The user \"" + username +
|
|
2732 |
"\" is not authorized for this action.");
|
|
2733 |
out.print("</error>");
|
|
2734 |
out.close();
|
|
2735 |
return;
|
|
2736 |
}
|
|
2737 |
|
|
2738 |
// Process all of the documents
|
|
2739 |
logMetacat.info("queueing doc index for all documents");
|
|
2740 |
try {
|
|
2741 |
List<String> allIdentifiers = IdentifierManager.getInstance().getAllSystemMetadataGUIDs();
|
|
2742 |
Iterator<String> it = allIdentifiers.iterator();
|
|
2743 |
results.append("<success>");
|
|
2744 |
while (it.hasNext()) {
|
|
2745 |
String id = it.next();
|
|
2746 |
Identifier identifier = new Identifier();
|
|
2747 |
identifier.setValue(id);
|
|
2748 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(identifier);
|
|
2749 |
if(sysMeta != null) {
|
|
2750 |
HazelcastService.getInstance().getIndexQueue().add(sysMeta);
|
|
2751 |
results.append("<pid>" + id + "</pid>\n");
|
|
2752 |
logMetacat.debug("queued SystemMetadata for index on pid: " + id);
|
|
2753 |
}
|
|
2754 |
|
|
2755 |
}
|
|
2756 |
results.append("</success>");
|
|
2757 |
logMetacat.info("done queueing index for all documents");
|
|
2758 |
} catch (Exception e) {
|
|
2759 |
// report the error
|
|
2760 |
results = new StringBuffer();
|
|
2761 |
results.append("<error>");
|
|
2762 |
results.append(e.getMessage());
|
|
2763 |
results.append("</error>");
|
|
2764 |
}
|
|
2765 |
|
|
2766 |
} catch (IOException e) {
|
|
2767 |
logMetacat.error("MetacatHandler.handleBuildIndexAction - " +
|
|
2768 |
"Could not open http response for writing: " +
|
|
2769 |
e.getMessage());
|
|
2770 |
e.printStackTrace();
|
|
2771 |
} catch (MetacatUtilException ue) {
|
|
2772 |
logMetacat.error("MetacatHandler.handleBuildIndexAction - " +
|
|
2773 |
"Could not determine if user is administrator: " +
|
|
2774 |
ue.getMessage());
|
|
2775 |
ue.printStackTrace();
|
|
2776 |
} finally {
|
|
2777 |
if(out != null) {
|
|
2778 |
out.print(results.toString());
|
|
2779 |
out.close();
|
|
2780 |
}
|
|
2781 |
|
|
2782 |
}
|
|
2783 |
}
|
|
2784 |
|
|
2785 |
/**
|
2693 |
2786 |
* Build the index for one document by reading the document and
|
2694 |
2787 |
* calling its buildIndex() method.
|
2695 |
2788 |
*
|
Sparate the action reindex and reindexall.