Esempio n. 1
0
 @RequestMapping(value = "/productos", params = "term", produces = "application/json")
 public @ResponseBody List<LabelValueBean> productos(
     HttpServletRequest request, @RequestParam("term") String filtro) {
   for (String nombre : request.getParameterMap().keySet()) {
     log.debug("Param: {} : {}", nombre, request.getParameterMap().get(nombre));
   }
   Map<String, Object> params = new HashMap<>();
   params.put("almacen", request.getSession().getAttribute("almacenId"));
   params.put("filtro", filtro);
   params = productoDao.lista(params);
   List<LabelValueBean> valores = new ArrayList<>();
   List<Producto> productos = (List<Producto>) params.get("productos");
   for (Producto producto : productos) {
     StringBuilder sb = new StringBuilder();
     sb.append(producto.getSku());
     sb.append(" | ");
     sb.append(producto.getNombre());
     sb.append(" | ");
     sb.append(producto.getDescripcion());
     sb.append(" | ");
     sb.append(producto.getExistencia()).append(" ").append(producto.getUnidadMedida());
     sb.append(" | ");
     sb.append(producto.getPrecioUnitario());
     valores.add(new LabelValueBean(producto.getId(), sb.toString()));
   }
   return valores;
 }
  /**
   * POST api/authentication?token=xxx
   *
   * <p>This action is called after signing the nonce on the client-side with the user's
   * certificate. We'll once again use the Authentication class to do the actual work.
   */
  @RequestMapping(
      value = "/api/authentication",
      method = {RequestMethod.POST})
  public AuthenticationPostResponse post(
      @RequestParam(value = "token", required = true) String token) throws RestException {

    // Instantiate the Authentication class
    Authentication auth = new Authentication(Util.getRestPkiClient());

    // Call the completeWithWebPki() method, which finalizes the authentication process. It receives
    // as input
    // only the token that was yielded previously (which we sent to the page and the page sent us
    // back on the URL).
    // The call yields a ValidationResults which denotes whether the authentication was successful
    // or not.
    ValidationResults vr = auth.completeWithWebPki(token);

    AuthenticationPostResponse response = new AuthenticationPostResponse();

    // Check the authentication result
    if (!vr.isValid()) {
      // If the authentication failed, inform the page
      response.setSuccess(false);
      response.setMessage("Authentication failed");
      response.setValidationResults(vr.toString());
      return response;
    }

    // At this point, you have assurance that the certificate is valid according to the
    // SecurityContext passed on the first step (see method get()) and that the user is indeed the
    // certificate's
    // subject. Now, you'd typically query your database for a user that matches one of the
    // certificate's fields, such as cert.getEmailAddress() or cert.getPkiBrazil().getCpf() (the
    // actual field
    // to be used as key depends on your application's business logic) and set the user
    // as authenticated with whatever web security framework your application uses.
    // For demonstration purposes, we'll just return a success and put on the message something
    // to show that we have access to the certificate's fields.

    PKCertificate userCert = auth.getPKCertificate();
    StringBuilder message = new StringBuilder();
    message.append("Welcome, " + userCert.getSubjectName().getCommonName() + "!");
    if (!StringUtils.isEmpty(userCert.getEmailAddress())) {
      message.append(" Your email address is " + userCert.getEmailAddress());
    }
    if (!StringUtils.isEmpty(userCert.getPkiBrazil().getCpf())) {
      message.append(" and your CPF is " + userCert.getPkiBrazil().getCpf());
    }

    // Return success to the page
    response.setSuccess(true);
    response.setMessage(message.toString());
    return response;
  }
Esempio n. 3
0
  public String jsonRestProjectList(Long projectId) throws IOException {
    StringBuilder sb = new StringBuilder();

    Project p = requestManager.getProjectById(projectId);
    sb.append("'id':'" + projectId + "'");
    sb.append(",");
    sb.append("'name':'" + p.getName() + "'");
    sb.append(",");
    sb.append("'alias':'" + p.getAlias() + "'");

    return "{" + sb.toString() + "}";
  }
  private static String getCommaseparatedStringFromList(List controllIdList) {
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < controllIdList.size(); i++) {
      Map map = (Map) controllIdList.get(i);
      if (map.get("control_ids") != null) {
        result.append(map.get("control_ids"));
        result.append(",");
      }
    }
    return result.length() > 0 ? result.substring(0, result.length() - 1) : "";
  }
Esempio n. 5
0
 private String getSelectedCalDateJson(TimeSheetForm tsForm) {
   StringBuilder sb = new StringBuilder();
   String date = "";
   sb.append("'");
   if (DateTimeUtil.isDateValid(tsForm.getCalDate())) {
     date = DateTimeUtil.formatDateString(tsForm.getCalDate());
     sb.append(date);
   }
   sb.append("'");
   logger.debug("SelectedCalDateJson = {}", date);
   return sb.toString();
 }
Esempio n. 6
0
 @RequestMapping(value = "projects", method = RequestMethod.GET)
 public @ResponseBody String jsonRest() throws IOException {
   StringBuilder sb = new StringBuilder();
   Collection<Project> lp = requestManager.listAllProjects();
   int pi = 0;
   for (Project p : lp) {
     pi++;
     sb.append(jsonRestProjectList(p.getProjectId()));
     if (pi < lp.size()) {
       sb.append(",");
     }
   }
   return "[" + sb.toString() + "]";
 }
Esempio n. 7
0
 private String getAvailableActCategoriesJson() {
   StringBuilder sb = new StringBuilder();
   List<DictionaryItem> actTypes = dictionaryItemService.getTypesOfActivity();
   List<ProjectRole> projectRoles = projectRoleService.getProjectRoles();
   sb.append("[");
   for (int i = 0; i < actTypes.size(); i++) {
     for (ProjectRole projectRole : projectRoles) {
       sb.append("{actType:'").append(actTypes.get(i).getId()).append("', ");
       sb.append("projRole:'").append(projectRole.getId()).append("', ");
       List<AvailableActivityCategory> avActCats =
           availableActivityCategoryService.getAvailableActivityCategories(
               actTypes.get(i), projectRole);
       sb.append("avActCats:[");
       for (int k = 0; k < avActCats.size(); k++) {
         sb.append("'").append(avActCats.get(k).getActCat().getId()).append("'");
         if (k < (avActCats.size() - 1)) {
           sb.append(", ");
         }
       }
       sb.append("]}");
       if (i < (actTypes.size())) {
         sb.append(", ");
       }
     }
   }
   return sb.toString().substring(0, (sb.toString().length() - 2)) + "]";
 }
Esempio n. 8
0
 private String getSelectedProjectRolesJson(TimeSheetForm tsForm) {
   StringBuilder sb = new StringBuilder();
   List<TimeSheetTableRowForm> tablePart = tsForm.getTimeSheetTablePart();
   if (tablePart != null) {
     sb.append("[");
     for (int i = 0; i < tablePart.size(); i++) {
       if (!"".equals(tablePart.get(i).getCqId())) {
         sb.append("{row:'").append(i).append("', ");
         sb.append("role:'").append(tablePart.get(i).getProjectRoleId()).append("'}");
         if (i < (tablePart.size() - 1)) {
           sb.append(", ");
         }
       }
     }
     sb.append("]");
   } else {
     sb.append("[{row:'0', role:''}]");
   }
   return sb.toString();
 }
Esempio n. 9
0
 @RequestMapping(value = "/proveedores", params = "term", produces = "application/json")
 public @ResponseBody List<LabelValueBean> proveedores(
     HttpServletRequest request, @RequestParam("term") String filtro) {
   for (String nombre : request.getParameterMap().keySet()) {
     log.debug("Param: {} : {}", nombre, request.getParameterMap().get(nombre));
   }
   Map<String, Object> params = new HashMap<>();
   params.put("empresa", request.getSession().getAttribute("empresaId"));
   params.put("filtro", filtro);
   params = proveedorDao.lista(params);
   List<LabelValueBean> valores = new ArrayList<>();
   List<Proveedor> proveedores = (List<Proveedor>) params.get("proveedores");
   for (Proveedor proveedor : proveedores) {
     StringBuilder sb = new StringBuilder();
     sb.append(proveedor.getNombre());
     sb.append(" | ");
     sb.append(proveedor.getRfc());
     sb.append(" | ");
     sb.append(proveedor.getNombreCompleto());
     valores.add(new LabelValueBean(proveedor.getId(), sb.toString(), proveedor.getNombre()));
   }
   return valores;
 }
Esempio n. 10
0
 @RequestMapping(value = "adminRoleInfo/{id}", method = RequestMethod.GET)
 public String adminRoleInfo(
     @PathVariable("id") int id, @RequestParam("account") String account, Model model) {
   List<OsRole> osRoleList = iRoleService.findAll();
   List<OsRole> own = iRoleService.findRoleByAdminId(id);
   StringBuilder stringBuilder = new StringBuilder(";");
   for (OsRole osRole : own) {
     stringBuilder.append(osRole.getId()).append(";");
   }
   model.addAttribute("osRoleList", osRoleList);
   model.addAttribute("hasRole", stringBuilder.toString());
   model.addAttribute("tmpAccount", account);
   model.addAttribute("tmpId", id);
   return "admin_role";
 }
Esempio n. 11
0
 @RequestMapping(value = "roleInfo/{id}", method = RequestMethod.GET)
 public String roleInfo(@PathVariable("id") int id, Model model) {
   OsRole osRole = iRoleService.findOne(id);
   StringBuilder stringBuilder = new StringBuilder(";");
   for (OsPermission osPermission : osRole.getOsPermissions()) {
     stringBuilder.append(osPermission.getId()).append(";");
   }
   List<OsPermission> osPermissionList = iRoleService.findUnAssignPermission();
   model.addAttribute("osRole", osRole);
   model.addAttribute("osPermissionList", osPermissionList);
   model.addAttribute("msg", "修改角色");
   model.addAttribute("type", "update");
   model.addAttribute("hasPermission", stringBuilder.toString());
   return "admin_addRole";
 }
Esempio n. 12
0
 private String getSelectedLongVacationIllnessJson(TimeSheetForm tsForm) {
   StringBuilder sb = new StringBuilder();
   if (tsForm.isLongIllness() || tsForm.isLongVacation()) {
     sb.append("[");
     sb.append("{vacation:'").append(tsForm.isLongVacation()).append("', ");
     sb.append("illness:'").append(tsForm.isLongIllness()).append("', ");
     sb.append("beginDate:'").append(tsForm.getBeginLongDate()).append("', ");
     sb.append("endDate:'").append(tsForm.getEndLongDate()).append("'}");
     sb.append("]");
   } else {
     sb.append("[{vacation:'false', illness:'false', beginDate:'', endDate:''}]");
   }
   return sb.toString();
 }
Esempio n. 13
0
  private String getDictionaryItemsInJson(List<DictionaryItem> items) {
    StringBuilder builder = new StringBuilder();
    builder.append("[");
    for (DictionaryItem item : items) {
      builder.append("{id:'");
      builder.append(item.getId().toString());
      builder.append("', value:'");
      builder.append(item.getValue());
      builder.append("'},");
    }
    if (builder.length() > 1) {
      builder.deleteCharAt(builder.length() - 1);
    }

    builder.append("]");
    return builder.toString();
  }
Esempio n. 14
0
 private String getSelectedActCategoriesJson(TimeSheetForm tsForm) {
   StringBuilder sb = new StringBuilder();
   List<TimeSheetTableRowForm> tablePart = tsForm.getTimeSheetTablePart();
   if (tablePart != null) {
     sb.append("[");
     for (int i = 0; i < tablePart.size(); i++) {
       sb.append("{row:'").append(i).append("', ");
       sb.append("actCat:'").append(tablePart.get(i).getActivityCategoryId()).append("'}");
       if (i < (tablePart.size() - 1)) {
         sb.append(", ");
       }
     }
     sb.append("]");
   } else {
     sb.append("[{row:'0', actCat:''}]");
   }
   return sb.toString();
 }
  /**
   * Mapping for delete submit
   *
   * @param id id of the entry or
   * @param title title of the entry
   * @param model model
   * @return template name
   */
  @RequestMapping(value = "/delete", method = RequestMethod.POST)
  public String deletePost(
      @RequestParam(value = "entryid", required = false, defaultValue = "") String id,
      @RequestParam(value = "title", required = false, defaultValue = "") String title,
      Model model) {
    Map<String, String> params = new HashMap<>();
    if (!id.isEmpty()) {
      params.put("id", id);
      restTemplate.delete(GET_ENTRY, params);

      model.addAttribute("resultmessage", "Eintrag mit id " + id + " erfolgreich entfernt!");
    } else if (!title.isEmpty()) {
      params.put("title", title);
      Entry[] entries = restTemplate.getForObject(GET_BY_TITLE, Entry[].class, params);
      StringBuilder sb = new StringBuilder();
      for (Entry cur : entries) {
        params.clear();
        params.put("id", String.valueOf(cur.getId()));
        restTemplate.delete(GET_ENTRY, params);
        sb.append(cur.getId()).append(", ");
      }

      if (entries.length == 0) {
        model.addAttribute("resultmessage", "Keine Eintraege entfernt!");
      } else if (entries.length == 1) {
        model.addAttribute(
            "resultmessage", "Eintrag mit id " + entries[0].getId() + " erfolgreich entfernt!");
      } else {
        model.addAttribute(
            "resultmessage", "Eintraege mit ids " + sb.toString() + " erfolgreich entfernt!");
      }
    } else {
      model.addAttribute("resultmessage", "Weder ID noch Titel angegeben!");
    }
    return "result_special";
  }
Esempio n. 16
0
  /*
   * Возвращает HashMap со значениями для заполнения списков сотрудников,
   * проектов, пресейлов, проектных задач, типов и категорий активности на
   * форме приложения.
   */
  private Map<String, Object> getListsToMAV() {
    Map<String, Object> result = new HashMap<String, Object>();

    List<DictionaryItem> typesOfActivity = dictionaryItemService.getTypesOfActivity();
    result.put("actTypeList", typesOfActivity);

    String typesOfActivityJson = getDictionaryItemsInJson(typesOfActivity);
    result.put("actTypeJson", typesOfActivityJson);

    String workplacesJson = getDictionaryItemsInJson(dictionaryItemService.getWorkplaces());
    result.put("workplaceJson", workplacesJson);

    result.put(
        "overtimeCauseJson", getDictionaryItemsInJson(dictionaryItemService.getOvertimeCauses()));
    result.put(
        "unfinishedDayCauseJson",
        getDictionaryItemsInJson(dictionaryItemService.getUnfinishedDayCauses()));
    result.put("overtimeThreshold", propertyProvider.getOvertimeThreshold());

    List<Division> divisions = divisionService.getDivisions();
    result.put("divisionList", divisions);

    result.put(
        "employeeListJson",
        employeeHelper.getEmployeeListJson(divisions, employeeService.isShowAll(request)));

    List<DictionaryItem> categoryOfActivity = dictionaryItemService.getCategoryOfActivity();
    result.put("actCategoryList", categoryOfActivity);

    String actCategoryListJson = getDictionaryItemsInJson(categoryOfActivity);
    result.put("actCategoryListJson", actCategoryListJson);

    result.put("availableActCategoriesJson", getAvailableActCategoriesJson());

    result.put("projectListJson", projectService.getProjectListJson(divisions));
    result.put("projectTaskListJson", getProjectTaskListJson(projectService.getProjectsWithCq()));

    List<ProjectRole> projectRoleList = projectRoleService.getProjectRoles();

    for (int i = 0; i < projectRoleList.size(); i++) {
      if (projectRoleList
          .get(i)
          .getCode()
          .equals("ND")) { // Убираем из списка роль "Не определена" APLANATS-270
        projectRoleList.remove(i);
        break;
      }
    }

    result.put("projectRoleList", projectRoleList);
    StringBuilder projectRoleListJson = new StringBuilder();
    projectRoleListJson.append("[");
    for (ProjectRole item : projectRoleList) {
      projectRoleListJson.append("{id:'");
      projectRoleListJson.append(item.getId().toString());
      projectRoleListJson.append("', value:'");
      projectRoleListJson.append(item.getName());
      projectRoleListJson.append("'},");
    }
    result.put(
        "projectRoleListJson",
        projectRoleListJson.toString().substring(0, (projectRoleListJson.toString().length() - 1))
            + "]");

    return result;
  }
Esempio n. 17
0
 private String getProjectTaskListJson(List<Project> projects) {
   StringBuilder sb = new StringBuilder();
   sb.append("[");
   for (int i = 0; i < projects.size(); i++) {
     Integer projectId = projects.get(i).getId();
     List<ProjectTask> tasks = projectTaskService.getProjectTasks(projectId);
     sb.append("{projId:'");
     sb.append(projectId);
     sb.append("', projTasks:[");
     for (int j = 0; j < tasks.size(); j++) {
       sb.append("{id:'");
       sb.append(tasks.get(j).getCqId());
       sb.append("', value:'");
       sb.append(tasks.get(j).getCqId());
       sb.append("'}");
       if (j < (tasks.size() - 1)) {
         sb.append(", ");
       }
     }
     sb.append("]}");
     if (i < (projects.size() - 1)) {
       sb.append(", ");
     }
   }
   sb.append("]");
   return sb.toString();
 }
 /**
  * Creates a redirect view path.
  *
  * @param requestMapping The request mapping of target controller method.
  * @return The created redirect view path.
  */
 private String createRedirectViewPath(String requestMapping) {
   StringBuilder redirectViewPath = new StringBuilder();
   redirectViewPath.append("redirect:");
   redirectViewPath.append(requestMapping);
   return redirectViewPath.toString();
 }
Esempio n. 19
0
  @RequestMapping(value = "project/{projectId}", method = RequestMethod.GET)
  public @ResponseBody String jsonRestProject(@PathVariable Long projectId, ModelMap model)
      throws IOException {
    StringBuilder sb = new StringBuilder();

    Project p = requestManager.getProjectById(projectId);
    sb.append("'id':'" + projectId + "'");
    sb.append(",");
    sb.append("'name':'" + p.getName() + "'");
    sb.append(",");
    sb.append("'alias':'" + p.getAlias() + "'");
    sb.append(",");
    sb.append("'progress':'" + p.getProgress().name() + "'");
    sb.append(",");
    sb.append("'description':'" + p.getDescription() + "'");
    sb.append(",");

    sb.append("'overviews':[");
    if (p.getOverviews().size() > 0) {
      int oi = 0;
      for (ProjectOverview overview : p.getOverviews()) {
        oi++;
        sb.append("{");
        sb.append("'allSampleQcPassed':" + overview.getAllSampleQcPassed());
        sb.append(",");
        sb.append("'libraryPreparationComplete':" + overview.getLibraryPreparationComplete());
        sb.append(",");
        sb.append("'allLibrariesQcPassed':" + overview.getAllLibrariesQcPassed());
        sb.append(",");
        sb.append("'allPoolsConstructed':" + overview.getAllPoolsConstructed());
        sb.append(",");
        sb.append("'allRunsCompleted':" + overview.getAllRunsCompleted());
        sb.append(",");
        sb.append("'primaryAnalysisCompleted':" + overview.getPrimaryAnalysisCompleted());
        sb.append("}");
        if (oi < p.getOverviews().size()) {
          sb.append(",");
        }
      }
    }
    sb.append("]");
    sb.append(",");

    sb.append("'samples':[");
    Collection<Sample> samples = requestManager.listAllSamplesByProjectId(projectId);
    if (samples.size() > 0) {
      int si = 0;
      for (Sample sample : samples) {
        si++;
        String sampleQubit = "not available";
        if (requestManager.listAllSampleQCsBySampleId(sample.getId()).size() > 0) {
          ArrayList<SampleQC> sampleQcList =
              new ArrayList(requestManager.listAllSampleQCsBySampleId(sample.getId()));
          SampleQC lastQc = sampleQcList.get(sampleQcList.size() - 1);
          sampleQubit = (lastQc.getResults() != null ? lastQc.getResults().toString() : "");
        }
        sb.append("{");
        sb.append("'alias':'" + sample.getAlias() + "'");
        sb.append(",");
        sb.append(
            "'qcPassed':'"
                + (sample.getQcPassed() != null ? sample.getQcPassed().toString() : "")
                + "'");
        sb.append(",");

        sb.append(
            "'receivedDate':'"
                + (sample.getReceivedDate() != null
                    ? LimsUtils.getDateAsString(sample.getReceivedDate())
                    : "not available")
                + "'");
        sb.append(",");
        sb.append(
            "'sampleType':'"
                + (sample.getSampleType() != null ? sample.getSampleType() : "")
                + "'");
        sb.append(",");
        sb.append("'sampleQubit':'" + sampleQubit + "'");
        sb.append("}");

        if (si < samples.size()) {
          sb.append(",");
        }
      }
    }
    sb.append("]");
    sb.append(",");

    sb.append("'runs':[");
    Collection<Run> runs = requestManager.listAllRunsByProjectId(projectId);
    if (runs.size() > 0) {
      int ri = 0;
      for (Run run : runs) {
        ri++;
        if (!run.getStatus().getHealth().getKey().equals("Failed")) {
          ArrayList<String> runSamples = new ArrayList();
          Collection<SequencerPartitionContainer<SequencerPoolPartition>> spcs =
              requestManager.listSequencerPartitionContainersByRunId(run.getId());
          if (spcs.size() > 0) {
            for (SequencerPartitionContainer<SequencerPoolPartition> spc : spcs) {

              if (spc.getPartitions().size() > 0) {
                for (SequencerPoolPartition spp : spc.getPartitions()) {
                  if (spp.getPool() != null) {
                    if (spp.getPool().getDilutions().size() > 0) {
                      for (Dilution dilution : spp.getPool().getDilutions()) {
                        Sample sample = dilution.getLibrary().getSample();
                        if (sample.getProject().equals(p)) {
                          runSamples.add(sample.getAlias());
                        }
                      }
                    }
                  }
                }
              }
            }
          }

          sb.append("{");
          sb.append("'name':'" + run.getName() + "'");
          sb.append(",");
          sb.append(
              "'status':'"
                  + (run.getStatus() != null && run.getStatus().getHealth() != null
                      ? run.getStatus().getHealth().getKey()
                      : "")
                  + "'");
          sb.append(",");
          sb.append(
              "'startDate':'"
                  + (run.getStatus() != null && run.getStatus().getStartDate() != null
                      ? run.getStatus().getStartDate().toString()
                      : "")
                  + "'");
          sb.append(",");
          sb.append(
              "'completionDate':'"
                  + (run.getStatus() != null && run.getStatus().getCompletionDate() != null
                      ? run.getStatus().getCompletionDate().toString()
                      : "")
                  + "'");
          sb.append(",");
          sb.append(
              "'platformType':'"
                  + (run.getPlatformType() != null ? run.getPlatformType().getKey() : "")
                  + "'");
          sb.append(",");
          sb.append("'samples':[");
          if (runSamples.size() > 0) {
            int rsi = 0;
            for (String alias : runSamples) {
              rsi++;
              sb.append("{'sampleAlias':'" + alias + "'}");
              if (rsi < runSamples.size()) {
                sb.append(",");
              }
            }
          }
          sb.append("]");
          sb.append("}");
          if (ri < runs.size()) {
            sb.append(",");
          }
        }
      }
    }
    sb.append("]");

    return "{" + sb.toString() + "}";
  }