Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -rf6222f18a5fc2d8d13d7514afadef0fb204fb968 -r313e29d4010a35282a7c56dd24971e40b442dfb0 Binary files differ Index: lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeAction.java =================================================================== diff -u -r7d7e4420720fa2caa466d0faa33f8a810c72af45 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeAction.java (.../OutcomeAction.java) (revision 7d7e4420720fa2caa466d0faa33f8a810c72af45) +++ lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeAction.java (.../OutcomeAction.java) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -43,6 +43,7 @@ import org.lamsfoundation.lams.lesson.service.ILessonService; import org.lamsfoundation.lams.outcome.Outcome; import org.lamsfoundation.lams.outcome.OutcomeScale; +import org.lamsfoundation.lams.outcome.service.IOutcomeService; import org.lamsfoundation.lams.security.ISecurityService; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.Role; @@ -64,8 +65,8 @@ private static ILessonService lessonService; private static ISecurityService securityService; private static IIntegrationService integrationService; + private static IOutcomeService outcomeService; - @SuppressWarnings("unchecked") public ActionForward outcomeManage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Integer userId = getUserDTO().getUserID(); @@ -85,7 +86,7 @@ return null; } } - List outcomes = getUserManagementService().findAll(Outcome.class); + List outcomes = getOutcomeService().getOutcomesForManagement(organisationId); request.setAttribute("outcomes", outcomes); request.setAttribute("canManageGlobal", getUserManagementService().isUserSysAdmin()); @@ -99,16 +100,15 @@ Long outcomeId = WebUtil.readLongParam(request, "outcomeId", true); Outcome outcome = null; Integer organisationId = null; - if (outcomeId != null) { + if (outcomeId == null) { + organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); + } else { outcome = (Outcome) getUserManagementService().findById(Outcome.class, outcomeId); - if (outcome != null && outcome.getOrganisation() != null) { + if (outcome.getOrganisation() != null) { // get organisation ID from the outcome - the safest way organisationId = outcome.getOrganisation().getOrganisationId(); } } - if (organisationId == null) { - organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); - } if (organisationId == null) { if (!getSecurityService().isSysadmin(userId, "add/edit global outcome", false)) { @@ -123,11 +123,10 @@ } } OutcomeForm outcomeForm = (OutcomeForm) form; - outcomeForm.setOrganisationId(outcome == null ? organisationId - : (outcome.getOrganisation() == null ? null : outcome.getOrganisation().getOrganisationId())); + outcomeForm.setOrganisationId(organisationId); + outcomeForm.setContentFolderId(getOutcomeService().getContentFolderId(organisationId)); if (outcome != null) { outcomeForm.setOutcomeId(outcome.getOutcomeId()); - outcomeForm.setName(outcome.getName()); outcomeForm.setCode(outcome.getCode()); outcomeForm.setDescription(outcome.getDescription()); @@ -146,19 +145,18 @@ HttpServletResponse response) throws Exception { OutcomeForm outcomeForm = (OutcomeForm) form; Integer userId = getUserDTO().getUserID(); - Long outcomeId = WebUtil.readLongParam(request, "outcomeId", true); + Long outcomeId = outcomeForm.getOutcomeId(); Outcome outcome = null; Integer organisationId = null; - if (outcomeId != null) { + if (outcomeId == null) { + organisationId = outcomeForm.getOrganisationId(); + } else { outcome = (Outcome) getUserManagementService().findById(Outcome.class, outcomeId); - if (outcome != null) { + if (outcome.getOrganisation() != null) { // get organisation ID from the outcome - the safest way organisationId = outcome.getOrganisation().getOrganisationId(); } } - if (organisationId == null) { - organisationId = outcomeForm.getOrganisationId(); - } if (organisationId == null) { if (!getSecurityService().isSysadmin(userId, "persist global outcome", false)) { @@ -191,7 +189,7 @@ outcome.setName(outcomeForm.getName()); outcome.setCode(outcomeForm.getCode()); outcome.setDescription(outcomeForm.getDescription()); - outcomeForm.setOrganisationId(organisationId); + outcome.setContentFolderId(outcomeForm.getContentFolderId()); if (outcomeForm.getScaleId() != null) { OutcomeScale scale = (OutcomeScale) getUserManagementService().findById(OutcomeScale.class, outcomeForm.getScaleId()); @@ -292,6 +290,15 @@ return OutcomeAction.securityService; } + private IOutcomeService getOutcomeService() { + if (OutcomeAction.outcomeService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + OutcomeAction.outcomeService = (IOutcomeService) ctx.getBean("outcomeService"); + } + return OutcomeAction.outcomeService; + } + private IIntegrationService getIntegrationService() { if (OutcomeAction.integrationService == null) { WebApplicationContext ctx = WebApplicationContextUtils Index: lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeForm.java =================================================================== diff -u -r7d7e4420720fa2caa466d0faa33f8a810c72af45 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeForm.java (.../OutcomeForm.java) (revision 7d7e4420720fa2caa466d0faa33f8a810c72af45) +++ lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeForm.java (.../OutcomeForm.java) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -33,21 +33,22 @@ private String name; private String code; private String description; + private String contentFolderId; public Long getOutcomeId() { return outcomeId; } public void setOutcomeId(Long outcomeId) { - this.outcomeId = outcomeId; + this.outcomeId = outcomeId != null && outcomeId < 1 ? null : outcomeId; } public Integer getOrganisationId() { return organisationId; } public void setOrganisationId(Integer organisationId) { - this.organisationId = organisationId; + this.organisationId = organisationId != null && organisationId < 1 ? null : organisationId; } public Long getScaleId() { @@ -81,4 +82,12 @@ public void setDescription(String description) { this.description = description; } + + public String getContentFolderId() { + return contentFolderId; + } + + public void setContentFolderId(String contentFolderId) { + this.contentFolderId = contentFolderId; + } } \ No newline at end of file Index: lams_central/web/includes/javascript/outcome.js =================================================================== diff -u -r7d7e4420720fa2caa466d0faa33f8a810c72af45 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_central/web/includes/javascript/outcome.js (.../outcome.js) (revision 7d7e4420720fa2caa466d0faa33f8a810c72af45) +++ lams_central/web/includes/javascript/outcome.js (.../outcome.js) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -15,9 +15,8 @@ // load contents after opening the dialog $('iframe', dialog) .attr('src', LAMS_URL - + 'outcome.do?method=outcomeEdit&organisationID=' - + organisationId - + (outcomeId ? "&outcomeId=" + outcomeId : "")); + + 'outcome.do?method=outcomeEdit&' + + (outcomeId ? "outcomeId=" + outcomeId : "organisationID=" + organisationId)); } }); } \ No newline at end of file Index: lams_central/web/outcome/outcomeEdit.jsp =================================================================== diff -u -r7d7e4420720fa2caa466d0faa33f8a810c72af45 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_central/web/outcome/outcomeEdit.jsp (.../outcomeEdit.jsp) (revision 7d7e4420720fa2caa466d0faa33f8a810c72af45) +++ lams_central/web/outcome/outcomeEdit.jsp (.../outcomeEdit.jsp) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -49,6 +49,7 @@ +
@@ -108,7 +109,7 @@ - +
Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/outcome/Outcome.hbm.xml =================================================================== diff -u -rf6222f18a5fc2d8d13d7514afadef0fb204fb968 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/outcome/Outcome.hbm.xml (.../Outcome.hbm.xml) (revision f6222f18a5fc2d8d13d7514afadef0fb204fb968) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/outcome/Outcome.hbm.xml (.../Outcome.hbm.xml) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -20,6 +20,9 @@ + + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/outcome/OutcomeScale.hbm.xml =================================================================== diff -u -rf6222f18a5fc2d8d13d7514afadef0fb204fb968 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/outcome/OutcomeScale.hbm.xml (.../OutcomeScale.hbm.xml) (revision f6222f18a5fc2d8d13d7514afadef0fb204fb968) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/outcome/OutcomeScale.hbm.xml (.../OutcomeScale.hbm.xml) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -17,8 +17,8 @@ - + Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml =================================================================== diff -u -re59191f853aa9bdaf89c4e430fa9517541c073ed -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision e59191f853aa9bdaf89c4e430fa9517541c073ed) +++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -493,6 +493,27 @@ + + + + + + + + + + true + + + + + + + + PROPAGATION_REQUIRED + + + @@ -637,11 +658,16 @@ - + + + + + + items) { this.items = items; } + + public String getContentFolderId() { + return contentFolderId; + } + + public void setContentFolderId(String contentFolderId) { + this.contentFolderId = contentFolderId; + } } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/outcome/dao/IOutcomeDAO.java =================================================================== diff -u -r7d7e4420720fa2caa466d0faa33f8a810c72af45 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_common/src/java/org/lamsfoundation/lams/outcome/dao/IOutcomeDAO.java (.../IOutcomeDAO.java) (revision 7d7e4420720fa2caa466d0faa33f8a810c72af45) +++ lams_common/src/java/org/lamsfoundation/lams/outcome/dao/IOutcomeDAO.java (.../IOutcomeDAO.java) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -22,8 +22,13 @@ package org.lamsfoundation.lams.outcome.dao; +import java.util.List; + import org.lamsfoundation.lams.dao.IBaseDAO; +import org.lamsfoundation.lams.outcome.Outcome; public interface IOutcomeDAO extends IBaseDAO { + String getContentFolderID(Integer organisationId); + List getOutcomesSortedByName(Integer organisationId); } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/outcome/dao/hibernate/OutcomeDAO.java =================================================================== diff -u -r7d7e4420720fa2caa466d0faa33f8a810c72af45 -r313e29d4010a35282a7c56dd24971e40b442dfb0 --- lams_common/src/java/org/lamsfoundation/lams/outcome/dao/hibernate/OutcomeDAO.java (.../OutcomeDAO.java) (revision 7d7e4420720fa2caa466d0faa33f8a810c72af45) +++ lams_common/src/java/org/lamsfoundation/lams/outcome/dao/hibernate/OutcomeDAO.java (.../OutcomeDAO.java) (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -22,10 +22,39 @@ package org.lamsfoundation.lams.outcome.dao.hibernate; +import java.util.List; + +import org.hibernate.Query; import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO; +import org.lamsfoundation.lams.outcome.Outcome; import org.lamsfoundation.lams.outcome.dao.IOutcomeDAO; import org.springframework.stereotype.Repository; @Repository public class OutcomeDAO extends LAMSBaseDAO implements IOutcomeDAO { + + private static final String FIND_CONTENT_FOLDER_ID_BY_ORGANISATION = "SELECT * FROM (SELECT content_folder_id FROM lams_outcome WHERE organisation_id ? " + + "UNION SELECT content_folder_id FROM lams_outcome_scale WHERE organisation_id ?) AS a WHERE content_folder_id IS NOT NULL LIMIT 1"; + + private static final String FIND_OUTCOMES_SORTED_BY_NAME = "FROM Outcome o WHERE o.organisation IS NULL ? ORDER BY o.name, o.code"; + + /** + * Finds an existing content folder ID for the given organisation outcomes or scales, or for global ones + */ + public String getContentFolderID(Integer organisationId) { + String queryString = FIND_CONTENT_FOLDER_ID_BY_ORGANISATION.replaceAll("\\?", + organisationId == null ? "IS NULL" : "=" + organisationId); + Query query = getSession().createSQLQuery(queryString); + return (String) query.uniqueResult(); + } + + /** + * Finds all global outcomes and ones for the given organisation + */ + @SuppressWarnings("unchecked") + public List getOutcomesSortedByName(Integer organisationId) { + String queryString = FIND_OUTCOMES_SORTED_BY_NAME.replaceAll("\\?", + organisationId == null ? "" : "OR o.organisation.organisationId = " + organisationId); + return find(queryString); + } } Index: lams_common/src/java/org/lamsfoundation/lams/outcome/service/IOutcomeService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/outcome/service/IOutcomeService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/outcome/service/IOutcomeService.java (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -0,0 +1,11 @@ +package org.lamsfoundation.lams.outcome.service; + +import java.util.List; + +import org.lamsfoundation.lams.outcome.Outcome; + +public interface IOutcomeService { + String getContentFolderId(Integer organisationId); + + List getOutcomesForManagement(Integer organisationId); +} Index: lams_common/src/java/org/lamsfoundation/lams/outcome/service/OutcomeService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/outcome/service/OutcomeService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/outcome/service/OutcomeService.java (revision 313e29d4010a35282a7c56dd24971e40b442dfb0) @@ -0,0 +1,24 @@ +package org.lamsfoundation.lams.outcome.service; + +import java.util.List; + +import org.lamsfoundation.lams.outcome.Outcome; +import org.lamsfoundation.lams.outcome.dao.IOutcomeDAO; +import org.lamsfoundation.lams.util.FileUtil; + +public class OutcomeService implements IOutcomeService { + private IOutcomeDAO outcomeDAO; + + public String getContentFolderId(Integer organisationId) { + String contentFolderId = outcomeDAO.getContentFolderID(organisationId); + return contentFolderId == null ? FileUtil.generateUniqueContentFolderID() : contentFolderId; + } + + public List getOutcomesForManagement(Integer organisationId) { + return outcomeDAO.getOutcomesSortedByName(organisationId); + } + + public void setOutcomeDAO(IOutcomeDAO outcomeDAO) { + this.outcomeDAO = outcomeDAO; + } +} \ No newline at end of file