Search in sources :

Example 91 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class VersionsFileManager method crawlForOrphans.

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));
                }
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 92 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class VersionsFileManager method pruneVersionHistory.

private void pruneVersionHistory(VFSLeaf versionsLeaf, long maxHistoryLength, ProgressDelegate progress) {
    if (versionsLeaf.getName().endsWith(".xml") && isVersionsXmlFile(versionsLeaf)) {
        File originalFile = reversedOriginFile(versionsLeaf);
        if (originalFile.exists()) {
            VFSLeaf original = new LocalFileImpl(originalFile);
            if (progress != null)
                progress.setInfo(original.getName());
            Versions versions = readVersions(original, versionsLeaf);
            List<VFSRevision> revisions = versions.getRevisions();
            if (revisions.size() > maxHistoryLength) {
                List<VFSRevision> revisionsToDelete = revisions.subList(0, revisions.size() - (int) maxHistoryLength);
                deleteRevisions((Versionable) original, revisionsToDelete);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 93 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class DrawingEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (readOnly)
        return;
    // title
    itemBuilder.setTitle(titleEl.getValue());
    File objectImg = null;
    if (backgroundImage != null) {
        objectImg = backgroundImage;
    } else if (initialBackgroundImage != null) {
        objectImg = initialBackgroundImage;
    }
    if (objectImg != null) {
        String filename = objectImg.getName();
        String mimeType = WebappHelper.getMimeType(filename);
        Size size = imageService.getSize(new LocalFileImpl(objectImg), null);
        int height = -1;
        int width = -1;
        if (size != null) {
            height = size.getHeight();
            width = size.getWidth();
        }
        itemBuilder.setBackground(filename, mimeType, height, width);
    }
    // question
    String questionText = textEl.getRawValue();
    itemBuilder.setQuestion(questionText);
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.drawing));
}
Also used : Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Example 94 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class CPFileImportController method uploadFiles.

/**
 * Upload the selected files and import them into the content package.
 */
private void uploadFiles() {
    VFSContainer root = cp.getRootDir();
    String filenName = file.getUploadFileName();
    // don't check on mimetypes - some browser use different mime types when sending files (OLAT-4547)
    if (filenName.toLowerCase().endsWith(".zip")) {
        // unzip and add files
        VFSLeaf archive = new LocalFileImpl(file.getUploadFile());
        String archiveName = file.getUploadFileName();
        String unzipDirName = archiveName.substring(0, archiveName.toLowerCase().indexOf(".zip"));
        unzipDirName = VFSManager.similarButNonExistingName(root, unzipDirName);
        VFSContainer unzipDir = root.createChildContainer(unzipDirName);
        ZipUtil.unzip(archive, unzipDir);
        // add items of unzipDir to tree
        pageToBeSelected = addItem(unzipDir, currentPage.getIdentifier(), true);
        CPManager.getInstance().writeToFile(cp);
    } else {
        // Single file
        VFSLeaf uploadedItem = new LocalFileImpl(file.getUploadFile());
        uploadedItem.rename(file.getUploadFileName());
        // rename to unique name in root folder
        renameToNonExistingDesignation(root, uploadedItem);
        // move item to root folder
        root.copyFrom(uploadedItem);
        pageToBeSelected = addItem(uploadedItem, currentPage.getIdentifier(), false);
        CPManager.getInstance().writeToFile(cp);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 95 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.

the class RepositoryEditDescriptionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (licenseModule.isEnabled(licenseHandler)) {
        if (licenseEl != null && licenseEl.isOneSelected()) {
            String licenseTypeKey = licenseEl.getSelectedKey();
            LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
            license.setLicenseType(licneseType);
        }
        String licensor = null;
        String freetext = null;
        if (licensorEl != null && licensorEl.isVisible()) {
            licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
        }
        if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
            freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
        }
        license.setLicensor(licensor);
        license.setFreetext(freetext);
        license = licenseService.update(license);
        licensorEl.setValue(license.getLicensor());
        licenseFreetextEl.setValue(license.getFreetext());
    }
    File uploadedImage = fileUpload.getUploadFile();
    if (uploadedImage != null && uploadedImage.exists()) {
        VFSContainer tmpHome = new LocalFolderImpl(new File(WebappHelper.getTmpDir()));
        VFSContainer container = tmpHome.createChildContainer(UUID.randomUUID().toString());
        // give it it's real name and extension
        VFSLeaf newFile = fileUpload.moveUploadFileTo(container);
        boolean ok = repositoryManager.setImage(newFile, repositoryEntry);
        if (!ok) {
            showWarning("cif.error.image");
        } else {
            VFSLeaf image = repositoryManager.getImage(repositoryEntry);
            if (image instanceof LocalFileImpl) {
                fileUpload.setInitialFile(((LocalFileImpl) image).getBasefile());
            }
        }
        container.delete();
    }
    File uploadedMovie = movieUpload.getUploadFile();
    if (uploadedMovie != null && uploadedMovie.exists()) {
        VFSContainer m = (VFSContainer) mediaContainer.resolve("media");
        VFSLeaf newFile = movieUpload.moveUploadFileTo(m);
        if (newFile == null) {
            showWarning("cif.error.movie");
        } else {
            String filename = movieUpload.getUploadFileName();
            String extension = FileUtils.getFileSuffix(filename);
            newFile.rename(repositoryEntry.getKey() + "." + extension);
        }
    }
    String displayname = displayName.getValue().trim();
    repositoryEntry.setDisplayname(displayname);
    String mainLanguage = language.getValue();
    if (StringHelper.containsNonWhitespace(mainLanguage)) {
        repositoryEntry.setMainLanguage(mainLanguage);
    } else {
        repositoryEntry.setMainLanguage(null);
    }
    if (dateTypesEl != null) {
        String type = "none";
        if (dateTypesEl.isOneSelected()) {
            type = dateTypesEl.getSelectedKey();
        }
        if ("none".equals(type)) {
            repositoryEntry.setLifecycle(null);
        } else if ("public".equals(type)) {
            String key = publicDatesEl.getSelectedKey();
            if (StringHelper.isLong(key)) {
                Long cycleKey = Long.parseLong(key);
                RepositoryEntryLifecycle cycle = lifecycleDao.loadById(cycleKey);
                repositoryEntry.setLifecycle(cycle);
            }
        } else if ("private".equals(type)) {
            Date start = startDateEl.getDate();
            Date end = endDateEl.getDate();
            RepositoryEntryLifecycle cycle = repositoryEntry.getLifecycle();
            if (cycle == null || !cycle.isPrivateCycle()) {
                String softKey = "lf_" + repositoryEntry.getSoftkey();
                cycle = lifecycleDao.create(displayname, softKey, true, start, end);
            } else {
                cycle.setValidFrom(start);
                cycle.setValidTo(end);
                cycle = lifecycleDao.updateLifecycle(cycle);
            }
            repositoryEntry.setLifecycle(cycle);
        }
    }
    if (externalRef != null && externalRef.isEnabled()) {
        String ref = externalRef.getValue().trim();
        repositoryEntry.setExternalRef(ref);
    }
    String desc = description.getValue().trim();
    repositoryEntry.setDescription(desc);
    if (authors != null) {
        String auth = authors.getValue().trim();
        repositoryEntry.setAuthors(auth);
    }
    if (objectives != null) {
        String obj = objectives.getValue().trim();
        repositoryEntry.setObjectives(obj);
    }
    if (requirements != null) {
        String req = requirements.getValue().trim();
        repositoryEntry.setRequirements(req);
    }
    if (credits != null) {
        String cred = credits.getValue().trim();
        repositoryEntry.setCredits(cred);
    }
    if (expenditureOfWork != null) {
        String exp = expenditureOfWork.getValue().trim();
        repositoryEntry.setExpenditureOfWork(exp);
    }
    if (location != null) {
        String loc = location.getValue().trim();
        repositoryEntry.setLocation(loc);
    }
    repositoryEntry = repositoryManager.setDescriptionAndName(repositoryEntry, repositoryEntry.getDisplayname(), repositoryEntry.getExternalRef(), repositoryEntry.getAuthors(), repositoryEntry.getDescription(), repositoryEntry.getObjectives(), repositoryEntry.getRequirements(), repositoryEntry.getCredits(), repositoryEntry.getMainLanguage(), repositoryEntry.getLocation(), repositoryEntry.getExpenditureOfWork(), repositoryEntry.getLifecycle());
    if (repositoryEntry == null) {
        showWarning("repositoryentry.not.existing");
        fireEvent(ureq, Event.CLOSE_EVENT);
    } else {
        fireEvent(ureq, Event.CHANGED_EVENT);
        MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, getIdentity(), Change.modifiedDescription, "authoring");
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Date(java.util.Date) LicenseType(org.olat.core.commons.services.license.LicenseType) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Aggregations

LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)126 File (java.io.File)70 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 Size (org.olat.core.commons.services.image.Size)22 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 RandomAccessFile (java.io.RandomAccessFile)14 FileChannel (java.nio.channels.FileChannel)12 FileChannelWrapper (org.jcodec.common.FileChannelWrapper)12 CannotGenerateThumbnailException (org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)12 OLATResource (org.olat.resource.OLATResource)10 Date (java.util.Date)8 MP4Demuxer (org.jcodec.containers.mp4.demuxer.MP4Demuxer)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)8 VFSCPNamedItem (org.olat.ims.cp.ui.VFSCPNamedItem)8 BufferedImage (java.awt.image.BufferedImage)6 InputStream (java.io.InputStream)6