Skip to content
Snippets Groups Projects
Commit 928c34c0 authored by uhensler's avatar uhensler
Browse files

OO-5530: Course element form: Show non members in user list to owners

parent 09d172aa
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ import org.olat.course.run.environment.CourseEnvironment;
import org.olat.course.run.userview.UserCourseEnvironment;
import org.olat.modules.ceditor.DataStorage;
import org.olat.modules.forms.EvaluationFormParticipation;
import org.olat.modules.forms.EvaluationFormParticipationRef;
import org.olat.modules.forms.EvaluationFormParticipationStatus;
import org.olat.modules.forms.EvaluationFormSession;
import org.olat.modules.forms.EvaluationFormSurvey;
......@@ -75,21 +76,19 @@ public interface FormManager {
public List<EvaluationFormParticipation> getParticipations(EvaluationFormSurvey survey,
EvaluationFormParticipationStatus status, boolean fetchExecutor);
public void reopenParticipation(EvaluationFormParticipation participation, CourseNode courseNode, CourseEnvironment courseEnv);
public void reopenParticipation(EvaluationFormParticipationRef participationRef, CourseNode courseNode, CourseEnvironment courseEnv);
public void deleteParticipation(EvaluationFormParticipation participation, CourseNode courseNode, CourseEnvironment courseEnv);
public void deleteParticipation(EvaluationFormParticipationRef participationRef, CourseNode courseNode, CourseEnvironment courseEnv);
public EvaluationFormSession loadOrCreateSession(EvaluationFormParticipation participation);
public EvaluationFormSession getDoneSession(EvaluationFormSurvey survey, Identity identity);
public List<EvaluationFormSession> getDoneSessions(EvaluationFormSurvey survey);
public void onQuickSave(CourseNode courseNode, UserCourseEnvironment userCourseEnv, Double completion);
public void onExecutionFinished(CourseNode courseNode, UserCourseEnvironment userCourseEnv);
public List<Identity> getCoachedIdentities(UserCourseEnvironment userCourseEnv);
public List<FormParticipation> getFormParticipations(EvaluationFormSurvey survey, UserCourseEnvironment userCourseEnv);
public Long getSessionsCount(SessionFilter filter);
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.course.nodes.form;
import java.util.Date;
import org.olat.core.id.Identity;
import org.olat.modules.forms.EvaluationFormParticipationRef;
import org.olat.modules.forms.EvaluationFormParticipationStatus;
/**
*
* Initial date: 17 Jun 2021<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public interface FormParticipation {
public Identity getIdentity();
public EvaluationFormParticipationRef getEvaluationFormParticipationRef();
public EvaluationFormParticipationStatus getParticipationStatus();
public Date getSubmissionDate();
}
......@@ -22,8 +22,14 @@ package org.olat.course.nodes.form.manager;
import static org.olat.modules.forms.handler.EvaluationFormResource.FORM_XML_FILE;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Logger;
......@@ -38,6 +44,8 @@ import org.olat.course.assessment.CourseAssessmentService;
import org.olat.course.nodes.CourseNode;
import org.olat.course.nodes.FormCourseNode;
import org.olat.course.nodes.form.FormManager;
import org.olat.course.nodes.form.FormParticipation;
import org.olat.course.nodes.form.model.FormParticipationImpl;
import org.olat.course.run.environment.CourseEnvironment;
import org.olat.course.run.userview.UserCourseEnvironment;
import org.olat.fileresource.FileResourceManager;
......@@ -47,6 +55,7 @@ import org.olat.modules.assessment.model.AssessmentEntryStatus;
import org.olat.modules.ceditor.DataStorage;
import org.olat.modules.forms.EvaluationFormManager;
import org.olat.modules.forms.EvaluationFormParticipation;
import org.olat.modules.forms.EvaluationFormParticipationRef;
import org.olat.modules.forms.EvaluationFormParticipationStatus;
import org.olat.modules.forms.EvaluationFormSession;
import org.olat.modules.forms.EvaluationFormSessionStatus;
......@@ -167,9 +176,10 @@ public class FormManagerImpl implements FormManager {
}
@Override
public void reopenParticipation(EvaluationFormParticipation participation, CourseNode courseNode, CourseEnvironment courseEnv) {
EvaluationFormSession session = evaluationFormManager.loadSessionByParticipation(participation);
if (session != null && EvaluationFormSessionStatus.done == session.getEvaluationFormSessionStatus()) {
public void reopenParticipation(EvaluationFormParticipationRef participationRef, CourseNode courseNode, CourseEnvironment courseEnv) {
EvaluationFormParticipation participation = evaluationFormManager.loadParticipationByKey(participationRef);
EvaluationFormSession session = evaluationFormManager.loadSessionByParticipation(participationRef);
if (session != null && participation != null && EvaluationFormSessionStatus.done == session.getEvaluationFormSessionStatus()) {
evaluationFormManager.reopenSession(session);
UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(
......@@ -184,16 +194,19 @@ public class FormManagerImpl implements FormManager {
}
@Override
public void deleteParticipation(EvaluationFormParticipation participation, CourseNode courseNode, CourseEnvironment courseEnv) {
evaluationFormManager.deleteParticipations(Collections.singletonList(participation));
UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(
participation.getExecutor(), courseEnv);
courseAssessmentService.updateCompletion(courseNode, assessedUserCourseEnv, Double.valueOf(0.0),
AssessmentEntryStatus.notStarted, Role.coach);
log.info(Tracing.M_AUDIT, "Form data deleted: {}, course node {}, participant {}",
courseEnv.getCourseGroupManager().getCourseEntry(), courseNode.getIdent(), participation.getExecutor());
public void deleteParticipation(EvaluationFormParticipationRef participationRef, CourseNode courseNode, CourseEnvironment courseEnv) {
EvaluationFormParticipation participation = evaluationFormManager.loadParticipationByKey(participationRef);
if (participation != null) {
evaluationFormManager.deleteParticipations(Collections.singletonList(participationRef));
UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(
participation.getExecutor(), courseEnv);
courseAssessmentService.updateCompletion(courseNode, assessedUserCourseEnv, Double.valueOf(0.0),
AssessmentEntryStatus.notStarted, Role.coach);
log.info(Tracing.M_AUDIT, "Form data deleted: {}, course node {}, participant {}",
courseEnv.getCourseGroupManager().getCourseEntry(), courseNode.getIdent(), participation.getExecutor());
}
}
@Override
......@@ -217,12 +230,6 @@ public class FormManagerImpl implements FormManager {
return null;
}
@Override
public List<EvaluationFormSession> getDoneSessions(EvaluationFormSurvey survey) {
SessionFilter filter = SessionFilterFactory.createSelectDone(survey);
return evaluationFormManager.loadSessionsFiltered(filter, 0, -1);
}
@Override
public void onQuickSave(CourseNode courseNode, UserCourseEnvironment userCourseEnv, Double competion) {
courseAssessmentService.updateCompletion(courseNode, userCourseEnv, competion, AssessmentEntryStatus.inProgress,
......@@ -259,13 +266,49 @@ public class FormManagerImpl implements FormManager {
}
@Override
public List<Identity> getCoachedIdentities(UserCourseEnvironment userCourseEnv) {
public List<FormParticipation> getFormParticipations(EvaluationFormSurvey survey, UserCourseEnvironment userCourseEnv) {
List<EvaluationFormParticipation> participations = getParticipations(survey, null, userCourseEnv.isAdmin());
List<Identity> coachedIdentities = getCoachedIdentities(userCourseEnv);
Set<Identity> allIdentities = new HashSet<>(coachedIdentities);
if (userCourseEnv.isAdmin()) {
// User who are not members but have participated as well (e.g. if course has open access)
List<Identity> executors = participations.stream().map(EvaluationFormParticipation::getExecutor).collect(Collectors.toList());
allIdentities.addAll(executors);
}
Map<Long, EvaluationFormParticipation> identityKeyToParticipations = participations
.stream()
.collect(Collectors.toMap(
participation -> participation.getExecutor().getKey(),
Function.identity()));
SessionFilter doneSessionsFilter = SessionFilterFactory.createSelectDone(survey);
Map<Long, Date> participationKeyToSubmissionDate = evaluationFormManager.loadSessionsFiltered(doneSessionsFilter, 0, -1)
.stream()
.collect(Collectors.toMap(
session -> session.getParticipation().getKey(),
EvaluationFormSession::getSubmissionDate));
List<FormParticipation> formParticipations = new ArrayList<>(coachedIdentities.size());
for (Identity identity : allIdentities) {
FormParticipationImpl formParticipationImpl = new FormParticipationImpl();
formParticipationImpl.setIdentity(identity);
EvaluationFormParticipation participation = identityKeyToParticipations.get(identity.getKey());
if (participation != null) {
formParticipationImpl.setEvaluationFormParticipation(participation);
if (EvaluationFormParticipationStatus.done == participation.getStatus()) {
formParticipationImpl.setSubmissionDate(participationKeyToSubmissionDate.get(participation.getKey()));
}
}
formParticipations.add(formParticipationImpl);
}
return formParticipations;
}
private List<Identity> getCoachedIdentities(UserCourseEnvironment userCourseEnv) {
if (userCourseEnv.isAdmin()) {
RepositoryEntry courseEntry = userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
return repositoryService.getMembers(courseEntry, RepositoryEntryRelationType.all, GroupRoles.participant.name())
.stream()
.distinct()
.collect(Collectors.toList());
return repositoryService.getMembers(courseEntry, RepositoryEntryRelationType.all, GroupRoles.participant.name());
} else if (userCourseEnv.isCoach()) {
return repositoryService.getCoachedParticipants(
userCourseEnv.getIdentityEnvironment().getIdentity(),
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.course.nodes.form.model;
import java.util.Date;
import org.olat.core.id.Identity;
import org.olat.course.nodes.form.FormParticipation;
import org.olat.modules.forms.EvaluationFormParticipation;
import org.olat.modules.forms.EvaluationFormParticipationRef;
import org.olat.modules.forms.EvaluationFormParticipationStatus;
/**
*
* Initial date: 17 Jun 2021<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public class FormParticipationImpl implements FormParticipation {
private Identity identity;
private EvaluationFormParticipationRef evaluationFormParticipationRef;
private EvaluationFormParticipationStatus participationStatus;
private Date submissionDate;
@Override
public Identity getIdentity() {
return identity;
}
public void setIdentity(Identity identity) {
this.identity = identity;
}
@Override
public EvaluationFormParticipationRef getEvaluationFormParticipationRef() {
return evaluationFormParticipationRef;
}
@Override
public EvaluationFormParticipationStatus getParticipationStatus() {
return participationStatus;
}
public void setEvaluationFormParticipation(EvaluationFormParticipation evaluationFormParticipation) {
this.evaluationFormParticipationRef = evaluationFormParticipation;
this.participationStatus = evaluationFormParticipation.getStatus();
}
@Override
public Date getSubmissionDate() {
return submissionDate;
}
public void setSubmissionDate(Date submissionDate) {
this.submissionDate = submissionDate;
}
}
......@@ -20,11 +20,7 @@
package org.olat.course.nodes.form.ui;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.BaseSecurityModule;
......@@ -65,11 +61,11 @@ import org.olat.core.util.resource.OresHelper;
import org.olat.course.assessment.AssessmentHelper;
import org.olat.course.nodes.FormCourseNode;
import org.olat.course.nodes.form.FormManager;
import org.olat.course.nodes.form.FormParticipation;
import org.olat.course.nodes.form.ui.FormParticipationTableModel.ParticipationCols;
import org.olat.course.run.userview.UserCourseEnvironment;
import org.olat.modules.forms.EvaluationFormParticipation;
import org.olat.modules.forms.EvaluationFormParticipationRef;
import org.olat.modules.forms.EvaluationFormParticipationStatus;
import org.olat.modules.forms.EvaluationFormSession;
import org.olat.modules.forms.EvaluationFormSurvey;
import org.olat.modules.forms.EvaluationFormSurveyIdentifier;
import org.olat.modules.forms.SessionFilterFactory;
......@@ -213,32 +209,21 @@ public class FormParticipationListController extends FormBasicController impleme
}
private void loadModel() {
List<Identity> coachedIdentities = formManager.getCoachedIdentities(coachCourseEnv);
Map<Long, EvaluationFormParticipation> identityKeyToParticipations = formManager.getParticipations(survey, null, false)
.stream()
.collect(Collectors.toMap(
participation -> participation.getExecutor().getKey(),
Function.identity()));
Map<Long, Date> participationKeyToSubmissionDate = formManager.getDoneSessions(survey)
.stream()
.collect(Collectors.toMap(
session -> session.getParticipation().getKey(),
EvaluationFormSession::getSubmissionDate));
List<FormParticipation> formParticipations = formManager.getFormParticipations(survey, coachCourseEnv);
List<FormParticipationRow> rows = new ArrayList<>(coachedIdentities.size());
for (Identity identiy: coachedIdentities) {
FormParticipationRow row = new FormParticipationRow(identiy, userPropertyHandlers, getLocale());
EvaluationFormParticipation participation = identityKeyToParticipations.get(identiy.getKey());
if (participation != null) {
row.setStatus(participation.getStatus());
if (EvaluationFormParticipationStatus.done == participation.getStatus()) {
row.setSubmissionDate(participationKeyToSubmissionDate.get(participation.getKey()));
List<FormParticipationRow> rows = new ArrayList<>(formParticipations.size());
for (FormParticipation formParticipation: formParticipations) {
FormParticipationRow row = new FormParticipationRow(formParticipation.getIdentity(), userPropertyHandlers, getLocale());
if (formParticipation.getEvaluationFormParticipationRef() != null) {
row.setStatus(formParticipation.getParticipationStatus());
if (EvaluationFormParticipationStatus.done == formParticipation.getParticipationStatus()) {
row.setSubmissionDate(formParticipation.getSubmissionDate());
}
String linkName = "tools-" + counter++;
FormLink toolsLink = uifactory.addFormLink(linkName, "", null, flc, Link.LINK | Link.NONTRANSLATED);
toolsLink.setIconRightCSS("o_icon o_icon_actions o_icon-fws o_icon-lg");
toolsLink.setUserObject(participation);
toolsLink.setUserObject(formParticipation);
row.setToolsLink(toolsLink);
}
rows.add(row);
......@@ -267,8 +252,8 @@ public class FormParticipationListController extends FormBasicController impleme
FormLink link = (FormLink)source;
String cmd = link.getCmd();
if(cmd != null && cmd.startsWith("tools-")) {
EvaluationFormParticipation participation = (EvaluationFormParticipation)link.getUserObject();
doOpenTools(ureq, participation, link);
FormParticipation formParticipation = (FormParticipation)link.getUserObject();
doOpenTools(ureq, formParticipation, link);
}
}
......@@ -285,13 +270,13 @@ public class FormParticipationListController extends FormBasicController impleme
}
} else if (source == resetParticipationCtrl) {
if (DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isOkEvent(event)) {
EvaluationFormParticipation participation = (EvaluationFormParticipation)resetParticipationCtrl.getUserObject();
doResetParticipation(participation);
EvaluationFormParticipationRef participationRef = (EvaluationFormParticipationRef)resetParticipationCtrl.getUserObject();
doResetParticipation(participationRef);
}
} else if (source == reopenParticipationCtrl) {
if (DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isOkEvent(event)) {
EvaluationFormParticipation participation = (EvaluationFormParticipation)reopenParticipationCtrl.getUserObject();
doReopenParticipation(participation);
EvaluationFormParticipationRef participationRef= (EvaluationFormParticipationRef)reopenParticipationCtrl.getUserObject();
doReopenParticipation(participationRef);
}
} else if (source == resetDataConfirmationCtrl) {
if (event == Event.DONE_EVENT) {
......@@ -340,11 +325,11 @@ public class FormParticipationListController extends FormBasicController impleme
stackPanel.pushController(fullName, particpationCtrl);
}
private void doOpenTools(UserRequest ureq, EvaluationFormParticipation participation, FormLink link) {
private void doOpenTools(UserRequest ureq, FormParticipation formParticipation, FormLink link) {
removeAsListenerAndDispose(toolsCtrl);
removeAsListenerAndDispose(toolsCalloutCtrl);
toolsCtrl = new ToolsController(ureq, getWindowControl(), participation);
toolsCtrl = new ToolsController(ureq, getWindowControl(), formParticipation);
listenTo(toolsCtrl);
toolsCalloutCtrl = new CloseableCalloutWindowController(ureq, getWindowControl(),
......@@ -375,27 +360,27 @@ public class FormParticipationListController extends FormBasicController impleme
loadModel();
}
private void doConfirmReset(UserRequest ureq, EvaluationFormParticipation participation) {
private void doConfirmReset(UserRequest ureq, EvaluationFormParticipationRef evaluationFormParticipationRef) {
String title = translate("reset.title");
String text = translate("reset.text");
resetParticipationCtrl = activateYesNoDialog(ureq, title, text, resetParticipationCtrl);
resetParticipationCtrl.setUserObject(participation);
resetParticipationCtrl.setUserObject(evaluationFormParticipationRef);
}
private void doResetParticipation(EvaluationFormParticipation participation) {
formManager.deleteParticipation(participation, courseNode, coachCourseEnv.getCourseEnvironment());
private void doResetParticipation(EvaluationFormParticipationRef participationRef) {
formManager.deleteParticipation(participationRef, courseNode, coachCourseEnv.getCourseEnvironment());
loadModel();
}
private void doConfirmReopen(UserRequest ureq, EvaluationFormParticipation participation) {
private void doConfirmReopen(UserRequest ureq, EvaluationFormParticipationRef participationRef) {
String title = translate("reopen.title");
String text = translate("reopen.text");
reopenParticipationCtrl = activateYesNoDialog(ureq, title, text, resetParticipationCtrl);
reopenParticipationCtrl.setUserObject(participation);
reopenParticipationCtrl.setUserObject(participationRef);
}
private void doReopenParticipation(EvaluationFormParticipation participation) {
formManager.reopenParticipation(participation, courseNode, coachCourseEnv.getCourseEnvironment());
private void doReopenParticipation(EvaluationFormParticipationRef participationRef) {
formManager.reopenParticipation(participationRef, courseNode, coachCourseEnv.getCourseEnvironment());
loadModel();
}
......@@ -405,15 +390,15 @@ public class FormParticipationListController extends FormBasicController impleme
private Link reopenLink;
private Link resetLink;
private final EvaluationFormParticipation participation;
private final FormParticipation formParticipation;
public ToolsController(UserRequest ureq, WindowControl wControl, EvaluationFormParticipation participation) {
public ToolsController(UserRequest ureq, WindowControl wControl, FormParticipation formParticipation) {
super(ureq, wControl);
this.participation = participation;
this.formParticipation = formParticipation;
VelocityContainer mainVC = createVelocityContainer("participation_tools");
if (EvaluationFormParticipationStatus.done == participation.getStatus()) {
if (EvaluationFormParticipationStatus.done == formParticipation.getParticipationStatus()) {
reopenLink = LinkFactory.createLink("reopen", "reopen", getTranslator(), mainVC, this, Link.LINK);
reopenLink.setIconLeftCSS("o_icon o_icon-fw o_icon_reopen");
}
......@@ -432,9 +417,9 @@ public class FormParticipationListController extends FormBasicController impleme
protected void event(UserRequest ureq, Component source, Event event) {
this.fireEvent(ureq, Event.DONE_EVENT);
if(reopenLink == source) {
doConfirmReopen(ureq, participation);
doConfirmReopen(ureq, formParticipation.getEvaluationFormParticipationRef());
} else if(resetLink == source) {
doConfirmReset(ureq, participation);
doConfirmReset(ureq, formParticipation.getEvaluationFormParticipationRef());
}
}
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.course.nodes.form;
import static org.olat.test.JunitTestHelper.random;
import java.util.List;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.olat.basesecurity.GroupRoles;
import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Identity;
import org.olat.core.id.IdentityEnvironment;
import org.olat.course.CourseFactory;
import org.olat.course.ICourse;
import org.olat.course.nodes.CourseNode;
import org.olat.course.nodes.FormCourseNode;
import org.olat.course.run.userview.UserCourseEnvironment;
import org.olat.course.run.userview.UserCourseEnvironmentImpl;
import org.olat.modules.forms.EvaluationFormManager;
import org.olat.modules.forms.EvaluationFormParticipation;
import org.olat.modules.forms.EvaluationFormParticipationStatus;
import org.olat.modules.forms.EvaluationFormSession;
import org.olat.modules.forms.EvaluationFormSurvey;
import org.olat.modules.forms.EvaluationFormSurveyIdentifier;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryService;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Initial date: 17 Jun 2021<br>
* @author uhensler, urs.hensler@frentix.com, http://www.frentix.com
*
*/
public class FormManagerTest extends OlatTestCase {
@Autowired
private DB dbInstance;
@Autowired
private EvaluationFormManager evaluationFormManager;
@Autowired
private RepositoryService repositoryService;
@Autowired
private FormManager sut;
@Test
public void shouldGetFormParticipationsOfOwner() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsAuthor(random());
RepositoryEntry courseEntry = JunitTestHelper.deployBasicCourse(owner);
Identity memberParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
Identity memberNotParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
Identity notMemeberParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
Identity notMemeberNotParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
dbInstance.commitAndCloseSession();
repositoryService.addRole(owner, courseEntry, GroupRoles.owner.name());
repositoryService.addRole(memberParticipated, courseEntry, GroupRoles.participant.name());
repositoryService.addRole(memberNotParticipated, courseEntry, GroupRoles.participant.name());
CourseNode courseNode = new FormCourseNode();
EvaluationFormSurveyIdentifier surveyIdent = sut.getSurveyIdentifier(courseNode, courseEntry);
EvaluationFormSurvey survey = sut.createSurvey(surveyIdent, courseEntry);
dbInstance.commitAndCloseSession();
// Member has participated
EvaluationFormParticipation participation1 = evaluationFormManager.createParticipation(survey, memberParticipated);
EvaluationFormSession session1 = evaluationFormManager.createSession(participation1);
evaluationFormManager.finishSession(session1);
// Non member has participated
EvaluationFormParticipation participation2 = evaluationFormManager.createParticipation(survey, notMemeberParticipated);
EvaluationFormSession session2 = evaluationFormManager.createSession(participation2);
evaluationFormManager.finishSession(session2);
dbInstance.commitAndCloseSession();
UserCourseEnvironment ownerCourseEnv = createUserCourseEnvironment(courseEntry, owner);
List<FormParticipation> formParticipations = sut.getFormParticipations(survey, ownerCourseEnv);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(formParticipations).as("Owner should see members and not members").hasSize(3);
FormParticipation memberParticipation = getFormParticipation(formParticipations, memberParticipated);
softly.assertThat(memberParticipation)
.as("Participating member has to be present").isNotNull();
if (memberParticipation != null) {
softly.assertThat(memberParticipation.getEvaluationFormParticipationRef())
.as("Participating member has EvaluationFormParticipationRef").isNotNull();
softly.assertThat(memberParticipation.getParticipationStatus())
.as("Participating member has status done").isEqualTo(EvaluationFormParticipationStatus.done);
softly.assertThat(memberParticipation.getSubmissionDate())
.as("Participating member has submission date").isNotNull();
}
FormParticipation memberNotParticipatedParticipation = getFormParticipation(formParticipations, memberNotParticipated);
softly.assertThat(memberNotParticipatedParticipation)
.as("Participating not member has to be present").isNotNull();
if (memberNotParticipatedParticipation != null) {
softly.assertThat(memberNotParticipatedParticipation.getEvaluationFormParticipationRef())
.as("Not participating member has no EvaluationFormParticipationRef").isNull();
softly.assertThat(memberNotParticipatedParticipation.getParticipationStatus())
.as("Not participating has no status").isNull();
softly.assertThat(memberNotParticipatedParticipation.getSubmissionDate())
.as("Not participating has no submission date").isNull();
}
FormParticipation notMemberParticipation = getFormParticipation(formParticipations, notMemeberParticipated);
softly.assertThat(notMemberParticipation)
.as("Participating not member has to be present").isNotNull();
if (notMemberParticipation != null) {
softly.assertThat(notMemberParticipation.getEvaluationFormParticipationRef())
.as("Participating not member has EvaluationFormParticipationRef").isNotNull();
softly.assertThat(notMemberParticipation.getParticipationStatus())
.as("Participating not member has status done").isEqualTo(EvaluationFormParticipationStatus.done);
softly.assertThat(notMemberParticipation.getSubmissionDate())
.as("Participating not member has submission date").isNotNull();
}
FormParticipation notMemberNotParticipatedParticipation = getFormParticipation(formParticipations, notMemeberNotParticipated);
softly.assertThat(notMemberNotParticipatedParticipation)
.as("Not participating not member must not be present").isNull();
softly.assertAll();
}
@Test
public void shouldGetFormParticipationsOfCoach() {
Identity owner = JunitTestHelper.createAndPersistIdentityAsAuthor(random());
RepositoryEntry courseEntry = JunitTestHelper.deployBasicCourse(owner);
Identity coach = JunitTestHelper.createAndPersistIdentityAsAuthor(random());
Identity memberParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
Identity memberNotParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
Identity notMemeberParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
Identity notMemeberNotParticipated = JunitTestHelper.createAndPersistIdentityAsUser(random());
dbInstance.commitAndCloseSession();
repositoryService.addRole(owner, courseEntry, GroupRoles.owner.name());
repositoryService.addRole(coach, courseEntry, GroupRoles.coach.name());
repositoryService.addRole(memberParticipated, courseEntry, GroupRoles.participant.name());
repositoryService.addRole(memberNotParticipated, courseEntry, GroupRoles.participant.name());
CourseNode courseNode = new FormCourseNode();
EvaluationFormSurveyIdentifier surveyIdent = sut.getSurveyIdentifier(courseNode, courseEntry);
EvaluationFormSurvey survey = sut.createSurvey(surveyIdent, courseEntry);
dbInstance.commitAndCloseSession();
// Member has participated
EvaluationFormParticipation participation1 = evaluationFormManager.createParticipation(survey, memberParticipated);
EvaluationFormSession session1 = evaluationFormManager.createSession(participation1);
evaluationFormManager.finishSession(session1);
// Non member has participated
EvaluationFormParticipation participation2 = evaluationFormManager.createParticipation(survey, notMemeberParticipated);
EvaluationFormSession session2 = evaluationFormManager.createSession(participation2);
evaluationFormManager.finishSession(session2);
dbInstance.commitAndCloseSession();
UserCourseEnvironment coachCourseEnv = createUserCourseEnvironment(courseEntry, coach);
List<FormParticipation> formParticipations = sut.getFormParticipations(survey, coachCourseEnv);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(formParticipations).as("Coach should see members").hasSize(2);
softly.assertThat(getFormParticipation(formParticipations, memberParticipated))
.as("Participating member has to be present").isNotNull();
softly.assertThat(getFormParticipation(formParticipations, memberNotParticipated))
.as("Participating not member has to be present").isNotNull();
softly.assertThat(getFormParticipation(formParticipations, notMemeberParticipated))
.as("Participating not member must not be present").isNull();
softly.assertThat(getFormParticipation(formParticipations, notMemeberNotParticipated))
.as("Not participating not member must not be present").isNull();
softly.assertAll();
}
private FormParticipation getFormParticipation(List<FormParticipation> formParticipations,
Identity memberParticipated) {
for (FormParticipation formParticipation : formParticipations) {
if (formParticipation.getIdentity().getKey().equals(memberParticipated.getKey())) {
return formParticipation;
}
}
return null;
}
private UserCourseEnvironment createUserCourseEnvironment(RepositoryEntry courseEntry, Identity identity) {
ICourse course = CourseFactory.loadCourse(courseEntry);
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(identity);
return new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
}
}
......@@ -187,6 +187,7 @@ import org.junit.runners.Suite;
org.olat.course.nodes.dialog.manager.DialogElementsManagerTest.class,
org.olat.course.nodes.en.EnrollmentManagerSerialTest.class,
org.olat.course.nodes.en.EnrollmentManagerConcurrentTest.class,
org.olat.course.nodes.form.FormManagerTest.class,
org.olat.course.nodes.form.rule.FormParticipationRuleSPITest.class,
org.olat.course.nodes.gta.manager.GTAManagerTest.class,
org.olat.course.nodes.gta.manager.GTATaskRevisionDAOTest.class,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment