001: /*
002: * snapper
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package org.enhydra.snapperAdmin.presentation;
009:
010: // Enhydra SuperServlet imports
011:
012: import java.util.HashMap;
013: import java.util.Iterator;
014: import java.util.Map;
015:
016: import org.enhydra.snapper.SnapperManager;
017: import org.enhydra.snapperAdmin.presentation.BasePO;
018: import org.enhydra.snapperAdmin.SnapperAdmin;
019: import org.enhydra.snapperAdmin.spec.Site;
020: import org.enhydra.snapperAdmin.spec.SiteList;
021: import org.enhydra.snapperAdmin.spec.SiteListFactory;
022: import org.enhydra.snapperAdmin.spec.Update;
023: import org.enhydra.snapperAdmin.spec.UpdateAll;
024: import org.enhydra.snapperAdmin.spec.UpdateAllFactory;
025: import org.enhydra.snapperAdmin.spec.UpdateThreadFactory;
026: import org.enhydra.xml.xmlc.XMLObject;
027:
028: import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
029:
030: // Standard imports
031:
032: public class UpdateSite extends BasePO {
033:
034: protected XMLObject getDOM() throws Exception {
035:
036: String siteID = comms.request.getParameter("id");
037:
038: try {
039: boolean com = true;
040: try {
041: Class pm = Class
042: .forName("org.enhydra.snapperAdmin.business.Updater");
043: if (pm != null)
044: com = false;
045: } catch (Exception e) {
046: }
047:
048: if (com)
049: throw new ClientPageRedirectException(comms.request
050: .getAppFileURIPath("SiteListPresentation.po?d="
051: + siteID));
052:
053: } catch (Exception e) {
054:
055: }
056:
057: Update update = null;
058:
059: if (comms.request.getParameter("action") != null) {
060: if (comms.request.getParameter("action").equals(
061: "updateAllAtOnce")) {
062: updateAtOnce();
063: } else
064: updateOneByOne();
065:
066: throw new ClientPageRedirectException(comms.request
067: .getAppFileURIPath("SiteListPresentation.po"));
068: }
069:
070: try {
071:
072: Map threads = new HashMap();
073: threads = SnapperManager.getInstance().getThreads();
074:
075: for (Iterator iterator = threads.entrySet().iterator(); iterator
076: .hasNext();) {
077: Map.Entry entry = (Map.Entry) iterator.next();
078: String key = (String) entry.getKey();
079:
080: if (siteID.equals(key)) {
081: SnapperAdmin.logInfo("Site " + siteID
082: + " locked! Indexing Aborted.");
083: throw new ClientPageRedirectException(
084: comms.request
085: .getAppFileURIPath("SiteListPresentation.po?l="
086: + siteID));
087: }
088: }
089: } catch (Exception e) {
090: SnapperAdmin.logError("Could not check lock");
091: }
092:
093: try {
094: update = UpdateThreadFactory
095: .getUpdateThread("org.enhydra.snapperAdmin.business.UpdateThread");
096: } catch (Exception ex) {
097: System.out.println("Exception: " + ex);
098: }
099:
100: SnapperManager.getInstance().addThread(siteID, update);
101: update.update(siteID);
102: Thread newThread = new Thread((Runnable) update, siteID);
103: newThread.start();
104:
105: throw new ClientPageRedirectException(comms.request
106: .getAppFileURIPath("SiteListPresentation.po?u="
107: + siteID));
108:
109: }
110:
111: private void updateAtOnce() {
112: Site[] list;
113: try {
114: SiteList sl = SiteListFactory
115: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
116: list = sl.getList();
117:
118: } catch (Exception ex) {
119: System.out.println("Exception: " + ex);
120: list = null;
121: }
122: if (list != null) {
123: for (int numSites = 0; numSites < list.length; numSites++) {
124: try {
125: String id = list[numSites].getNAME();
126: Update update = UpdateThreadFactory
127: .getUpdateThread("org.enhydra.snapperAdmin.business.UpdateThread");
128: update.update(id);
129: Thread newThread = new Thread((Runnable) update, id);
130: newThread.start();
131:
132: SnapperManager.getInstance().addThread(id, update);
133: } catch (Exception e) {
134: SnapperAdmin.logError("Could not update site");
135: }
136: }
137: }
138: }
139:
140: private void updateOneByOne() {
141: Site[] list;
142: try {
143: SiteList sl = SiteListFactory
144: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
145: list = sl.getList();
146: if (list == null) {
147: return;
148: }
149:
150: String[] ids = new String[list.length];
151: for (int i = 0; i < list.length; i++) {
152: ids[i] = list[i].getNAME();
153: }
154:
155: UpdateAll updateall;
156: updateall = UpdateAllFactory
157: .getUpdateAll("org.enhydra.snapperAdmin.business.UpdateAllImpl");
158: updateall.update(ids);
159: Thread newThread = new Thread((Runnable) updateall);
160: newThread.start();
161:
162: } catch (Exception ex) {
163: System.out.println("Exception: " + ex);
164: list = null;
165: }
166:
167: }
168:
169: }
|