Ejemplo n.º 1
0
  public void setUp() throws Exception {
    super.setUp();

    userprofileOS.setModel(Model.getInstanceByName("userprofile"));
    Model testmodel = Model.getInstanceByName("testmodel");
    query = new PathQuery(testmodel);

    query.addView("Employee");
    query.addView("Employee.name");
    queryBag = new PathQuery(testmodel);

    queryBag.addView("Employee");
    queryBag.addView("Employee.name");
    queryBag.addConstraint(Constraints.in("Employee", "bag2"));
    sq = new SavedQuery("query1", date, query);
    sqBag = new SavedQuery("query3", date, queryBag);
    hist = new SavedQuery("query2", date, (PathQuery) query.clone());
    hist2 = new SavedQuery("query1", date, query.clone());
    template = new TemplateQuery("template", "ttitle", "tdesc", new PathQuery(testmodel));

    SessionMethods.initSession(this.getSession());
    Profile profile = (Profile) getSession().getAttribute(Constants.PROFILE);
    profile.saveQuery(sq.getName(), sq);
    profile.saveQuery(sqBag.getName(), sqBag);
    profile.saveHistory(hist);
    profile.saveHistory(hist2);
  }
Ejemplo n.º 2
0
  /**
   * Convert a SavedQuery to XML and write XML to given writer.
   *
   * @param query the SavedQuery
   * @param writer the XMLStreamWriter to write to
   * @param version the version number of the XML format, an attribute of the ProfileManager
   */
  public static void marshal(SavedQuery query, XMLStreamWriter writer, int version) {
    try {
      writer.writeCharacters("\n");
      writer.writeStartElement("saved-query");

      writer.writeAttribute("name", query.getName());
      if (query.getDateCreated() != null) {
        writer.writeAttribute("date-created", "" + query.getDateCreated().getTime());
      }
      PathQueryBinding.marshal(
          query.getPathQuery(),
          query.getName(),
          query.getPathQuery().getModel().getName(),
          writer,
          version);
      writer.writeEndElement();
    } catch (XMLStreamException e) {
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 3
0
  /**
   * Either display the query builder or redirect to project.sitePrefix.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @return an ActionForward object defining where control goes next
   * @exception Exception if the application business logic throws an exception
   */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HttpSession session = request.getSession();
    PathQuery query = SessionMethods.getQuery(session);
    boolean showTemplate = (request.getParameter("showTemplate") != null);

    if (query == null) {
      return new ForwardParameters(
              getWebProperties(request).getProperty("project.sitePrefix"), true)
          .forward();
    }

    if (query instanceof TemplateQuery && showTemplate) {
      TemplateQuery template = (TemplateQuery) query;
      Profile profile = SessionMethods.getProfile(session);
      String temporaryName = null;
      for (SavedQuery sq : profile.getHistory().values()) {
        if (sq.getPathQuery() instanceof TemplateQuery
            && ((TemplateQuery) sq.getPathQuery()).getName().equals(template.getName())) {
          temporaryName = sq.getName();
        }
      }
      if (temporaryName != null) {
        return new ForwardParameters(mapping.findForward("template"))
            .addParameter("loadModifiedTemplate", "true")
            .addParameter("name", template.getName())
            .addParameter("savedQueryName", temporaryName)
            .forward();
      }
      return new ForwardParameters(mapping.findForward("template"))
          .addParameter("name", template.getName())
          .forward();
    }
    if (!(query instanceof TemplateQuery)) {
      session.removeAttribute(Constants.EDITING_TEMPLATE);
      session.removeAttribute(Constants.NEW_TEMPLATE);
    }
    return mapping.findForward("query");
  }