Exemplo n.º 1
0
  protected OriginalFile findOrCreateInDb(
      CheckedPath checked, String mode, String mimetype, Ice.Current curr) throws ServerError {

    OriginalFile ofile = findInDb(checked, mode, curr);
    if (ofile != null) {
      return ofile;
    }

    if (checked.exists()) {
      omero.grid.UnregisteredFileException ufe = new omero.grid.UnregisteredFileException();
      ofile = (OriginalFile) new IceMapper().map(checked.asOriginalFile(mimetype));
      ufe.file = ofile;
      throw ufe;
    }

    ofile = repositoryDao.register(repoUuid, checked, null, curr);
    final long originalFileId = ofile.getId().getValue();
    setOriginalFileHasherToSHA1(originalFileId, curr);
    checked.setId(originalFileId);
    return ofile;
  }
Exemplo n.º 2
0
  /**
   * Find the given path in the DB or create.
   *
   * <p>"requiresWrite" is set to true unless the mode is "r". If requiresWrite is true, then the
   * caller needs the file to be modifiable (both on disk and the DB). If this doesn't hold, then a
   * SecurityViolation will be thrown.
   */
  protected OriginalFile findInDb(CheckedPath checked, String mode, Ice.Current current)
      throws ServerError {

    final OriginalFile ofile = repositoryDao.findRepoFile(repoUuid, checked, null, current);

    if (ofile == null) {
      return null; // EARLY EXIT!
    }

    boolean requiresWrite = true;
    if ("r".equals(mode)) {
      requiresWrite = false;
    }

    checked.setId(ofile.getId().getValue());
    boolean canUpdate = repositoryDao.canUpdate(ofile, current);
    if (requiresWrite && !canUpdate) {
      throw new omero.SecurityViolation(null, null, "requiresWrite is true but cannot modify");
    }

    return ofile;
  }
Exemplo n.º 3
0
 /**
  * Downloads the file.
  *
  * @see EditorLoader#cancel()
  */
 public void load() {
   if (data != null) {
     OriginalFile f = ((FileAnnotation) data.asAnnotation()).getFile();
     if (f.isLoaded()) {
       handle = mhView.loadFile(file, f.getId().getValue(), f.getSize().getValue(), this);
     }
   } else {
     Entry entry;
     Iterator i = files.entrySet().iterator();
     FileAnnotationData fa;
     filesMap = new HashMap<FileAnnotationData, File>(files.size());
     File f;
     // int index = 0;
     String dir = MetadataViewerAgent.getTmpDir();
     while (i.hasNext()) {
       entry = (Entry) i.next();
       fa = (FileAnnotationData) entry.getKey();
       f = new File(dir + File.separator + fa.getFileID() + "_" + fa.getFileName());
       f.deleteOnExit();
       filesMap.put(fa, f);
     }
     handle = mhView.loadFiles(filesMap, this);
   }
 }