Ejemplo n.º 1
0
  @Override
  public void pruneHistory(long maxHistoryLength, ProgressDelegate progress) {
    VFSContainer versionsContainer = getRootVersionsContainer();
    if (!versionsContainer.exists()) {
      return;
    }
    // delete folder without versioning first

    int count = 0;
    String[] excludedRootFolders = new String[] {"tmp", "scorm", "forum", "portfolio"};
    for (String excludedRootFolder : excludedRootFolders) {
      VFSItem excludedContainer = versionsContainer.resolve(excludedRootFolder);
      if (excludedContainer instanceof LocalFolderImpl) {
        File excludedFile = ((LocalFolderImpl) excludedContainer).getBasefile();
        FileUtils.deleteQuietly(excludedFile);
        if (progress != null) progress.setInfo(excludedContainer.getName());
      }
      if (progress != null) progress.setActual(++count);
    }

    if (maxHistoryLength < 0) {
      // nothing to do
    } else if (maxHistoryLength == 0 && versionsContainer instanceof LocalFolderImpl) {
      // delete all the stuff
      FileUtils.deleteQuietly(((LocalFolderImpl) versionsContainer).getBasefile());
    } else {
      pruneVersionHistory(versionsContainer, maxHistoryLength, progress, count);
    }

    if (progress != null) progress.finished();
  }
Ejemplo n.º 2
0
  @Override
  public List<Versions> getDeletedFiles(VFSContainer container) {
    List<Versions> deletedRevisions = new ArrayList<Versions>();

    VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
    if (versionContainer != null) {
      Set<String> currentNames = new HashSet<String>();
      for (VFSItem item : container.getItems(new VFSLeafFilter())) {
        currentNames.add(item.getName() + ".xml");
      }

      List<VFSItem> versionItems =
          versionContainer.getItems(new VFSItemSuffixFilter(new String[] {"xml"}));
      for (VFSItem versionItem : versionItems) {
        String name = versionItem.getName();
        if (versionItem instanceof VFSLeaf
            && !currentNames.contains(name)
            && isVersionsXmlFile((VFSLeaf) versionItem)) {
          Versions versions = readVersions(null, (VFSLeaf) versionItem);
          if (versions != null) {
            List<VFSRevision> revisions = versions.getRevisions();
            if (!revisions.isEmpty()) {
              deletedRevisions.add(versions);
            }
          }
        }
      }
    }
    return deletedRevisions;
  }
Ejemplo n.º 3
0
  private void crawlForOrphans(VFSContainer container, List<OrphanVersion> orphans) {
    if (!container.exists()) {
      return;
    }

    List<VFSItem> children = container.getItems();
    for (VFSItem child : children) {
      if (child instanceof VFSContainer) {
        crawlForOrphans((VFSContainer) child, orphans);
      }
      if (child instanceof VFSLeaf) {
        VFSLeaf versionsLeaf = (VFSLeaf) child;
        if (child.getName().endsWith(".xml")) {
          Versions versions = isOrphan(versionsLeaf);
          if (versions == null) {
            continue;
          } else {
            List<VFSRevision> revisions = versions.getRevisions();
            if (revisions != null) {
              for (VFSRevision revision : revisions) {
                if (revision instanceof RevisionFileImpl) {
                  ((RevisionFileImpl) revision).setContainer(container);
                }
              }
            }
          }
          File originalFile = reversedOriginFile(child);
          if (!originalFile.exists()) {
            VFSLeaf orphan = new LocalFileImpl(originalFile);
            orphans.add(new OrphanVersion(orphan, versionsLeaf, versions));
          }
        }
      }
    }
  }
Ejemplo n.º 4
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);
          }
        }
      }
    }
  }
  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();
        }
      }
    }
  }
Ejemplo n.º 6
0
 private String getRelativePath(VFSItem item) {
   String path = "";
   while (item != null && !isSameAsRootContainer(item)) {
     path = "/" + item.getName() + path;
     item = item.getParentContainer();
   }
   return path;
 }
Ejemplo n.º 7
0
 private CourseNode createCourseNode(VFSItem item, String type) {
   CourseNodeConfiguration newNodeConfig =
       CourseNodeFactory.getInstance().getCourseNodeConfiguration(type);
   CourseNode newNode = newNodeConfig.getInstance();
   newNode.setShortTitle(item.getName());
   newNode.setLongTitle(item.getName());
   newNode.setLearningObjectives(item.getName());
   newNode.setNoAccessExplanation("You don't have access");
   return newNode;
 }
Ejemplo n.º 8
0
  private File reversedOriginFile(VFSItem versionXml) {
    String path =
        File.separatorChar + versionXml.getName().substring(0, versionXml.getName().length() - 4);
    for (VFSContainer parent = versionXml.getParentContainer();
        parent != null && !parent.isSame(getRootVersionsContainer());
        parent = parent.getParentContainer()) {
      path = File.separatorChar + parent.getName() + path;
    }

    return new File(getCanonicalRoot(), path);
  }
  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();
  }
Ejemplo n.º 10
0
 @Override
 public boolean accept(VFSItem vfsItem) {
   String name = vfsItem.getName();
   return !name.startsWith(".");
 }
Ejemplo n.º 11
0
 public String getIconCssClass() {
   if (item instanceof VFSContainer) {
     return "b_filetype_folder";
   }
   return CSSHelper.createFiletypeIconCssClassFor(item.getName());
 }
Ejemplo n.º 12
0
 public String getName() {
   return item.getName();
 }
Ejemplo n.º 13
0
 private boolean isVersioned(VFSItem item) {
   if (item == null) return false;
   VFSContainer parent = item.getParentContainer();
   return FolderConfig.versionsEnabled(parent);
 }