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