Search in sources :

Example 11 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project openolat by klemens.

the class TestFileResource method validate.

/**
 * @param unzippedDir
 * @return True if is of type.
 */
public static boolean validate(File unzippedDir) {
    // no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedDir);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    // getDocument(..) ensures that InputStream is closed in every case.
    Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    return validateQti(doc, new ResourceEvaluation(false)).isValid();
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 12 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.

the class CourseHandler method acceptImport.

@Override
public ResourceEvaluation acceptImport(File file, String filename) {
    ResourceEvaluation eval = new ResourceEvaluation();
    try {
        IndexFileFilter visitor = new IndexFileFilter();
        Path fPath = PathUtils.visit(file, filename, visitor);
        if (visitor.isValid()) {
            Path repoXml = fPath.resolve("export/repo.xml");
            if (repoXml != null) {
                eval.setValid(true);
                RepositoryEntryImport re = RepositoryEntryImportExport.getConfiguration(repoXml);
                if (re != null) {
                    eval.setDisplayname(re.getDisplayname());
                    eval.setDescription(re.getDescription());
                }
                eval.setReferences(hasReferences(fPath));
            }
        }
        eval.setValid(visitor.isValid());
        PathUtils.closeSubsequentFS(fPath);
    } catch (IOException | IllegalArgumentException e) {
        log.error("", e);
    }
    return eval;
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) Path(java.nio.file.Path) IOException(java.io.IOException) RepositoryEntryImport(org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport)

Example 13 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.

the class VideoHandler method acceptImport.

@Override
public ResourceEvaluation acceptImport(File file, String filename) {
    if (!StringHelper.containsNonWhitespace(filename)) {
        filename = file.getName();
    }
    ResourceEvaluation eval = new ResourceEvaluation(false);
    String extension = FileUtils.getFileSuffix(filename);
    if (StringHelper.containsNonWhitespace(extension)) {
        VideoFileResource.validate(file, filename, eval);
    }
    return eval;
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation)

Example 14 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.

the class RepositoryEntriesResource method importFileResource.

private RepositoryEntry importFileResource(Identity identity, File fResource, String resourcename, String displayname, String softkey, int access) {
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryHandlerFactory handlerFactory = CoreSpringFactory.getImpl(RepositoryHandlerFactory.class);
    try {
        RepositoryHandler handler = null;
        for (String type : handlerFactory.getSupportedTypes()) {
            RepositoryHandler h = handlerFactory.getRepositoryHandler(type);
            ResourceEvaluation eval = h.acceptImport(fResource, fResource.getName());
            if (eval != null && eval.isValid()) {
                handler = h;
                break;
            }
        }
        RepositoryEntry addedEntry = null;
        if (handler != null) {
            Locale locale = I18nModule.getDefaultLocale();
            addedEntry = handler.importResource(identity, null, displayname, "", true, locale, fResource, fResource.getName());
            if (StringHelper.containsNonWhitespace(resourcename)) {
                addedEntry.setResourcename(resourcename);
            }
            if (StringHelper.containsNonWhitespace(softkey)) {
                addedEntry.setSoftkey(softkey);
            }
            if (access < RepositoryEntry.ACC_OWNERS || access > RepositoryEntry.ACC_USERS_GUESTS) {
                addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
            } else {
                addedEntry.setAccess(access);
            }
            addedEntry = repositoryService.update(addedEntry);
        }
        return addedEntry;
    } catch (Exception e) {
        log.error("Fail to import a resource", e);
        throw new WebApplicationException(e);
    }
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) Locale(java.util.Locale) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryHandlerFactory(org.olat.repository.handlers.RepositoryHandlerFactory) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryService(org.olat.repository.RepositoryService)

Example 15 with ResourceEvaluation

use of org.olat.fileresource.types.ResourceEvaluation in project OpenOLAT by OpenOLAT.

the class FileResourceTest method scormPackage_scosInSubDirectory.

@Test
public void scormPackage_scosInSubDirectory() throws URISyntaxException, IOException {
    URL fileUrl = FileResourceTest.class.getResource("scorm_scos_in_sub_directory.zip");
    File file = new File(fileUrl.toURI());
    ResourceEvaluation eval = ScormCPFileResource.evaluate(file, file.getName());
    Assert.assertTrue(eval.isValid());
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ResourceEvaluation (org.olat.fileresource.types.ResourceEvaluation)30 File (java.io.File)10 IOException (java.io.IOException)10 Path (java.nio.file.Path)10 URL (java.net.URL)8 Document (org.dom4j.Document)8 Test (org.junit.Test)8 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSItem (org.olat.core.util.vfs.VFSItem)4 QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)4 RepositoryEntryImport (org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport)4 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)4 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryService (org.olat.repository.RepositoryService)2 RepositoryHandlerFactory (org.olat.repository.handlers.RepositoryHandlerFactory)2