diff --git a/src/main/java/org/olat/course/nodes/survey/SurveyConfigController.java b/src/main/java/org/olat/course/nodes/survey/SurveyConfigController.java index c885f6e75735ee9436eeabe71e1b559ff5a0b4c8..de8d1b35050d06899a5096faf5cfad38b1c1d933 100644 --- a/src/main/java/org/olat/course/nodes/survey/SurveyConfigController.java +++ b/src/main/java/org/olat/course/nodes/survey/SurveyConfigController.java @@ -19,6 +19,9 @@ */ package org.olat.course.nodes.survey; +import static org.olat.modules.forms.handler.EvaluationFormResource.FORM_XML_FILE; + +import java.io.File; import java.util.Collection; import java.util.stream.Stream; @@ -43,6 +46,7 @@ import org.olat.core.util.StringHelper; import org.olat.course.ICourse; import org.olat.course.editor.NodeEditController; import org.olat.course.nodes.SurveyCourseNode; +import org.olat.fileresource.FileResourceManager; import org.olat.modules.ModuleConfiguration; import org.olat.modules.forms.EvaluationFormManager; import org.olat.modules.forms.EvaluationFormSurvey; @@ -257,8 +261,10 @@ public class SurveyConfigController extends FormBasicController { private void doPreviewQuestionnaire(UserRequest ureq) { RepositoryEntry formEntry = survey.getFormEntry(); - Controller controller = new EvaluationFormExecutionController(ureq, getWindowControl(), null, null, formEntry, false, - false); + File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(formEntry.getOlatResource()), FileResourceManager.ZIPDIR); + File formFile = new File(repositoryDir, FORM_XML_FILE); + Controller controller = new EvaluationFormExecutionController(ureq, getWindowControl(), formFile); + previewCtr = new LayoutMain3ColsPreviewController(ureq, getWindowControl(), null, controller.getInitialComponent(), null); previewCtr.addDisposableChildController(controller); diff --git a/src/main/java/org/olat/modules/forms/EvaluationFormManager.java b/src/main/java/org/olat/modules/forms/EvaluationFormManager.java index 2f47a618a1cd5ca084826cda210537c3d95586c0..0dee1ddc1b6e906af47ca3b57207c4a007183bb6 100644 --- a/src/main/java/org/olat/modules/forms/EvaluationFormManager.java +++ b/src/main/java/org/olat/modules/forms/EvaluationFormManager.java @@ -28,24 +28,24 @@ import org.olat.basesecurity.IdentityRef; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.util.vfs.VFSLeaf; -import org.olat.modules.portfolio.PageBody; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntryRef; /** * * Initial date: 12 déc. 2016<br> + * * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com * */ public interface EvaluationFormManager { - + public EvaluationFormSurvey createSurvey(OLATResourceable ores, String subIdent, RepositoryEntry formEntry); - + public EvaluationFormSurvey loadSurvey(OLATResourceable ores, String subIdent); public boolean isFormUpdateable(EvaluationFormSurvey survey); - + /** * Update the form of a survey. Use {@link isFormUpdateable(survey)} to check if * the form can be updated before using this method. If the form can not be @@ -65,12 +65,20 @@ public interface EvaluationFormManager { */ public void deleteAllData(EvaluationFormSurvey survey); + /** + * Delete the survey and all data but the evaluation form. + * + * @param survey + */ + public void deleteSurvey(EvaluationFormSurvey survey); + public EvaluationFormParticipation createParticipation(EvaluationFormSurvey survey); - + public EvaluationFormParticipation createParticipation(EvaluationFormSurvey survey, Identity executor); - - public EvaluationFormParticipation createParticipation(EvaluationFormSurvey survey, EvaluationFormParticipationIdentifier identifier); - + + public EvaluationFormParticipation createParticipation(EvaluationFormSurvey survey, + EvaluationFormParticipationIdentifier identifier); + public EvaluationFormParticipation updateParticipation(EvaluationFormParticipation participation); public EvaluationFormParticipation loadParticipationByExecutor(EvaluationFormSurvey survey, IdentityRef executor); @@ -89,63 +97,61 @@ public interface EvaluationFormManager { public EvaluationFormParticipation loadParticipationByIdentifier(EvaluationFormSurvey survey, EvaluationFormParticipationIdentifier identifier); - + public EvaluationFormSession createSession(EvaluationFormParticipation participation); - + public EvaluationFormSession loadSessionByParticipation(EvaluationFormParticipation participation); - - public List<EvaluationFormSession> loadSessionsBySurvey(EvaluationFormSurvey survey, EvaluationFormSessionStatus status); - + + public List<EvaluationFormSession> loadSessionsBySurvey(EvaluationFormSurvey survey, + EvaluationFormSessionStatus status); + + /** + * Finish a session and the correspondent participation. + * + * @param session + * @return + */ public EvaluationFormSession finishSession(EvaluationFormSession session); - //TODO uh replace - public EvaluationFormSession createSessionForPortfolioEvaluation(Identity identity, PageBody body, RepositoryEntry formEntry); - - //TODO uh replace - public EvaluationFormSession getSessionForPortfolioEvaluation(IdentityRef identity, PageBody anchor); - - //TODO uh replace - public List<EvaluationFormResponse> getResponsesFromPortfolioEvaluation(IdentityRef identity, PageBody anchor); - - //TODO uh replace - public List<EvaluationFormResponse> getResponsesFromPortfolioEvaluation(List<? extends IdentityRef> identities, PageBody anchor, EvaluationFormSessionStatus status); - - //TODO uh replace - public EvaluationFormResponse createResponseForPortfolioEvaluation(String responseIdentifier, - BigDecimal numericalValue, String stringuifiedResponse, EvaluationFormSession session); + /** + * Reopen a session and the correspondent participation. It is not possible to + * reopen a anonymous session. + * + * @param session + * @return + */ + public EvaluationFormSession reopenSession(EvaluationFormSession session); + + public EvaluationFormResponse createStringResponse(String responseIdentifier, EvaluationFormSession session, + String value); + + public EvaluationFormResponse createNumericalResponse(String responseIdentifier, EvaluationFormSession session, + BigDecimal value); + + public EvaluationFormResponse createFileResponse(String responseIdentifier, EvaluationFormSession session, + File file, String filename) throws IOException; - //TODO uh replace - public EvaluationFormResponse createResponseForPortfolioEvaluation(String responseIdentifier, File file, - String filename, EvaluationFormSession session) throws IOException; - - public EvaluationFormResponse createStringResponse(String responseIdentifier, EvaluationFormSession session, String value); - - public EvaluationFormResponse createNumericalResponse(String responseIdentifier, EvaluationFormSession session, BigDecimal value); - public EvaluationFormResponse createNoResponse(String responseIdentifier, EvaluationFormSession session); public EvaluationFormResponse updateNumericalResponse(EvaluationFormResponse response, BigDecimal value); - - public EvaluationFormResponse updateResponseForPortfolioEvaluation(BigDecimal numericalValue, - String stringuifiedResponse, EvaluationFormResponse response); - + public EvaluationFormResponse updateResponse(EvaluationFormResponse response, String stringValue); - public EvaluationFormResponse updateResponseForPortfolioEvaluation(File file, String filename, - EvaluationFormResponse response) throws IOException; - + public EvaluationFormResponse updateFileResponse(EvaluationFormResponse response, File file, String filename) + throws IOException; + public EvaluationFormResponse updateNoResponse(EvaluationFormResponse response); - + public EvaluationFormResponse loadResponse(String responseIdentifier, EvaluationFormSessionRef session); - + public List<EvaluationFormResponse> loadResponses(String responseIdentifier, EvaluationFormSessionRef session); - + public File loadResponseFile(EvaluationFormResponse response); - + public VFSLeaf loadResponseLeaf(EvaluationFormResponse response); - + public void deleteResponse(EvaluationFormResponse response); - + public void deleteResponses(List<EvaluationFormResponse> response); /** diff --git a/src/main/java/org/olat/modules/forms/EvaluationFormSession.java b/src/main/java/org/olat/modules/forms/EvaluationFormSession.java index b15848f91a4ec0c4721049af7f7fafabed0956db..61b9fde5bbdf449176b8730648000774ac79f3cc 100644 --- a/src/main/java/org/olat/modules/forms/EvaluationFormSession.java +++ b/src/main/java/org/olat/modules/forms/EvaluationFormSession.java @@ -25,6 +25,7 @@ import org.olat.core.id.CreateInfo; import org.olat.core.id.Identity; import org.olat.core.id.ModifiedInfo; import org.olat.modules.portfolio.PageBody; +import org.olat.modules.portfolio.PortfolioService; import org.olat.repository.RepositoryEntry; /** @@ -51,26 +52,22 @@ public interface EvaluationFormSession extends EvaluationFormSessionRef, CreateI public EvaluationFormSurvey getSurvey(); - //TODO uh remove - public void setEvaluationFormSessionStatus(EvaluationFormSessionStatus sessionStatus); - /** - * The author of the evaluation - * - * @return + * @deprecated Use getParticipation().getExecutor() */ - //TODO uh remove + @Deprecated public Identity getIdentity(); /** - * The anchor for portfolio evaluation - * - * @return + * @deprecated Use the survey for the PageBody. See {@link PortfolioService#loadOrCreateSurvey(PageBody)}. */ - //TODO uh remove + @Deprecated public PageBody getPageBody(); - //TODO uh remove + /** + * @deprecated Use getSurvey().getFormEntry() + */ + @Deprecated public RepositoryEntry getFormEntry(); } diff --git a/src/main/java/org/olat/modules/forms/manager/EvaluationFormManagerImpl.java b/src/main/java/org/olat/modules/forms/manager/EvaluationFormManagerImpl.java index ab3c10c16915c81b477ece9b9ad812ea930e6210..4b2505fb32f5b46d472fbb5eca78919c2409d0d5 100644 --- a/src/main/java/org/olat/modules/forms/manager/EvaluationFormManagerImpl.java +++ b/src/main/java/org/olat/modules/forms/manager/EvaluationFormManagerImpl.java @@ -40,7 +40,6 @@ import org.olat.modules.forms.EvaluationFormSession; import org.olat.modules.forms.EvaluationFormSessionRef; import org.olat.modules.forms.EvaluationFormSessionStatus; import org.olat.modules.forms.EvaluationFormSurvey; -import org.olat.modules.portfolio.PageBody; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntryRef; import org.springframework.beans.factory.annotation.Autowired; @@ -91,11 +90,20 @@ public class EvaluationFormManagerImpl implements EvaluationFormManager { @Override public void deleteAllData(EvaluationFormSurvey survey) { + if (survey == null) return; + List<EvaluationFormResponse> responses = evaluationFormResponseDao.loadResponsesBySurvey(survey); deleteResponses(responses); evaluationFormSessionDao.deleteSessions(survey); evaluationFormParticipationDao.deleteParticipations(survey); } + + @Override + public void deleteSurvey(EvaluationFormSurvey survey) { + if (survey == null) return; + deleteAllData(survey); + evaluationFormSurveyDao.delete(survey); + } @Override public EvaluationFormParticipation createParticipation(EvaluationFormSurvey survey) { @@ -152,18 +160,9 @@ public class EvaluationFormManagerImpl implements EvaluationFormManager { return evaluationFormSessionDao.loadSessionsBySurvey(survey, status); } - @Override - public EvaluationFormSession createSessionForPortfolioEvaluation(Identity identity, PageBody body, RepositoryEntry formEntry) { - return evaluationFormSessionDao.createSessionForPortfolio(identity, body, formEntry); - } - - @Override - public EvaluationFormSession getSessionForPortfolioEvaluation(IdentityRef identity, PageBody anchor) { - return evaluationFormSessionDao.getSessionForPortfolioEvaluation(identity, anchor); - } - @Override public EvaluationFormSession finishSession(EvaluationFormSession session) { + if (session == null) return null; EvaluationFormSession finishedSesssion = session; EvaluationFormParticipation participation = session.getParticipation(); if (participation != null) { @@ -175,26 +174,22 @@ public class EvaluationFormManagerImpl implements EvaluationFormManager { finishedSesssion = evaluationFormSessionDao.changeStatus(finishedSesssion, EvaluationFormSessionStatus.done); return finishedSesssion; } - - @Override - public List<EvaluationFormResponse> getResponsesFromPortfolioEvaluation(IdentityRef identity, PageBody anchor) { - return evaluationFormResponseDao.getResponsesFromPortfolioEvaluation(identity, anchor); - } - - @Override - public List<EvaluationFormResponse> getResponsesFromPortfolioEvaluation(List<? extends IdentityRef> identities, PageBody anchor, EvaluationFormSessionStatus status) { - return evaluationFormResponseDao.getResponsesFromPortfolioEvaluation(identities, anchor, status); - } - + @Override - public EvaluationFormResponse createResponseForPortfolioEvaluation(String responseIdentifier, BigDecimal numericalValue, String stringuifiedResponse, - EvaluationFormSession session) { - return evaluationFormResponseDao.createResponse(responseIdentifier, numericalValue, stringuifiedResponse, null, session); + public EvaluationFormSession reopenSession(EvaluationFormSession session) { + if (session == null) return null; + EvaluationFormSession finishedSesssion = session; + EvaluationFormParticipation participation = session.getParticipation(); + if (participation != null) { + participation = evaluationFormParticipationDao.changeStatus(participation, EvaluationFormParticipationStatus.prepared); + finishedSesssion = evaluationFormSessionDao.changeStatus(finishedSesssion, EvaluationFormSessionStatus.inProgress); + } + return finishedSesssion; } @Override - public EvaluationFormResponse createResponseForPortfolioEvaluation(String responseIdentifier, File file, - String filename, EvaluationFormSession session) throws IOException { + public EvaluationFormResponse createFileResponse(String responseIdentifier, EvaluationFormSession session, + File file, String filename) throws IOException { Path relativePath = evaluationFormStorage.save(file, filename); return evaluationFormResponseDao.createResponse(responseIdentifier, null, filename, relativePath, session); @@ -223,13 +218,8 @@ public class EvaluationFormManagerImpl implements EvaluationFormManager { } @Override - public EvaluationFormResponse updateResponseForPortfolioEvaluation(BigDecimal numericalValue, String stringuifiedResponse, EvaluationFormResponse response) { - return evaluationFormResponseDao.updateResponse(numericalValue, stringuifiedResponse, null, response); - } - - @Override - public EvaluationFormResponse updateResponseForPortfolioEvaluation(File file, String filename, - EvaluationFormResponse response) throws IOException { + public EvaluationFormResponse updateFileResponse(EvaluationFormResponse response, File file, + String filename) throws IOException { if (response.getFileResponse() != null) { evaluationFormStorage.delete(response.getFileResponse()); } @@ -296,6 +286,6 @@ public class EvaluationFormManagerImpl implements EvaluationFormManager { @Override public boolean isEvaluationFormActivelyUsed(RepositoryEntryRef formEntry) { - return evaluationFormSessionDao.isInUse(formEntry); + return evaluationFormSessionDao.hasSessions(formEntry); } } diff --git a/src/main/java/org/olat/modules/forms/manager/EvaluationFormSessionDAO.java b/src/main/java/org/olat/modules/forms/manager/EvaluationFormSessionDAO.java index c6678f8485d12d7de67a3d146b601ef024802516..17c0db96fe302264d6af04d372afce4b47bdd95c 100644 --- a/src/main/java/org/olat/modules/forms/manager/EvaluationFormSessionDAO.java +++ b/src/main/java/org/olat/modules/forms/manager/EvaluationFormSessionDAO.java @@ -22,17 +22,13 @@ package org.olat.modules.forms.manager; import java.util.Date; import java.util.List; -import org.olat.basesecurity.IdentityRef; import org.olat.core.commons.persistence.DB; -import org.olat.core.id.Identity; import org.olat.modules.forms.EvaluationFormParticipation; import org.olat.modules.forms.EvaluationFormSession; -import org.olat.modules.forms.EvaluationFormSessionRef; import org.olat.modules.forms.EvaluationFormSessionStatus; import org.olat.modules.forms.EvaluationFormSurvey; import org.olat.modules.forms.model.jpa.EvaluationFormSessionImpl; import org.olat.modules.portfolio.PageBody; -import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntryRef; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -44,12 +40,12 @@ import org.springframework.stereotype.Service; * */ @Service -public class EvaluationFormSessionDAO { +class EvaluationFormSessionDAO { @Autowired private DB dbInstance; - public EvaluationFormSession createSession(EvaluationFormParticipation participation) { + EvaluationFormSession createSession(EvaluationFormParticipation participation) { EvaluationFormSessionImpl session = new EvaluationFormSessionImpl(); session.setCreationDate(new Date()); session.setLastModified(session.getCreationDate()); @@ -60,23 +56,6 @@ public class EvaluationFormSessionDAO { return session; } - public EvaluationFormSession createSessionForPortfolio(Identity identity, PageBody body, RepositoryEntry formEntry) { - EvaluationFormSessionImpl session = createSession(identity, formEntry); - session.setPageBody(body); - dbInstance.getCurrentEntityManager().persist(session); - return session; - } - - private EvaluationFormSessionImpl createSession(Identity identity, RepositoryEntry formEntry) { - EvaluationFormSessionImpl session = new EvaluationFormSessionImpl(); - session.setCreationDate(new Date()); - session.setLastModified(session.getCreationDate()); - session.setIdentity(identity); - session.setFormEntry(formEntry); - session.setEvaluationFormSessionStatus(EvaluationFormSessionStatus.inProgress); - return session; - } - EvaluationFormSession loadSessionByParticipation(EvaluationFormParticipation participation) { if (participation == null) return null; @@ -136,49 +115,38 @@ public class EvaluationFormSessionDAO { return sessions == null || sessions.isEmpty() || sessions.get(0) == null ? false : true; } - public boolean hasSessionForPortfolioEvaluation(PageBody anchor) { + boolean hasSessions(RepositoryEntryRef formEntry) { + if (formEntry == null) return false; + StringBuilder sb = new StringBuilder(); - sb.append("select session.key from evaluationformsession as session") - .append(" where session.pageBody.key=:bodyKey"); + sb.append("select session.key from evaluationformsession as session"); + sb.append(" where session.survey.formEntry.key=:formKey"); + List<Long> sessions = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), Long.class) - .setParameter("bodyKey", anchor.getKey()) - .getResultList(); - return sessions == null || sessions.isEmpty() || sessions.get(0) == null ? false : sessions.get(0).longValue() > 0; - } - - public EvaluationFormSession getSessionForPortfolioEvaluation(IdentityRef identity, PageBody anchor) { - StringBuilder sb = new StringBuilder(); - sb.append("select session from evaluationformsession as session") - .append(" where session.identity.key=:identityKey and session.pageBody.key=:bodyKey"); - List<EvaluationFormSession> sessions = dbInstance.getCurrentEntityManager() - .createQuery(sb.toString(), EvaluationFormSession.class) - .setParameter("identityKey", identity.getKey()) - .setParameter("bodyKey", anchor.getKey()) + .setParameter("formKey", formEntry.getKey()) + .setFirstResult(0) + .setMaxResults(1) .getResultList(); - return sessions == null || sessions.isEmpty() ? null : sessions.get(0); - } - - public EvaluationFormSessionRef changeStatusOfSessionForPortfolioEvaluation(IdentityRef identity, PageBody anchor, EvaluationFormSessionStatus status) { - EvaluationFormSession session = getSessionForPortfolioEvaluation(identity, anchor); - return changeStatus(session, status); + return sessions == null || sessions.isEmpty() || sessions.get(0) == null ? false : true; } - public EvaluationFormSession changeStatus(EvaluationFormSession session, EvaluationFormSessionStatus newStatus) { - if(session != null) { + EvaluationFormSession changeStatus(EvaluationFormSession session, EvaluationFormSessionStatus newStatus) { + if(session instanceof EvaluationFormSessionImpl) { + EvaluationFormSessionImpl sessionImpl = (EvaluationFormSessionImpl) session; + sessionImpl.setEvaluationFormSessionStatus(newStatus); if(newStatus == EvaluationFormSessionStatus.done && session.getEvaluationFormSessionStatus() != EvaluationFormSessionStatus.done) { - ((EvaluationFormSessionImpl)session).setSubmissionDate(new Date()); + sessionImpl.setSubmissionDate(new Date()); if(session.getFirstSubmissionDate() == null) { - ((EvaluationFormSessionImpl)session).setFirstSubmissionDate(session.getSubmissionDate()); + sessionImpl.setFirstSubmissionDate(sessionImpl.getSubmissionDate()); } } - session.setEvaluationFormSessionStatus(newStatus); - dbInstance.getCurrentEntityManager().merge(session); + dbInstance.getCurrentEntityManager().merge(sessionImpl); } return session; } - public void deleteSessions(EvaluationFormSurvey survey) { + void deleteSessions(EvaluationFormSurvey survey) { if (survey == null) return; StringBuilder sb = new StringBuilder(); @@ -191,7 +159,7 @@ public class EvaluationFormSessionDAO { .executeUpdate(); } - public int deleteSessionForPortfolioEvaluation(PageBody anchor) { + int deleteSessionForPortfolioEvaluation(PageBody anchor) { //delete responses int rows = 0; StringBuilder responseQ = new StringBuilder(); @@ -212,15 +180,4 @@ public class EvaluationFormSessionDAO { return rows; } - public boolean isInUse(RepositoryEntryRef formEntry) { - String query = "select session.key from evaluationformsession as session where session.formEntry.key=:formEntryKey"; - List<Long> sessions = dbInstance.getCurrentEntityManager() - .createQuery(query, Long.class) - .setParameter("formEntryKey", formEntry.getKey()) - .setFirstResult(0) - .setMaxResults(1) - .getResultList(); - return sessions == null || sessions.isEmpty() || sessions.get(0) == null ? false : true; - } - } diff --git a/src/main/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAO.java b/src/main/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAO.java index bc5e68bff2a8ae9b9a0844121c0b117b7d0316f1..977d538c038b6a769cc13b5220474e706d1df294 100644 --- a/src/main/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAO.java +++ b/src/main/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAO.java @@ -94,4 +94,14 @@ class EvaluationFormSurveyDAO { return surveys.isEmpty() ? null : surveys.get(0); } + void delete(EvaluationFormSurvey survey) { + if (survey == null) return; + + String query = "delete from evaluationformsurvey as survey where survey.key=:surveyKey"; + + dbInstance.getCurrentEntityManager().createQuery(query) + .setParameter("surveyKey", survey.getKey()) + .executeUpdate(); + } + } diff --git a/src/main/java/org/olat/modules/forms/model/jpa/EvaluationFormSessionImpl.java b/src/main/java/org/olat/modules/forms/model/jpa/EvaluationFormSessionImpl.java index bd20d80e3fce4a2c4abd674a73f676154b251fb5..b0a0bdef10de47d826104870e939654265358fe6 100644 --- a/src/main/java/org/olat/modules/forms/model/jpa/EvaluationFormSessionImpl.java +++ b/src/main/java/org/olat/modules/forms/model/jpa/EvaluationFormSessionImpl.java @@ -80,7 +80,7 @@ public class EvaluationFormSessionImpl implements EvaluationFormSession, Persist private Date firstSubmissionDate; @ManyToOne(targetEntity=EvaluationFormSurveyImpl.class,fetch=FetchType.LAZY,optional=true) - @JoinColumn(name="fk_survey", nullable=true, insertable=true, updatable=false) + @JoinColumn(name="fk_survey", nullable=true, insertable=true, updatable=true) private EvaluationFormSurvey survey; @OneToOne(targetEntity=EvaluationFormParticipationImpl.class,fetch=FetchType.LAZY,optional=true) @JoinColumn(name="fk_participation", nullable=true, insertable=true, updatable=true) @@ -144,7 +144,6 @@ public class EvaluationFormSessionImpl implements EvaluationFormSession, Persist return null; } - @Override public void setEvaluationFormSessionStatus(EvaluationFormSessionStatus sessionStatus) { if(sessionStatus == null) { status = null; diff --git a/src/main/java/org/olat/modules/forms/ui/EvaluationFormExecutionController.java b/src/main/java/org/olat/modules/forms/ui/EvaluationFormExecutionController.java index 14262e76b10298cb0c6a69e3f282d3f2e9e26df5..5d9063b2560a2614fe83cac58a270770aeb52778 100644 --- a/src/main/java/org/olat/modules/forms/ui/EvaluationFormExecutionController.java +++ b/src/main/java/org/olat/modules/forms/ui/EvaluationFormExecutionController.java @@ -56,7 +56,6 @@ import org.olat.modules.forms.model.xml.AbstractElement; import org.olat.modules.forms.model.xml.Form; import org.olat.modules.forms.model.xml.FormXStream; import org.olat.modules.forms.ui.model.EvaluationFormExecutionElement; -import org.olat.modules.portfolio.PageBody; import org.olat.modules.portfolio.ui.editor.ValidatingController; import org.olat.modules.portfolio.ui.editor.ValidationMessage; import org.olat.modules.portfolio.ui.editor.ValidationMessage.Level; @@ -93,8 +92,13 @@ public class EvaluationFormExecutionController extends FormBasicController imple private EvaluationFormManager evaluationFormManager; public EvaluationFormExecutionController(UserRequest ureq, WindowControl wControl, EvaluationFormSession session) { + this(ureq, wControl, session, false, true); + } + + public EvaluationFormExecutionController(UserRequest ureq, WindowControl wControl, EvaluationFormSession session, + boolean readOnly, boolean showDoneButton) { super(ureq, wControl, "execute"); - + RepositoryEntry formEntry = session.getSurvey().getFormEntry(); File repositoryDir = new File( FileResourceManager.getInstance().getFileResourceRoot(formEntry.getOlatResource()), @@ -103,40 +107,13 @@ public class EvaluationFormExecutionController extends FormBasicController imple this.form = (Form)XStreamHelper.readObject(FormXStream.getXStream(), formFile); this.session = session; - this.readOnly = false; - this.showDoneButton = true; - - initForm(ureq); - } - - public EvaluationFormExecutionController(UserRequest ureq, WindowControl wControl, Identity evaluator, - PageBody anchor, RepositoryEntry formEntry, boolean readOnly, boolean showDoneButton) { - super(ureq, wControl, "execute"); - - File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(formEntry.getOlatResource()), FileResourceManager.ZIPDIR); - File formFile = new File(repositoryDir, FORM_XML_FILE); - this.form = (Form)XStreamHelper.readObject(FormXStream.getXStream(), formFile); - - this.session = loadOrCreateSession(evaluator, anchor, formEntry); this.readOnly = readOnly; this.showDoneButton = showDoneButton; initForm(ureq); - } - - public EvaluationFormExecutionController(UserRequest ureq, WindowControl wControl, Identity evaluator, - PageBody pageBody, String xmlForm, boolean readOnly) { - super(ureq, wControl, "execute"); - - form = (Form)XStreamHelper.readObject(FormXStream.getXStream(), xmlForm); - - this.session = loadOrCreateSession(evaluator, pageBody, null); - this.readOnly = readOnly; - this.showDoneButton = false; - initForm(ureq); } - + public EvaluationFormExecutionController(UserRequest ureq, WindowControl wControl, File formFile) { super(ureq, wControl, "execute"); @@ -166,24 +143,20 @@ public class EvaluationFormExecutionController extends FormBasicController imple showHideButtons(); } - private EvaluationFormSession loadOrCreateSession(Identity evaluator, PageBody anchor, RepositoryEntry formEntry) { - if (evaluator == null || anchor == null) return null; - - EvaluationFormSession session = evaluationFormManager.getSessionForPortfolioEvaluation(evaluator, anchor); - if (session == null && formEntry != null) { - session = evaluationFormManager.createSessionForPortfolioEvaluation(evaluator, anchor, formEntry); - } - return session; - } - private void ajustFromSession() { if (session == null) return; if(session.getEvaluationFormSessionStatus() == EvaluationFormSessionStatus.done) { readOnly = true; showDoneButton = false; - } else if(session.getIdentity() != null && !session.getIdentity().equals(getIdentity())) { - flc.contextPut("messageNotDone", Boolean.TRUE); + } else { + Identity executor = null; + if (session.getParticipation() != null) { + executor = session.getParticipation().getExecutor(); + } + if (executor != null && !executor.equals(getIdentity())) { + flc.contextPut("messageNotDone", Boolean.TRUE); + } } } diff --git a/src/main/java/org/olat/modules/forms/ui/FileUploadController.java b/src/main/java/org/olat/modules/forms/ui/FileUploadController.java index 39661a861a0e3fa0421e1f7f1faff2359f99e911..4934a04df17cb6966100e5b43b237450d7a9dec0 100644 --- a/src/main/java/org/olat/modules/forms/ui/FileUploadController.java +++ b/src/main/java/org/olat/modules/forms/ui/FileUploadController.java @@ -153,10 +153,10 @@ public class FileUploadController extends FormBasicController implements Evaluat String filename = fileEl.getUploadFileName(); try { if (response == null) { - response = evaluationFormManager.createResponseForPortfolioEvaluation(fileUpload.getId(), file, - filename, session); + response = evaluationFormManager.createFileResponse(fileUpload.getId(), session, + file, filename); } else { - response = evaluationFormManager.updateResponseForPortfolioEvaluation(file, filename, response); + response = evaluationFormManager.updateFileResponse(response, file, filename); } newFileUploaded = false; } catch (IOException e) { diff --git a/src/main/java/org/olat/modules/forms/ui/LegendNameGenerator.java b/src/main/java/org/olat/modules/forms/ui/LegendNameGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..d0bd07153c354ae12ed5ddb8dd8dc6efe280dda3 --- /dev/null +++ b/src/main/java/org/olat/modules/forms/ui/LegendNameGenerator.java @@ -0,0 +1,34 @@ +/** + * <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.modules.forms.ui; + +import org.olat.core.id.Identity; + +/** + * + * Initial date: 08.05.2018<br> + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + */ +public interface LegendNameGenerator { + + public String getName(Identity identity); + +} diff --git a/src/main/java/org/olat/modules/forms/ui/ReportHelper.java b/src/main/java/org/olat/modules/forms/ui/ReportHelper.java index 214690797f54e4810dd04b074d18f7cc732f3be8..b7855a82210f88aadf0f5766bc4d4db6d1a0a3c8 100644 --- a/src/main/java/org/olat/modules/forms/ui/ReportHelper.java +++ b/src/main/java/org/olat/modules/forms/ui/ReportHelper.java @@ -29,7 +29,6 @@ import org.olat.core.util.StringHelper; import org.olat.core.util.Util; import org.olat.modules.forms.EvaluationFormParticipation; import org.olat.modules.forms.EvaluationFormSession; -import org.olat.user.UserManager; /** * @@ -47,16 +46,13 @@ public class ReportHelper { private final Legend anonymousLegend; private final ColorGenerator colorGenerator; + private final LegendNameGenerator legendNameGenerator; private final Map<EvaluationFormSession, Legend> sessionToData = new HashMap<>(); private final Map<EvaluationFormParticipation, Legend> participationToLegend = new HashMap<>(); private final Map<Identity, Legend> executorToLegend = new HashMap<>(); - private UserManager userManager; - private ReportHelper(Builder builder) { - this.userManager = UserManager.getInstance(); - String anonymousName; if (StringHelper.containsNonWhitespace(builder.anonymousName)) { anonymousName = builder.anonymousName; @@ -64,8 +60,10 @@ public class ReportHelper { Translator translator = Util.createPackageTranslator(ReportHelper.class, builder.locale); anonymousName = translator.translate("report.anonymous.user"); } - String anonymousColor = builder.anonymousColor; - if (!StringHelper.containsNonWhitespace(anonymousColor)) { + String anonymousColor; + if (StringHelper.containsNonWhitespace(builder.anonymousColor)) { + anonymousColor = builder.anonymousColor; + } else { anonymousColor = DEFAULT_COLOR; } this.anonymousLegend = new Legend(anonymousName, anonymousColor); @@ -77,15 +75,12 @@ public class ReportHelper { colors = new String[] { DEFAULT_COLOR }; } this.colorGenerator = new ColorGenerator(colors); - } - - /** - * Use this method only for testing purposes. - * - * @param userManager - */ - void setUserManager(UserManager userManager) { - this.userManager = userManager; + + if (builder.legendNameGenerator != null) { + this.legendNameGenerator = builder.legendNameGenerator; + } else { + this.legendNameGenerator = new UserDisplayNameGenerator(); + } } Legend getLegend(EvaluationFormSession session) { @@ -97,7 +92,8 @@ public class ReportHelper { } } if (legend == null) { - legend = addLegend(session); + legend = getLegendFromSession(session); + cacheLegend(session, legend); } if (legend == null) { legend = anonymousLegend; @@ -105,18 +101,29 @@ public class ReportHelper { return legend; } - private Legend addLegend(EvaluationFormSession session) { + private Legend getLegendFromSession(EvaluationFormSession session) { + Legend legend = null; if (session.getParticipation() != null && session.getParticipation().getExecutor() != null) { Identity executor = session.getParticipation().getExecutor(); - String name = userManager.getUserDisplayName(executor); + String name = legendNameGenerator.getName(executor); String color = colorGenerator.getColor(); - Legend legend = new Legend(name, color); + legend = new Legend(name, color); + } + return legend ; + } + + private void cacheLegend(EvaluationFormSession session, Legend legend) { + if (session != null && legend != null) { sessionToData.put(session, legend); - participationToLegend.put(session.getParticipation(), legend); - executorToLegend.put(executor, legend); - return legend; + EvaluationFormParticipation participation = session.getParticipation(); + if (participation != null) { + participationToLegend.put(participation, legend); + Identity executor = participation.getExecutor(); + if (executor != null) { + executorToLegend.put(executor, legend); + } + } } - return null; } public static Builder builder(Locale locale) { @@ -129,6 +136,7 @@ public class ReportHelper { private String anonymousName = null; private String anonymousColor = null; private boolean hasColors = false; + private LegendNameGenerator legendNameGenerator; Builder(Locale locale) { this.locale = locale; @@ -138,17 +146,22 @@ public class ReportHelper { this.anonymousName = name; return this; } - + public Builder withAnonymousColor(String color) { this.anonymousColor = color; return this; } - + public Builder withColors() { this.hasColors = true; return this; } + public Builder withLegendNameGenrator(LegendNameGenerator legendNameGenerator) { + this.legendNameGenerator = legendNameGenerator; + return this; + } + public ReportHelper build() { return new ReportHelper(this); } diff --git a/src/main/java/org/olat/modules/forms/ui/RubricAvgSlidersController.java b/src/main/java/org/olat/modules/forms/ui/RubricAvgSlidersController.java index f6c469e92453722648c6a321f563817a60ce49e4..fb0b143ca4885a466cfedcff7391c82bb019fa30 100644 --- a/src/main/java/org/olat/modules/forms/ui/RubricAvgSlidersController.java +++ b/src/main/java/org/olat/modules/forms/ui/RubricAvgSlidersController.java @@ -95,7 +95,6 @@ public class RubricAvgSlidersController extends BasicController { } overviewEl.setValues(sliderPoints); mainVC.put(id, overviewEl.getComponent()); - System.out.println("" + responseIdentifier + ": " +value); return new SliderWrapper(slider, overviewEl); } diff --git a/src/main/java/org/olat/modules/forms/ui/UserDisplayNameGenerator.java b/src/main/java/org/olat/modules/forms/ui/UserDisplayNameGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..6421ade4a4a42d8860ecb5baec183eb23ee2587f --- /dev/null +++ b/src/main/java/org/olat/modules/forms/ui/UserDisplayNameGenerator.java @@ -0,0 +1,46 @@ +/** + * <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.modules.forms.ui; + +import org.olat.core.id.Identity; +import org.olat.user.UserManager; + +/** + * + * Initial date: 08.05.2018<br> + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + */ +public class UserDisplayNameGenerator implements LegendNameGenerator { + + private UserManager userManager; + + + public UserDisplayNameGenerator() { + super(); + this.userManager = UserManager.getInstance(); + } + + @Override + public String getName(Identity identity) { + return userManager.getUserDisplayName(identity); + } + +} diff --git a/src/main/java/org/olat/modules/portfolio/PortfolioService.java b/src/main/java/org/olat/modules/portfolio/PortfolioService.java index a6dba3935317f3bca5c92af9ff6ca6c5970b0441..292c6e6c691d69b922cfbe15ef34c16d4c1c4d27 100644 --- a/src/main/java/org/olat/modules/portfolio/PortfolioService.java +++ b/src/main/java/org/olat/modules/portfolio/PortfolioService.java @@ -31,6 +31,8 @@ import org.olat.core.util.vfs.VFSLeaf; import org.olat.course.nodes.PortfolioCourseNode; import org.olat.modules.assessment.Role; import org.olat.modules.assessment.model.AssessmentEntryStatus; +import org.olat.modules.forms.EvaluationFormSession; +import org.olat.modules.forms.EvaluationFormSurvey; import org.olat.modules.portfolio.model.AccessRightChange; import org.olat.modules.portfolio.model.AccessRights; import org.olat.modules.portfolio.model.AssessedBinder; @@ -632,6 +634,10 @@ public interface PortfolioService { public void setAssessmentStatus(Identity assessedIdentity, BinderRef binderRef, AssessmentEntryStatus status, Identity coachingIdentity); + public EvaluationFormSurvey loadOrCreateSurvey(PageBody body, RepositoryEntry formEntry); + public EvaluationFormSession loadOrCreateSession(EvaluationFormSurvey survey, Identity executor); + + public void deleteSurvey(PageBody body); } diff --git a/src/main/java/org/olat/modules/portfolio/handler/EvaluationFormHandler.java b/src/main/java/org/olat/modules/portfolio/handler/EvaluationFormHandler.java index 58ba3e3789caa62085b1be0e124c618cfe966355..3dc46e02f1e121f02b1884bdbf1c6b14720a091d 100644 --- a/src/main/java/org/olat/modules/portfolio/handler/EvaluationFormHandler.java +++ b/src/main/java/org/olat/modules/portfolio/handler/EvaluationFormHandler.java @@ -35,6 +35,8 @@ import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; import org.olat.core.util.Util; import org.olat.fileresource.FileResourceManager; +import org.olat.modules.forms.EvaluationFormSession; +import org.olat.modules.forms.EvaluationFormSurvey; import org.olat.modules.forms.ui.EvaluationFormExecutionController; import org.olat.modules.portfolio.Assignment; import org.olat.modules.portfolio.Page; @@ -81,9 +83,7 @@ public class EvaluationFormHandler implements PageElementHandler { EvaluationFormPart eva = (EvaluationFormPart)element; PageBody body = eva.getBody(); Assignment assignment = portfolioService.getAssignment(body); - if(assignment == null) { - ctrl = getController(ureq, wControl, body, eva); - } else { + if(assignment != null) { ctrl = getControllerForAssignment(ureq, wControl, body, assignment, hints.isOnePage()); } } @@ -98,31 +98,12 @@ public class EvaluationFormHandler implements PageElementHandler { } - private Controller getController(UserRequest ureq, WindowControl wControl, PageBody body, EvaluationFormPart eva) { - PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class); - - Controller ctrl = null; - Page page = portfolioService.getPageByBody(body); - List<AccessRights> accessRights = portfolioService.getAccessRights(page); - if(hasRole(PortfolioRoles.owner, ureq.getIdentity(), accessRights)) { - ctrl = new EvaluationFormExecutionController(ureq, wControl, ureq.getIdentity(), body, eva.getContent(), false); - } else if(hasRole(PortfolioRoles.coach, ureq.getIdentity(), accessRights)) { - Identity owner = getOwner(accessRights); - ctrl = new EvaluationFormExecutionController(ureq, wControl, owner, body, eva.getContent(), true); - } else if(hasRole(PortfolioRoles.reviewer, ureq.getIdentity(), accessRights) - || hasRole(PortfolioRoles.invitee, ureq.getIdentity(), accessRights)) { - Identity owner = getOwner(accessRights); - ctrl = new EvaluationFormExecutionController(ureq, wControl, owner, body, eva.getContent(), true); - } - - return ctrl; - } - private Controller getControllerForAssignment(UserRequest ureq, WindowControl wControl, PageBody body, Assignment assignment, boolean onePage) { PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class); //find the evaluation form RepositoryEntry re = assignment.getFormEntry(); + EvaluationFormSurvey survey = portfolioService.loadOrCreateSurvey(body, re); Page page = assignment.getPage(); PageStatus pageStatus = page.getPageStatus(); @@ -132,21 +113,25 @@ public class EvaluationFormHandler implements PageElementHandler { boolean anonym = assignment.isAnonymousExternalEvaluation(); if(pageStatus == null || pageStatus == PageStatus.draft) { if(hasRole(PortfolioRoles.owner, ureq.getIdentity(), accessRights)) { - ctrl = new EvaluationFormExecutionController(ureq, wControl, ureq.getIdentity(), body, re, false, false); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, ureq.getIdentity()); + ctrl = new EvaluationFormExecutionController(ureq, wControl, session, false, false); } } else if (assignment.isOnlyAutoEvaluation()) { // only the auto evaluation is shown if(hasRole(PortfolioRoles.owner, ureq.getIdentity(), accessRights)) { boolean readOnly = (pageStatus == PageStatus.published) || (pageStatus == PageStatus.closed) || (pageStatus == PageStatus.deleted); - ctrl = new EvaluationFormExecutionController(ureq, wControl, ureq.getIdentity(), body, re, readOnly, false); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, ureq.getIdentity()); + ctrl = new EvaluationFormExecutionController(ureq, wControl, session, readOnly, false); } else if(hasRole(PortfolioRoles.coach, ureq.getIdentity(), accessRights)) { Identity owner = getOwner(accessRights); - ctrl = new EvaluationFormExecutionController(ureq, wControl, owner, body, re, true, false); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, owner); + ctrl = new EvaluationFormExecutionController(ureq, wControl, session, true, false); } else if(hasRole(PortfolioRoles.reviewer, ureq.getIdentity(), accessRights) || hasRole(PortfolioRoles.invitee, ureq.getIdentity(), accessRights)) { if(assignment.isReviewerSeeAutoEvaluation()) { Identity owner = getOwner(accessRights); - ctrl = new EvaluationFormExecutionController(ureq, wControl, owner, body, re, true, false); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, owner); + ctrl = new EvaluationFormExecutionController(ureq, wControl, session, true, false); } } } else { @@ -155,31 +140,32 @@ public class EvaluationFormHandler implements PageElementHandler { Identity owner = getOwner(accessRights); List<Identity> coachesAndReviewers = getCoachesAndReviewers(accessRights); if(coachesAndReviewers.size() > 0) { - ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, body, re, false, readOnly, onePage, anonym); + ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, survey, false, readOnly, onePage, anonym); } else { - ctrl = new EvaluationFormExecutionController(ureq, wControl, ureq.getIdentity(), body, re, readOnly, false); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, ureq.getIdentity()); + ctrl = new EvaluationFormExecutionController(ureq, wControl, session, readOnly, false); } } else if(hasRole(PortfolioRoles.coach, ureq.getIdentity(), accessRights)) { Identity owner = getOwner(accessRights); List<Identity> coachesAndReviewers = getCoachesAndReviewers(accessRights); boolean readOnly = (pageStatus == PageStatus.draft) || (pageStatus == PageStatus.closed) || (pageStatus == PageStatus.deleted) || onePage; - ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, body, re, false, readOnly, onePage, anonym); + ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, survey, false, readOnly, onePage, anonym); } else if(hasRole(PortfolioRoles.reviewer, ureq.getIdentity(), accessRights) || hasRole(PortfolioRoles.invitee, ureq.getIdentity(), accessRights)) { boolean readOnly = (pageStatus == PageStatus.draft) || (pageStatus == PageStatus.closed) || (pageStatus == PageStatus.deleted) || onePage; if(assignment.isReviewerSeeAutoEvaluation()) { Identity owner = getOwner(accessRights); List<Identity> reviewers = Collections.singletonList(ureq.getIdentity()); - ctrl = new MultiEvaluationFormController(ureq, wControl, owner, reviewers, body, re, true, readOnly, onePage, anonym); + ctrl = new MultiEvaluationFormController(ureq, wControl, owner, reviewers, survey, true, readOnly, onePage, anonym); } else { - ctrl = new EvaluationFormExecutionController(ureq, wControl, ureq.getIdentity(), body, re, readOnly, !readOnly); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, ureq.getIdentity()); + ctrl = new EvaluationFormExecutionController(ureq, wControl, session, readOnly, !readOnly); } } } return ctrl; } - - + private Identity getOwner(List<AccessRights> accessRights) { for(AccessRights accessRight:accessRights) { if(PortfolioRoles.owner == accessRight.getRole()) { diff --git a/src/main/java/org/olat/modules/portfolio/manager/PageDAO.java b/src/main/java/org/olat/modules/portfolio/manager/PageDAO.java index 184f437449047608541c7a394449097a29702d4f..686ac02fe2b7c5bf2cbc52ce751567967801c8a7 100644 --- a/src/main/java/org/olat/modules/portfolio/manager/PageDAO.java +++ b/src/main/java/org/olat/modules/portfolio/manager/PageDAO.java @@ -38,7 +38,6 @@ import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.util.StringHelper; import org.olat.core.util.resource.OresHelper; -import org.olat.modules.forms.manager.EvaluationFormSessionDAO; import org.olat.modules.portfolio.AssignmentStatus; import org.olat.modules.portfolio.BinderRef; import org.olat.modules.portfolio.Page; @@ -47,6 +46,7 @@ import org.olat.modules.portfolio.PageImageAlign; import org.olat.modules.portfolio.PagePart; import org.olat.modules.portfolio.PageStatus; import org.olat.modules.portfolio.PortfolioRoles; +import org.olat.modules.portfolio.PortfolioService; import org.olat.modules.portfolio.Section; import org.olat.modules.portfolio.SectionRef; import org.olat.modules.portfolio.model.AbstractPart; @@ -71,7 +71,7 @@ public class PageDAO { @Autowired private UserCommentsDAO userCommentsDAO; @Autowired - private EvaluationFormSessionDAO evaluationFormSessionDao; + private PortfolioService portfolioService; /** * @@ -460,13 +460,13 @@ public class PageDAO { .setParameter("pageKey", page.getKey()) .executeUpdate(); - int evaluations = evaluationFormSessionDao.deleteSessionForPortfolioEvaluation(body); + portfolioService.deleteSurvey(body); dbInstance.getCurrentEntityManager().remove(page); dbInstance.getCurrentEntityManager().remove(body); int comments = userCommentsDAO.deleteAllComments(ores, null); - return comments + parts + evaluations + assignments + 2; + return comments + parts + assignments + 2; } } diff --git a/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java b/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java index de5500e0b027af5605c14ea1ad591e262f7a9a9c..c2906a0fed617d60775bfa8b0b1224c11bc1f1ce 100644 --- a/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java +++ b/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java @@ -64,8 +64,10 @@ import org.olat.modules.assessment.AssessmentEntry; import org.olat.modules.assessment.AssessmentService; import org.olat.modules.assessment.Role; import org.olat.modules.assessment.model.AssessmentEntryStatus; -import org.olat.modules.forms.EvaluationFormSessionStatus; -import org.olat.modules.forms.manager.EvaluationFormSessionDAO; +import org.olat.modules.forms.EvaluationFormManager; +import org.olat.modules.forms.EvaluationFormParticipation; +import org.olat.modules.forms.EvaluationFormSession; +import org.olat.modules.forms.EvaluationFormSurvey; import org.olat.modules.portfolio.AssessmentSection; import org.olat.modules.portfolio.Assignment; import org.olat.modules.portfolio.AssignmentStatus; @@ -172,7 +174,7 @@ public class PortfolioServiceImpl implements PortfolioService { @Autowired private RepositoryService repositoryService; @Autowired - private EvaluationFormSessionDAO evaluationFormSessionDao; + private EvaluationFormManager evaluationFormManager; @Autowired private BinderUserInformationsDAO binderUserInformationsDao; @@ -427,7 +429,8 @@ public class PortfolioServiceImpl implements PortfolioService { Page page = appendNewPage(author, reloadedAssignment.getTitle(), reloadedAssignment.getSummary(), null, false, null, section); reloadedAssignment = assignmentDao.startFormAssignment(reloadedAssignment, page, author); // create the session for the assignee - evaluationFormSessionDao.createSessionForPortfolio(author, page.getBody(), formEntry); + EvaluationFormSurvey survey = loadOrCreateSurvey(page.getBody(), formEntry); + loadOrCreateSession(survey, author); } } dbInstance.commit(); @@ -1064,9 +1067,6 @@ public class PortfolioServiceImpl implements PortfolioService { } ((PageImpl)reloadedPage).setLastPublicationDate(now); Section section = reloadedPage.getSection(); - // auto update the status of the evaluation form of the authors of the binder - changeAssignmentStatus(page, section, EvaluationFormSessionStatus.done); - if(section != null) { SectionStatus sectionStatus = section.getSectionStatus(); if(currentStatus == PageStatus.closed) { @@ -1078,10 +1078,16 @@ public class PortfolioServiceImpl implements PortfolioService { ((SectionImpl)section).setSectionStatus(SectionStatus.inProgress); binderDao.updateSection(section); } + List<Identity> owners = getOwners(page, section); + for (Identity owner: owners) { + EvaluationFormSurvey survey = evaluationFormManager.loadSurvey(getOLATResourceableForEvaluationForm(page.getBody()), null); + EvaluationFormParticipation participation = evaluationFormManager.loadParticipationByExecutor(survey, owner); + EvaluationFormSession session = evaluationFormManager.loadSessionByParticipation(participation); + evaluationFormManager.finishSession(session); + } } } else if(status == PageStatus.inRevision) { Section section = reloadedPage.getSection(); - changeAssignmentStatus(page, section, EvaluationFormSessionStatus.inProgress); if(section != null) { SectionStatus sectionStatus = section.getSectionStatus(); if(sectionStatus == null || sectionStatus == SectionStatus.notStarted || sectionStatus == SectionStatus.closed) { @@ -1090,6 +1096,13 @@ public class PortfolioServiceImpl implements PortfolioService { binderDao.updateSection(section); } } + List<Identity> owners = getOwners(page, section); + for (Identity owner: owners) { + EvaluationFormSurvey survey = evaluationFormManager.loadSurvey(getOLATResourceableForEvaluationForm(page.getBody()), null); + EvaluationFormParticipation participation = evaluationFormManager.loadParticipationByExecutor(survey, owner); + EvaluationFormSession session = evaluationFormManager.loadSessionByParticipation(participation); + evaluationFormManager.reopenSession(session); + } } pageUserInfosDao.updateStatus(reloadedPage, PageUserStatus.inProcess, PageUserStatus.done); } else if(status == PageStatus.closed) { @@ -1104,27 +1117,12 @@ public class PortfolioServiceImpl implements PortfolioService { return pageDao.updatePage(reloadedPage); } - /** - * Auto update the status of the evaluation form of the authors of the binder. - * - * @param page The page where the evaluation is - * @param section The section of the page - * @param newStatus The new status of the evaluation - */ - private void changeAssignmentStatus(Page page, Section section, EvaluationFormSessionStatus newStatus) { - // auto update the status of the evaluation form of the authors of the binder + private List<Identity> getOwners(Page page, Section section) { Assignment assignment = assignmentDao.loadAssignment(page.getBody()); if(assignment != null && assignment.getAssignmentType() == AssignmentType.form) { - List<Identity> owners = getMembers(section.getBinder(), PortfolioRoles.owner.name()); - for(Identity owner:owners) { - evaluationFormSessionDao.changeStatusOfSessionForPortfolioEvaluation(owner, page.getBody(), newStatus); - } - } else if(evaluationFormSessionDao.hasSessionForPortfolioEvaluation(page.getBody())) { - List<Identity> owners = getMembers(section.getBinder(), PortfolioRoles.owner.name()); - for(Identity owner:owners) { - evaluationFormSessionDao.changeStatusOfSessionForPortfolioEvaluation(owner, page.getBody(), newStatus); - } + return getMembers(section.getBinder(), PortfolioRoles.owner.name()); } + return new ArrayList<>(); } @Override @@ -1376,5 +1374,42 @@ public class PortfolioServiceImpl implements PortfolioService { } } + @Override + public EvaluationFormSurvey loadOrCreateSurvey(PageBody body, RepositoryEntry formEntry) { + OLATResourceable ores = getOLATResourceableForEvaluationForm(body); + EvaluationFormSurvey survey = evaluationFormManager.loadSurvey(ores, null); + if (survey == null) { + survey = evaluationFormManager.createSurvey(ores, null, formEntry); + } + return survey; + } + + private OLATResourceable getOLATResourceableForEvaluationForm(PageBody body) { + OLATResourceable ores = OresHelper.createOLATResourceableInstance("portfolio-evaluation", body.getKey()); + return ores; + } + + @Override + public EvaluationFormSession loadOrCreateSession(EvaluationFormSurvey survey, Identity executor) { + EvaluationFormParticipation participation = evaluationFormManager.loadParticipationByExecutor(survey, executor); + if (participation == null) { + participation = evaluationFormManager.createParticipation(survey, executor); + } + + EvaluationFormSession session = evaluationFormManager.loadSessionByParticipation(participation); + if (session == null) { + session = evaluationFormManager.createSession(participation); + } + return session; + } + + @Override + public void deleteSurvey(PageBody body) { + OLATResourceable ores = getOLATResourceableForEvaluationForm(body); + EvaluationFormSurvey survey = evaluationFormManager.loadSurvey(ores, null); + if (survey != null) { + evaluationFormManager.deleteSurvey(survey); + } + } } diff --git a/src/main/java/org/olat/modules/portfolio/ui/MultiEvaluationFormController.java b/src/main/java/org/olat/modules/portfolio/ui/MultiEvaluationFormController.java index f48b281b8c6bf7777daff6aed21d9aa47099fbea..d0bd8895fae50155de1cdf28e652113183980dd0 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/MultiEvaluationFormController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/MultiEvaluationFormController.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; import org.olat.core.gui.UserRequest; @@ -42,13 +41,15 @@ import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; import org.olat.core.id.Identity; +import org.olat.core.util.StringHelper; import org.olat.core.util.xml.XStreamHelper; import org.olat.fileresource.FileResourceManager; import org.olat.modules.forms.EvaluationFormManager; -import org.olat.modules.forms.EvaluationFormResponse; +import org.olat.modules.forms.EvaluationFormParticipation; +import org.olat.modules.forms.EvaluationFormParticipationStatus; import org.olat.modules.forms.EvaluationFormSession; -import org.olat.modules.forms.EvaluationFormSessionRef; import org.olat.modules.forms.EvaluationFormSessionStatus; +import org.olat.modules.forms.EvaluationFormSurvey; import org.olat.modules.forms.handler.EvaluationFormReportHandler; import org.olat.modules.forms.handler.EvaluationFormReportProvider; import org.olat.modules.forms.handler.FileUploadListingHandler; @@ -71,11 +72,11 @@ import org.olat.modules.forms.model.xml.TextInput; import org.olat.modules.forms.model.xml.Title; import org.olat.modules.forms.ui.EvaluationFormExecutionController; import org.olat.modules.forms.ui.EvaluationFormReportController; +import org.olat.modules.forms.ui.LegendNameGenerator; import org.olat.modules.forms.ui.ReportHelper; import org.olat.modules.forms.ui.model.Evaluator; -import org.olat.modules.portfolio.PageBody; +import org.olat.modules.portfolio.PortfolioService; import org.olat.modules.portfolio.ui.editor.PageElement; -import org.olat.repository.RepositoryEntry; import org.olat.user.UserManager; import org.springframework.beans.factory.annotation.Autowired; @@ -88,11 +89,10 @@ import org.springframework.beans.factory.annotation.Autowired; public class MultiEvaluationFormController extends BasicController { private int count = 0; - private final PageBody anchor; private final Identity owner; private final boolean readOnly; private final boolean doneFirst; - private final RepositoryEntry formEntry; + private final EvaluationFormSurvey survey; private Link ownerLink; private Link compareLink; @@ -108,16 +108,17 @@ public class MultiEvaluationFormController extends BasicController { private UserManager userManager; @Autowired private EvaluationFormManager evaluationFormManager; + @Autowired + private PortfolioService portfolioService; public MultiEvaluationFormController(UserRequest ureq, WindowControl wControl, - Identity owner, List<Identity> otherEvaluators, PageBody anchor, RepositoryEntry formEntry, + Identity owner, List<Identity> otherEvaluators, EvaluationFormSurvey survey, boolean doneFirst, boolean readOnly, boolean onePage, boolean anonym) { super(ureq, wControl); this.owner = owner; - this.anchor = anchor; + this.survey = survey; this.readOnly = readOnly; this.doneFirst = doneFirst; - this.formEntry = formEntry; if(onePage) { initOnePageView(ureq, otherEvaluators, anonym); @@ -181,7 +182,8 @@ public class MultiEvaluationFormController extends BasicController { private Controller createEvalutationForm(UserRequest ureq, Identity evaluator) { boolean ro = readOnly || !evaluator.equals(getIdentity()); boolean doneButton = !ro && evaluator.equals(getIdentity()) && (owner == null || !owner.equals(evaluator)); - Controller evalutionFormCtrl = new EvaluationFormExecutionController(ureq, getWindowControl(), evaluator, anchor, formEntry, ro, doneButton); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, evaluator); + Controller evalutionFormCtrl = new EvaluationFormExecutionController(ureq, getWindowControl(), session, ro, doneButton); listenTo(evalutionFormCtrl); return evalutionFormCtrl; } @@ -243,8 +245,8 @@ public class MultiEvaluationFormController extends BasicController { private boolean isViewOthers() { boolean viewOthers; if(doneFirst) { - EvaluationFormSession session = evaluationFormManager.getSessionForPortfolioEvaluation(getIdentity(), anchor); - viewOthers = session == null ? false : session.getEvaluationFormSessionStatus() == EvaluationFormSessionStatus.done; + EvaluationFormParticipation participation = evaluationFormManager.loadParticipationByExecutor(survey, getIdentity()); + viewOthers = participation == null ? false : participation.getStatus() == EvaluationFormParticipationStatus.done; } else { viewOthers = true; } @@ -262,8 +264,8 @@ public class MultiEvaluationFormController extends BasicController { if(event == Event.DONE_EVENT) { if(doneFirst) { // check if it's really done - EvaluationFormSession session = evaluationFormManager.getSessionForPortfolioEvaluation(getIdentity(), anchor); - if(session != null && session.getEvaluationFormSessionStatus() == EvaluationFormSessionStatus.done) { + EvaluationFormParticipation participation = evaluationFormManager.loadParticipationByExecutor(survey, getIdentity()); + if(participation != null && participation.getStatus() == EvaluationFormParticipationStatus.done) { segmentView.setVisible(true); } } @@ -297,37 +299,46 @@ public class MultiEvaluationFormController extends BasicController { private void doOpenEvalutationForm(UserRequest ureq, Identity evaluator) { boolean ro = readOnly || !evaluator.equals(getIdentity()); boolean doneButton = !ro && evaluator.equals(getIdentity()) && (owner == null || !owner.equals(evaluator)); - currentEvalutionFormCtrl = new EvaluationFormExecutionController(ureq, getWindowControl(), evaluator, anchor, formEntry, ro, doneButton); + EvaluationFormSession session = portfolioService.loadOrCreateSession(survey, evaluator); + currentEvalutionFormCtrl = new EvaluationFormExecutionController(ureq, getWindowControl(), session, ro, doneButton); listenTo(currentEvalutionFormCtrl); mainVC.put("segmentCmp", currentEvalutionFormCtrl.getInitialComponent()); } private void doOpenOverview(UserRequest ureq) { - //TODO uh delete -// Controller ctrl = new EvaluationFormCompareController(ureq, getWindowControl(), evaluators, anchor, formEntry); Controller ctrl = createReportController(ureq); mainVC.put("segmentCmp", ctrl.getInitialComponent()); } private EvaluationFormReportController createReportController(UserRequest ureq) { - File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(formEntry.getOlatResource()), FileResourceManager.ZIPDIR); + File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(survey.getFormEntry().getOlatResource()), FileResourceManager.ZIPDIR); File formFile = new File(repositoryDir, FORM_XML_FILE); Form form = (Form)XStreamHelper.readObject(FormXStream.getXStream(), formFile); - //TODO uh delete class Evaluator - List<Identity> evaluatorIdentities = evaluators.stream().map(evaluator -> evaluator.getIdentity()).collect(Collectors.toList()); - List<EvaluationFormResponse> responses = evaluationFormManager.getResponsesFromPortfolioEvaluation(evaluatorIdentities, anchor, EvaluationFormSessionStatus.done); - Set<EvaluationFormSession> responseSessions = responses.stream().map(EvaluationFormResponse::getSession).collect(Collectors.toSet()); - List<? extends EvaluationFormSessionRef> sessions = new ArrayList<>(responseSessions); + List<EvaluationFormSession> sessions = evaluationFormManager.loadSessionsBySurvey(survey, EvaluationFormSessionStatus.done); + sessions.removeIf(session -> notEvaluator(session)); EvaluationFormReportProvider provider = new ReportProvider(); + LegendNameGenerator legendNameGenerator = new EvaluatorNameGenerator(evaluators); ReportHelper reportHelper = ReportHelper.builder(getLocale()) .withColors() + .withLegendNameGenrator(legendNameGenerator) .build(); return new EvaluationFormReportController(ureq, getWindowControl(), form, sessions, provider, reportHelper); } + private boolean notEvaluator(EvaluationFormSession session) { + if (session != null && session.getParticipation() != null && session.getParticipation().getExecutor() != null) { + Identity executor = session.getParticipation().getExecutor(); + List<Identity> evaluatorIdentities = evaluators.stream().map(Evaluator::getIdentity).collect(Collectors.toList()); + if (evaluatorIdentities.contains(executor)) { + return false; + } + } + return true; + } + private final static class ReportProvider implements EvaluationFormReportProvider { private final Map<String, EvaluationFormReportHandler> handlers = new HashMap<>(); @@ -348,6 +359,24 @@ public class MultiEvaluationFormController extends BasicController { return handlers.get(element.getType()); } } + + private final static class EvaluatorNameGenerator implements LegendNameGenerator { + + private final Map<Identity, String> identityToName; + + public EvaluatorNameGenerator(List<Evaluator> evaluators) { + super(); + this.identityToName = evaluators.stream() + .collect(Collectors.toMap(Evaluator::getIdentity, Evaluator::getFullName)); + } + + @Override + public String getName(Identity identity) { + String name = identityToName.get(identity); + return StringHelper.containsNonWhitespace(name)? name: "???"; + } + + } public static class EvaluatorPanel { diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java index 8535c0de3e067924171588f14b25d95e32985434..8834e6d353e587734d7a9766434cc45a94240d3f 100644 --- a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java @@ -30,6 +30,15 @@ import org.olat.basesecurity.manager.OrganisationDAO; import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; import org.olat.core.id.Organisation; +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.EvaluationFormSessionStatus; +import org.olat.modules.forms.EvaluationFormSurvey; +import org.olat.modules.forms.model.jpa.EvaluationFormParticipationImpl; +import org.olat.modules.forms.model.jpa.EvaluationFormSessionImpl; +import org.olat.modules.portfolio.PortfolioService; import org.springframework.beans.factory.annotation.Autowired; /** @@ -42,6 +51,7 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { private static final String VERSION = "OLAT_13.0.0"; private static final String MIGRATE_ROLE = "MIGRATE ROLE"; + private static final String MIGRATE_PORTFOLIO_EVAL_FORM = "PORTFOLIO EVALUATION FORM"; @Autowired private DB dbInstance; @@ -49,6 +59,10 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { private OrganisationDAO organisationDao; @Autowired private OrganisationService organisationService; + @Autowired + private PortfolioService portfolioService; + @Autowired + private EvaluationFormManager evaManger; public OLATUpgrade_13_0_0() { super(); @@ -76,6 +90,7 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { boolean allOk = true; allOk &= migrateRole(upgradeManager, uhd); + allOk &= migratePortfolioEvaluationForm(upgradeManager, uhd); uhd.setInstallationComplete(allOk); upgradeManager.setUpgradesHistory(uhd, VERSION); @@ -148,4 +163,78 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { .setParameter("groupName", securityGroupName) .getResultList(); } + + private boolean migratePortfolioEvaluationForm(UpgradeManager upgradeManager, UpgradeHistoryData uhd) { + boolean allOk = true; + if (!uhd.getBooleanDataValue(MIGRATE_PORTFOLIO_EVAL_FORM)) { + try { + migrateSessions(); + dbInstance.commitAndCloseSession(); + } catch (Exception e) { + log.error("", e); + allOk &= false; + } + + uhd.setBooleanDataValue(MIGRATE_PORTFOLIO_EVAL_FORM, allOk); + upgradeManager.setUpgradesHistory(uhd, VERSION); + } + return allOk; + } + + @SuppressWarnings("deprecation") + private void migrateSessions() { + log.info("Start migration of sessions of porfolio evaluation forms."); + List<EvaluationFormSession> sessions = loadPortfolioSessions(); + for(int i=0; i<sessions.size(); i++) { + EvaluationFormSession session = sessions.get(i); + if (session.getPageBody() == null || session.getFormEntry() == null || session.getIdentity() == null) { + log.warn("EvaluationFormSession " + session.getKey() + " was not migrated. [FormEntry: " + + session.getFormEntry().toString() + "], [Identity: " + session.getIdentity().toString() + "]"); + } + EvaluationFormSurvey survey = portfolioService.loadOrCreateSurvey(session.getPageBody(), session.getFormEntry()); + EvaluationFormParticipation participation = loadOrCreateParticipation(session, survey); + if (session instanceof EvaluationFormSessionImpl) { + EvaluationFormSessionImpl sessionImpl = (EvaluationFormSessionImpl) session; + sessionImpl.setParticipation(participation); + sessionImpl.setSurvey(survey); + dbInstance.getCurrentEntityManager().merge(sessionImpl); + } + if(i % 20 == 0) { + dbInstance.commitAndCloseSession(); + } + if(i % 500 == 0) { + log.info("" + i + " sessions migrated."); + } + } + dbInstance.commit(); + log.info("End migration of " + sessions.size() + " sessions of porfolio evaluation forms."); + } + + @SuppressWarnings("deprecation") + private EvaluationFormParticipation loadOrCreateParticipation(EvaluationFormSession session, EvaluationFormSurvey survey) { + EvaluationFormParticipation participation = evaManger.loadParticipationByExecutor(survey, session.getIdentity()); + if (participation == null) { + participation = evaManger.createParticipation(survey, session.getIdentity()); + if (EvaluationFormSessionStatus.done.equals(session.getEvaluationFormSessionStatus())) { + if (participation instanceof EvaluationFormParticipationImpl) { + EvaluationFormParticipationImpl participationImpl = (EvaluationFormParticipationImpl) participation; + participationImpl.setStatus(EvaluationFormParticipationStatus.done); + dbInstance.getCurrentEntityManager().merge(participationImpl); + } + } + } + return participation; + } + + private List<EvaluationFormSession> loadPortfolioSessions() { + StringBuilder sb = new StringBuilder(); + sb.append("select session from evaluationformsession as session"); + sb.append(" where session.pageBody is not null"); + sb.append(" and session.participation is null"); // exclude already migrated session + + return dbInstance.getCurrentEntityManager() + .createQuery(sb.toString(), EvaluationFormSession.class) + .getResultList(); + } + } diff --git a/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql b/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql index 9b843c995cf6ee38c8e2a1ae1997c0da40538deb..b7df40b7ddb14ae08e5bc2ddbca7e7acf9263db7 100644 --- a/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql +++ b/src/main/resources/database/mysql/alter_12_4_x_to_13_0_0.sql @@ -185,3 +185,5 @@ create unique index idx_eva_part_executor_idx on o_eva_form_participation (fk_ex alter table o_eva_form_session add constraint eva_sess_to_surv_idx foreign key (fk_survey) references o_eva_form_survey (id); alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); +create index idx_eva_resp_report_idx on o_eva_form_response (fk_session, e_responseidentifier, e_no_response); + diff --git a/src/main/resources/database/mysql/setupDatabase.sql b/src/main/resources/database/mysql/setupDatabase.sql index 61aede1656309135dd8e2811bdc8c4ceaa504045..fdff0153bead9b03f96d7e0ae92c8619c3b6bb53 100644 --- a/src/main/resources/database/mysql/setupDatabase.sql +++ b/src/main/resources/database/mysql/setupDatabase.sql @@ -3295,6 +3295,7 @@ alter table o_eva_form_session add constraint eva_sess_to_form_idx foreign key ( create index idx_eva_surv_ores_idx on o_eva_form_session (e_resid, e_resname, e_sub_ident(255)); alter table o_eva_form_response add constraint eva_resp_to_sess_idx foreign key (fk_session) references o_eva_form_session (id); +create index idx_eva_resp_report_idx on o_eva_form_response (fk_session, e_responseidentifier, e_no_response); -- question pool alter table o_qp_pool add constraint idx_qp_pool_owner_grp_id foreign key (fk_ownergroup) references o_bs_secgroup(id); diff --git a/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql b/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql index 9adea335db6e376b95fc15dac4cee3196501f9f2..71dc21dd606a5108c7a76f9fdd8e3f7ac88669fa 100644 --- a/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql +++ b/src/main/resources/database/oracle/alter_12_4_x_to_13_0_0.sql @@ -184,3 +184,5 @@ alter table o_eva_form_session add constraint eva_sess_to_surv_idx foreign key ( create index idx_eva_sess_to_surv_idx on o_eva_form_session (fk_survey); alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); +create index idx_eva_resp_report_idx on o_eva_form_response (fk_session, e_responseidentifier, e_no_response); + diff --git a/src/main/resources/database/oracle/setupDatabase.sql b/src/main/resources/database/oracle/setupDatabase.sql index 77ab5a68214a824d354675debb9f5368d1efaa9f..26b1ece1687b2c022ba0cfeb3c1adc9375cb4576 100644 --- a/src/main/resources/database/oracle/setupDatabase.sql +++ b/src/main/resources/database/oracle/setupDatabase.sql @@ -3430,6 +3430,7 @@ create index idx_eva_sess_ores_idx on o_eva_form_session (e_resid, e_resname, e_ alter table o_eva_form_response add constraint eva_resp_to_sess_idx foreign key (fk_session) references o_eva_form_session (id); create index idx_eva_resp_to_sess_idx on o_eva_form_response (fk_session); +create index idx_eva_resp_report_idx on o_eva_form_response (fk_session, e_responseidentifier, e_no_response); -- question pool alter table o_qp_pool add constraint idx_qp_pool_owner_grp_id foreign key (fk_ownergroup) references o_bs_secgroup(id); diff --git a/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql b/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql index 0904cd04b05ae70f40daac79662f03aed3491ef4..1569884b288081b863f602744f8e229ad7efe0b7 100644 --- a/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql +++ b/src/main/resources/database/postgresql/alter_12_4_x_to_13_0_0.sql @@ -189,3 +189,5 @@ create index idx_eva_sess_to_surv_idx on o_eva_form_session (fk_survey); alter table o_eva_form_session add constraint eva_sess_to_part_idx foreign key (fk_participation) references o_eva_form_participation (id); create unique index idx_eva_sess_to_part_idx on o_eva_form_session (fk_participation); +create index idx_eva_resp_report_idx on o_eva_form_response (fk_session, e_responseidentifier, e_no_response); + diff --git a/src/main/resources/database/postgresql/setupDatabase.sql b/src/main/resources/database/postgresql/setupDatabase.sql index 753003e6c4baf3d0ba093bd494279e75c93cd66d..31b8ab1cf6d4342ccd86a78ae1704272a601a192 100644 --- a/src/main/resources/database/postgresql/setupDatabase.sql +++ b/src/main/resources/database/postgresql/setupDatabase.sql @@ -3281,6 +3281,7 @@ create index idx_eva_sess_to_form_idx on o_eva_form_session (fk_form_entry); alter table o_eva_form_response add constraint eva_resp_to_sess_idx foreign key (fk_session) references o_eva_form_session (id); create index idx_eva_resp_to_sess_idx on o_eva_form_response (fk_session); +create index idx_eva_resp_report_idx on o_eva_form_response (fk_session, e_responseidentifier, e_no_response); -- question pool alter table o_qp_pool add constraint idx_qp_pool_owner_grp_id foreign key (fk_ownergroup) references o_bs_secgroup(id); diff --git a/src/test/java/org/olat/modules/forms/manager/EvaluationFormMangerImplTest.java b/src/test/java/org/olat/modules/forms/manager/EvaluationFormMangerImplTest.java index d1d12fe1b3fcffb6b62651bf1f89fd281ff25023..48c1721aae082f631d5a08b61a3da2cc97403c00 100644 --- a/src/test/java/org/olat/modules/forms/manager/EvaluationFormMangerImplTest.java +++ b/src/test/java/org/olat/modules/forms/manager/EvaluationFormMangerImplTest.java @@ -19,6 +19,7 @@ */ package org.olat.modules.forms.manager; +import static org.mockito.AdditionalAnswers.returnsFirstArg; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -81,26 +82,26 @@ public class EvaluationFormMangerImplTest { verify(surveyDaoMock, never()).updateForm(surveyMock, formEntryMock); } - @Test - public void shouldMakeParticipationDoneWhenFinishingSession() { + public void shouldMakeSessionDoneWhenFinishingSession() { EvaluationFormSession sessionMock = mock(EvaluationFormSession.class); - EvaluationFormParticipation participationMock = mock(EvaluationFormParticipation.class); - when(sessionMock.getParticipation()).thenReturn(participationMock); sut.finishSession(sessionMock); - verify(particopationDaoMock).changeStatus(participationMock, EvaluationFormParticipationStatus.done); + verify(sessionDaoMock).changeStatus(sessionMock, EvaluationFormSessionStatus.done); } @Test - public void shouldMakeSessionDoneWhenFinishingSession() { + public void shouldMakeParticipationDoneWhenFinishingSession() { EvaluationFormSession sessionMock = mock(EvaluationFormSession.class); + EvaluationFormParticipation participationMock = mock(EvaluationFormParticipation.class); + when(sessionMock.getParticipation()).thenReturn(participationMock); + when(particopationDaoMock.changeStatus(participationMock, EvaluationFormParticipationStatus.done)).then(returnsFirstArg()); sut.finishSession(sessionMock); - verify(sessionDaoMock).changeStatus(sessionMock, EvaluationFormSessionStatus.done); + verify(particopationDaoMock).changeStatus(participationMock, EvaluationFormParticipationStatus.done); } @Test @@ -109,6 +110,7 @@ public class EvaluationFormMangerImplTest { EvaluationFormParticipation participationMock = mock(EvaluationFormParticipation.class); when(participationMock.isAnonymous()).thenReturn(Boolean.TRUE); when(sessionMock.getParticipation()).thenReturn(participationMock); + when(particopationDaoMock.changeStatus(participationMock, EvaluationFormParticipationStatus.done)).then(returnsFirstArg()); sut.finishSession(sessionMock); @@ -121,10 +123,45 @@ public class EvaluationFormMangerImplTest { EvaluationFormParticipation participationMock = mock(EvaluationFormParticipation.class); when(participationMock.isAnonymous()).thenReturn(Boolean.FALSE); when(sessionMock.getParticipation()).thenReturn(participationMock); + when(particopationDaoMock.changeStatus(participationMock, EvaluationFormParticipationStatus.done)).then(returnsFirstArg()); sut.finishSession(sessionMock); verify(sessionDaoMock, never()).makeAnonymous(sessionMock); } + + @Test + public void shouldMakeSessionInProgressWhenReopeningSession() { + EvaluationFormSession sessionMock = mock(EvaluationFormSession.class); + EvaluationFormParticipation participationMock = mock(EvaluationFormParticipation.class); + when(sessionMock.getParticipation()).thenReturn(participationMock); + + sut.reopenSession(sessionMock); + + verify(sessionDaoMock).changeStatus(sessionMock, EvaluationFormSessionStatus.inProgress); + } + + @Test + public void shouldMakeParticipationPreparedWhenReopeningSession() { + EvaluationFormSession sessionMock = mock(EvaluationFormSession.class); + EvaluationFormParticipation participationMock = mock(EvaluationFormParticipation.class); + when(sessionMock.getParticipation()).thenReturn(participationMock); + + sut.reopenSession(sessionMock); + + verify(particopationDaoMock).changeStatus(participationMock, EvaluationFormParticipationStatus.prepared); + } + + @Test + public void shouldNotReopenWhenIsAnonymousSession() { + EvaluationFormSession sessionMock = mock(EvaluationFormSession.class); + EvaluationFormParticipation participationMock = mock(EvaluationFormParticipation.class); + when(sessionMock.getParticipation()).thenReturn(null); + + sut.reopenSession(sessionMock); + + verify(sessionDaoMock, never()).changeStatus(sessionMock, EvaluationFormSessionStatus.inProgress); + verify(particopationDaoMock, never()).changeStatus(participationMock, EvaluationFormParticipationStatus.prepared); + } } diff --git a/src/test/java/org/olat/modules/forms/manager/EvaluationFormResponseDAOTest.java b/src/test/java/org/olat/modules/forms/manager/EvaluationFormResponseDAOTest.java index 8e53610bf9795b56ef2facccd13f231244f04c5f..36d2324aeaa387b7a768fdd6bc36d03832a374a4 100644 --- a/src/test/java/org/olat/modules/forms/manager/EvaluationFormResponseDAOTest.java +++ b/src/test/java/org/olat/modules/forms/manager/EvaluationFormResponseDAOTest.java @@ -28,22 +28,12 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.olat.core.commons.persistence.DB; -import org.olat.core.id.Identity; import org.olat.modules.forms.EvaluationFormResponse; import org.olat.modules.forms.EvaluationFormSession; import org.olat.modules.forms.EvaluationFormSurvey; -import org.olat.modules.portfolio.Page; -import org.olat.modules.portfolio.PageBody; -import org.olat.modules.portfolio.Section; -import org.olat.modules.portfolio.manager.BinderDAO; -import org.olat.modules.portfolio.manager.PageDAO; -import org.olat.modules.portfolio.model.BinderImpl; -import org.olat.repository.RepositoryEntry; -import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; import org.springframework.beans.factory.annotation.Autowired; @@ -58,12 +48,6 @@ public class EvaluationFormResponseDAOTest extends OlatTestCase { @Autowired private DB dbInstance; @Autowired - private PageDAO pageDao; - @Autowired - private BinderDAO binderDao; - @Autowired - private EvaluationFormSessionDAO evaluationFormSessionDao; - @Autowired private EvaluationFormTestsHelper evaTestHelper; @Autowired @@ -74,46 +58,9 @@ public class EvaluationFormResponseDAOTest extends OlatTestCase { evaTestHelper.deleteAll(); } - @Test - public void createResponseForPortfolio() { - //prepare a test case with the binder up to the page body - Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("eva-1"); - BinderImpl binder = binderDao.createAndPersist("Binder evaluation 1", "A binder with an evaluation", null, null); - Section section = binderDao.createSection("Section", "First section", null, null, binder); - dbInstance.commit(); - Section reloadedSection = binderDao.loadSectionByKey(section.getKey()); - Page page = pageDao.createAndPersist("Page 1", "A page with an evalutation.", null, null, true, reloadedSection, null); - dbInstance.commit(); - RepositoryEntry formEntry = evaTestHelper.createFormEntry(); - - PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey()); - EvaluationFormSession session = evaluationFormSessionDao.createSessionForPortfolio(id, reloadedBody, formEntry); - dbInstance.commit(); - - //create a response - String responseIdentifier = UUID.randomUUID().toString(); - BigDecimal numericalValue = new BigDecimal("2.2"); - String stringuifiedResponse = numericalValue.toPlainString(); - Path fileResponse = Paths.get("this", "is", "a", "path"); - EvaluationFormResponse response = sut.createResponse(responseIdentifier, - numericalValue, stringuifiedResponse, fileResponse, session); - dbInstance.commit(); - - Assert.assertNotNull(response); - Assert.assertNotNull(response.getKey()); - Assert.assertNotNull(response.getCreationDate()); - Assert.assertNotNull(response.getLastModified()); - Assert.assertFalse(response.isNoResponse()); - Assert.assertEquals(session, response.getSession()); - Assert.assertEquals(numericalValue, response.getNumericalResponse()); - Assert.assertEquals(stringuifiedResponse, response.getStringuifiedResponse()); - Assert.assertEquals(fileResponse, response.getFileResponse()); - Assert.assertEquals(responseIdentifier, response.getResponseIdentifier()); - } - @Test public void shouldUpdateResponse() { - EvaluationFormSession session = createSession(); + EvaluationFormSession session = evaTestHelper.createSession(); EvaluationFormResponse response = createResponse(session); dbInstance.commit(); @@ -130,7 +77,7 @@ public class EvaluationFormResponseDAOTest extends OlatTestCase { @Test public void shouldCreateNoResponse() { - EvaluationFormSession session = createSession(); + EvaluationFormSession session = evaTestHelper.createSession(); String responseIdentifier = UUID.randomUUID().toString(); EvaluationFormResponse response = sut.createNoResponse(responseIdentifier, session); dbInstance.commit(); @@ -147,7 +94,7 @@ public class EvaluationFormResponseDAOTest extends OlatTestCase { @Test public void shouldUpdateNoResponse() { - EvaluationFormSession session = createSession(); + EvaluationFormSession session = evaTestHelper.createSession(); EvaluationFormResponse initialResponse = createResponse(session); dbInstance.commit(); @@ -180,7 +127,7 @@ public class EvaluationFormResponseDAOTest extends OlatTestCase { @Test public void shouldDeleteResponses() { - EvaluationFormSession session = createSession(); + EvaluationFormSession session = evaTestHelper.createSession(); String responseIdentifier = UUID.randomUUID().toString(); createResponse(session, responseIdentifier); createResponse(session, responseIdentifier); @@ -213,11 +160,4 @@ public class EvaluationFormResponseDAOTest extends OlatTestCase { fileResponse, session); } - private EvaluationFormSession createSession() { - Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("eva-resp"); - RepositoryEntry formEntry = evaTestHelper.createFormEntry(); - EvaluationFormSession session = evaluationFormSessionDao.createSessionForPortfolio(id, null, formEntry); - return session; - } - } diff --git a/src/test/java/org/olat/modules/forms/manager/EvaluationFormSessionDAOTest.java b/src/test/java/org/olat/modules/forms/manager/EvaluationFormSessionDAOTest.java index 00448ae4af90fb82a21222466e4b61daa4b536d7..e6682da41d911ef10ce2f52ce1cdcf4296e64c95 100644 --- a/src/test/java/org/olat/modules/forms/manager/EvaluationFormSessionDAOTest.java +++ b/src/test/java/org/olat/modules/forms/manager/EvaluationFormSessionDAOTest.java @@ -23,24 +23,16 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.olat.core.commons.persistence.DB; -import org.olat.core.id.Identity; import org.olat.modules.forms.EvaluationFormParticipation; import org.olat.modules.forms.EvaluationFormSession; import org.olat.modules.forms.EvaluationFormSessionRef; import org.olat.modules.forms.EvaluationFormSessionStatus; import org.olat.modules.forms.EvaluationFormSurvey; -import org.olat.modules.portfolio.Page; -import org.olat.modules.portfolio.PageBody; -import org.olat.modules.portfolio.Section; import org.olat.modules.portfolio.manager.BinderDAO; import org.olat.modules.portfolio.manager.PageDAO; -import org.olat.modules.portfolio.model.BinderImpl; -import org.olat.repository.RepositoryEntry; -import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; import org.springframework.beans.factory.annotation.Autowired; @@ -128,7 +120,7 @@ public class EvaluationFormSessionDAOTest extends OlatTestCase { @Test - public void shouldCheckIfHasSessions() { + public void shouldCheckIfSurveyHasSessions() { EvaluationFormParticipation participation = evaTestHelper.createParticipation(); EvaluationFormSurvey survey = participation.getSurvey(); sut.createSession(participation); @@ -140,7 +132,7 @@ public class EvaluationFormSessionDAOTest extends OlatTestCase { } @Test - public void shouldCheckIfHasNoSessions() { + public void shouldCheckIfSurveyHasNoSessions() { EvaluationFormSurvey survey = evaTestHelper.createSurvey(); dbInstance.commit(); @@ -149,6 +141,28 @@ public class EvaluationFormSessionDAOTest extends OlatTestCase { assertThat(hasSessions).isFalse(); } + @Test + public void shouldCheckIfFormHasSessions() { + EvaluationFormParticipation participation = evaTestHelper.createParticipation(); + EvaluationFormSurvey survey = participation.getSurvey(); + sut.createSession(participation); + dbInstance.commitAndCloseSession(); + + boolean hasSessions = sut.hasSessions(survey.getFormEntry()); + + assertThat(hasSessions).isTrue(); + } + + @Test + public void shouldCheckIfFormHasNoSessions() { + EvaluationFormSurvey survey = evaTestHelper.createSurvey(); + dbInstance.commit(); + + boolean hasSessions = sut.hasSessions(survey.getFormEntry()); + + assertThat(hasSessions).isFalse(); + } + @Test public void shouldDeleteSessionsOfSurvey() { EvaluationFormSurvey survey = evaTestHelper.createSurvey(); @@ -168,28 +182,4 @@ public class EvaluationFormSessionDAOTest extends OlatTestCase { assertThat(loadedOtherSession).isEqualTo(otherSession); } - @Test - public void createSessionForPortfolio() { - Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("eva-1"); - - BinderImpl binder = binderDao.createAndPersist("Binder evaluation 1", "A binder with an evaluation", null, null); - Section section = binderDao.createSection("Section", "First section", null, null, binder); - dbInstance.commit(); - Section reloadedSection = binderDao.loadSectionByKey(section.getKey()); - Page page = pageDao.createAndPersist("Page 1", "A page with an evalutation.", null, null, true, reloadedSection, null); - dbInstance.commit(); - RepositoryEntry formEntry = evaTestHelper.createFormEntry(); - - PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey()); - EvaluationFormSession session = sut.createSessionForPortfolio(id, reloadedBody, formEntry); - dbInstance.commit(); - - Assert.assertNotNull(session); - Assert.assertNotNull(session.getKey()); - Assert.assertNotNull(session.getCreationDate()); - Assert.assertNotNull(session.getLastModified()); - Assert.assertEquals(reloadedBody, session.getPageBody()); - Assert.assertEquals(id, session.getIdentity()); - } - } diff --git a/src/test/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAOTest.java b/src/test/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAOTest.java index c46d1a97f822b1834dfb4d481bdc62cfb61deda7..943b573464ab7b51f9282e992d538c6df5f3cb44 100644 --- a/src/test/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAOTest.java +++ b/src/test/java/org/olat/modules/forms/manager/EvaluationFormSurveyDAOTest.java @@ -94,4 +94,19 @@ public class EvaluationFormSurveyDAOTest extends OlatTestCase { assertThat(loadedSurvey).isEqualTo(survey); } + + @Test + public void shouldDeleteSurvey() { + OLATResourceable ores = JunitTestHelper.createRandomResource(); + RepositoryEntry formEntry = evaTestHelper.createFormEntry(); + EvaluationFormSurvey survey = sut.createSurvey(ores, null, formEntry); + dbInstance.commit(); + + sut.delete(survey); + dbInstance.commit(); + + EvaluationFormSurvey loadedSurvey = sut.loadByResourceable(ores, null); + assertThat(loadedSurvey).isNull(); + } + } diff --git a/src/test/java/org/olat/modules/forms/ui/ReportHelperTest.java b/src/test/java/org/olat/modules/forms/ui/ReportHelperTest.java index 932c5d4d30a4e8fefbdfed31c0e8049334989bc9..3a0ab7cbddf53f8eabd924ea71e5f48eee0dd888 100644 --- a/src/test/java/org/olat/modules/forms/ui/ReportHelperTest.java +++ b/src/test/java/org/olat/modules/forms/ui/ReportHelperTest.java @@ -20,8 +20,6 @@ package org.olat.modules.forms.ui; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import java.util.Date; import java.util.Locale; @@ -39,7 +37,6 @@ import org.olat.modules.forms.EvaluationFormSurvey; import org.olat.modules.forms.ui.ReportHelper.Legend; import org.olat.modules.portfolio.PageBody; import org.olat.repository.RepositoryEntry; -import org.olat.user.UserManager; /** * @@ -52,8 +49,6 @@ public class ReportHelperTest { private static final String ANONYMOUS_NAME = "name"; private static final String ANONYMOUS_COLOR = "color"; - private UserManager userManagerMock; - private ReportHelper sut; @Before @@ -62,9 +57,8 @@ public class ReportHelperTest { .withAnonymousName(ANONYMOUS_NAME) .withAnonymousColor(ANONYMOUS_COLOR) .withColors() + .withLegendNameGenrator(new IdentityNameGenarator()) .build(); - userManagerMock = mock(UserManager.class); - sut.setUserManager(userManagerMock); } @Test @@ -76,8 +70,6 @@ public class ReportHelperTest { EvaluationFormParticipation participation = new TestableParticipation(Long.valueOf(1), executor); EvaluationFormSession session = new TestableSession(Long.valueOf(1), participation); - when(userManagerMock.getUserDisplayName(executor)).thenReturn(executor.getName()); - Legend legend1 = sut.getLegend(session); Legend legend2 = sut.getLegend(session); @@ -96,8 +88,6 @@ public class ReportHelperTest { EvaluationFormSession session1 = new TestableSession(Long.valueOf(1), participation); EvaluationFormSession session2 = new TestableSession(Long.valueOf(2), participation); - when(userManagerMock.getUserDisplayName(executor)).thenReturn(executor.getName()); - Legend legend1 = sut.getLegend(session1); Legend legend2 = sut.getLegend(session2); @@ -117,8 +107,6 @@ public class ReportHelperTest { EvaluationFormParticipation participation2 = new TestableParticipation(Long.valueOf(2), executor); EvaluationFormSession session2 = new TestableSession(Long.valueOf(1), participation2); - when(userManagerMock.getUserDisplayName(executor)).thenReturn(executor.getName()); - Legend legend1 = sut.getLegend(session1); Legend legend2 = sut.getLegend(session2); @@ -142,9 +130,6 @@ public class ReportHelperTest { EvaluationFormParticipation participation2 = new TestableParticipation(Long.valueOf(2), executor2); EvaluationFormSession session2 = new TestableSession(Long.valueOf(2), participation2); - when(userManagerMock.getUserDisplayName(executor1)).thenReturn(executor1.getName()); - when(userManagerMock.getUserDisplayName(executor2)).thenReturn(executor2.getName()); - Legend legend1 = sut.getLegend(session1); Legend legend2 = sut.getLegend(session2); @@ -230,11 +215,6 @@ public class ReportHelperTest { return null; } - @Override - public void setEvaluationFormSessionStatus(EvaluationFormSessionStatus sessionStatus) { - // - } - @Override public Identity getIdentity() { return null; @@ -311,5 +291,14 @@ public class ReportHelperTest { return executor; } } + + private final static class IdentityNameGenarator implements LegendNameGenerator { + + @Override + public String getName(Identity identity) { + return identity.getName(); + } + + } }