Search in sources :

Example 86 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class EvaluationFormHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    EvaluationFormResource ores = new EvaluationFormResource();
    OLATResource resource = olatResourceManager.createAndPersistOLATResourceInstance(ores);
    File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(resource).getBasefile();
    File zipDir = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
    copyResource(file, filename, zipDir);
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    dbInstance.commit();
    return re;
}
Also used : OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File)

Example 87 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class LiveBlogArtefact method getFeedLight.

public Feed getFeedLight() {
    String businessPath = getBusinessPath();
    Long resid = Long.parseLong(businessPath.substring(10, businessPath.length() - 1));
    OLATResource ores = OLATResourceManager.getInstance().findResourceable(resid, BlogFileResource.TYPE_NAME);
    return FeedManager.getInstance().loadFeed(ores);
}
Also used : OLATResource(org.olat.resource.OLATResource)

Example 88 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class FeedManagerImpl method createFeedResource.

/**
 * This method creates an OLATResource in the database and
 * initializes the container on the file system.
 *
 * @param feedResource
 * @return The feed resourcable
 */
private OLATResourceable createFeedResource(FeedFileResource feedResource) {
    // save the resource in the database
    OLATResource ores = resourceManager.createOLATResourceInstance(feedResource);
    resourceManager.saveOLATResource(ores);
    // create a feed and save it in the database
    feedDAO.createFeedForResourcable(feedResource);
    // Create a resource folder for storing the images
    feedFileStorage.getOrCreateFeedContainer(feedResource);
    return feedResource;
}
Also used : OLATResource(org.olat.resource.OLATResource)

Example 89 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class CoursesWebService method copyCourse.

private static ICourse copyCourse(Long copyFrom, UserRequest ureq, Identity initialAuthor, String shortTitle, String longTitle, String displayName, String description, String softKey, int access, boolean membersOnly, String authors, String location, String externalId, String externalRef, String managedFlags, CourseConfigVO courseConfigVO) {
    // String learningObjectives = name + " (Example of creating a new course)";
    OLATResourceable originalOresTrans = OresHelper.createOLATResourceableInstance(CourseModule.class, copyFrom);
    RepositoryEntry src = RepositoryManager.getInstance().lookupRepositoryEntry(originalOresTrans, false);
    if (src == null) {
        src = RepositoryManager.getInstance().lookupRepositoryEntry(copyFrom, false);
    }
    if (src == null) {
        log.warn("Cannot find course to copy from: " + copyFrom);
        return null;
    }
    OLATResource originalOres = OLATResourceManager.getInstance().findResourceable(src.getOlatResource());
    boolean isAlreadyLocked = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).isLocked(originalOres);
    LockResult lockResult = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).acquireLock(originalOres, ureq.getIdentity());
    // check range of access
    if (access < 1 || access > RepositoryEntry.ACC_USERS_GUESTS) {
        access = RepositoryEntry.ACC_OWNERS;
    }
    if (lockResult == null || (lockResult != null && lockResult.isSuccess()) && !isAlreadyLocked) {
        RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
        // create new repo entry
        String name;
        if (description == null || description.trim().length() == 0) {
            description = src.getDescription();
        }
        if (courseConfigVO != null && StringHelper.containsNonWhitespace(displayName)) {
            name = displayName;
        } else {
            name = "Copy of " + src.getDisplayname();
        }
        String resName = src.getResourcename();
        if (resName == null) {
            resName = "";
        }
        OLATResource sourceResource = src.getOlatResource();
        OLATResource copyResource = OLATResourceManager.getInstance().createOLATResourceInstance(sourceResource.getResourceableTypeName());
        RepositoryEntry preparedEntry = repositoryService.create(initialAuthor, null, resName, name, description, copyResource, RepositoryEntry.ACC_OWNERS);
        RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src);
        preparedEntry = handler.copy(initialAuthor, src, preparedEntry);
        preparedEntry.setCanDownload(src.getCanDownload());
        if (StringHelper.containsNonWhitespace(softKey)) {
            preparedEntry.setSoftkey(softKey);
        }
        if (StringHelper.containsNonWhitespace(externalId)) {
            preparedEntry.setExternalId(externalId);
        }
        if (StringHelper.containsNonWhitespace(externalRef)) {
            preparedEntry.setExternalRef(externalRef);
        }
        if (StringHelper.containsNonWhitespace(authors)) {
            preparedEntry.setAuthors(authors);
        }
        if (StringHelper.containsNonWhitespace(location)) {
            preparedEntry.setLocation(location);
        }
        if (StringHelper.containsNonWhitespace(managedFlags)) {
            preparedEntry.setManagedFlagsString(managedFlags);
        }
        if (membersOnly) {
            preparedEntry.setMembersOnly(true);
            preparedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
        } else {
            preparedEntry.setAccess(access);
        }
        preparedEntry.setAllowToLeaveOption(src.getAllowToLeaveOption());
        repositoryService.update(preparedEntry);
        // copy image if available
        RepositoryManager.getInstance().copyImage(src, preparedEntry);
        ICourse course = prepareCourse(preparedEntry, shortTitle, longTitle, courseConfigVO);
        RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).releaseLock(lockResult);
        return course;
    }
    return null;
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) OLATResourceable(org.olat.core.id.OLATResourceable) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryService(org.olat.repository.RepositoryService)

Example 90 with OLATResource

use of org.olat.resource.OLATResource in project OpenOLAT by OpenOLAT.

the class CoursesWebService method getCourse.

@Path("{courseId}")
public CourseWebService getCourse(@PathParam("courseId") Long courseId) {
    ICourse course = loadCourse(courseId);
    if (course == null) {
        return null;
    }
    OLATResource ores = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    return new CourseWebService(ores, course);
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) Path(javax.ws.rs.Path)

Aggregations

OLATResource (org.olat.resource.OLATResource)706 Test (org.junit.Test)304 RepositoryEntry (org.olat.repository.RepositoryEntry)198 Identity (org.olat.core.id.Identity)170 File (java.io.File)80 Date (java.util.Date)72 Feed (org.olat.modules.webFeed.Feed)72 ArrayList (java.util.ArrayList)64 ICourse (org.olat.course.ICourse)64 RepositoryService (org.olat.repository.RepositoryService)62 OLATResourceable (org.olat.core.id.OLATResourceable)60 BusinessGroup (org.olat.group.BusinessGroup)58 Item (org.olat.modules.webFeed.Item)44 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)38 OLATResourceManager (org.olat.resource.OLATResourceManager)34 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)34 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)30 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)30 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)28 Group (org.olat.basesecurity.Group)26