/**
  * Set the import log file's size in the database to its current size on the filesystem.
  *
  * @throws ServerError if the import log's size could not be updated in the database
  */
 private void setLogFileSize() throws ServerError {
   final OriginalFile logFile =
       (OriginalFile)
           sf.getQueryService().get(OriginalFile.class.getSimpleName(), logPath.getId());
   logFile.setSize(omero.rtypes.rlong(logPath.size()));
   sf.getUpdateService().saveObject(logFile);
 }
Exemplo n.º 2
0
  /** Opens the file. */
  private void openFile() {
    if (!(data instanceof FileAnnotationData)) return;

    FileAnnotationData fa = (FileAnnotationData) data;
    Registry reg = MetadataViewerAgent.getRegistry();
    UserNotifier un = reg.getUserNotifier();
    OriginalFile f = (OriginalFile) fa.getContent();
    Environment env = (Environment) reg.lookup(LookupNames.ENV);
    DownloadAndLaunchActivityParam activity;
    final long dataId = fa.getId();
    final File dir =
        new File(env.getOmeroFilesHome() + File.separatorChar + "file annotation " + dataId);
    if (!dir.exists()) {
      dir.mkdir();
    }
    if (f != null && f.isLoaded()) {
      activity = new DownloadAndLaunchActivityParam(f, dir, null);
    } else {
      activity =
          new DownloadAndLaunchActivityParam(
              dataId, DownloadAndLaunchActivityParam.FILE_ANNOTATION, dir, null);
    }
    un.notifyActivity(model.getSecurityContext(), activity);
    return;
  }
Exemplo n.º 3
0
 public List<String> list(String path, Current __current) throws ServerError {
   List<OriginalFile> ofiles = listFiles(path, __current);
   List<String> contents = new ArrayList<String>(ofiles.size());
   for (OriginalFile ofile : ofiles) {
     contents.add(ofile.getPath().getValue() + ofile.getName().getValue());
   }
   return contents;
 }
Exemplo n.º 4
0
 /**
  * Get an {@link OriginalFile} object based on its id. Returns null if the file does not exist or
  * does not belong to this repo.
  *
  * @param id long, db id of original file.
  * @return OriginalFile object.
  */
 private CheckedPath checkId(final long id, final Ice.Current curr)
     throws SecurityViolation, ValidationException {
   // TODO: could getOriginalFile and getFile be reduced to a single call?
   final FsFile file = this.repositoryDao.getFile(id, curr, this.repoUuid);
   if (file == null) {
     throw new SecurityViolation(null, null, "FileNotFound: " + id);
   }
   final OriginalFile originalFile = this.repositoryDao.getOriginalFile(id, curr);
   if (originalFile == null) {
     /* reachable even if file != null because getFile uses SQL,
      * evading the filter on the HQL used here by getOriginalFile */
     throw new SecurityViolation(null, null, "FileNotAccessible: " + id);
   }
   final CheckedPath checked =
       new CheckedPath(
           this.serverPaths, file.toString(), checksumProviderFactory, originalFile.getHasher());
   checked.setId(id);
   return checked;
 }
Exemplo n.º 5
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.º 6
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.º 7
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);
   }
 }