public JSONObject changePlateLocation(HttpSession session, JSONObject json) {
    Long plateId = json.getLong("plateId");
    String locationBarcode = json.getString("locationBarcode");

    try {
      String newLocation = LimsUtils.lookupLocation(locationBarcode);
      if (newLocation != null) {
        User user =
            securityManager.getUserByLoginName(
                SecurityContextHolder.getContext().getAuthentication().getName());
        // Plate<LinkedList<Plateable>, Plateable> plate = requestManager.<LinkedList<Plateable>,
        // Plateable> getPlateById(plateId);
        Plate<? extends List<? extends Plateable>, ? extends Plateable> plate =
            requestManager.getPlateById(plateId);
        plate.setLocationBarcode(locationBarcode);
        /*
        Note note = new Note();
        note.setInternalOnly(true);
        note.setText("Location changed to " + newLocation + " by " + user.getLoginName() + " on " + new Date());
        note.setOwner(user);
        note.setCreationDate(new Date());
        plate.getNotes().add(note);
        requestManager.saveSampleNote(sample, note);
        */
        requestManager.savePlate(plate);
      } else {
        return JSONUtils.SimpleJSONError("New location barcode not recognised");
      }
    } catch (IOException e) {
      e.printStackTrace();
      return JSONUtils.SimpleJSONError(e.getMessage());
    }

    return JSONUtils.SimpleJSONResponse("Plate saved successfully");
  }
Exemplo n.º 2
0
 public void updateGroupWatcher(Long userId) throws IOException {
   User user = securityManager.getUserById(userId);
   if (user != null) {
     for (Run r : runs.values()) {
       if (user.getGroups().contains(securityManager.getGroupByName("RunWatchers"))) {
         addWatcher(r, userId);
       } else {
         if (r.getSecurityProfile() != null
             && r.getSecurityProfile().getOwner() != null
             && !r.getSecurityProfile().getOwner().equals(user)) {
           removeWatcher(r, userId);
         }
       }
     }
   }
 }
Exemplo n.º 3
0
  private void update(Run r) throws IOException {
    if (enabled) {
      Run clone = runs.get(r.getId());
      if (clone == null) {
        log.debug("Update: no clone - pushing");
        // new run - add all RunWatchers!
        for (User u : securityManager.listUsersByGroupName("RunWatchers")) {
          r.addWatcher(u);
        }
        push(r);
      } else {
        log.debug("Update: got clone of " + clone.getId());
        if (r.getStatus() != null) {
          clone.setStatus(r.getStatus());
        }

        // run QC added
        if (r.getRunQCs().size() > clone.getRunQCs().size()) {
          Set<RunQC> clonedQCs = new HashSet<RunQC>(clone.getRunQCs());
          for (RunQC qc : r.getRunQCs()) {
            if (!clonedQCs.contains(qc)) {
              try {
                clone.addQc(cloner.deepClone(qc));
              } catch (MalformedRunQcException e) {
                throw new IOException(e);
              }
            }
          }
        }

        pop(clone);
        push(r);
      }
    }
  }
  public JSONObject printPlateBarcodes(HttpSession session, JSONObject json) {
    try {
      User user =
          securityManager.getUserByLoginName(
              SecurityContextHolder.getContext().getAuthentication().getName());

      String serviceName = null;
      if (json.has("serviceName")) {
        serviceName = json.getString("serviceName");
      }

      MisoPrintService<File, PrintContext<File>> mps = null;
      if (serviceName == null) {
        Collection<MisoPrintService> services =
            printManager.listPrintServicesByBarcodeableClass(Plate.class);
        if (services.size() == 1) {
          mps = services.iterator().next();
        } else {
          return JSONUtils.SimpleJSONError(
              "No serviceName specified, but more than one available service able to print this barcode type.");
        }
      } else {
        mps = printManager.getPrintService(serviceName);
      }

      Queue<File> thingsToPrint = new LinkedList<File>();
      JSONArray ss = JSONArray.fromObject(json.getString("plates"));
      for (JSONObject s : (Iterable<JSONObject>) ss) {
        try {
          Long plateId = s.getLong("plateId");
          // Plate<LinkedList<Plateable>, Plateable>  plate = requestManager.<LinkedList<Plateable>,
          // Plateable> getPlateById(plateId);
          Plate<? extends List<? extends Plateable>, ? extends Plateable> plate =
              requestManager.getPlateById(plateId);
          // autosave the barcode if none has been previously generated
          if (plate.getIdentificationBarcode() == null
              || "".equals(plate.getIdentificationBarcode())) {
            requestManager.savePlate(plate);
          }
          File f = mps.getLabelFor(plate);
          if (f != null) thingsToPrint.add(f);
        } catch (IOException e) {
          e.printStackTrace();
          return JSONUtils.SimpleJSONError("Error printing barcodes: " + e.getMessage());
        }
      }
      PrintJob pj = printManager.print(thingsToPrint, mps.getName(), user);
      return JSONUtils.SimpleJSONResponse("Job " + pj.getJobId() + " : Barcodes printed.");
    } catch (MisoPrintException e) {
      e.printStackTrace();
      return JSONUtils.SimpleJSONError("Failed to print barcodes: " + e.getMessage());
    } catch (IOException e) {
      e.printStackTrace();
      return JSONUtils.SimpleJSONError("Failed to print barcodes: " + e.getMessage());
    }
  }
 @RequestMapping("/tech/groups")
 public ModelAndView techListGroups() throws IOException {
   try {
     return new ModelAndView("/pages/listGroups.jsp", "groups", securityManager.listAllGroups());
   } catch (IOException ex) {
     if (log.isDebugEnabled()) {
       log.debug("Failed to list groups", ex);
     }
     throw ex;
   }
 }
Exemplo n.º 6
0
 public void removeWatcher(Run run, Long userId) throws IOException {
   User user = securityManager.getUserById(userId);
   if (user != null) {
     Run clone = runs.get(run.getId());
     if (clone == null) {
       run.removeWatcher(user);
       push(run);
     } else {
       clone.removeWatcher(user);
     }
   }
 }
 public JSONObject deletePlate(HttpSession session, JSONObject json) {
   try {
     User user =
         securityManager.getUserByLoginName(
             SecurityContextHolder.getContext().getAuthentication().getName());
     if (user.isAdmin()) {
       if (json.has("plateId")) {
         Long plateId = json.getLong("plateId");
         requestManager.deletePlate(requestManager.getPlateById(plateId));
         return JSONUtils.SimpleJSONResponse("Plate deleted");
       } else {
         return JSONUtils.SimpleJSONError("No plate specified to delete.");
       }
     } else {
       return JSONUtils.SimpleJSONError("Only admins can delete objects.");
     }
   } catch (IOException e) {
     e.printStackTrace();
     return JSONUtils.SimpleJSONError("Error getting currently logged in user.");
   }
 }