Beispiel #1
0
  public static void removeSpec() {
    String id = params.get("id");
    Specification spec = Specification.findById(Long.valueOf(id));
    List<Request> requests =
        Request.em()
            .createQuery(
                "select r from Request r join fetch r.specifications s where s.id="
                    + Long.valueOf(id),
                Request.class)
            .getResultList();

    for (Request req : requests) {
      req.specifications.remove(spec);
      req.save();
    }
    if (spec != null) spec.delete();
    renderText(id);
  }
Beispiel #2
0
  public static void removeProperty() {
    String id = params.get("id");
    Prop p = Prop.findById(Long.valueOf(id));
    List<Specification> specifications =
        Specification.em()
            .createQuery(
                "select r from Specification r join fetch r.properties s where s.id="
                    + Long.valueOf(id),
                Specification.class)
            .getResultList();

    for (Specification spec : specifications) {
      spec.properties.remove(p);
      spec.save();
    }
    if (p != null) p.delete();
    renderText(id);
  }
Beispiel #3
0
  public static void editSpec(Long id) {
    Specification spec = null;
    if (id != null) spec = Specification.findById(id);
    List<Material> materials = Material.findAll();
    String username = session.get("username");
    if (username != null) {

      User user = User.getByUserName(username);
      if (user.role.name.equalsIgnoreCase("operator")) {
        materials = user.materials;
      }
    }
    render(spec, materials);
  }
Beispiel #4
0
  public static void impSpec(File file) {
    if (file != null) {
      List<Specification> specifications = new ArrayList<Specification>();
      Specification spec = null;
      Material material = null;
      try {
        FileInputStream fileInputStream = new FileInputStream(file);
        HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
        HSSFSheet worksheet = workbook.getSheetAt(0);
        HSSFRow row = null;
        HSSFCell cell = null;
        Map<Integer, String> headerMap = new HashMap<Integer, String>();
        Prop prop = null;
        if (worksheet.getLastRowNum() > 0) {
          row = worksheet.getRow(0);
          for (int i = 0; i < row.getLastCellNum(); i++) {
            headerMap.put(Integer.valueOf(i), row.getCell(i).getStringCellValue());
          }
        }
        for (int i = 1; i < worksheet.getLastRowNum(); i++) {
          row = worksheet.getRow(i);
          cell = row.getCell(0);
          String materialName = cell.getStringCellValue();

          cell = row.getCell(1);
          String specification = cell.getStringCellValue();

          cell = row.getCell(2);
          Double number = cell.getNumericCellValue();

          cell = row.getCell(3);
          String unit = cell.getStringCellValue();

          cell = row.getCell(4);
          String company = cell.getStringCellValue();

          cell = row.getCell(5);
          Date date = cell.getDateCellValue();

          cell = row.getCell(6);
          String description = cell.getStringCellValue();

          spec = new Specification();

          for (int x = 7; x < row.getLastCellNum(); x++) {
            cell = row.getCell(x);
            String value = "";
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            prop = new Prop();
            prop.name = headerMap.get(x);
            prop.value = value;
            prop.save();
            spec.properties.add(prop);
          }

          spec.name = specification;
          spec.specification = specification;
          if (number != null && !"".equals(number)) spec.amount = number;
          spec.unit = unit;
          spec.company = company;
          if (materialName != null && !"".equals(materialName)) {
            material = Material.find("name=?", materialName.trim()).first();
            spec.material = material;
          }
          spec.arrival_time = date;
          spec.description = description;
          spec.save();
          specifications.add(spec);
        }

        renderJSON(specifications);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }