Search in sources :

Example 11 with RepositoryService

use of org.olat.repository.RepositoryService 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 12 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class RepositoryEntriesResource method getRepositoryEntryResource.

@Path("{repoEntryKey}")
public RepositoryEntryResource getRepositoryEntryResource() {
    RepositoryManager rm = RepositoryManager.getInstance();
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    return new RepositoryEntryResource(rm, repositoryService, securityManager);
}
Also used : RepositoryManager(org.olat.repository.RepositoryManager) BaseSecurity(org.olat.basesecurity.BaseSecurity) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path)

Example 13 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class RepositoryEntryResource method deleteCoursePermanently.

/**
 * Change the status of a course by id. The possible status are:
 * <ul>
 * 	<li>closed</li>
 * 	<li>unclosed</li>
 * 	<li>unpublished</li>
 * 	<li>deleted</li>
 * 	<li>restored</li>
 * </ul>
 *
 * @response.representation.200.doc The metadatas of the deleted course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param request The HTTP request
 * @return It returns the XML representation of the <code>Structure</code>
 *         object representing the course.
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("status")
public Response deleteCoursePermanently(@PathParam("repoEntryKey") String repoEntryKey, @FormParam("newStatus") String newStatus, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!isAuthorEditor(re, request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    if ("closed".equals(newStatus)) {
        rs.closeRepositoryEntry(re);
        log.audit("REST closing course: " + re.getDisplayname() + " [" + re.getKey() + "]");
        ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_CLOSE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
    } else if ("unclosed".equals(newStatus)) {
        rs.uncloseRepositoryEntry(re);
        log.audit("REST unclosing course: " + re.getDisplayname() + " [" + re.getKey() + "]");
        ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_UPDATE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
    } else if ("unpublished".equals(newStatus)) {
        rs.unpublishRepositoryEntry(re);
        log.audit("REST unpublishing course: " + re.getDisplayname() + " [" + re.getKey() + "]");
        ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DEACTIVATE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
    } else if ("deleted".equals(newStatus)) {
        Identity identity = getIdentity(request);
        rs.deleteSoftly(re, identity, true);
        log.audit("REST deleting (soft) course: " + re.getDisplayname() + " [" + re.getKey() + "]");
        ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_TRASH, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
    } else if ("restored".equals(newStatus)) {
        rs.restoreRepositoryEntry(re);
        log.audit("REST restoring course: " + re.getDisplayname() + " [" + re.getKey() + "]");
        ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_RESTORE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
    }
    return Response.ok().build();
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 14 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class CourseHandler method createResource.

@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource resource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    DBFactory.getInstance().commit();
    String shortDisplayname = Formatter.truncateOnly(displayname, 25);
    ICourse course = CourseFactory.createCourse(re, shortDisplayname, displayname, "");
    log.audit("Course created: " + course.getCourseTitle());
    return re;
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 15 with RepositoryService

use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.

the class PortfolioHandler method createResource.

@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
    EPFrontendManager ePFMgr = CoreSpringFactory.getImpl(EPFrontendManager.class);
    EPStructureManager eSTMgr = CoreSpringFactory.getImpl(EPStructureManager.class);
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource resource = eSTMgr.createPortfolioMapTemplateResource();
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    PortfolioStructureMap mapTemp = eSTMgr.createAndPersistPortfolioMapTemplateFromEntry(initialAuthor, re);
    // add a page, as each map should have at least one per default!
    Translator pt = Util.createPackageTranslator(EPCreateMapController.class, locale);
    String pageTitle = pt.translate("new.page.title");
    String pageDescription = pt.translate("new.page.desc");
    ePFMgr.createAndPersistPortfolioPage(mapTemp, pageTitle, pageDescription);
    DBFactory.getInstance().commit();
    return re;
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) Translator(org.olat.core.gui.translator.Translator) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager) EPStructureManager(org.olat.portfolio.manager.EPStructureManager) RepositoryService(org.olat.repository.RepositoryService)

Aggregations

RepositoryService (org.olat.repository.RepositoryService)76 RepositoryEntry (org.olat.repository.RepositoryEntry)72 OLATResource (org.olat.resource.OLATResource)32 Identity (org.olat.core.id.Identity)20 Produces (javax.ws.rs.Produces)18 Path (javax.ws.rs.Path)16 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)14 File (java.io.File)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 GET (javax.ws.rs.GET)10 UserRequest (org.olat.core.gui.UserRequest)8 WindowControl (org.olat.core.gui.control.WindowControl)8 ICourse (org.olat.course.ICourse)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 UserVO (org.olat.user.restapi.UserVO)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Before (org.junit.Before)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 GlossaryResource (org.olat.fileresource.types.GlossaryResource)6