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;
}
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);
}
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();
}
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;
}
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;
}
Aggregations