Skip to content
Snippets Groups Projects
Commit 386f8047 authored by srosse's avatar srosse
Browse files

OO-2556: the assignment can be deleted by the author of the template,...

OO-2556: the assignment can be deleted by the author of the template, implement the fallback using the saved form in the page part
parent 5696bcb1
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@
package org.olat.core.util.xml;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......@@ -345,6 +346,22 @@ public class XStreamHelper {
FileUtils.closeSafely(is);
}
}
/**
* Read an object from the given xml string using the xStream object.
*
* @param xStream The XStream deserializer
* @param xml XML in form of a string
* @return
*/
public static Object readObject(XStream xStream, String xml) {
try(InputStream is = new ByteArrayInputStream(xml.getBytes(ENCODING))) {
return readObject(xStream, is);
} catch (Exception e) {
throw new OLATRuntimeException(XStreamHelper.class,
"could not read Object from string: " + xml, e);
}
}
/**
* Write a an object to an XML file. UTF-8 is used as encoding. It is
......
......@@ -100,6 +100,26 @@ public class EvaluationFormController extends FormBasicController implements Val
@Autowired
private EvaluationFormManager evaluationFormManager;
/**
* The responses are saved, it's aimed at the binder where the assignment was deleted.
*
* @param ureq
* @param wControl
* @param xmlForm
*/
public EvaluationFormController(UserRequest ureq, WindowControl wControl, Identity evaluator, PageBody pageBody, String xmlForm, boolean readOnly) {
super(ureq, wControl, "run");
form = (Form)XStreamHelper.readObject(FormXStream.getXStream(), xmlForm);
this.evaluator = evaluator;
this.readOnly = readOnly;
this.anchor = pageBody;
formEntry = null;
doneButton = false;
loadResponses();
initForm(ureq);
}
/**
* The responses are not saved, it's only a preview.
*
......
......@@ -432,8 +432,22 @@ public interface PortfolioService {
*/
public Page appendNewPage(Identity owner, String title, String summary, String imagePath, PageImageAlign align, SectionRef section);
/**
* Load a page with its primary key.
*
* @param key The primary key of the page
* @return A page
*/
public Page getPageByKey(Long key);
/**
* Load the page associated with the specified page body.
*
* @param body The body associated with the searched page
* @return A page
*/
public Page getPageByBody(PageBody body);
public Page getLastPage(Identity owner, boolean binderMandatory);
/**
......
......@@ -80,59 +80,10 @@ public class EvaluationFormHandler implements PageElementHandler {
EvaluationFormPart eva = (EvaluationFormPart)element;
PageBody body = eva.getBody();
Assignment assignment = portfolioService.getAssignment(body);
//find the evaluation form
RepositoryEntry re = assignment.getFormEntry();
Page page = assignment.getPage();
PageStatus pageStatus = page.getPageStatus();
List<AccessRights> accessRights = portfolioService.getAccessRights(page);
boolean anonym = assignment.isAnonymousExternalEvaluation();
if(pageStatus == null || pageStatus == PageStatus.draft) {
if(hasRole(PortfolioRoles.owner, ureq.getIdentity(), accessRights)) {
ctrl = new EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, 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 EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, readOnly, false);
} else if(hasRole(PortfolioRoles.coach, ureq.getIdentity(), accessRights)) {
Identity owner = getOwner(accessRights);
ctrl = new EvaluationFormController(ureq, wControl, owner, body, re, 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 EvaluationFormController(ureq, wControl, owner, body, re, true, false);
}
}
if(assignment == null) {
ctrl = getController(ureq, wControl, body, eva);
} else {
if(hasRole(PortfolioRoles.owner, ureq.getIdentity(), accessRights)) {
boolean readOnly = (pageStatus == PageStatus.published) || (pageStatus == PageStatus.closed) || (pageStatus == PageStatus.deleted);
Identity owner = getOwner(accessRights);
List<Identity> coachesAndReviewers = getCoachesAndReviewers(accessRights);
if(coachesAndReviewers.size() > 0) {
ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, body, re, false, readOnly, anonym);
} else {
ctrl = new EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, 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);
ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, body, re, false, readOnly, 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);
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, anonym);
} else {
ctrl = new EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, readOnly, !readOnly);
}
}
ctrl = getControllerForAssignment(ureq, wControl, body, assignment);
}
}
......@@ -145,6 +96,89 @@ public class EvaluationFormHandler implements PageElementHandler {
return new PageRunControllerElement(ctrl);
}
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 EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, eva.getContent(), false);
} else if(hasRole(PortfolioRoles.coach, ureq.getIdentity(), accessRights)) {
Identity owner = getOwner(accessRights);
ctrl = new EvaluationFormController(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 EvaluationFormController(ureq, wControl, owner, body, eva.getContent(), true);
}
return ctrl;
}
private Controller getControllerForAssignment(UserRequest ureq, WindowControl wControl, PageBody body, Assignment assignment) {
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
//find the evaluation form
RepositoryEntry re = assignment.getFormEntry();
Page page = assignment.getPage();
PageStatus pageStatus = page.getPageStatus();
Controller ctrl = null;
List<AccessRights> accessRights = portfolioService.getAccessRights(page);
boolean anonym = assignment.isAnonymousExternalEvaluation();
if(pageStatus == null || pageStatus == PageStatus.draft) {
if(hasRole(PortfolioRoles.owner, ureq.getIdentity(), accessRights)) {
ctrl = new EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, 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 EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, readOnly, false);
} else if(hasRole(PortfolioRoles.coach, ureq.getIdentity(), accessRights)) {
Identity owner = getOwner(accessRights);
ctrl = new EvaluationFormController(ureq, wControl, owner, body, re, 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 EvaluationFormController(ureq, wControl, owner, body, re, true, false);
}
}
} else {
if(hasRole(PortfolioRoles.owner, ureq.getIdentity(), accessRights)) {
boolean readOnly = (pageStatus == PageStatus.published) || (pageStatus == PageStatus.closed) || (pageStatus == PageStatus.deleted);
Identity owner = getOwner(accessRights);
List<Identity> coachesAndReviewers = getCoachesAndReviewers(accessRights);
if(coachesAndReviewers.size() > 0) {
ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, body, re, false, readOnly, anonym);
} else {
ctrl = new EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, 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);
ctrl = new MultiEvaluationFormController(ureq, wControl, owner, coachesAndReviewers, body, re, false, readOnly, 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);
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, anonym);
} else {
ctrl = new EvaluationFormController(ureq, wControl, ureq.getIdentity(), body, re, readOnly, !readOnly);
}
}
}
return ctrl;
}
private Identity getOwner(List<AccessRights> accessRights) {
for(AccessRights accessRight:accessRights) {
if(PortfolioRoles.owner == accessRight.getRole()) {
......
......@@ -279,6 +279,22 @@ public class PageDAO {
return pages == null || pages.isEmpty() ? null : pages.get(0);
}
public Page loadByBody(PageBody body) {
StringBuilder sb = new StringBuilder();
sb.append("select page from pfpage as page")
.append(" inner join fetch page.baseGroup as baseGroup")
.append(" left join fetch page.section as section")
.append(" left join fetch section.binder as binder")
.append(" left join fetch page.body as body")
.append(" where body.key=:bodyKey");
List<Page> pages = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Page.class)
.setParameter("bodyKey", body.getKey())
.getResultList();
return pages == null || pages.isEmpty() ? null : pages.get(0);
}
public PageBody loadPageBodyByKey(Long key) {
StringBuilder sb = new StringBuilder();
sb.append("select body from pfpagebody as body")
......
......@@ -848,6 +848,11 @@ public class PortfolioServiceImpl implements PortfolioService {
return pageDao.loadByKey(key);
}
@Override
public Page getPageByBody(PageBody body) {
return pageDao.loadByBody(body);
}
@Override
public Page getLastPage(Identity owner, boolean mandatoryBinder) {
return pageDao.getLastPage(owner, mandatoryBinder);
......
......@@ -123,6 +123,21 @@ public class PageDAOTest extends OlatTestCase {
Assert.assertEquals(htmlPart, onlyParts.get(0));
}
@Test
public void loadPageByBody() {
BinderImpl binder = binderDao.createAndPersist("Binder body", "A binder with a page and a page body", null, null);
Section section = binderDao.createSection("Section", "Body section", null, null, binder);
dbInstance.commitAndCloseSession();
Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
Page page = pageDao.createAndPersist("Page 1", "A page with body.", null, null, true, reloadedSection, null);
dbInstance.commitAndCloseSession();
Page reloadedPage = pageDao.loadByBody(page.getBody());
Assert.assertNotNull(reloadedPage);
Assert.assertEquals(page, reloadedPage);
}
@Test
public void getPages_binder() {
BinderImpl binder = binderDao.createAndPersist("Binder p2", "A binder with 2 page", null, null);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment