public FeedFileResource(File root, File resourceFolder, String type) {
    super.setTypeName(type);
    // After unziping the uploaded folder, I would like to copy it to the
    // appropriate location right away (and not on the next read). So, I put the
    // code here. Note that this constructor is also called on copying a
    // resource. We know that the resource folder is valid.

    // Let's now copy the resource folder to the root folder.
    VFSContainer rootContainer = new LocalFolderImpl(root);
    String folderName = FeedManager.getInstance().getFeedKind(this);
    if (rootContainer.resolve(folderName) == null) {
      // If the podcast directory doesn't exist yet, create it and copy content
      // from uploaded folder
      rootContainer = rootContainer.createChildContainer(folderName);
      VFSContainer resourceContainer = new LocalFolderImpl(resourceFolder);
      for (VFSItem item : resourceContainer.getItems()) {
        rootContainer.copyFrom(item);
        // Delete the item if it is located in the _unzipped_ dir.
        // Remember that the resource folder could be a valid folder of a
        // different resource (when copying the resource).
        if (resourceContainer.getName().equals(FileResourceManager.ZIPDIR)) {
          item.delete();
        }
      }
    }
  }
Example #2
0
  private void processReturnFile(
      AssessableCourseNode courseNode,
      BulkAssessmentRow row,
      UserCourseEnvironment uce,
      File assessedFolder) {
    String assessedId = row.getAssessedId();
    Identity identity = uce.getIdentityEnvironment().getIdentity();
    VFSContainer returnBox = getReturnBox(uce, courseNode, identity);
    if (returnBox != null) {
      for (String returnFilename : row.getReturnFiles()) {
        File returnFile = new File(assessedFolder, returnFilename);
        VFSItem currentReturnLeaf = returnBox.resolve(returnFilename);
        if (currentReturnLeaf != null) {
          // remove the current file (delete make a version if it is enabled)
          currentReturnLeaf.delete();
        }

        VFSLeaf returnLeaf = returnBox.createChildLeaf(returnFilename);
        if (returnFile.exists()) {
          try {
            InputStream inStream = new FileInputStream(returnFile);
            VFSManager.copyContent(inStream, returnLeaf);
          } catch (FileNotFoundException e) {
            log.error("Cannot copy return file " + returnFilename + " from " + assessedId, e);
          }
        }
      }
    }
  }
  private void doDelete(UserRequest ureq, SolutionRow solution) {
    String documentName = solution.getSolution().getFilename();
    VFSItem item = solutionContainer.resolve(documentName);
    if (item != null) {
      item.delete();
    }
    solutions.getSolutions().remove(solution.getSolution());

    fireEvent(ureq, Event.DONE_EVENT);
    updateModel();
  }