incubator-lokahi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tob...@apache.org
Subject svn commit: r392982 [14/25] - in /incubator/lokahi/lokahi/trunk: ./ conf/ database/ docs/ lib/ src/ src/java/ src/java/lokahi/ src/java/lokahi/core/ src/java/lokahi/core/agent/ src/java/lokahi/core/agent/callable/ src/java/lokahi/core/agent/callable/co...
Date Mon, 10 Apr 2006 16:20:11 GMT
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/BuildDeployApacheConfig.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/BuildDeployApacheConfig.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/BuildDeployApacheConfig.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/BuildDeployApacheConfig.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,80 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.controller.task;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.job.Job;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.httpd.api.worker.ApacheWorker;
+import lokahi.httpd.api.worker.ApacheWorkerModel;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: BuildDeployApacheConfig.java,v 1.1 2006/03/07 19:52:00 drtobes Exp $
+ */
+public class BuildDeployApacheConfig implements Runnable {
+  public static final Logger logger = Logger.getLogger(BuildDeployApacheConfig.class);
+
+  private final ApacheWorker aw;
+  private final JobPool jp;
+  private final boolean graceful;
+  private final Job prereq;
+
+  public BuildDeployApacheConfig(ApacheWorker aw, JobPool jobPool, boolean shouldGraceful) {
+    this.aw = aw;
+    this.graceful = shouldGraceful;
+    this.jp = jobPool;
+    this.prereq = null;
+  }
+
+  public BuildDeployApacheConfig(Job j, ApacheWorker aw, JobPool jobPool, boolean shouldGraceful) {
+    this.aw = aw;
+    this.graceful = shouldGraceful;
+    this.jp = jobPool;
+    this.prereq = j;
+  }
+
+  public void run() {
+    try {
+      Function f = Function.getFunction("PutFile");
+      ApacheWorkerModel awm = new ApacheWorkerModel();
+      Job j = new Job(prereq, aw.getApache().getServerRoot() + "/conf/httpsd.conf", aw.getHardware(), f, jp);
+      j.setResult(awm.buildConf(aw));
+      j = Job.store(j);
+      j = new Job(j, aw.getApache().getServerRoot() + "/conf/workers.properties", aw.getHardware(), f, jp);
+      j.setResult(awm.buildWorkerProperties(aw));
+      j = Job.store(j);
+      if (j != null && graceful) {
+        j = new Job(j, aw.getApache().getServerRoot(), aw.getHardware(), Function.getFunction("GracefulApache"), jp);
+        Job.store(j);
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/CheckJobPoolTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/CheckJobPoolTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/CheckJobPoolTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/CheckJobPoolTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,63 @@
+package lokahi.core.controller.task;
+
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.api.state.State;
+import org.apache.log4j.Logger;
+
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: CheckJobPoolTask.java,v 1.1 2006/03/07 19:52:00 drtobes Exp $
+ */
+public class CheckJobPoolTask implements Runnable {
+  public static final Logger logger = Logger.getLogger(CheckJobPoolTask.class);
+  private JobPool jp;
+
+  public CheckJobPoolTask(JobPool jp) {
+    this.jp = jp;
+  }
+
+  public void run() {
+    boolean flag = false;
+    try {
+      if (logger.isDebugEnabled()) {
+        logger.debug("starting jp.getPk()=" + jp.getPk());
+        logger.debug("starting jp.getName()=" + jp.getName());
+      }
+      flag = jp.setCurrentState();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("End set Current State.");
+    }
+    if (jp.getState().getPk() >= State.COMPLETE.getPk()) {
+      try {
+        JobPool.complete(jp);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    } else if (flag) {
+      try {
+        JobPool.update(jp);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("ending jp.getPk()=" + jp.getPk());
+      logger.debug("ending jp.getName()=" + jp.getName());
+    }
+
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/PingPong.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/PingPong.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/PingPong.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/PingPong.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,46 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.controller.task;
+
+import lokahi.core.controller.CheckJvmThread;
+import org.apache.log4j.Logger;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: PingPong.java,v 1.1 2006/03/07 19:52:00 drtobes Exp $
+ */
+public class PingPong {
+  public static final Logger logger = Logger.getLogger(PingPong.class);
+
+  public static String isTheThreadRunning(String test) {
+    CheckJvmThread thread = new CheckJvmThread();
+    if (logger.isDebugEnabled()) {
+      logger.debug("runThread=" + thread.runTheThread());
+      logger.debug("test=" + test);
+    }
+    String ret = "FAILED";
+    if (thread.runTheThread()) {
+      ret = thread.getContentMatch();
+    }
+    return ret;
+  } // end runTheThread
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/SendJobTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/SendJobTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/SendJobTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/task/SendJobTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,60 @@
+package lokahi.core.controller.task;
+
+import lokahi.core.api.job.Job;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: SendJobTask.java,v 1.1 2006/03/07 19:52:00 drtobes Exp $
+ */
+public class SendJobTask implements Runnable {
+  public static final Logger logger = Logger.getLogger(SendJobTask.class);
+  private Job j = null;
+
+  public SendJobTask(Job j) {
+    this.j = j;
+  }
+
+  public void run() {
+    if (j != null) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("About to send Job j=" + j);
+      }
+      if (j.send()) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("Job.send Worked...");
+        }
+        j.setStateId(1);
+        try {
+          Job.update(j);
+        } catch (SQLException e) {
+          if (logger.isInfoEnabled()) {
+            logger.info("Exception: " + e.getMessage());
+          }
+        } catch (IOException e) {
+          if (logger.isInfoEnabled()) {
+            logger.info("Exception: " + e.getMessage());
+          }
+        } catch (Exception e) {
+          logger.error("Exception: " + e.getMessage());
+          logger.error("Exception: " + e.getClass());
+          logger.error("Exception: ", e);
+
+        } catch (Throwable t) {
+          logger.error("Exception: " + t.getMessage());
+          logger.error("Exception: " + t.getClass());
+          logger.error("Exception: ", t);
+        }
+      } else {
+        if (logger.isDebugEnabled()) {
+          logger.debug("Job.send Failed...");
+        }
+      }
+    }
+  }
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,125 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.help;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.user.User;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.gui.www.TMCAction;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HelpItemAction.java,v 1.3 2006/03/07 20:18:57 drtobes Exp $
+ */
+public class HelpItemAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(HelpItemAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User u) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      HelpItemDAO hi = getTemplate(form);
+      String name = hi.getName();
+      HelpItemModel him = new HelpItemModel();
+      him.perform(f, new Class[]{User.class, HelpItemDAO.class, f.getClass()}, new Object[]{u, hi, f});
+      messages = this.addMessage(messages, SUCCESS_MESSAGE, new ActionMessage("function.success." + f.getCommand(), name));  //todo add these to teh prop file
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private HelpItemDAO getTemplate(DynaValidatorForm dynaForm) {
+    HelpItemDAO hi = new HelpItemDAO();
+    String Id = null;
+    if (dynaForm.getMap().containsKey("id")) {
+      Id = (String) dynaForm.get("id");
+    }
+    String topic = (String) dynaForm.get("topic");
+    String subtopic = (String) dynaForm.get("subtopic");
+    String title = (String) dynaForm.get("hiTitle");
+    String content = (String) dynaForm.get("content");
+    String summary = (String) dynaForm.get("summary");
+    String functionIdString = (String) dynaForm.get("functionIdString");
+    String keywordslong = (String) dynaForm.get("keywords");
+    String isValid = (String) dynaForm.get("valid");
+    if (Id != null && !"".equals(Id)) {
+      hi.setPk(Integer.parseInt(Id));
+    }
+    if (topic != null && !"".equals(topic)) {
+      hi.setTopic(topic);
+    }
+    if (subtopic != null && !"".equals(subtopic)) {
+      hi.setSubtopic(subtopic);
+    }
+    if (title != null && !"".equals(title)) {
+      hi.setTitle(title);
+    }
+    if (content != null && !"".equals(content)) {
+      hi.setContent(content);
+    }
+    if (summary != null && !"".equals(summary)) {
+      hi.setSummary(summary);
+    }
+    if (keywordslong != null && !"".equals(keywordslong)) {
+      String[] keywords = keywordslong.split(",");
+      for (int i = 0; i < keywords.length; i++) {
+        keywords[i] = keywords[i].trim();
+      }
+      hi.setKeywords(keywords);
+    }
+    if (functionIdString != null && !"".equalsIgnoreCase(functionIdString)) {
+      hi.setFunctionId(Integer.parseInt(functionIdString));
+    }
+    hi.setValid("true".equalsIgnoreCase(isValid));
+    return hi;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemDAO.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemDAO.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemDAO.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemDAO.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,389 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.help;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.user.User;
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.Collectable;
+import lokahi.core.common.interfaces.Dao;
+import lokahi.core.common.interfaces.TMCBroker;
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HelpItemDAO.java,v 1.4 2006/03/07 20:18:57 drtobes Exp $
+ */
+public class HelpItemDAO implements Dao, Collectable {
+  private static final TMCBroker<HelpItemDAO> broker = new BrokerFactory<HelpItemDAO>().getBroker();
+  static final Logger logger = Logger.getLogger(HelpItemDAO.class);
+  private int pk;
+  private String title;
+  private boolean valid;
+  private int functionId;
+  private String summary;
+
+  private String content;
+  private String topic;
+  private String subtopic;
+  private String[] keywords;
+
+  private Function function;
+
+  public Element buildXMLRepresention() {
+    return null;  //TODO finish this.
+  }
+
+  public Element buildShortXMLRepresentation() {
+    return null;  //TODO finish this.
+  }
+
+  public int getPk() {
+    return pk;
+  }
+
+  public void setPk(int pk) {
+    this.pk = pk;
+  }
+
+  public String getName() {
+    return this.getTitle();
+  }
+
+  public void setName(String title) {
+    this.setTitle(title);
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public String getTopic() {
+    return topic;
+  }
+
+  public void setTopic(String topic) {
+    this.topic = topic;
+  }
+
+  public String getSubtopic() {
+    if (subtopic == null) {
+      subtopic = "";
+    }
+    return subtopic;
+  }
+
+  public void setSubtopic(String subtopic) {
+    this.subtopic = subtopic;
+  }
+
+  public String getContent() {
+    return content;
+  }
+
+  public void setContent(String content) {
+    this.content = content;
+  }
+
+  public void setContent(Blob content) throws SQLException {
+    if (content != null) {
+      this.content = new String(content.getBytes(1, (int) content.length()));
+    } else {
+      this.content = "";
+    }
+  }
+
+  public String getSummary() {
+    return summary;
+  }
+
+  public void setSummary(String summary) {
+    this.summary = summary;
+  }
+
+  public String[] getKeywords() {
+    return keywords;
+  }
+
+  public String[] getKeywordsForWeb() { //todo make this return a csv
+    return keywords;
+  }
+
+  public void setKeywords(String[] keywords) {
+    this.keywords = keywords;
+  }
+
+  public Function getFunction() {
+    if (function == null && functionId != 0) {
+//      try {
+      function = Function.getFunction(functionId);
+//      } catch (SQLException e) {
+//        if (logger.isInfoEnabled()) {
+//          logger.info("Exception: " + e.getMessage());
+//        }
+//      }
+    }
+    return function;
+  }
+
+  public void setFunction(Function f) {
+    if (f != null) {
+      functionId = f.getPk();
+    }
+    this.function = f;
+  }
+
+  public boolean isValid() {
+    return valid;
+  }
+
+  public void setValid(boolean valid) {
+    this.valid = valid;
+  }
+
+  public int getFunctionId() {
+    return functionId;
+  }
+
+  public void setFunctionId(int functionId) {
+    this.functionId = functionId;
+  }
+
+  public int getValid() {
+    return valid ? 1 : 0;
+  }
+
+  public void setValid(int valid) {
+    this.valid = valid == 1;
+  }
+
+  public HelpItemDAO() {
+  }
+
+  public HelpItemDAO(String title, String topic, String subtopic, String summary, int functionId, int valid) {
+    this.setTitle(title);
+    this.setTopic(topic);
+    this.setSubtopic(subtopic);
+    this.setSummary(summary);
+    this.setFunctionId(functionId);
+    this.setValid(valid);
+  }
+
+  public HelpItemDAO(int pk, String title, String topic, String subtopic, String summary, int functionId, Blob content, int valid) throws SQLException {
+    this.setPk(pk);
+    this.setTitle(title);
+    this.setTopic(topic);
+    this.setSubtopic(subtopic);
+    this.setSummary(summary);
+    this.setFunctionId(functionId);
+    this.setContent(content);
+    this.setValid(valid);
+  }
+
+  public HelpItemDAO fillObject(ResultSet r) throws SQLException {
+    return new HelpItemDAO(r.getInt("HELP_ITEM_ID"),
+                           r.getString("HELP_ITEM_TITLE"),
+                           r.getString("TOPIC_NAME"),
+                           r.getString("SUBTOPIC_NAME"),
+                           r.getString("SUMMARY"),
+                           r.getInt("FUNCTION_ID"),
+                           r.getBlob("CONTENT"),
+                           r.getInt("VALID"));
+  }
+
+  public static Collection<HelpItemDAO> getMenu(User u) { //todo finish making the menu.
+    Collection<HelpItemDAO> c = null;
+    return c;
+  }
+
+  public static HelpItemDAO getHelpItem(int id) {
+    HelpItemDAO h = null;
+    try {
+      h = broker.getObject(HelpItemDAO.class, "util.help.by.id", false, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return h;
+  }
+
+  public static Collection<HelpItemDAO> getHelpItems(int functionId, int valid) {
+    Collection<HelpItemDAO> c = null;
+    try {
+      c = broker.getObjects(HelpItemDAO.class, false, "util.help.by.function", functionId, valid);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  public static Collection<HelpItemDAO> getHelpItems() {
+    Collection<HelpItemDAO> c = null;
+    try {
+      c = broker.getObjects(HelpItemDAO.class, false, "util.help.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  public static Collection getHelpItems(String keyword, int valid) {
+    Collection c = null;
+    try {
+      c = broker.getObjects(HelpItemDAO.class, false, "util.help.by.keyword", keyword, valid);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  public static HelpItemDAO store(HelpItemDAO hi) throws SQLException {  //todo F_TMC_GET_HELP_ITEM_BY_TITLE
+    hi.setPk(broker.save("util.help.store", hi.getTitle(), hi.getValid(), hi.getFunctionId(), hi.getSummary(), hi.getContent().getBytes()));
+    hi.storeTopic(hi.getTopic(), hi.getSubtopic());
+    hi.storeKeywords(hi.getKeywords());
+    return hi;
+  }
+
+  public static boolean delete(HelpItemDAO hi) throws SQLException {
+    return broker.delete("util.help.delete", hi.getPk());
+  }
+
+  public static void update(HelpItemDAO hi) throws SQLException {
+    broker.update("util.help.update", hi.getPk(), hi.getTitle(), hi.getValid(), hi.getFunctionId(), hi.getSummary(), hi.getContent().getBytes());
+    hi.updateTopic(hi.getTopic(), hi.getSubtopic());
+    hi.updateKeywords(hi.getKeywords());
+  }
+
+  private void storeKeywords(String[] toStore) throws SQLException {
+    for (final String newVar : toStore) {
+      this.storeKeyword(newVar);
+    }
+  }
+
+  private void storeKeyword(String keyword) throws SQLException {
+    int kId = this.storeItem("util.help.keyword.add", keyword);
+    this.storeRelKeyword(kId);
+  }
+
+  private void updateKeywords(String[] toStore) throws SQLException {
+    for (final String newVar : toStore) {
+      this.updateKeyword(newVar);
+    }
+  }
+
+  private void updateKeyword(String keyword) throws SQLException {
+    int kId = this.storeItem("util.help.rel.keyword.add", keyword);
+    this.updateRelKeyword(kId);
+  }
+
+  private void storeTopic(String t, String subt) throws SQLException {
+    int tId = this.storeItem("util.help.topic.store", t);
+    int sId = this.storeItem("util.help.topic.store", subt);
+    this.storeRelTopic(tId, sId);
+  }
+
+  private void updateTopic(String t, String subt) throws SQLException {
+    int tId = this.storeItem("util.help.topic.store", t);
+    int sId = this.storeItem("util.help.topic.store", subt);
+    this.updateRelTopic(tId, sId);
+  }
+
+  private int storeItem(String statement, String toStore) throws SQLException {
+    return broker.save(statement, toStore);
+  }
+
+  private void storeRelTopic(int topicId, int subtopicId) throws SQLException {
+    broker.update("util.help.rel.topic.add", this.getPk(), topicId, subtopicId);
+  }
+
+  private void updateRelTopic(int topicId, int subtopicId) throws SQLException {
+    broker.update("util.help.rel.topic.update", this.getPk(), topicId, subtopicId);
+  }
+
+  private void storeRelKeyword(int keywordId) throws SQLException {
+    broker.modifyRelationship("util.help.rel.keyword.add", this.getPk(), keywordId);
+  }
+
+  private void updateRelKeyword(int keywordId) throws SQLException {
+    broker.modifyRelationship("util.help.rel.keyword.update", this.getPk(), keywordId);
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof HelpItemDAO)) return false;
+
+    final HelpItemDAO helpItemDAO = (HelpItemDAO) o;
+
+    if (functionId != helpItemDAO.functionId) return false;
+    if (pk != helpItemDAO.pk) return false;
+    if (valid != helpItemDAO.valid) return false;
+    if (keywords != null ? !keywords.equals(helpItemDAO.keywords) : helpItemDAO.keywords != null) return false;
+    if (subtopic != null ? !subtopic.equals(helpItemDAO.subtopic) : helpItemDAO.subtopic != null) return false;
+    if (summary != null ? !summary.equals(helpItemDAO.summary) : helpItemDAO.summary != null) return false;
+    if (title != null ? !title.equals(helpItemDAO.title) : helpItemDAO.title != null) return false;
+    if (topic != null ? !topic.equals(helpItemDAO.topic) : helpItemDAO.topic != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = pk;
+    result = 29 * result + (title != null ? title.hashCode() : 0);
+    result = 29 * result + (topic != null ? topic.hashCode() : 0);
+    result = 29 * result + (subtopic != null ? subtopic.hashCode() : 0);
+    result = 29 * result + (summary != null ? summary.hashCode() : 0);
+    result = 29 * result + (keywords != null ? keywords.hashCode() : 0);
+    result = 29 * result + functionId;
+    result = 29 * result + (valid ? 1 : 0);
+    return result;
+  }
+
+  public String toString() {
+    return "HelpItemDAO{" +
+        "pk=" + pk +
+        ", title='" + title + '\'' +
+        ", topic='" + topic + '\'' +
+        ", subtopic='" + subtopic + '\'' +
+        ", summary='" + summary + '\'' +
+        ", keywords=" + keywords +
+        ", functionId=" + functionId +
+        ", valid=" + valid +
+        ", function=" + function +
+        '}';
+  }
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,91 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.help;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.api.state.State;
+import lokahi.core.api.user.User;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.common.interfaces.LokahiModel;
+import lokahi.core.common.interfaces.TMCDao;
+import org.apache.log4j.Logger;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HelpItemModel.java,v 1.5 2006/03/07 20:18:57 drtobes Exp $
+ */
+public class HelpItemModel extends LokahiModel {
+  static final Logger logger = Logger.getLogger(HelpItemModel.class);
+
+  public HelpItemModel() {
+  }
+
+  public void add(User u, HelpItemDAO hi, Function f) throws SQLException, AuthorizationException {
+    if (u.isAllowed(f) && "AddHelpItem".equals(f.getCommand())) {
+      this.jpInit(f, u, hi.getName());
+      HelpItemDAO.store(hi);
+      jp.setState(State.COMPLETE);
+      JobPool.complete(jp);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+  }
+
+  public void delete(User u, HelpItemDAO hi, Function f) throws SQLException, AuthorizationException, TMCIllegalArgumentException {
+    if (u.isAllowed(f) && "AddHelpItem".equals(f.getCommand())) {
+      if (hi == null || hi.getPk() < 1) throw new TMCIllegalArgumentException("Help Item can not be null");
+      this.jpInit(f, u, hi.getName());
+      HelpItemDAO.delete(hi);
+      jp.setState(State.COMPLETE);
+      JobPool.complete(jp);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+  }
+
+  public void update(User u, HelpItemDAO hi, Function f) throws SQLException, AuthorizationException, TMCIllegalArgumentException {
+    if (u.isAllowed(f) && "UpdateHelpItem".equals(f.getCommand())) {
+      if (hi.getPk() >= 1 && hi.getName() != null && !"".equals(hi.getName())) {
+        this.jpInit(f, u, hi.getName());
+        HelpItemDAO.update(hi);
+        jp.setState(State.COMPLETE);
+        JobPool.complete(jp);
+      } else {
+        throw new TMCIllegalArgumentException("Help Item can not be null");
+      }
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+  }
+
+  public Collection<TMCDao> getObjects() throws SQLException {
+    return null;  //TODO finish this.
+  }
+
+  public TMCDao getObject(int id) throws SQLException {
+    return null;  //TODO finish this.
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemTool.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemTool.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemTool.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/help/HelpItemTool.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,61 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.help;
+
+import lokahi.core.api.user.User;
+import org.apache.log4j.Logger;
+
+import java.util.Collection;
+import java.util.SortedSet;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HelpItemTool.java,v 1.2 2006/03/06 22:31:55 drtobes Exp $
+ */
+public class HelpItemTool {
+  static final Logger logger = Logger.getLogger(HelpItemTool.class);
+
+  public HelpItemTool() {
+  }
+
+  public SortedSet getMenu(User u) {//todo fix this it won't work.
+//    TMCCollectionImpl<HelpItemDAO> col;
+//    col = new TMCCollectionImpl<HelpItemDAO>(HelpItemDAO.getMenu(u));
+//    SortedSet set = col.getSortedSetByDate(new DateComparator<HelpItemDAO>(), 5);
+//    if (logger.isDebugEnabled()) {
+//      logger.debug("set=" + set);
+//    }
+    return null;
+  }
+
+  public Collection<HelpItemDAO> getHelpItems() {
+    return HelpItemDAO.getHelpItems();
+  }
+
+  public HelpItemDAO getHelpItem(String id) {//todo make this check for errors
+    return getHelpItem(Integer.parseInt(id));
+  }
+
+  public HelpItemDAO getHelpItem(int id) {//todo make this check for errors
+    return HelpItemDAO.getHelpItem(id);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/AlertAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/AlertAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/AlertAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/AlertAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,118 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.alert.AlertDAO;
+import lokahi.core.api.alert.AlertModel;
+import lokahi.core.api.function.Function;
+import lokahi.core.api.user.User;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.net.MalformedURLException;
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AlertAction.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+
+public class AlertAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(AlertAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User u) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      AlertDAO a = getTemplate(form);
+      String name = a.getName();
+      AlertModel am = new AlertModel();
+      am.perform(f, new Class[]{User.class, AlertDAO.class, f.getClass()}, new Object[]{u, a, f});
+      messages = this.addMessage(messages, SUCCESS_MESSAGE, new ActionMessage("function.success." + f.getCommand(), name));
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    } catch (MalformedURLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private AlertDAO getTemplate(DynaValidatorForm dynaForm) throws MalformedURLException {
+    AlertDAO al = new AlertDAO();
+    String Id = null;
+    if (dynaForm.getMap().containsKey("id")) {
+      Id = (String) dynaForm.get("id");
+    }
+    String title = (String) dynaForm.get("alertTitle");
+    String link = (String) dynaForm.get("alertLink");
+    String contents = (String) dynaForm.get("content");
+    String format = (String) dynaForm.get("format");
+    if (Id != null && !"".equals(Id)) {
+      al.setPk(Integer.parseInt(Id));
+    }
+    if (title != null && !"".equals(title)) {
+      al.setName(title);
+    }
+    if (link != null && !"".equals(link)) {
+      al.setLink(link);
+    }
+    if (contents != null && !"".equals(contents)) {
+      al.setContent(contents);
+    }
+    if (format != null && !"".equals(format)) {
+      if ("yes".equalsIgnoreCase(format))
+        al.setFormat(true);
+      else
+        al.setFormat(false);
+    }
+    return al;
+  }
+
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/Authorization.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/Authorization.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/Authorization.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/Authorization.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,154 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.user.User;
+import lokahi.core.common.authentication.AuthenticationFactory;
+import lokahi.core.common.exception.AuthenticationException;
+import lokahi.core.common.interfaces.TMCConstants;
+import lokahi.core.common.util.PropertiesFile;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.action.DynaActionForm;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Authorization.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+
+public final class Authorization extends Action implements TMCConstants {
+  static final Logger logger = Logger.getLogger(Authorization.class);
+
+  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
+    if (logger.isDebugEnabled()) {
+      logger.debug("Starting AUTH SERVLET ");
+    }
+    ActionMessages messages = new ActionMessages();
+    ActionForward actionForward;
+    boolean wap = false;
+    messages.clear();
+    String url = "";
+    DynaActionForm f = (DynaActionForm) form;
+    String logout = (String) f.get(LOGOUT_PARAM);
+    if (f.get("wap") != null && "true".equalsIgnoreCase((String) f.get("wap"))) {
+      wap = true;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("logout=" + logout);
+    }
+    if ("".equals(logout)) {
+      if (request.getSession().getAttribute(SESSION_LOGGED_IN_OBJ_PARAM) == null) {
+        String userName = (String) f.get("userName");
+        String password = (String) f.get("passWord");
+        url = (String) f.get("redirectUrl");
+        if (logger.isDebugEnabled()) {
+          logger.debug("f.get(\"wap\")=" + f.get("wap"));
+        }
+        boolean authenticated = false;
+        try {
+          authenticated = AuthenticationFactory.authenticate(userName, password);
+        } catch (AuthenticationException e) {
+          if (logger.isInfoEnabled()) {
+            logger.info("Exception: " + e.getMessage());
+          }
+          messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("login.exception", e.getMessage()));
+        }
+        if (authenticated) {
+          User u = null;
+          try {
+            u = User.getUser(userName);
+          } catch (SQLException e) {
+            if (logger.isInfoEnabled()) {
+              logger.info("Exception: " + e.getMessage());
+            }
+          }
+          HttpSession session = request.getSession();
+          if (u != null && u.isActive()) {
+            session.setAttribute("User", u);
+          } else {
+            messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("login.error.account.inactive", new Object[]{userName}));
+          }
+        } else {
+          messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("login.error", new Object[]{userName}));
+        }
+      } else {
+        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.loggedin"));
+      }
+      if (logger.isDebugEnabled()) {
+        logger.debug("wap=" + wap);
+      }
+      if (messages.isEmpty()) {
+        if (wap) {
+          actionForward = mapping.findForward("wap.success");
+        } else {
+          if ("".equals(url)) {
+            actionForward = mapping.findForward("success");
+          } else {
+            url = url.replaceAll("'", "");
+            url = url.replaceAll(PropertiesFile.getConstantValue("application.root"), "");
+            url = url.replaceAll("//", "/");
+//            if (logger.isInfoEnabled()) {
+//              logger.info("url=" + url);
+//            }
+            actionForward = new ActionForward(url, true);
+          }
+        }
+      } else {
+        if (wap) {
+          actionForward = mapping.findForward("wap.failure");
+        } else {
+          actionForward = mapping.findForward("failure");
+        }
+      }
+      saveMessages(request, messages);
+      if (logger.isDebugEnabled()) {
+        logger.debug("messages=" + messages);
+      }
+    } else {
+      logout(request.getSession());
+      if (wap) {
+        actionForward = mapping.findForward("wap.failure");
+      } else {
+        actionForward = mapping.findForward(FORWARD_LOGGED_OUT);
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Ending AUTH SERVLET");
+    }
+    return actionForward;
+  }
+
+  public void logout(HttpSession session) {
+    if (session.getAttribute("User") != null) {
+      session.removeAttribute("User");
+    }
+    //   session.invalidate();
+  }
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/EnviromentAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/EnviromentAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/EnviromentAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/EnviromentAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,99 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.environment.Environment;
+import lokahi.core.api.environment.EnvironmentModel;
+import lokahi.core.api.function.Function;
+import lokahi.core.api.user.User;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: EnviromentAction.java,v 1.1 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class EnviromentAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(EnviromentAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      Environment s = getTemplate(form);
+      String name = s.getName();
+      EnvironmentModel em = new EnvironmentModel();
+      em.perform(f, new Class[]{user.getClass(), s.getClass(), f.getClass()}, new Object[]{user, s, f});
+      messages = this.addMessage(messages, SUCCESS_MESSAGE, new ActionMessage("function.success." + f.getCommand(), name));
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private Environment getTemplate(DynaValidatorForm dynaForm) {
+    Environment e = new Environment();
+    String Id = null;
+    if (dynaForm.getMap().containsKey("envId")) {
+      Id = (String) dynaForm.get("envId");
+    }
+    String name = (String) dynaForm.get("envName");
+    String comment = (String) dynaForm.get("comments");
+    if (Id != null && !"".equals(Id)) {
+      e.setPk(Integer.parseInt(Id));
+    }
+    if (name != null && !"".equals(name)) {
+      e.setName(name);
+    }
+    if (comment != null && !"".equals(comment)) {
+      e.setComment(comment);
+    }
+    return e;
+  }
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/FileAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/FileAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/FileAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/FileAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,134 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.file.File;
+import lokahi.core.api.file.FileModel;
+import lokahi.core.api.function.Function;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: FileAction.java,v 1.1 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class FileAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(FileAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      FileModel fm = new FileModel();
+      if ("AddFile".equalsIgnoreCase(f.getCommand()) || "UpdateFile".equalsIgnoreCase(f.getCommand())) {
+        File fi = getTemplate(form);
+        fm.perform(f, new Class[]{user.getClass(), fi.getClass(), f.getClass()}, new Object[]{user, fi, f});
+      } else {
+        Collection<File> c = getMultiTemplate(form);
+        fm.perform(f, new Class[]{user.getClass(), Collection.class, f.getClass()}, new Object[]{user, c, f});
+      }
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private Collection<File> getMultiTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Collection<File> c = new TMCSet<File>();
+    String[] ids = (String[]) dynaForm.get("id");
+    if (ids != null && ids.length > 0) {
+      StringBuffer names = new StringBuffer();
+      for (int i = 0; i < ids.length; i++) {
+        if (!"".equals(ids[i])) {
+          File f = File.getFile(Integer.parseInt(ids[i]));
+          if (f != null) {
+            c.add(f);
+            names.append(f.getName());
+            names.append(',');
+          }
+        }
+      }
+    }
+    return c;
+  }
+
+  private File getTemplate(DynaValidatorForm dynaForm) {
+    File f = new File();
+    String Id = null;
+    if (dynaForm.getMap().containsKey("id")) {
+      Id = (String) dynaForm.get("id");
+    }
+    String name = (String) dynaForm.get("name");
+    String content = (String) dynaForm.get("content");
+    String path = (String) dynaForm.get("path");
+    String descriptor = (String) dynaForm.get("descriptor");
+    if (Id != null && !"".equals(Id)) {
+      f.setPk(Integer.parseInt(Id));
+    }
+    if (name != null && !"".equals(name)) {
+      f.setName(name);
+    }
+    if (content != null && !"".equals(content)) {
+      content.replaceAll("\r\n", "\n");
+      f.setContent(content);
+    }
+    if (path != null && !"".equals(path)) {
+      f.setPath(path);
+    }
+    if (descriptor != null && !"".equals(descriptor)) {
+      f.setDescriptor(descriptor);
+    }
+    return f;
+  }
+}
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HardwareAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HardwareAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HardwareAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HardwareAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,174 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.ipaddress.Ip;
+import lokahi.core.api.server.Hardware;
+import lokahi.core.api.server.HardwareModel;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HardwareAction.java,v 1.2 2006/03/10 22:46:08 drtobes Exp $
+ */
+public class HardwareAction extends TMCAction<Hardware> {
+  static final Logger logger = Logger.getLogger(HardwareAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      HardwareModel hm = new HardwareModel();
+      if ("AddHardware".equalsIgnoreCase(f.getCommand()) || "UpdateHardware".equalsIgnoreCase(f.getCommand())) {
+        Hardware h = getTemplate(messages, form);
+        hm.perform(f, new Class[]{user.getClass(), h.getClass()}, new Object[]{user, h});
+      } else {
+        Collection<Hardware> c = getMultiTemplate(form, Hardware.class);
+        hm.perform(f, new Class[]{user.getClass(), Collection.class, f.getClass()}, new Object[]{user, c, f});
+      }
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (IllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    } catch (IllegalAccessException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (InstantiationException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    }
+    return messages;
+  }
+
+//  private Collection<Hardware> getMultiTemplate(DynaValidatorForm dynaForm) throws SQLException {
+//    Collection<Hardware> c = new TMCSet<Hardware>();
+//    String[] ids = (String[]) dynaForm.get("id");
+//    if (ids != null && ids.length > 0) {
+//      for (int i = 0; i < ids.length; i++) {
+//        if (!"".equals(ids[i])) {
+//          Hardware h = Hardware.getHardware(Integer.parseInt(ids[i]), true);
+//          if (h != null) {
+//            c.add(h);
+//          }
+//        }
+//      }
+//    }
+//    return c;
+//  }
+
+  private Hardware getTemplate(ActionMessages am, DynaValidatorForm dynaForm) throws SQLException {
+    Hardware h = new Hardware();
+    String Id = null;
+    if (dynaForm.getMap().containsKey("hardwareId")) {
+      Id = (String) dynaForm.get("hardwareId");
+    }
+    final String name = (String) dynaForm.get("hardwareName");
+    final String location = (String) dynaForm.get("physicalLocation");
+    final String comment = (String) dynaForm.get("comments");
+    final String instanceId = (String) dynaForm.get("instanceId");
+    final String envIdst = (String) dynaForm.get("envId");
+    final String stateId = (String) dynaForm.get("statusId");
+    final String[] ips = ((String) dynaForm.get("ips")).split(",");
+    final String defaultIp = (String) dynaForm.get("defaultIp");
+    if (Id != null && !"".equals(Id)) {
+      h.setPk(Integer.parseInt(Id));
+    }
+    final int envId;
+    if (envIdst != null && !"".equals(envIdst)) {
+      envId = Integer.parseInt(envIdst);
+    }
+    if (stateId != null && !"".equals(stateId)) {
+      h.setStatusId(Integer.parseInt(stateId));
+    }
+    if (instanceId != null && !"".equals(instanceId)) {
+      h.setInstanceId(Integer.parseInt(instanceId));
+    }
+    h.setName(name);
+    if (defaultIp != null && !"".equals(defaultIp)) {
+      Ip ip = new Ip(defaultIp);
+      ip = Ip.store(ip);
+      if (ip == null) {
+        this.addMessage(am, new ActionMessage("error.db"));
+      } else {
+        h.setDefaultIp(ip);
+      }
+    }
+    h.setComments(comment);
+    h.setPhysicalLocation(location);
+    Collection<Ip> newIps = new TMCSet<Ip>();
+    if (!"".equals(dynaForm.get("ips"))) {
+      for (int i = 0; i < ips.length; i++) {
+        Ip ip = Ip.getIp(ips[i], true);
+        if (ip == null) {
+          ip = new Ip(ips[i]);
+          ip = Ip.store(ip);
+          if (ip == null) {
+            this.addMessage(am, new ActionMessage("error.db"));
+          } else {
+            newIps.add(ip);
+          }
+        } else {
+          newIps.add(ip);
+        }
+      }
+    }
+    h.setIpAddresses(newIps);
+    return h;
+  }
+
+  protected String getString(DynaValidatorForm dynaForm, String key) {
+    return (String) dynaForm.get(key);
+  }
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HostingPoolAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HostingPoolAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HostingPoolAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/HostingPoolAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,133 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.pool.HostingPool;
+import lokahi.core.api.pool.HostingPoolModel;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HostingPoolAction.java,v 1.1 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class HostingPoolAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(HostingPoolAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      HostingPoolModel hpm = new HostingPoolModel();
+      if ("AddHostingPool".equalsIgnoreCase(f.getCommand()) || "UpdateHostingPool".equalsIgnoreCase(f.getCommand())) {
+        HostingPool tp = getTemplate(form);
+        hpm.perform(f, new Class[]{user.getClass(), tp.getClass(), f.getClass()}, new Object[]{user, tp, f});
+      } else {
+        Collection<HostingPool> c = getMultiTemplate(form);
+        hpm.perform(f, new Class[]{user.getClass(), Collection.class, f.getClass()}, new Object[]{user, c, f});
+      }
+      messages = this.addMessage(messages, SUCCESS_MESSAGE, new ActionMessage("function.success." + f.getCommand()));
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (lokahi.core.common.exception.TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private Collection<HostingPool> getMultiTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Collection<HostingPool> c = new TMCSet<HostingPool>();
+    String[] ids = (String[]) dynaForm.get("id");
+    if (ids != null && ids.length > 0) {
+      StringBuffer names = new StringBuffer();
+      for (final String newVar : ids) {
+        if (!"".equals(newVar)) {
+          HostingPool hp = HostingPool.getHostingPool(Integer.parseInt(newVar), true);
+          if (hp != null) {
+            c.add(hp);
+            names.append(hp.getName());
+            names.append(',');
+          }
+        }
+      }
+    }
+    return c;
+  }
+
+  private HostingPool getTemplate(DynaValidatorForm dynaForm) {
+    HostingPool hp = new HostingPool();
+    String Id = null;
+    if (dynaForm.getMap().containsKey("id")) {
+      Id = (String) dynaForm.get("id");
+    }
+    String tpId = (String) dynaForm.get("tomcatPoolId");
+    String envId = (String) dynaForm.get("envId");
+    String apId = (String) dynaForm.get("apachePoolId");
+    String name = (String) dynaForm.get("poolName");
+    if (Id != null && !"".equals(Id)) {
+      hp.setPk(Integer.parseInt(Id));
+    }
+    if (name != null && !"".equals(name)) {
+      hp.setName(name);
+    }
+    if (tpId != null && !"".equals(tpId)) {
+      hp.setTomcatPoolId(Integer.parseInt(tpId));
+    }
+    if (envId != null && !"".equals(envId)) {
+      hp.setEnvId(Integer.parseInt(envId));
+    }
+    if (apId != null && !"".equals(apId)) {
+      hp.setApachePoolId(Integer.parseInt(apId));
+    }
+    return hp;
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/InstanceAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/InstanceAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/InstanceAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/InstanceAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,99 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.instance.Instance;
+import lokahi.core.api.instance.InstanceModel;
+import lokahi.core.api.user.User;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: InstanceAction.java,v 1.1 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class InstanceAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(InstanceAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      Instance i = getTemplate(form);
+      String name = i.getName();
+      InstanceModel im = new InstanceModel();
+      im.perform(f, new Class[]{user.getClass(), i.getClass(), f.getClass()}, new Object[]{user, i, f});
+      messages = this.addMessage(messages, SUCCESS_MESSAGE, new ActionMessage("function.success." + f.getCommand(), name));
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private Instance getTemplate(DynaValidatorForm dynaForm) {
+    Instance i = new Instance();
+    String Id = null;
+    if (dynaForm.getMap().containsKey("instanceId")) {
+      Id = (String) dynaForm.get("instanceId");
+    }
+    String name = (String) dynaForm.get("instanceName");
+    String comment = (String) dynaForm.get("comments");
+    if (Id != null && !"".equals(Id)) {
+      i.setPk(Integer.parseInt(Id));
+    }
+    if (name != null && !"".equals(name)) {
+      i.setName(name);
+    }
+    if (comment != null && !"".equals(comment)) {
+      i.setComments(comment);
+    }
+    return i;
+  }
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/ProjectAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/ProjectAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/ProjectAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/ProjectAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,148 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.project.Project;
+import lokahi.core.api.project.ProjectModel;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.httpd.api.entity.VirtualHost;
+import lokahi.tomcat.api.entity.TomcatContext;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ProjectAction.java,v 1.1 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class ProjectAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(ProjectAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      ProjectModel pm = new ProjectModel();
+      if ("AddProject".equalsIgnoreCase(f.getCommand()) || "UpdateProject".equalsIgnoreCase(f.getCommand())) {
+        Project p = getTemplate(form);
+        pm.perform(f, new Class[]{user.getClass(), p.getClass(), f.getClass()}, new Object[]{user, p, f});
+      } else {
+        Collection<Project> c = getMultiTemplate(form);
+        pm.perform(f, new Class[]{user.getClass(), Collection.class, f.getClass()}, new Object[]{user, c, f});
+      }
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private Collection<Project> getMultiTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Collection<Project> c = new TMCSet<Project>();
+    String[] ids = (String[]) dynaForm.get("id");
+    if (ids != null && ids.length > 0) {
+      StringBuffer sb = new StringBuffer();
+      for (int i = 0; i < ids.length; i++) {
+        if (!"".equals(ids[i])) {
+          Project p = Project.getProject(Integer.parseInt(ids[i]));
+          if (p != null) {
+            c.add(p);
+            sb.append(p.getName());
+            sb.append(',');
+          }
+        }
+      }
+    }
+    return c;
+  }
+
+  private Project getTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Project p = new Project();
+    String id = null;
+    if (dynaForm.getMap().containsKey("id")) {
+      id = (String) dynaForm.get("id");
+    }
+    String name = (String) dynaForm.get("name");
+    String[] vhosts = (String[]) dynaForm.get("virtualHosts");
+    String[] contexts = (String[]) dynaForm.get("tomcatContexts");
+
+    if (id != null && !"".equals(id)) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("id=" + id);
+      }
+      p.setPk(Integer.parseInt(id));
+    }
+    if (name != null && !"".equals(name)) {
+      p.setName(name);
+    }
+    if (vhosts != null && vhosts.length > 0) {
+      Collection<VirtualHost> c = new TMCSet<VirtualHost>();
+      for (int i = 0; i < vhosts.length; i++) {
+        VirtualHost v = VirtualHost.getVirtualHost(Integer.parseInt(vhosts[i]));
+        if (v != null) {
+          c.add(v);
+        }
+      }
+      p.setVirtualHosts(c);
+    }
+    if (contexts != null && contexts.length > 0) {
+      Collection<TomcatContext> c = new TMCSet<TomcatContext>();
+      for (int i = 0; i < contexts.length; i++) {
+        TomcatContext con = TomcatContext.getTomcatContext(Integer.parseInt(contexts[i]));
+        if (con != null) {
+          c.add(con);
+        }
+      }
+      p.setTomcatContexts(c);
+    }
+    return p;
+  }
+
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/RestServlet.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/RestServlet.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/RestServlet.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/gui/www/RestServlet.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,202 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.gui.www;
+
+import lokahi.core.api.environment.EnvironmentModel;
+import lokahi.core.api.file.FileModel;
+import lokahi.core.api.function.FunctionModel;
+import lokahi.core.api.instance.InstanceModel;
+import lokahi.core.api.job.JobModel;
+import lokahi.core.api.jobpool.JobPoolModel;
+import lokahi.core.api.pool.HostingPoolModel;
+import lokahi.core.api.project.ProjectModel;
+import lokahi.core.api.server.HardwareModel;
+import lokahi.core.api.state.StateModel;
+import lokahi.core.api.user.UserModel;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.interfaces.LokahiModel;
+import lokahi.core.common.interfaces.Restable;
+import lokahi.core.common.interfaces.TMCDao;
+import lokahi.core.common.util.PropertiesFile;
+import lokahi.httpd.api.entity.VirtualHostModel;
+import lokahi.httpd.api.pool.ApachePoolModel;
+import lokahi.httpd.api.server.ApacheModel;
+import lokahi.httpd.api.worker.ApacheWorkerModel;
+import lokahi.tomcat.api.entity.TomcatContextModel;
+import lokahi.tomcat.api.pool.TomcatPoolModel;
+import lokahi.tomcat.api.server.TomcatModel;
+import lokahi.tomcat.api.worker.TomcatWorkerModel;
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RestServlet.java,v 1.5 2006/03/07 20:18:55 drtobes Exp $
+ */
+public class RestServlet extends HttpServlet {
+  static final Logger logger = Logger.getLogger(RestServlet.class);
+
+  public void doGet(HttpServletRequest request, HttpServletResponse response) {
+    String uri = request.getRequestURI();
+    uri = uri.replaceAll(PropertiesFile.getConstantValue("application.root").replaceFirst("/", ""), "");
+    uri = uri.replaceAll("rest", "");
+    uri = uri.replaceAll("//+", "/");
+    String[] data = uri.split("/");
+    String output = "";
+    if (data.length >= 2) {
+      String whatToDisplay = data[1];
+      String idOfObject = "";
+      if (data.length >= 3) {
+        idOfObject = data[2];
+      }
+      String rootName = "";
+      Element e = null;
+      LokahiModel model = null;
+      if ("apache".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "apaches";
+        model = new ApacheModel();
+      } else if ("apacheworker".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "Apacheworkers";
+        model = new ApacheWorkerModel();
+      } else if ("apachepool".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "apachepools";
+        model = new ApachePoolModel();
+      } else if ("environment".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "environments";
+        model = new EnvironmentModel();
+      } else if ("file".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "files";
+        model = new FileModel();
+      } else if ("function".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "functions";
+        model = new FunctionModel();
+      } else if ("hardware".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "hardware";
+        model = new HardwareModel();
+      } else if ("hostingpool".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "hostingpools";
+        model = new HostingPoolModel();
+      } else if ("instance".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "instances";
+        model = new InstanceModel();
+      } else if ("job".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "jobs";
+        model = new JobModel();
+      } else if ("jobpool".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "jobpools";
+        model = new JobPoolModel();
+      } else if ("project".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "projects";
+        model = new ProjectModel();
+      } else if ("state".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "states";
+        model = new StateModel();
+      } else if ("tomcat".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "tomcats";
+        model = new TomcatModel();
+      } else if ("context".equalsIgnoreCase(whatToDisplay) || "tomcatcontext".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "contexts";
+        model = new TomcatContextModel();
+      } else if ("tomcatpool".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "tomcatpools";
+        model = new TomcatPoolModel();
+      } else if ("tomcatworker".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "tomcatworkers";
+        model = new TomcatWorkerModel();
+      } else if ("user".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "users";
+        model = new UserModel();
+      } else if ("virtualhost".equalsIgnoreCase(whatToDisplay) || "vhost".equalsIgnoreCase(whatToDisplay)) {
+        rootName = "virtualhosts";
+        model = new VirtualHostModel();
+      }
+      if (model != null) {
+        try {
+          if ("".equals(idOfObject)) {
+            output = this.buildMultiREST(rootName, model);
+          } else {
+            int id = Integer.parseInt(idOfObject);
+            Restable d = model.getObject(id);
+            output = d.buildXMLRepresention().toString();
+          }
+        } catch (SQLException ex) {
+          if (logger.isInfoEnabled()) {
+            logger.info("Exception: " + ex.getMessage());
+          }
+          output = "<rest><error>Service Unavailable</error><rest>";
+        }
+        response.setContentType("text/xml");
+      }
+    }
+    if ("".equals(output) || output == null) {
+      output = usage();
+      response.setContentType("text/html");
+    }
+    PrintWriter pw = null;
+    try {
+      pw = response.getWriter();
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (pw != null)
+      pw.println(output);
+  }
+
+  public void doPost(HttpServletRequest request, HttpServletResponse response) {
+    this.doGet(request, response);
+  }
+
+  private String buildMultiREST(String rootName, LokahiModel m) throws SQLException {
+    Collection<TMCDao> c = new TMCSet<TMCDao>();
+    c.addAll(m.getObjects());
+    StringBuilder ret = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<");
+    ret.append(rootName);
+    ret.append(">\n");
+    for (final Restable dao : c) {
+      ret.append(dao.buildShortXMLRepresentation());
+    }
+    ret.append("</");
+    ret.append(rootName);
+    ret.append(">\n");
+    return ret.toString();
+  }
+
+  private String usage() {
+    StringBuffer temp = new StringBuffer();
+    temp.append("<html><head><title>");
+    temp.append(PropertiesFile.getConstantValue("application.title"));
+    temp.append("</title></head><body>");
+    temp.append("Yup we still need a page to tell us how to use this...");
+    temp.append("</body></html>");
+    return temp.toString();
+  }
+
+}
+
+
+
+
+



Mime
View raw message