private void updateModel() {
    List<Solution> solutionList = solutions.getSolutions();
    List<SolutionRow> rows = new ArrayList<>(solutionList.size());
    for (Solution solution : solutionList) {
      String filename = solution.getFilename();
      String author = null;

      VFSItem item = solutionContainer.resolve(filename);
      if (item instanceof MetaTagged) {
        MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
        if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
          author = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
        }
      }

      rows.add(new SolutionRow(solution, author));
    }
    solutionModel.setObjects(rows);
    solutionTable.reset();
  }
예제 #2
0
  /**
   * @see
   *     org.olat.core.util.vfs.version.VersionsManager#addToRevisions(org.olat.core.util.vfs.version.Versionable,
   *     org.olat.core.id.Identity, java.lang.String)
   */
  @Override
  public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) {
    int maxNumOfVersions = versioningConfigurator.getMaxNumOfVersionsAllowed();
    if (maxNumOfVersions == 0) {
      return true; // deactivated, return all ok
    }

    VFSLeaf currentFile = (VFSLeaf) currentVersion;

    VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
    if (versionFile == null) {
      return false; // cannot do something with the current file
    }

    VFSContainer versionContainer = versionFile.getParentContainer();

    String name = currentFile.getName();

    // read from the
    Versions v = readVersions(currentFile, versionFile);
    if (!(v instanceof VersionsFileImpl)) {
      log.error("Wrong implementation of Versions: " + v);
      return false;
    }
    VersionsFileImpl versions = (VersionsFileImpl) v;
    boolean sameFile = isSameFile(currentFile, versions);
    String uuid =
        sameFile ? getLastRevisionFilename(versions) : UUID.randomUUID().toString() + "_" + name;

    String versionNr = getNextRevisionNr(versions);
    String currentAuthor = versions.getAuthor();
    long lastModifiedDate = 0;
    if (currentFile instanceof MetaTagged) {
      MetaInfo metaInfo = ((MetaTagged) currentFile).getMetaInfo();
      if (metaInfo != null) {
        metaInfo.clearThumbnails();
        if (currentAuthor == null) {
          currentAuthor = metaInfo.getAuthor();
        }
        lastModifiedDate = metaInfo.getLastModified();
      }
    }

    if (lastModifiedDate <= 0) {
      Calendar cal = Calendar.getInstance();
      cal.setTime(new Date());
      lastModifiedDate = cal.getTimeInMillis();
    }

    RevisionFileImpl newRevision = new RevisionFileImpl();
    newRevision.setUuid(UUID.randomUUID().toString());
    newRevision.setName(name);
    newRevision.setFilename(uuid);
    newRevision.setRevisionNr(versionNr);
    newRevision.setComment(versions.getComment());
    newRevision.setAuthor(currentAuthor);
    newRevision.setLastModified(lastModifiedDate);

    if (versions.getRevisions().isEmpty() && currentVersion instanceof MetaTagged) {
      MetaTagged metaTagged = (MetaTagged) currentVersion;
      versions.setCreator(metaTagged.getMetaInfo().getAuthor());
    }

    if (sameFile || VFSManager.copyContent(currentFile, versionContainer.createChildLeaf(uuid))) {
      if (identity != null) {
        versions.setAuthor(identity.getName());
      }

      if (maxNumOfVersions >= 0 && versions.getRevisions().size() >= maxNumOfVersions) {
        List<VFSRevision> revisions = versions.getRevisions();
        int numOfVersionsToDelete =
            Math.min(revisions.size(), (revisions.size() - maxNumOfVersions) + 1);
        if (numOfVersionsToDelete > 0) {
          List<VFSRevision> versionsToDelete = revisions.subList(0, numOfVersionsToDelete);
          deleteRevisions(currentVersion, versionsToDelete);
          versions = (VersionsFileImpl) currentVersion.getVersions();
        }
      }
      versions.setComment(comment);
      versions.getRevisions().add(newRevision);
      versions.setRevisionNr(getNextRevisionNr(versions));
      XStreamHelper.writeObject(mystream, versionFile, versions);
      if (currentVersion.getVersions() instanceof VersionsFileImpl) {
        ((VersionsFileImpl) currentVersion.getVersions()).update(versions);
      }
      return true;
    } else {
      log.error("Cannot create a version of this file: " + currentVersion);
    }
    return false;
  }