use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.
the class ProjectBrokerManagerTest method getProjectsWith.
@Test
public void getProjectsWith() {
ProjectBroker projectBroker = projectBrokerManager.createAndSaveProjectBroker();
BusinessGroup projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), id1, "getProjectsWith", "getProjectsWithGroupDescription", resourceableId);
Project project = projectBrokerManager.createAndSaveProjectFor("getProjectsWith", "getProjectsWith", projectBroker.getKey(), projectGroup);
dbInstance.commitAndCloseSession();
List<Project> projects = projectBrokerManager.getProjectsWith(projectGroup);
Assert.assertNotNull(projects);
Assert.assertEquals(1, projects.size());
Assert.assertEquals(project, projects.get(0));
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.
the class ProjectBrokerManagerTest method testExistsProject.
@Test
public void testExistsProject() throws Exception {
// 1. test project does not exists
assertFalse("Wrong return value true, project does not exist", projectBrokerManager.existsProject(39927492743L));
// 2. test project exists
ProjectBroker projectBrokerD = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerD = projectBrokerD.getKey();
Project testProjectA = createProject("thema existsProject-Test", id1, idProjectBrokerD, resourceableId);
dbInstance.closeSession();
assertTrue("Wrong return value false, project exists", projectBrokerManager.existsProject(testProjectA.getKey()));
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.
the class ProjectBrokerManagerTest method testIsProjectManager.
@Test
public void testIsProjectManager() throws Exception {
ProjectBroker projectBrokerD = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerD = projectBrokerD.getKey();
Project testProjectA = createProject("thema A", id1, idProjectBrokerD, resourceableId);
List<Identity> projectManagerList = new ArrayList<Identity>();
projectManagerList.add(id1);
Project testProjectB = createProject("thema B", id2, idProjectBrokerD, resourceableId);
// check project leader in ProjectA
assertTrue("Must be project-leader of project A", projectGroupManager.isProjectManager(id1, testProjectA));
assertFalse("Can not be project leader of project B", projectGroupManager.isProjectManager(id1, testProjectB));
assertTrue("Must be project-leader of project A", projectGroupManager.isProjectManager(id2, testProjectB));
CoreSpringFactory.getImpl(BusinessGroupService.class).removeOwners(id1, projectManagerList, testProjectA.getProjectGroup());
// check no project leader anymore
assertFalse("Can not be project leader of project A", projectGroupManager.isProjectManager(id1, testProjectA));
assertFalse("Can not be project leader of project B", projectGroupManager.isProjectManager(id1, testProjectB));
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.
the class ProjectBrokerCourseNode method createInstanceForCopy.
/**
* @see org.olat.course.nodes.CourseNode#createInstanceForCopy()
*/
@Override
public CourseNode createInstanceForCopy(boolean isNewTitle, ICourse course, Identity author) {
// create the instance for the copy
CourseNode copyInstance = super.createInstanceForCopy(isNewTitle, course, author);
// get all the different managers
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
// get the pbID from the source pb
Long oldProjectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
// create a new projectBroker for the copyInstance
ProjectBroker newBroker = projectBrokerManager.createAndSaveProjectBroker();
Long projectBrokerId = newBroker.getKey();
projectBrokerManager.saveProjectBrokerId(projectBrokerId, cpm, copyInstance);
// configure the new Project like the old one
// copy the old accountManagergroup to preserve the
// "persons in charge"
Long originalAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(cpm, this);
if (originalAccountGroupKey != null) {
BusinessGroup originalAccountGroup = projectGroupManager.getAccountManagerGroupFor(cpm, this, course, getShortTitle(), getShortTitle(), null);
BusinessGroup newAccountManagerGroup = bgs.copyBusinessGroup(author, originalAccountGroup, originalAccountGroup.getName(), originalAccountGroup.getDescription(), originalAccountGroup.getMinParticipants(), originalAccountGroup.getMaxParticipants(), false, false, true, false, false, true, false, false);
projectGroupManager.saveAccountManagerGroupKey(newAccountManagerGroup.getKey(), cpm, copyInstance);
bgs.addResourceTo(newAccountManagerGroup, course.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
}
if (oldProjectBrokerId != null) {
List<Project> projects = projectBrokerManager.getProjectListBy(oldProjectBrokerId);
for (Project project : projects) {
// create projectGroup
BusinessGroup projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
Project newProject = projectBrokerManager.createAndSaveProjectFor(project.getTitle(), project.getDescription(), projectBrokerId, projectGroup);
// copy all project configurations
newProject.setMailNotificationEnabled(project.isMailNotificationEnabled());
newProject.setMaxMembers(project.getMaxMembers());
for (int i = 0; i < project.getCustomFieldSize(); i++) {
newProject.setCustomFieldValue(i, project.getCustomFieldValue(i));
}
projectGroupManager.setDeselectionAllowed(newProject, project.getProjectGroup().isAllowToLeave());
projectBrokerManager.updateProject(newProject);
// attachment file
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, course.getCourseEnvironment(), this), null);
VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
if (item instanceof VFSLeaf) {
projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), copyInstance);
newProject.setAttachedFileName(project.getAttachmentFileName());
projectBrokerManager.updateProject(newProject);
}
}
}
return copyInstance;
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.
the class ProjectEditDetailsFormController method formOK.
@Override
protected void formOK(UserRequest ureq) {
boolean projectChanged = false;
if (!project.getTitle().equals(projectTitle.getValue())) {
// title has been changed => change project-group name too
String newProjectGroupName = translate("project.member.groupname", projectTitle.getValue());
String newProjectGroupDescription = translate("project.member.groupdescription", projectTitle.getValue());
OLATResource courseResource = courseEnv.getCourseGroupManager().getCourseResource();
projectGroupManager.changeProjectGroupName(getIdentity(), project.getProjectGroup(), newProjectGroupName, newProjectGroupDescription, courseResource);
projectGroupManager.sendGroupChangeEvent(project, courseEnv.getCourseResourceableId(), ureq.getIdentity());
projectChanged = true;
}
if (!project.getTitle().equals(projectTitle.getValue())) {
project.setTitle(projectTitle.getValue());
projectChanged = true;
}
if (!project.getDescription().equals(projectDescription.getValue())) {
project.setDescription(projectDescription.getValue());
projectChanged = true;
}
if (project.getMaxMembers() != maxMembers.getIntValue()) {
project.setMaxMembers(maxMembers.getIntValue());
projectGroupManager.setProjectGroupMaxMembers(getIdentity(), project.getProjectGroup(), maxMembers.getIntValue());
projectChanged = true;
}
if (StringHelper.containsNonWhitespace(attachmentFileName.getUploadFileName())) {
// First call uploadFiles than setAttachedFileName because uploadFiles needs old attachment name
uploadFiles(attachmentFileName);
project.setAttachedFileName(attachmentFileName.getUploadFileName());
projectChanged = true;
} else if (StringHelper.containsNonWhitespace(project.getAttachmentFileName()) && attachmentFileName.getInitialFile() == null) {
// Attachment file has been removed
project.setAttachedFileName("");
projectChanged = true;
}
// store customfields
int index = 0;
for (Iterator<FormItem> iterator = customfieldElementList.iterator(); iterator.hasNext(); ) {
FormItem element = iterator.next();
String value = "";
if (element instanceof TextElement) {
TextElement textElement = (TextElement) element;
value = textElement.getValue();
} else if (element instanceof SingleSelection) {
SingleSelection selectionElement = (SingleSelection) element;
if (!selectionElement.getSelectedKey().equals(DROPDOWN_NO_SELECETION)) {
value = selectionElement.getValue(selectionElement.getSelected());
} else {
value = "";
}
}
getLogger().debug("customfield index=" + index + " value=" + value + " project.getCustomFieldValue(index)=" + project.getCustomFieldValue(index));
if (!project.getCustomFieldValue(index).equals(value)) {
project.setCustomFieldValue(index, value);
projectChanged = true;
}
index++;
}
// store events
for (Project.EventType eventType : eventStartElementList.keySet()) {
Date startDate = eventStartElementList.get(eventType).getDate();
Date endDate = eventEndElementList.get(eventType).getDate();
// First handle startdate
if (hasBeenChanged(project.getProjectEvent(eventType).getStartDate(), startDate) || hasBeenChanged(project.getProjectEvent(eventType).getEndDate(), endDate)) {
project.setProjectEvent(new ProjectEvent(eventType, startDate, endDate));
projectChanged = true;
}
}
if (mailNotification.isSelected(0) != project.isMailNotificationEnabled()) {
project.setMailNotificationEnabled(mailNotification.isSelected(0));
projectChanged = true;
}
if (projectChanged) {
if (projectBrokerManager.existsProject(project.getKey())) {
projectBrokerManager.updateProject(project);
projectBrokerMailer.sendProjectChangedEmailToParticipants(ureq.getIdentity(), project, this.getTranslator());
} else {
showInfo("info.project.nolonger.exist", project.getTitle());
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
Aggregations