Search in sources :

Example 1 with RepositoryHandlerFactory

use of org.olat.repository.handlers.RepositoryHandlerFactory 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 2 with RepositoryHandlerFactory

use of org.olat.repository.handlers.RepositoryHandlerFactory in project openolat by klemens.

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)

Aggregations

Locale (java.util.Locale)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ResourceEvaluation (org.olat.fileresource.types.ResourceEvaluation)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryService (org.olat.repository.RepositoryService)2 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)2 RepositoryHandlerFactory (org.olat.repository.handlers.RepositoryHandlerFactory)2