Esempio n. 1
0
  public ActionForward createCopyCalendar(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response,
      SessionAPI session)
      throws Exception {

    // Comprobar si el usuario tiene asignadas las funciones adecuadas
    FunctionHelper.checkFunctions(
        request, session.getClientContext(), new int[] {ISecurityAPI.FUNC_COMP_CALENDARS_EDIT});

    ClientContext cct = session.getClientContext();
    IInvesflowAPI invesFlowAPI = session.getAPI();
    ICatalogAPI catalogAPI = invesFlowAPI.getCatalogAPI();

    // Formulario asociado a la acción
    CalendarForm defaultForm = (CalendarForm) form;

    String entityId = request.getParameter("entityId");
    String keyId = request.getParameter("regId");
    String name = defaultForm.getProperty("NEW_CALENDAR_NAME");
    IItemCollection calendar = null;
    IItem icalendar = null;
    IItem newCalendar = null;

    // Ejecución en un contexto transaccional
    boolean bCommit = false;

    try {
      // Abrir transacción
      cct.beginTX();

      List errorList = validate(name, session);

      if (!errorList.isEmpty()) {

        ActionMessages errors = new ActionMessages();
        Iterator iteError = errorList.iterator();
        while (iteError.hasNext()) {
          ValidationError validError = (ValidationError) iteError.next();
          ActionMessage error = new ActionMessage(validError.getErrorKey(), validError.getArgs());
          errors.add("property(NEW_CALENDAR_NAME)", error);
        }
        saveErrors(request, errors);

        return mapping.findForward("validate");
      }

      calendar =
          (IItemCollection)
              catalogAPI.queryCTEntities(ICatalogAPI.ENTITY_SPAC_CALENDARIOS, "where ID=" + keyId);
      icalendar = calendar.value();
      newCalendar = catalogAPI.createCTEntity(ICatalogAPI.ENTITY_SPAC_CALENDARIOS);
      newCalendar.set("NOMBRE", name);
      newCalendar.set("CALENDARIO", icalendar.get("CALENDARIO"));
      newCalendar.store(cct);

      // Si todo ha sido correcto se hace commit de la transacción
      bCommit = true;
    } catch (ISPACException e) {

      throw new ISPACInfo(e.getMessage());
    } finally {
      cct.endTX(bCommit);
    }

    request.setAttribute("target", "top");
    request.setAttribute(
        "url",
        "?method=show&entityId=" + entityId + "&regId=" + newCalendar.getKeyInteger().toString());

    return mapping.findForward("loadOnTarget");
  }
Esempio n. 2
0
  public ActionForward saveholydays(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response,
      SessionAPI session)
      throws Exception {

    // Comprobar si el usuario tiene asignadas las funciones adecuadas
    FunctionHelper.checkFunctions(
        request, session.getClientContext(), new int[] {ISecurityAPI.FUNC_COMP_CALENDARS_EDIT});

    ClientContext cct = session.getClientContext();
    CalendarForm defaultForm = (CalendarForm) form;
    // Validar el formulario
    defaultForm.setEntityAppName("SaveHolydaysCalendar");
    ActionMessages errors = defaultForm.validate(mapping, request);

    String entityId = defaultForm.getEntity();
    String regId = defaultForm.getKey();
    String nombre = request.getParameter("nombre");
    String dias = request.getParameter("weekDaysSelect");

    // Ejecución en un contexto transaccional
    boolean bCommit = false;

    try {
      // Abrir transacción
      cct.beginTX();

      if (errors.isEmpty()) {

        IInvesflowAPI invesFlowAPI = session.getAPI();
        ICatalogAPI catalogAPI = invesFlowAPI.getCatalogAPI();

        // Bloqueo
        catalogAPI.queryCTEntities(ICatalogAPI.ENTITY_SPAC_CALENDARIOS, "");

        IItem item = (IItem) request.getSession().getAttribute("CALENDAR");
        // deberia ir abajo
        String calendarioXML = (String) item.getString("CALENDARIO");
        validateHolyday(item, defaultForm.getProperty("HOLYDAY_DATE"), session, errors);

        if (!errors.isEmpty()) {

          saveErrors(request, errors);
          return mapping.findForward("success_holydays");
        }

        CalendarDef calendarDef = new CalendarDef(calendarioXML);
        calendarDef.addHolyday(
            defaultForm.getProperty("HOLYDAY_NAME"), defaultForm.getProperty("HOLYDAY_DATE"));
        item.set("CALENDARIO", calendarDef.getXmlValues());
        item.store(session.getClientContext());

        // Si todo ha sido correcto se hace commit de la transacción
        bCommit = true;

        // Para que vaya a la direccion donde yo quiero
        String url =
            "?method=show&entityId="
                + entityId
                + "&regId="
                + regId
                + "&save=true&nombre="
                + nombre
                + "&weekDaysSelect="
                + dias;

        request.setAttribute("target", "top");
        request.setAttribute("url", url);

        return mapping.findForward("loadOnTarget");
      } else {
        saveErrors(request, errors);
        return getActionForwardHolydays();
      }
    } catch (ISPACException e) {

      throw new ISPACInfo(e.getMessage());
    } finally {
      cct.endTX(bCommit);
    }
  }
Esempio n. 3
0
  // Esta función guarda en la base de datos correspondiente los dias seleccionados en la página.
  public ActionForward saveFixedHolidays(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response,
      SessionAPI session)
      throws Exception {

    // Comprobar si el usuario tiene asignadas las funciones adecuadas
    FunctionHelper.checkFunctions(
        request, session.getClientContext(), new int[] {ISecurityAPI.FUNC_COMP_CALENDARS_EDIT});

    ClientContext cct = session.getClientContext();
    CalendarForm defaultForm = (CalendarForm) form;
    String[] selectFixedHolidays = (String[]) defaultForm.getSelectFixedHolidays();
    String year = (String) defaultForm.getProperty("YEAR");

    // Validación
    ActionMessages errors = new ActionMessages();
    defaultForm.setEntityAppName("EditCTCalendar");
    errors = defaultForm.validate(mapping, request);

    if (errors.isEmpty()) {

      String entityId = defaultForm.getEntity();
      String regId = defaultForm.getKey();
      String nombre = request.getParameter("nombre");
      String dias = request.getParameter("weekDaysSelect");

      // Ejecución en un contexto transaccional
      boolean bCommit = false;

      try {
        // Abrir transacción
        cct.beginTX();

        IInvesflowAPI invesFlowAPI = session.getAPI();
        ICatalogAPI catalogAPI = invesFlowAPI.getCatalogAPI();

        // Bloquear
        catalogAPI.queryCTEntities(ICatalogAPI.ENTITY_SPAC_CALENDARIOS, "");
        IItem item = (IItem) request.getSession().getAttribute("CALENDAR");

        String calendarioXML = (String) item.getString("CALENDARIO");
        CalendarDef calendarDef = new CalendarDef(calendarioXML);

        for (int i = 0; i < selectFixedHolidays.length; i++) {
          String[] date = selectFixedHolidays[i].split("---");
          ActionMessages errorsFixedHolidays = new ActionMessages();
          validateHolyday(item, date[0] + "/" + year, session, errorsFixedHolidays);

          if (errorsFixedHolidays.isEmpty()) {
            calendarDef.addHolyday(date[1], date[0] + "/" + year);
          }
        }

        item.set("CALENDARIO", calendarDef.getXmlValues());
        item.store(session.getClientContext());

        // Si todo ha sido correcto se hace commit de la transacción
        bCommit = true;

        String url =
            "?method=show&entityId="
                + entityId
                + "&regId="
                + regId
                + "&save=true&nombre="
                + nombre
                + "&weekDaysSelect="
                + dias;

        request.setAttribute("target", "top");
        request.setAttribute("url", url);

        return mapping.findForward("loadOnTarget");
      } catch (ISPACException e) {

        throw new ISPACInfo(e.getMessage());
      } finally {
        cct.endTX(bCommit);
      }
    }

    saveErrors(request, errors);
    request.setAttribute(DAYS_LIST, request.getAttribute(DAYS_LIST));

    return mapping.findForward("errorYear");
  }