Package de.iritgo.aktera.model

Examples of de.iritgo.aktera.model.ModelResponse


  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    log.info("*** Unblock firewall for database update...");
    SystemFirewall.disable();

    ModelResponse res = req.createResponse();

    Command cmd = res.createCommand("aktera.database.update");

    cmd.setName("update");
    cmd.setLabel("$updateDatabase");
    res.add(cmd);

    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);

    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 outList = response.createOutput("list");

    response.add(outList);

    List<File> files = new LinkedList(FileUtils.listFiles(FileTools.newAkteraFile(downloadDir),
            TrueFileFilter.INSTANCE, 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());

      outFile.setContent(file.getName());
      outFile.setAttribute("extension", FilenameUtils.getExtension(file.getName()));
      outFile.setAttribute("url", urlBase + "/" + file.getName());
      outList.add(outFile);
    }

    response.setAttribute("forward", "aktera.tools.download-list");

    return response;
  }
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();

    try
    {
      UpdateHelper.update(req, res, null);
    }
    catch (ServiceException x)
    {
      throw new ModelException(x);
    }

    Command cmd = res.createCommand("aktera.tools.goto-start-model");

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

    return res;
  }
View Full Code Here

  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    PersistentFactory persistentFactory = (PersistentFactory) req.getService(PersistentFactory.ROLE, req
            .getDomain());

    ModelResponse res = req.createResponse();

    DataSourceComponent dataSourceComponent = (DataSourceComponent) req.getService(DataSourceComponent.ROLE,
            "keel-dbpool");

    List<Configuration> moduleConfigs = de.iritgo.aktera.base.module.ModuleInfo
            .moduleConfigsSortedByDependency(req);

    try
    {
      Connection connection = null;

      try
      {
        connection = dataSourceComponent.getConnection();

        for (Configuration moduleConfig : moduleConfigs)
        {
          String moduleId = moduleConfig.getAttribute("id", "unkown");
          String createHandlerClassName = moduleConfig.getChild("create").getAttribute("class", null);

          if (createHandlerClassName != null)
          {
            try
            {
              System.out.println("CreateDatabase: Creating tables of module '" + moduleId
                      + "' with handler '" + createHandlerClassName + "'");

              Class klass = Class.forName(createHandlerClassName);

              if (klass != null)
              {
                CreateHandler createHandler = (CreateHandler) klass.newInstance();
                createHandler.setConnection(connection);
                createHandler.createTables(req, persistentFactory, connection, log);
              }
              else
              {
                log
                        .error("CreateDatabase: Unable to find create handler for module '"
                                + moduleId + "'");
              }
            }
            catch (ClassNotFoundException x)
            {
              log.error("CreateDatabase: Unable call create handler for module '" + moduleId + "': " + x);
            }
            catch (Exception x)
            {
              res.addOutput("databaseError", x.getMessage());
              res.addOutput("databaseErrorStackTrace", StringTools.stackTraceToString(x).replaceAll("\n",
                      "<br>"));

              return res;
            }
          }
        }
      }
      catch (SQLException x)
      {
        log.error("Unable to create database connection", x);
      }
      finally
      {
        try
        {
          connection.close();
        }
        catch (SQLException x)
        {
        }
      }

      connection = null;

      try
      {
        connection = dataSourceComponent.getConnection();

        for (Configuration moduleConfig : moduleConfigs)
        {
          String moduleId = moduleConfig.getAttribute("id", "unkown");
          String createHandlerClassName = moduleConfig.getChild("create").getAttribute("class", null);

          if (createHandlerClassName != null)
          {
            try
            {
              System.out.println("CreateDatabase: Creating data of module '" + moduleId
                      + "' with handler '" + createHandlerClassName + "'");

              Class klass = Class.forName(createHandlerClassName);

              if (klass != null)
              {
                CreateHandler createHandler = (CreateHandler) klass.newInstance();
                createHandler.setConnection(connection);
                createHandler.createData(persistentFactory, connection, log, req);
              }
              else
              {
                log
                        .error("CreateDatabase: Unable to find create handler for module '"
                                + moduleId + "'");
              }
            }
            catch (ClassNotFoundException x)
            {
              log.error("CreateDatabase: Unable call create handler for module '" + moduleId + "': " + x);
            }
            catch (Exception x)
            {
              res.addOutput("databaseError", x.getMessage());
              res.addOutput("databaseErrorStackTrace", StringTools.stackTraceToString(x).replaceAll("\n",
                      "<br>"));

              return res;
            }
          }
        }
      }
      catch (SQLException x)
      {
        log.error("Unable to create database connection", x);
      }
      finally
      {
        try
        {
          connection.close();
        }
        catch (SQLException x)
        {
        }
      }

      try
      {
        for (Configuration moduleConfig : moduleConfigs)
        {
          Persistent version = persistentFactory.create("aktera.Version");

          version.setField("type", "M");
          version.setField("name", moduleConfig.getAttribute("id", "unkown"));
          version.setField("version", moduleConfig.getChild("version").getValue("0.0.0"));
          version.add();
        }
      }
      catch (Exception x)
      {
        System.out.println(x.toString());
      }

      try
      {
        Model appInfo = (Model) req.getService(Model.ROLE, "aktera.app-info");

        Configuration[] appConfigs = appInfo.getConfiguration().getChildren("app");

        for (int i = 0; i < appConfigs.length; ++i)
        {
          Configuration appConfig = appConfigs[i];

          Persistent version = persistentFactory.create("aktera.Version");

          version.setField("type", "A");
          version.setField("name", appConfig.getAttribute("id", "unkown"));
          version.setField("version", appConfig.getChild("version").getValue("0.0.0"));
          version.add();
        }
      }
      catch (Exception x)
      {
        System.out.println(x.toString());
      }

      try
      {
        Persistent config = persistentFactory.create("aktera.SystemConfig");

        config.setField("category", "system");
        config.setField("name", "databaseCreated");
        config.setField("type", "B");
        config.setField("value", "true");

        if (! config.find())
        {
          config.add();
        }
      }
      catch (Exception x)
      {
        System.out.println(x.toString());
      }
    }
    catch (ModelException x)
    {
      res.addOutput("databaseError", x.getMessage());
      res.addOutput("databaseErrorStackTrace", x.getStackTraceAsString().replaceAll("\n", "<br>"));

      return res;
    }

    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();

    response.setAttribute("forward", "aktera.redirect");

    String scheme = request.getScheme();
    String serverName = request.getServerName();
    int port = request.getServerPort();
    String baseUrl = scheme + "://" + serverName + (port != ("https".equals(scheme) ? 443 : 80) ? ":" + port : "");
    String contextPath = request.getContextPath();

    String url = configuration.getChild("url").getValue("#");

    url = url.replaceAll("\\#\\{scheme\\}", scheme);
    url = url.replaceAll("\\#\\{server\\}", serverName);
    url = url.replaceAll("\\#\\{port\\}", String.valueOf(port));
    url = url.replaceAll("\\#\\{context\\}", contextPath);
    url = url.replaceAll("\\#\\{baseUrl\\}", baseUrl);
    response.addOutput("url", url);

    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();

    String command = req.getParameterAsString("command");

    if ("update".equals(command))
    {
View Full Code Here

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

    if (req.getParameter("license") != null)
    {
      try
      {
        String license = req.getParameterAsString("license").replaceAll("\r", "");

        if (! license.endsWith("\n"))
        {
          license += "\n";
        }

        File file = new File(System.getProperty("iritgo.license.path"));
        PrintWriter fileOut = new PrintWriter(file);

        fileOut.print(license);
        fileOut.close();
      }
      catch (Exception x)
      {
        System.out.println("[StoreLicense] " + x);
      }
    }
    else if (req.getParameter("fileUpload1") != null)
    {
      try
      {
        BinaryWrapper data = (BinaryWrapper) req.getParameter("fileUpload1");

        if (data != null)
        {
          File file = new File(System.getProperty("iritgo.license.path"));

          data.write(file);
        }
      }
      catch (Exception x)
      {
        System.out.println("[StoreLicense] " + x);
      }
    }

    Command cmd = res.createCommand("aktera.tools.goto-start-model");

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

    return 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();

    Input license = res.createInput("license");

    res.add(license);

    Input fileUpload1 = res.createInput("fileUpload1");

    res.add(fileUpload1);

    Command cmd = res.createCommand("aktera.session.store-license");

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

    return 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();

    Context c = req.getContext();

    if (c == null)
    {
      throw new ModelException("No context established - request should have established context");
    }

    UserEnvironment userEnv = null;

    try
    {
      userEnv = (UserEnvironment) c.get(UserEnvironment.CONTEXT_KEY);

      if (userEnv != null)
      {
        int uid = userEnv.getUid();

        if (uid != UserEnvironment.ANONYMOUS_UID)
        {
          AuthenticationManager authMgr = (AuthenticationManager) req.getService(AuthenticationManager.ROLE,
                  "*");

          authMgr.setUsername(userEnv.getLoginName());
          authMgr.setPassword("");
          authMgr.setDomain(userEnv.getDomain());

          HashMap map = new HashMap();

          map.put("request", req);
          map.put("response", res);
          map.put("remember", new Boolean("off"));
          map.put("configuration", getConfiguration());
          authMgr.setOtherConfig(map);

          //Clear cookies if the clear-cookies config. attribute is true
          boolean clearCookies = configuration.getAttributeAsBoolean("clear-cookies", true);

          if (clearCookies)
          {
            HashMap cookies = new HashMap();

            cookies.put(getLoginCookieName(configuration), "");
            cookies.put(getPasswordCookieName(configuration), "");
            cookies.put(getDomainCookieName(configuration), "");
            res.setAttribute("cookies", cookies);
          }

          try
          {
            authMgr.logout(userEnv);
          }
          catch (Exception ee)
          {
            log.error("Logout Error", ee);
            throw new ModelException(ee);
          }

          userEnv.clearAttributes();
          userEnv.reset();

          //          DefaultContext dc = (DefaultContext) req.getContext ();
          //          dc.put (UserEnvironment.CONTEXT_KEY, null);
          PreferencesManager preferencesManager = (PreferencesManager) SpringTools
                  .getBean(PreferencesManager.ID);

          preferencesManager.clearCache(uid);
        }
      }
    }
    catch (ContextException e)
    {
      throw new ModelException("Unable to retrieve user env. to context", e);
    }
    catch (AuthorizationException e)
    {
      throw new ModelException("Authroization error", e);
    }

    res.addOutput("loggedOff", "Logged Off");

    return 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();

    System.out.println("\nModel Request:");

    System.out.println("  Source: " + req.getSource());

    Output source = res.createOutput("source", req.getSource());

    res.add(source);

    System.out.println("  Headers:");

    Output headerList = res.createOutput("headers");

    res.add(headerList);

    int num = 1;

    for (Iterator i = req.getHeaders().entrySet().iterator(); i.hasNext();)
    {
      Map.Entry entry = (Map.Entry) i.next();

      System.out.println("   " + (String) entry.getKey() + ": " + req.getHeader((String) entry.getKey()));

      Output header = res.createOutput("header" + num++, (String) entry.getKey());

      header.setAttribute("value", req.getHeader((String) entry.getKey()));
      headerList.add(header);
    }

    System.out.println("  Parameters:");

    Output parameterList = res.createOutput("parameters");

    res.add(parameterList);

    num = 1;

    for (Iterator i = req.getParameters().entrySet().iterator(); i.hasNext();)
    {
      Map.Entry entry = (Map.Entry) i.next();

      System.out.println("   " + (String) entry.getKey() + " = " + req.getParameter((String) entry.getKey()));

      Output parameter = res.createOutput("parameter" + num++, (String) entry.getKey());

      parameter.setAttribute("value", req.getParameter((String) entry.getKey()));
      parameterList.add(parameter);
    }

    System.out.println("  Attributes:");

    Output attributeList = res.createOutput("attributes");

    res.add(attributeList);

    num = 1;

    for (Iterator i = req.getAttributes().entrySet().iterator(); i.hasNext();)
    {
      Map.Entry entry = (Map.Entry) i.next();

      System.out.println("   " + (String) entry.getKey() + " = " + req.getAttribute((String) entry.getKey()));

      Output attribute = res.createOutput("attribute" + num++, (String) entry.getKey());

      attribute.setAttribute("value", req.getAttribute((String) entry.getKey()));
      attributeList.add(attribute);
    }

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.