Exemplo n.º 1
0
 /**
  * Obtiene la lista de expedientes enviados a la papelera
  *
  * @fechaInicio Fecha de creación del expediente
  * @fechaEliminacion Fecha de eliminación del expediente
  * @procedimiento Procedimiento al que pertenece el expediente
  * @return
  * @throws ISPACException
  */
 public IItemCollection getExpedientsSentToTrash(
     String fechaInicio, String fechaEliminacion, int procedimiento) throws ISPACException {
   DbCnt cnt = mcontext.getConnection();
   try {
     String sMaxResultados =
         ISPACConfiguration.getInstance().get(ISPACConfiguration.MAX_EXPS_SHOW_TRASH);
     int max = 0;
     if (StringUtils.isNotBlank(sMaxResultados)) {
       max = TypeConverter.parseInt(sMaxResultados.trim(), 0);
     }
     return TXProcesoDAO.getExpedients(
         cnt,
         "PROCESOS.TIPO="
             + IProcess.PROCESS_TYPE
             + " AND PROCESOS.ESTADO="
             + TXConstants.STATUS_DELETED,
         max,
         fechaInicio,
         fechaEliminacion,
         procedimiento);
   } catch (ISPACException ie) {
     throw new ISPACException("Error en invesflowAPI:getExpedientsSentToTrash()", ie);
   } finally {
     mcontext.releaseConnection(cnt);
   }
 }
Exemplo n.º 2
0
  public static String addAndInResponsibleOrExistPermissionCondition(String resp)
      throws ISPACException {
    String sql = addInResponsibleOrExistPermissionCondition(resp);

    if (StringUtils.isNotBlank(sql)) {
      sql = " AND " + sql;
    }

    return sql;
  }
Exemplo n.º 3
0
  public static int countProcess(DbCnt cnt, String numexp, String query) throws ISPACException {
    String sql = "WHERE ";
    if (StringUtils.isNotBlank(numexp)) {
      sql += " NUMEXP = '" + DBUtil.replaceQuotes(numexp) + "'";
    }
    if (sql != null && sql.length() > 0) sql += query;

    CollectionDAO objlist = new CollectionDAO(TXProcesoDAO.class);
    return objlist.count(cnt, sql);
  }
Exemplo n.º 4
0
  public static IItemCollection getExpedients(
      DbCnt cnt,
      String query,
      int limit,
      String fechaInicio,
      String fechaEliminacion,
      int idProcedimiento)
      throws ISPACException {

    TableJoinFactoryDAO factory = new TableJoinFactoryDAO();

    factory.addTable(TABLENAME, "PROCESOS");
    factory.addTable("SPAC_P_PROCEDIMIENTOS", "PPROCEDIMIENTOS");

    String sql = " WHERE PPROCEDIMIENTOS.ID = PROCESOS.ID_PCD" + " AND " + query;

    // Fecha de inicio
    if (StringUtils.isNotBlank(fechaInicio)) {

      sql += " AND PROCESOS.FECHA_INICIO >= " + DBUtil.getToTimestampByBD(cnt, fechaInicio);
    }

    // Fecha de eliminacion
    if (StringUtils.isNotBlank(fechaEliminacion)) {
      sql +=
          " AND  PROCESOS.FECHA_ELIMINACION <=  "
              + DBUtil.getToTimestampByBD(cnt, fechaEliminacion);
    }

    if (idProcedimiento != -1) {
      sql += " AND PROCESOS.ID_PCD=" + idProcedimiento;
    }

    sql += " ORDER BY PPROCEDIMIENTOS.NOMBRE";

    return factory.queryTableJoin(cnt, sql, limit).disconnect();
  }
Exemplo n.º 5
0
  public static String addInResponsibleOrExistPermissionCondition(
      String inResponsibleCondition, String inPermResponsibleCondition) throws ISPACException {
    StringBuffer sql = new StringBuffer();

    if (StringUtils.isNotBlank(inResponsibleCondition)) {

      // Añadir la responsabilidad
      // y consultar los permisos asignados
      sql.append(
          getSqlInResponsibleOrExistPermissionCondition(
              inResponsibleCondition, inPermResponsibleCondition));
    }

    return sql.toString();
  }
Exemplo n.º 6
0
  /**
   * Obtiene la URL de un fichero. La búsqueda de realiza en el orden siguiente:
   *
   * <ul>
   *   <li>Classpath de la aplicación
   *   <li>Classpath del sistema
   *   <li>Ruta absoluta
   * </ul>
   *
   * @param resource Nombre del fichero.
   * @return URL del fichero.
   */
  public static URL getFileURL(String resource) {

    URL url = null;

    if (resource != null) {

      // Comprobar el fichero en el classpath de la aplicación
      url = ISPACConfigLocation.class.getClassLoader().getResource(resource);
      if (url == null) {

        // Comprobar el fichero en el classpath del sistema
        url = ClassLoader.getSystemResource(resource);
        if (url == null) {

          try {

            // Fichero con path relativo a la aplicación
            String appPath = ISPACConfigLocation.getInstance().get(APP_PATH);
            if (StringUtils.isNotBlank(appPath)) {
              File file = new File(appPath + resource);
              if (file.isFile()) {
                url = file.toURL();
              }
            }
          } catch (Exception e) {
            url = null;
          }

          if (url == null) {
            try {

              // Fichero con path absoluto
              File file = new File(resource);
              if (file.isFile()) {
                url = file.toURL();
              }

            } catch (Exception e) {
              url = null;
            }
          }
        }
      }
    }

    return url;
  }
Exemplo n.º 7
0
  public static String addInResponsibleOrExistPermissionCondition(String resp)
      throws ISPACException {
    String sql = " ";

    // Obtener la condición SQL de responsabilidad y de permisos
    // siempre que la responsabilidad no sea de Supervisor
    if (StringUtils.isNotBlank(resp) && !Responsible.SUPERVISOR.equalsIgnoreCase(resp)) {

      String sqlResponsibles = DBUtil.addInResponsibleCondition("ID_RESP", resp);

      // Añadir la responsabilidad y consultar los permisos asignados
      sql =
          getSqlInResponsibleOrExistPermissionCondition(
              sqlResponsibles, DBUtil.addInResponsibleCondition("SPC_PERMS.ID_RESP", resp));
    }

    return sql;
  }
Exemplo n.º 8
0
  public ActionForward executeAction(
      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_INV_DOCTYPES_EDIT, ISecurityAPI.FUNC_INV_TEMPLATES_EDIT});

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

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

    int keyId = Integer.parseInt(defaultForm.getKey());
    int entityId = Integer.parseInt(defaultForm.getEntity());
    String name = defaultForm.getProperty("NOMBRE");
    String code = defaultForm.getProperty("COD_PLANT");
    CTTemplate template = null;

    try {

      if (keyId == ISPACEntities.ENTITY_NULLREGKEYID) {

        int type = Integer.parseInt(defaultForm.getProperty("ID_TPDOC"));
        String expresion = defaultForm.getProperty("EXPRESION");
        FormFile fichero = defaultForm.getUploadFile();
        EntityApp entityapp = catalogAPI.getCTDefaultEntityApp(entityId, getRealPath(""));

        // Comprobar si existe otra plantilla con el mismo nombre
        IItemCollection itemcol =
            catalogAPI.queryCTEntities(
                ICatalogAPI.ENTITY_CT_TEMPLATE,
                " WHERE NOMBRE = '" + DBUtil.replaceQuotes(name) + "'");
        if (itemcol.next() && !isGeneric(templateAPI, itemcol)) {
          ActionMessages errors = new ActionMessages();
          errors.add(
              "property(NOMBRE)",
              new ActionMessage("error.template.nameDuplicated", new String[] {name}));
          saveAppErrors(request, errors);

          return new ActionForward(mapping.getInput());
        }

        // Comprobar si existe otra plantilla con el mismo código
        if (StringUtils.isNotBlank(code)) {
          itemcol =
              catalogAPI.queryCTEntities(
                  ICatalogAPI.ENTITY_CT_TEMPLATE,
                  " WHERE COD_PLANT = '" + DBUtil.replaceQuotes(code) + "'");
          if (itemcol.next()) {
            ActionMessages errors = new ActionMessages();
            errors.add(
                "property(COD_PLANT)",
                new ActionMessage("error.template.codeDuplicated", new String[] {code}));
            saveAppErrors(request, errors);

            return new ActionForward(mapping.getInput());
          }
        }

        if (!entityapp.validate()) {

          ActionMessages errors = new ActionMessages();
          List errorList = entityapp.getErrors();
          Iterator iteError = errorList.iterator();
          while (iteError.hasNext()) {

            ValidationError validError = (ValidationError) iteError.next();
            ActionMessage error = new ActionMessage(validError.getErrorKey(), validError.getArgs());
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
          }
          saveAppErrors(request, errors);

          return new ActionForward(mapping.getInput());
        }

        if (fichero.getFileName().equals("")) {
          template = templateAPI.newTemplate(type, name, code, 0, expresion, null);
        } else {
          if (fichero.getFileSize() > 0) {

            // Comprobar si el tipo MIME de la plantilla está soportado
            String mimeType = MimetypeMapping.getFileMimeType(fichero.getFileName());
            // Se comprueba si esta habilitado el uso de plantillas ODT
            if (StringUtils.equals(mimeType, "application/vnd.oasis.opendocument.text")
                && !ConfigurationMgr.getVarGlobalBoolean(
                    session.getClientContext(), ConfigurationMgr.USE_ODT_TEMPLATES, false)) {
              throw new ISPACInfo(
                  getResources(request).getMessage("exception.template.odt.disabled"));
            }

            if (templateAPI.isMimeTypeSupported(mimeType)) {
              template =
                  templateAPI.newTemplate(
                      type, name, code, 0, expresion, fichero.getInputStream(), mimeType);
            } else {
              throw new ISPACInfo(
                  getResources(request).getMessage("exception.template.document.invalidFile"));
            }
          } else {
            throw new ISPACInfo("exception.uploadfile.empty");
          }
        }
      } else {
        EntityApp entityapp = catalogAPI.getCTDefaultEntityApp(entityId, getRealPath(""));

        // Comprobar si existe otra plantilla con el mismo nombre
        IItemCollection itemcol =
            catalogAPI.queryCTEntities(
                ICatalogAPI.ENTITY_CT_TEMPLATE,
                " WHERE NOMBRE = '" + DBUtil.replaceQuotes(name) + "' AND ID != " + keyId);
        if (itemcol.next() && !isGeneric(templateAPI, itemcol)) {
          ActionMessages errors = new ActionMessages();
          errors.add(
              "property(NOMBRE)",
              new ActionMessage("error.template.nameDuplicated", new String[] {name}));
          saveAppErrors(request, errors);

          return new ActionForward(mapping.getInput());
        }

        // Comprobar si existe otra plantilla con el mismo código
        if (StringUtils.isNotBlank(code)) {
          itemcol =
              catalogAPI.queryCTEntities(
                  ICatalogAPI.ENTITY_CT_TEMPLATE,
                  " WHERE COD_PLANT = '" + DBUtil.replaceQuotes(code) + "' AND ID != " + keyId);
          if (itemcol.next()) {
            ActionMessages errors = new ActionMessages();
            errors.add(
                "property(COD_PLANT)",
                new ActionMessage("error.template.codeDuplicated", new String[] {code}));
            saveAppErrors(request, errors);

            return new ActionForward(mapping.getInput());
          }
        }

        defaultForm.processEntityApp(entityapp);
        entityapp.getItem().set("FECHA", new Date());
        entityapp.store();
      }

    } catch (Exception e) {
      ActionForward action = mapping.findForward("success");
      String url =
          action.getPath()
              + "?entity="
              + entityId
              + "&type="
              + defaultForm.getProperty("ID_TPDOC")
              + "&key="
              + keyId;

      request.getSession().setAttribute(BaseAction.LAST_URL_SESSION_KEY, url);

      if (e instanceof ISPACInfo) {
        throw e;
      } else {
        throw new ISPACInfo(e.getMessage());
      }
    }

    if (template != null) {
      keyId = template.getInt("TEMPLATE:ID");
    }

    ActionForward action = mapping.findForward("success");
    String redirected =
        action.getPath()
            + "?entity="
            + entityId
            + "&type="
            + defaultForm.getProperty("ID_TPDOC")
            + "&key="
            + keyId;
    return new ActionForward(action.getName(), redirected, true);
  }