Package de.iritgo.aktera.model

Examples of de.iritgo.aktera.model.ModelResponse


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

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

      Configuration fileConfig = getConfiguration().getChild("file", false);

      if (fileConfig != null)
      {
        BinaryWrapper data = new BinaryWrapper(fileConfig.getAttribute("name"),
                fileConfig.getAttribute("type"), fileConfig.getAttribute("path"), 1024 * 1024, null);

        out.setContent(data);
      }

      res.add(out);
    }
    catch (ConfigurationException x)
    {
    }

View Full Code Here


      {
        throw new ModelException("Invalid sequence '" + seqString + "'", ne);
      }
    }

    ModelResponse currentResponse = null;
    SequenceContext seqContext = null;

    try
    {
      seqContext = SequenceContext.getSequenceContext(req);

      if (seqContext != null)
      {
        //                 log.debug("Found existing sequence context. Seq= " + (seq));
        String oldSeqName = seqContext.getSequenceName();

        /**
         * Added by ACR. Up until now, problems occured when seq steps from one sequence would
         * bleed into the next sequence, jumping the user up steps.
         * I have changed the system to now assume that when you jump from one sequence to another
         * you want to go to the first step of the next sequence.
         *
         */
        if (! seqName.equals(oldSeqName))
        {
          //                     if (log.isDebugEnabled()) {
          //                       log.debug(
          //                         "Sequence is transitioning, from sequence "
          //                             + oldSeqName
          //                             + " to sequence "
          //                             + seqName
          //                             + ". Clearing sequence variables....");
          //                     }
          //Don't change the seq parameter, because we already read it in above, and we have already set it 1 if
          //there was no sequence param.
          clearSequence(req);
          currentResponse = req.createResponse();
        }
        else
        {
          if (seq != 1)
          {
            //we want to "recycle" the response to keep it going, since we are still in the same sequence....
            currentResponse = seqContext.getCurrentResponse();
          }
          else
          {
            currentResponse = req.createResponse();
          }
        } //end-if-else
      }
      else
      { //seqContext is null, so create a new one
        createNewSeqContext = true;
      } //end-if-else
    }
    catch (ModelException e)
    {
      //Error occured. Start a fresh response....
      currentResponse = req.createResponse();
      createNewSeqContext = true;
      log.error(e.toString());
    }

    clearSequence(req);
    createNewSeqContext = true;
    //Set flag to create a new sequence context.
    params.putAll(req.getParameters());

    Configuration[] children = myConf.getChildren();

    if (seq > children.length)
    {
      log.warn("Requested seq " + seq + " which is more than available steps " + children.length);
      clearSequence(req);

      if (currentResponse != null)
      {
        return currentResponse;
      }
      else
      {
        throw new ModelException("Response for end of sequence was null");
      }
    }

    //Added by Phil Brown to create and save a new Sequence Context if we don't have
    //This is desired so that our models have the sequenceContext available in case they
    //wish to examine it.
    if (seqContext == null || createNewSeqContext)
    {
      seqContext = setNewSequenceContext(seqName, seq, children, mergeDefaultForThisSequence, req,
              currentResponse);
    }

    /* If a particular step in the sequence has "return='false'" then */
    /* we simply continue on to the next step, without returning control */
    /* to the user. If "return" is not specified, it is assumed "true" */
    ModelResponse previousResponse = SequenceContext.mergeResponse(req.createResponse(), currentResponse);
    ModelResponse theResponse = req.createResponse();

    //Create a response to return. We will merge later if we need to.
    while (keepRunning)
    {
      //             log.debug("Seq is " + seq);
      if (seq > children.length)
      {
        keepRunning = false;

        //                 log.debug(
        //                     "No more steps in sequence (length "
        //                         + children.length
        //                         + ")");
      }
      else
      {
        Configuration oneElement = children[seq - 1];

        seqContext.setSeqStepNum(seq);
        //Update the current step in the seqContext -- add by Phil Brown
        seqContext.setCurrentResponse(currentResponse);

        //Update the "current" response.  -- add by Phil Brown
        if (oneElement.getName().equals("model"))
        {
          currentResponse = runModel(oneElement, req, previousResponse, seq, seqName, seqContext);
        }
        else if (oneElement.getName().equals("if"))
        {
          //                     log.debug("Processing conditional in sequence");
          currentResponse = runIfTrue(oneElement);
        }
        else
        {
          throw new ConfigurationException("Element '" + oneElement.getName()
                  + "' should be either 'model' or 'if'");
        }

        if (oneElement.getAttribute("return", "").equals("ifinput"))
        {
          //                     log.debug("We return if model just run has inputs");
          if (containsInputs(currentResponse))
          {
            keepRunning = false;

            //                         log.debug("Model just run has inputs - returning");
          }
          else
          {
            seq = getNextSequence(seq, req);
          }
        }
        else
        {
          if (oneElement.getAttributeAsBoolean("return", true))
          {
            keepRunning = false;

            //                         log.debug("Model has input set to true - returning");
          }
          else
          {
            seq = getNextSequence(seq, req);
          }
        }

        //ACR & PJB - Gets merge attribute from <model> element.  If not found, then uses default from SequenceContext
        if (oneElement.getAttributeAsBoolean("merge", seqContext.getMergeResponsesDefault()))
        {
          mergeResponses = true;
        }
        else
        {
          mergeResponses = false;
        }
      } /* else we're still on a valid sequence */
      //ACR: Here is the merge...if a condition has been met where
      //multiple models are run in this "pass", they are each merged here.
      if (mergeResponses)
      {
        theResponse.removeAttribute("forward");
        theResponse.removeAttribute("stylesheet");
        theResponse = SequenceContext.mergeResponse(theResponse, currentResponse);
      }
      else
      {
        theResponse = currentResponse;
View Full Code Here

    c.setParameter(Sequence.SEQUENCE_NUMBER, "" + seqNumber);

    //c.setParameter(SequenceContext.CONTEXT_KEY, seqContext);
    //Add by Phil Brow to pass the seq Context as a param to each model
    //MN: Can't serialize a SequenceContext in the response
    ModelResponse commandRes = c.execute(req, existingResponse);

    //         log.debug("Executed command.");
    for (Iterator ii = postAttribs.keySet().iterator(); ii.hasNext();)
    {
      String oneKey = (String) ii.next();

      commandRes.setAttribute(oneKey, postAttribs.get(oneKey));
    }

    return commandRes;
  }
View Full Code Here

   * @return a ModelResponse from the specified model
   * @throws ModelException If the model is not configured correctly
   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    ModelResponse res = req.createResponse();

    try
    {
      Command c = res.createCommand(getConfiguration().getChild("model").getValue());

      res.addErrors(req.getErrors());

      return c.execute(req, res, true, true);
    }
    catch (ConfigurationException ce)
    {
View Full Code Here

   * @return The model response
   * @throws ModelException
   */
  protected ModelResponse execute(ModelRequest request, String[] ids) throws ModelException
  {
    ModelResponse res = request.createResponse();

    for (String id : ids)
    {
      execute(request, res, id);
    }
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 originalURL = null;
    try
    {
      originalURL = (String) req.getContext().get("originalURL");
    }
    catch (ContextException x)
    {
    }
    if (originalURL != null)
    {
      res.addOutput("originalURL", originalURL.toString());
    }

    String domain = (String) req.getParameter("domain");

    String loginName = (String) req.getParameter("loginName");
    if (loginName.equals(""))
    {
      res.addError("GLOBAL_loginError", "$youNeedToProvideALoginName");
      return res.createCommand(Constants.PROMPT_LOGIN).execute(req, res);
    }

    PermissionManager permissionManager = (PermissionManager) SpringTools.getBean(PermissionManager.ID);
    if (! permissionManager.hasPermission(loginName, "de.iritgo.aktera.web.login"))
    {
      res.addError("GLOBAL_loginError", "$youAreNotAllowedToLogin");
      return res.createCommand(Constants.PROMPT_LOGIN).execute(req, res);
    }

    try
    {
      String providedPassword = (String) req.getParameter("password");
      if (providedPassword.equals(""))
      {
        res.addError("GLOBAL_loginError", "$youNeedToProvideAPassword");
        return res.createCommand(Constants.PROMPT_LOGIN).execute(req, res);
      }
      boolean remember = false;
      if (req.getParameters().containsKey("remember"))
      {
        remember = true;
      }

      AuthenticationManager authMgr = (AuthenticationManager) req.getService(AuthenticationManager.ROLE, domain);
      authMgr.setUsername(loginName);
      authMgr.setPassword(providedPassword);
      authMgr.setDomain(domain);

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

      UserEnvironment ue = null;
      Context c = req.getContext();

      try
      {
        ue = (UserEnvironment) c.get(UserEnvironment.CONTEXT_KEY);
      }
      catch (ContextException e)
      {
        if (c instanceof DefaultContext)
        {
          ue = new DefaultUserEnvironment();
          ((DefaultContext) c).put(UserEnvironment.CONTEXT_KEY, ue);
        }
        else
        {
          throw new ModelException("Unable to write user env. to context, was '" + c.getClass().getName());
        }
      }

      authMgr.login(ue);

      try
      {
        HashMap cookies = new HashMap();

        if (remember)
        {
          String[] cookieSeq = getCryptSeq(configuration, "cookie");
          cookies.put(getLoginCookieName(configuration), encodeWithSeq(cookieSeq, loginName, req));
          cookies.put(getPasswordCookieName(configuration), encodeWithSeq(cookieSeq, providedPassword, req));
          cookies.put(getDomainCookieName(configuration), encodeWithSeq(cookieSeq, domain, req));
          res.addOutput("remembered", "$loginRemembered");
        }
        else
        {
          cookies.put(getLoginCookieName(configuration), "");
          cookies.put(getPasswordCookieName(configuration), "");
          cookies.put(getDomainCookieName(configuration), "");
          res.addOutput("remembered", "$loginNotRemembered");
        }

        res.setAttribute("cookies", cookies);
      }
      catch (ModelException e)
      {
        throw new LoginException("Error setting cookies - " + e.getMessage());
      }

      if (log.isDebugEnabled())
      {
        log.debug("Logged in authenticated user: " + loginName + " domain: " + domain);
        log.debug("\tPrincipals:");

        Iterator i = ue.getSubject().getPrincipals().iterator();
        while (i.hasNext())
        {
          Principal p = (Principal) i.next();
          log.debug(p.toString());
        }
      }
    }
    catch (LoginException e)
    {
      if (e.getMessage().matches(".*([Ll]ogin|[Aa]ccount).*"))
      {
        res.addError("GLOBAL_loginError", "$badLoginName");
      }
      else if (e.getMessage().matches(".*[Pp]assword.*"))
      {
        res.addError("GLOBAL_loginError", "$badPassword");
      }
      else
      {
        res.addError("GLOBAL_loginError", "$loginError");
      }

      log.warn("Login error for user '" + loginName + "': " + e.getMessage());

      return res.createCommand(Constants.PROMPT_LOGIN).execute(req, res);
    }
    catch (Exception dbe)
    {
      res.addError("GLOBAL_loginError", dbe);
      log.error("loginError", dbe);

      return res.createCommand(Constants.PROMPT_LOGIN).execute(req, res);
    }

    try
    {
      log.debug(loginName + " logged in successfully");

      res.addCommand(Constants.LOGOFF, "Log Off");
    }
    catch (Exception x)
    {
      log.error("Login Error", x);
      throw new ModelException(x);
    }

    if (res.getErrors().size() == 0)
    {
      Properties props = new Properties();

      props.put("command", "login");
      ModelTools.callModel(req, "aktera.session.session-manager", props);
View Full Code Here

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

    AppInfo.Info appInfo = AppInfo.getAppInfo(AppInfo.SYSTEM);

    Output outName = res.createOutput("name", appInfo.getNameLong());

    res.add(outName);

    Output outVersion = res.createOutput("version", appInfo.getVersionLong());

    res.add(outVersion);

    Output outCopyright = res.createOutput("copyright", appInfo.getCopyright().replaceAll("\\\\n", "<br>"));

    res.add(outCopyright);

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

    int size = NumberTools.toInt(req.getParameter("size"), 10 * 1024 * 1024);

    consumedMemory.add(new byte[size]);

View Full Code Here

   */
  public ModelResponse execute(ModelRequest req) throws ModelException
  {
    SystemFirewall.disable();

    ModelResponse res = req.createResponse();
    Command cmd = res.createCommand("aktera.database.create");
    cmd.setName("create");
    cmd.setLabel("$createDatabase");
    res.add(cmd);

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

    Output outUserId = res.createOutput("userId");

    outUserId.setContent(new Integer(1));
    res.add(outUserId);

    return res;
  }
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.