use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNodeIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, TYPE);
Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
indexWriter.addDocument(nodeDocument);
// go further, index my projects
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
Long projectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, courseNode);
if (projectBrokerId != null) {
List<Project> projects = projectBrokerManager.getProjectListBy(projectBrokerId);
for (Project project : projects) {
Document document = ProjectBrokerProjectDocument.createDocument(courseNodeResourceContext, project);
indexWriter.addDocument(document);
}
} else {
log.debug("projectBrokerId is null, courseNode=" + courseNode + " , course=" + course);
}
}
use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNode method postImport.
@Override
public void postImport(File importDirectory, ICourse course, CourseEnvironmentMapper envMapper, Processing processType) {
// initialize managers
if (processType == Processing.editor && importDirectory != null) {
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
// create a new projectBroker
ProjectBroker projectBroker = projectBrokerManager.createAndSaveProjectBroker();
projectBrokerManager.saveProjectBrokerId(projectBroker.getKey(), cpm, this);
// get the node folder inside of the importDirectory
File folderNodeData = new File(importDirectory, getIdent());
// for the broker prefs
File projectBrokerFile = new File(folderNodeData, "projectbroker.xml");
if (projectBrokerFile.exists()) {
XStream xstream = XStreamHelper.createXStreamInstance();
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
ProjectBrokerConfig brokerConfig = (ProjectBrokerConfig) XStreamHelper.readObject(xstream, projectBrokerFile);
if (brokerConfig != null && brokerConfig.getAccountGroupKey() != null) {
Long accountGroupKey = envMapper.toGroupKeyFromOriginalKey(brokerConfig.getAccountGroupKey());
if (accountGroupKey != null) {
projectGroupManager.saveAccountManagerGroupKey(accountGroupKey, cpm, this);
}
}
}
// loop through the project directories
if (folderNodeData.exists()) {
for (File projectDir : folderNodeData.listFiles(DirectoryFilter.DIRECTORY_FILTER)) {
for (File projectFile : projectDir.listFiles(new FileNameSuffixFilter("xml"))) {
importProject(projectDir, projectFile, projectBroker, course, envMapper);
}
}
}
}
super.postImport(importDirectory, course, envMapper, processType);
}
use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNode method cleanupOnDelete.
/**
* @see org.olat.course.nodes.CourseNode#cleanupOnDelete(
* org.olat.course.ICourse)
*/
@Override
public void cleanupOnDelete(ICourse course) {
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
Long projectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
File fDropBox = new File(FolderConfig.getCanonicalRoot() + DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
if (fDropBox.exists()) {
FileUtils.deleteDirsAndFiles(fDropBox, true, true);
}
File fReturnBox = new File(FolderConfig.getCanonicalRoot() + ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
if (fReturnBox.exists()) {
FileUtils.deleteDirsAndFiles(fReturnBox, true, true);
}
File attachmentDir = new File(FolderConfig.getCanonicalRoot() + projectBrokerManager.getAttachmentBasePathRelToFolderRoot(course.getCourseEnvironment(), this));
if (attachmentDir.exists()) {
FileUtils.deleteDirsAndFiles(attachmentDir, true, true);
}
// Delete project-broker, projects and project-groups
if (projectBrokerId != null) {
projectBrokerManager.deleteProjectBroker(projectBrokerId, course.getCourseEnvironment(), this);
}
// Delete all properties...
cpm.deleteNodeProperties(this, null);
OLATResource resource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(resource, getIdent());
}
use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNode method importProject.
private void importProject(File projectDir, File projectFile, ProjectBroker projectBroker, ICourse course, CourseEnvironmentMapper envMapper) {
XStream xstream = XStreamHelper.createXStreamInstance();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
// read the projectConfiguration from the importDirectory
try {
@SuppressWarnings("unchecked") Map<String, Object> projectConfig = (HashMap<String, Object>) XStreamHelper.readObject(xstream, projectFile);
String projectTitle = (String) projectConfig.get("title");
Long originalGroupKey = null;
if (projectConfig.containsKey("businessGroupKey")) {
originalGroupKey = (Long) projectConfig.get("businessGroupKey");
} else {
for (BusinessGroupReference ref : envMapper.getGroups()) {
if (ref.getName().endsWith(projectTitle)) {
originalGroupKey = ref.getOriginalKey();
}
}
}
BusinessGroup projectGroup = null;
if (originalGroupKey != null) {
Long groupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
projectGroup = bgs.loadBusinessGroup(groupKey);
}
if (projectGroup == null) {
projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), envMapper.getAuthor(), projectTitle, (String) projectConfig.get("description"), course.getResourceableId());
}
if (envMapper.getAuthor() != null) {
Identity author = envMapper.getAuthor();
bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
}
Project project = projectBrokerManager.createAndSaveProjectFor(projectTitle, (String) projectConfig.get("description"), projectBrokerManager.getProjectBrokerId(cpm, this), projectGroup);
projectGroupManager.setDeselectionAllowed(project, (boolean) projectConfig.get("allowDeselection"));
project.setMailNotificationEnabled((boolean) projectConfig.get("mailNotificationEnabled"));
project.setMaxMembers((int) projectConfig.get("maxMembers"));
project.setAttachedFileName(projectConfig.get("attachmentFileName").toString());
for (int i = 0; i < (int) projectConfig.get("customeFieldSize"); i++) {
project.setCustomFieldValue(i, projectConfig.get("customFieldValue" + i).toString());
}
projectBrokerManager.updateProject(project);
// get the attachment directory within the project
// directory
// .getParentFile().listFiles(attachmentFilter);
File attachmentDir = new File(projectDir, "attachment");
if (attachmentDir.exists()) {
File[] attachment = attachmentDir.listFiles();
if (attachment.length > 0) {
VFSLeaf attachmentLeaf = new LocalFileImpl(attachment[0]);
projectBrokerManager.saveAttachedFile(project, projectConfig.get("attachmentFileName").toString(), attachmentLeaf, course.getCourseEnvironment(), this);
}
}
} catch (Exception e) {
// handle/log error in case of FileIO exception or cast
// exception if import input is not correct
log.error("Error while importing a project into projectbroker", e);
}
}
use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project openolat by klemens.
the class ProjectBrokerCourseNode method cleanupOnDelete.
/**
* @see org.olat.course.nodes.CourseNode#cleanupOnDelete(
* org.olat.course.ICourse)
*/
@Override
public void cleanupOnDelete(ICourse course) {
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
Long projectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
File fDropBox = new File(FolderConfig.getCanonicalRoot() + DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
if (fDropBox.exists()) {
FileUtils.deleteDirsAndFiles(fDropBox, true, true);
}
File fReturnBox = new File(FolderConfig.getCanonicalRoot() + ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
if (fReturnBox.exists()) {
FileUtils.deleteDirsAndFiles(fReturnBox, true, true);
}
File attachmentDir = new File(FolderConfig.getCanonicalRoot() + projectBrokerManager.getAttachmentBasePathRelToFolderRoot(course.getCourseEnvironment(), this));
if (attachmentDir.exists()) {
FileUtils.deleteDirsAndFiles(attachmentDir, true, true);
}
// Delete project-broker, projects and project-groups
if (projectBrokerId != null) {
projectBrokerManager.deleteProjectBroker(projectBrokerId, course.getCourseEnvironment(), this);
}
// Delete all properties...
cpm.deleteNodeProperties(this, null);
OLATResource resource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(resource, getIdent());
}
Aggregations