Package de.iritgo.aktera.model

Examples of de.iritgo.aktera.model.ModelResponse


   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    SystemConfigManager systemConfigManager = (SystemConfigManager) req.getSpringBean(SystemConfigManager.ID);

    ModelResponse res = req.createResponse();

    if (! UpdateHelper.databaseExists(req))
    {
      return res.createCommand("aktera.database.create-prompt").execute(req, res);
    }

    try
    {
      if (UpdateHelper.needUpdate(req))
      {
        return res.createCommand("aktera.database.update-prompt").execute(req, res);
      }
    }
    catch (ConfigurationException x)
    {
      throw new ModelException("ConfigurationException during needUpdate() check", x);
    }

    try
    {
      SystemCheckService systemCheckService = (SystemCheckService) SpringTools.getBean(SystemCheckService.ID);
      if (systemCheckService != null && ! systemCheckService.isSystemReady())
      {
        return res.createCommand(systemCheckService.getSystemCheckModel()).execute(req, res);
      }
    }
    catch (Exception ignore)
    {
      // No system check service configured.
    }

    String startModel = (String) systemConfigManager.get("system", "startModel");

    if (startModel != null && UserTools.getCurrentUserId(req) == null)
    {
      return res.createCommand("aktera.session.prompt-login").execute(req, res);
    }

    if (UserTools.currentUserIsInGroup(req, "admin"))
    {
      return res.createCommand((String) systemConfigManager.get("system", "startModelAdmin")).execute(req, res);
    }
    else if (UserTools.currentUserIsInGroup(req, "manager"))
    {
      return res.createCommand((String) systemConfigManager.get("system", "startModelManager")).execute(req, res);
    }

    return res.createCommand(startModel).execute(req, res);
  }
View Full Code Here


   * @param req The model request.
   * @return The model response.
   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    ModelResponse res = req.createResponse();

    return res;
  }
View Full Code Here

   * @param request The model request.
   * @return The model response.
   */
  public ModelResponse execute(ModelRequest request) throws ModelException
  {
    ModelResponse response = request.createResponse();

    String downloadDir = getConfiguration().getChild("directory").getValue(null);
    String alternativeForward = getConfiguration().getChild("forward").getValue(null);
    final String filetype = getConfiguration().getChild("filetype").getValue(null) == null ? ".flv"
            : getConfiguration().getChild("filetype").getValue(null);

    if (downloadDir == null)
    {
      log.error("No download directory specified");
      throw new ModelException("No download directory specified");
    }

    String urlBase = getConfiguration().getChild("url").getValue(null);

    if (urlBase == null)
    {
      log.error("No URL base specified");
      throw new ModelException("No URL base specified");
    }

    Output player = response.createOutput("player");

    player.setAttribute("playerUrl", getConfiguration().getChild("playerUrl").getValue(null));
    player.setAttribute("urlBase", urlBase);
    player.setAttribute("server", request.getServerName());

    response.add(player);

    Output outList = response.createOutput("list");

    response.add(outList);

    List<File> files = new LinkedList(FileUtils.listFiles(FileTools.newAkteraFile(downloadDir), new IOFileFilter()
    {
      public boolean accept(File file)
      {
        return file.getName().endsWith(filetype);
      }

      public boolean accept(File arg0, String arg1)
      {
        return false;
      }
    }, null));

    Collections.sort(files, new Comparator<File>()
    {
      public int compare(File o1, File o2)
      {
        return o1.getName().compareToIgnoreCase(o2.getName());
      }
    });

    for (File file : files)
    {
      Output outFile = response.createOutput("file" + file.hashCode());

      try
      {
        outFile.setContent(file.getName());
        outFile.setAttribute("extension", FilenameUtils.getExtension(file.getName()));
        outFile.setAttribute("url", urlBase + "/" + file.getName());
        outFile.setAttribute("filename", file.getName());

        String videoNameFile = FilenameUtils.removeExtension(file.getName()) + ".name";
        String descriptionFile = FilenameUtils.removeExtension(file.getName()) + ".description";

        outFile.setAttribute("videoName", FileUtils
                .readFileToString(new File(downloadDir + "/" + videoNameFile)));
        outFile.setAttribute("description", FileUtils.readFileToString(new File(downloadDir + "/"
                + descriptionFile)));
      }
      catch (IOException x)
      {
      }

      outList.add(outFile);
    }

    if (alternativeForward == null)
    {
      response.setAttribute("forward", "aktera.tools.video-list");
    }
    else
    {
      response.setAttribute("forward", alternativeForward);
    }

    return response;
  }
View Full Code Here

   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    String lastLine = "";

    ModelResponse res = req.createResponse();

    try
    {
      Output report = res.createOutput("report");

      res.add(report);

      String reportFileName = getConfiguration().getChild("fileName").getValue(null);

      if (! StringTools.isTrimEmpty(reportFileName))
      {
        StringBuilder reportBuf = new StringBuilder();
        File reportFile = FileTools.newAkteraFile(reportFileName);
        BufferedReader in = new BufferedReader(new FileReader(reportFile));
        String line = null;

        while ((line = in.readLine()) != null)
        {
          reportBuf.append(line + "\n");
          lastLine = line;
        }

        report.setContent(reportBuf.toString());
      }
      else
      {
        String beanName = getConfiguration().getChild("bean").getValue(null);
        String methodName = getConfiguration().getChild("method").getValue(null);

        if (! StringTools.isTrimEmpty(beanName) && ! StringTools.isTrimEmpty(methodName))
        {
          Object bean = req.getSpringBean(beanName);

          lastLine = (String) MethodUtils.invokeExactMethod(bean, methodName, null);
          report.setContent(lastLine);
        }
      }

      if (lastLine != null && lastLine.indexOf("Result: OK") != - 1)
      {
        Command cmd = res.createCommand(getConfiguration().getChild("cmd-ok").getValue());

        cmd.setName("cmdOk");
        res.add(cmd);
      }
      else if (lastLine != null && lastLine.indexOf("Result: ERROR") != - 1)
      {
        Command cmd = res.createCommand(getConfiguration().getChild("cmd-error").getValue());

        cmd.setName("cmdError");
        res.add(cmd);

        res.add(res.createOutput("error", "Y"));
      }
      else
      {
        Command cmd = res.createCommand(getConfiguration().getChild("cmd-report").getValue());

        cmd.setName("cmdReport");
        res.add(cmd);
      }

      res
              .setAttribute("forward", getConfiguration().getChild("forward").getValue(
                      "aktera.tools.progress-report"));
    }
    catch (IOException x)
    {
View Full Code Here

   * @param req The model request.
   * @throws ModelException In case of a business failure.
   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    ModelResponse res = req.createResponse();
    Locale locale = req.getLocale();
    Output outDate = res.createOutput("currentDate");
    SimpleDateFormat simpleDate = new SimpleDateFormat("EEE, dd. MMM yyyy - HH:mm", locale);

    outDate.setContent(simpleDate.format(new Date(System.currentTimeMillis())));
    res.add(outDate);

    return res;
  }
View Full Code Here

   * @param req The model request.
   * @throws ModelException In case of a business failure.
   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    ModelResponse res = req.createResponse();

    int uid = 0;

    try
    {
      Context ctx = req.getContext();
      UserEnvironment ue = null;

      if (ctx != null)
      {
        try
        {
          ue = (UserEnvironment) ctx.get(UserEnvironment.CONTEXT_KEY);
          uid = ue.getUid();
        }
        catch (ContextException ce)
        {
          log.debug("Unable to acces user environment from context!");
        }
        catch (AuthorizationException x)
        {
          log.debug("AuthorizationException!");
        }

        if (ue != null)
        {
          try
          {
            if (ue.getUid() == UserEnvironment.ANONYMOUS_UID)
            {
              log.debug("BUG, this can't true");
            }
          }
          catch (AuthorizationException e)
          {
            log.debug("Unable to acces user environment from context!");
            throw new ModelException("Unable to acces user environment from context!", e);
          }
        }
        else
        {
          log.debug("Unable to acces user environment from context!");
          throw new ModelException("Unable to acces user environment from context!");
        }
      }

      PersistentFactory persistentManager = (PersistentFactory) req.getService(PersistentFactory.ROLE, req
              .getDomain());

      Persistent keelUser = persistentManager.create("keel.user");

      keelUser.setField("uid", new Integer(uid));

      if (! keelUser.find())
      {
        ThreadedModel.sleep(3000);
        res.addError("notLoggedIn", "You are not logged in.");

        return res;
      }
    }
    catch (PersistenceException x)
    {
      log.error("Database Error", x);
      throw new ModelException("$databaseError", x);
    }
    catch (InterruptedException ie)
    {
    }

    res.setAttribute("userId", new Integer(uid));

    return res;
  }
View Full Code Here

   * @param request The model request.
   * @return The model response.
   */
  public ModelResponse execute(ModelRequest request) throws ModelException
  {
    ModelResponse response = request.createResponse();

    return response;
  }
View Full Code Here

   * @param req The model request.
   * @return The model response.
   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    ModelResponse res = req.createResponse();

    try
    {
      AkteraJvmMemoryManager jvmMemoryManager = (AkteraJvmMemoryManager) req
              .getSpringBean(AkteraJvmMemoryManager.ID);

      BufferedImage image = new BufferedImage(1024 + 91, 768 + 92, BufferedImage.TYPE_INT_RGB);
      String name = req.getParameterAsString("name");

      jvmMemoryManager.generateGraph(name, image);

      ByteArrayOutputStream os = new ByteArrayOutputStream();

      ImageIO.write(image, "jpg", os);

      Output out = res.createOutput("data");

      out.setContent(os.toByteArray());
      res.add(out);
      os.close();

      res.addOutput("contentType", "image/png");
      res.addOutput("diagram", "diagram.png");
    }
    catch (Exception x)
    {
    }

View Full Code Here

{
  private Context context = null;

  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    ModelResponse res = req.createResponse();

    try
    {
      Configuration sysConfig = (Configuration) context.get("keel.config.system");
      Output sysOutput = res.createOutput("system");

      addChildren(res, sysOutput, sysConfig);
      res.add(sysOutput);

      Configuration logConfig = (Configuration) context.get("keel.config.log");
      Output logOutput = res.createOutput("log");

      addChildren(res, logOutput, logConfig);
      res.add(logOutput);

      Configuration roleConfig = (Configuration) context.get("keel.config.roles");
      Output roleOutput = res.createOutput("role");

      addChildren(res, roleOutput, roleConfig);
      res.add(roleOutput);

      Configuration instrConfig = (Configuration) context.get("keel.config.instr");
      Output instrOutput = res.createOutput("instrument");

      addChildren(res, instrOutput, instrConfig);
      res.add(instrOutput);
    }
    catch (ConfigurationException ce)
    {
      throw new ModelException(ce);
    }
View Full Code Here

      }
    }

    String forward = null;

    ModelResponse res = req.createResponse();

    if (modelName != null && ! modelName.equals("null") && ! modelName.startsWith("_BEAN_."))
    {
      Model model = (Model) req.getService(Model.ROLE, modelName);

      ModelRequest mreq = (ModelRequest) req.getService(ModelRequest.ROLE, "default");

      mreq.copyFrom(req);
      mreq.removeParameter("listSearch");

      for (Iterator i = req.getParameters().keySet().iterator(); i.hasNext();)
      {
        String key = (String) i.next();

        if (key.startsWith("_lep"))
        {
          String keyName = key.substring(4);

          if (req.getParameter(keyName) == null)
          {
            mreq.setParameter(keyName, req.getParameter(key));
          }
        }

        if (key.startsWith("_lp"))
        {
          String keyName = key.substring(3);

          if (req.getParameter(keyName) == null)
          {
            mreq.setParameter(keyName, req.getParameter(key));
          }
        }
      }

      res = model.execute(mreq);

      try
      {
        Configuration[] attributes = model.getConfiguration().getChildren("attribute");

        for (int i = 0; i < attributes.length; ++i)
        {
          if ("forward".equals(attributes[i].getAttribute("name", null)))
          {
            forward = attributes[i].getAttribute("value");
          }
        }
      }
      catch (ConfigurationException x)
      {
      }
    }
    else if (modelName != null && modelName.startsWith("_BEAN_."))
    {
      try
      {
        Map<String, Object> parameters = new HashMap();

        for (Iterator i = req.getParameters().keySet().iterator(); i.hasNext();)
        {
          String key = (String) i.next();

          if (key.startsWith("_lep"))
          {
            String keyName = key.substring(4);

            if (req.getParameter(keyName) == null)
            {
              parameters.put(keyName, req.getParameter(key));
            }
          }
          else if (key.startsWith("_lp"))
          {
            String keyName = key.substring(3);

            if (req.getParameter(keyName) == null)
            {
              parameters.put(keyName, req.getParameter(key));
            }
          }
          else
          {
            parameters.put(key, req.getParameter(key));
          }
        }

        BeanRequest uiRequest = new BeanRequest();

        uiRequest.setLocale(req.getLocale());
        uiRequest.setBean(modelName.replace("_BEAN_.", ""));
        uiRequest.setParameters(parameters);
        uiRequest.setUserEnvironment((UserEnvironment) req.getContext().get(UserEnvironment.CONTEXT_KEY));

        BeanResponse uiResponse = new BeanResponse();

        BeanAction.execute(uiRequest, uiResponse);

        if (! UIController.DEFAULT_FORWARD.equals(uiResponse.getForward()))
        {
          res.setAttribute("forward", uiResponse.getForward());
        }

        for (Map.Entry<String, ResponseElement> re : uiResponse.getElements().entrySet())
        {
          res.add(re.getValue());
        }
      }
      catch (ContextException x)
      {
        throw new ModelException(x);
      }
      catch (AuthorizationException x)
      {
        throw new ModelException(x);
      }
      catch (UIControllerException x)
      {
        throw new ModelException(x);
      }
    }

    if (forward == null)
    {
      forward = (String) res.getAttribute("forward");
    }

    if (forward != null)
    {
      res.setAttribute("forward", forward);

      return res;
    }
    else
    {
      Command cmd = res.createCommand((String) req.getParameter("_lm"));

      for (Iterator i = req.getParameters().keySet().iterator(); i.hasNext();)
      {
        String key = (String) i.next();
View Full Code Here

TOP

Related Classes of de.iritgo.aktera.model.ModelResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.