Esempio n. 1
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);
  }
Esempio n. 2
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);
  }