Index: lams_admin/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -596,12 +596,11 @@ label.policy.status =Policy status label.version =Version label.last.modified =Last modified -label.agreements =Agreements +label.consents =Consents label.add.new.policy =Add a new policy label.policy.status.hint =An active policy will require consent from new users. Existing users will need to consent to this policy on their next log in. label.policy.status.active =Active label.policy.status.inactive =Inactive -label.policy.status.draft =Draft label.policy.type.site =Site policy label.policy.type.privacy =Privacy policy label.policy.type.third.party =Third party policy @@ -611,14 +610,14 @@ label.view.previous.versions =View previous versions label.set.status.to =Set status to "{0}" label.minor.change =Minor change +label.create.new.draft =Create a new draft +label.policy.consents =Policy consents +label.consented =Consented? +label.consented.on =Consented on +label.user.consents =User consents label. = label. = label. = label. = -label. = -label. = -label. = -label. = -label. = #======= End labels: Exported 582 labels for en AU ===== Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/PolicyManagementAction.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/PolicyManagementAction.java (.../PolicyManagementAction.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/PolicyManagementAction.java (.../PolicyManagementAction.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -5,6 +5,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -21,7 +22,9 @@ import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; +import org.lamsfoundation.lams.admin.web.dto.UserPolicyConsentDTO; import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.PolicyConsent; import org.lamsfoundation.lams.policies.service.IPolicyService; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -66,8 +69,8 @@ return edit(mapping, form, request, response); } else if (StringUtils.equals(method, "save")) { return save(mapping, form, request, response); - } else if (StringUtils.equals(method, "delete")) { - return delete(mapping, form, request, response); + } else if (StringUtils.equals(method, "displayUserConsents")) { + return displayUserConsents(mapping, form, request, response); } else if (StringUtils.equals(method, "viewPreviousVersions")) { return viewPreviousVersions(mapping, form, request, response); } else if (StringUtils.equals(method, "changeStatus")) { @@ -80,18 +83,18 @@ private ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - List policies = policyService.getPolicies(); + List policies = policyService.getAllPoliciesWithUserConsentsCount(); - //calculate which policies have previous version instanses - HashMap policyCount = new HashMap(); + //calculate which policies have previous version instances + HashMap policyCount = new LinkedHashMap(); for (Policy policy : policies) { Long policyId = policy.getPolicyId(); int previousVersionsCount = policyCount.get(policyId) == null ? 0 : policyCount.get(policyId); policyCount.put(policy.getPolicyId(), previousVersionsCount + 1); } //filter out older versioned policies - HashMap filteredPolicies = new HashMap(); + HashMap filteredPolicies = new LinkedHashMap(); for (Policy policy : policies) { Long policyId = policy.getPolicyId(); boolean hasPreviousVersions = policyCount.get(policyId) != null && policyCount.get(policyId) > 1; @@ -105,9 +108,8 @@ if (Policy.STATUS_ACTIVE.equals(policyStateId)) { filteredPolicies.put(policyId, policy); - //if both are inactive - newer has priority - } else if (Policy.STATUS_INACTIVE.equals(policyStateId) - && Policy.STATUS_INACTIVE.equals(alreadyAddedPolicy.getPolicyStateId()) + //if neither are active - newer has priority + } else if (!Policy.STATUS_ACTIVE.equals(alreadyAddedPolicy.getPolicyStateId()) && policy.getLastModified().after(alreadyAddedPolicy.getLastModified())) { filteredPolicies.put(policyId, policy); } @@ -128,6 +130,7 @@ HttpServletResponse response) { Long policyUid = WebUtil.readLongParam(request, "policyUid", true); + boolean isEditingPreviousVersion = WebUtil.readBooleanParam(request, "isEditingPreviousVersion", false); if (policyUid != null && policyUid > 0) { Policy policy = policyService.getPolicyByUid(policyUid); if (policy != null) { @@ -140,6 +143,7 @@ policyForm.set("policyTypeId", policy.getPolicyTypeId()); policyForm.set("version", policy.getVersion()); policyForm.set("policyStateId", policy.getPolicyStateId()); + policyForm.set("editingPreviousVersion", isEditingPreviousVersion); request.setAttribute("policyForm", policyForm); } } @@ -152,61 +156,69 @@ DynaActionForm policyForm = (DynaActionForm) form; String currentDate = ZonedDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE); -// ActionMessages errors = new ActionMessages(); -// -// // validate -// if (!StringUtils.equals(policyForm.getString("courseKey"), policyForm.getString("confirmCourseKey"))) { -// errors.add("courseKey", new ActionMessage("error.course.keys.unequal")); -// } -// if (policyService.contextExists((Integer) policyForm.get("signupOrganisationId"), -// policyForm.getString("context"))) { -// errors.add("context", new ActionMessage("error.context.exists")); -// } -// -// if (!errors.isEmpty()) { -// saveErrors(request, errors); -// } else { Object policyUid = policyForm.get("policyUid"); String version = policyForm.getString("version"); Integer policyStateId = (Integer) policyForm.get("policyStateId"); Boolean isMinorChange = (Boolean) policyForm.get("minorChange"); - + Boolean isEditingPreviousVersion = (Boolean) policyForm.get("editingPreviousVersion"); - Policy policy; - // edit existing policy - if (policyUid != null && (Long) policyUid > 0) { - policy = policyService.getPolicyByUid((Long) policyUid); - - //if it's not a minor change - then instantiate a new child policy - if (!isMinorChange) { - Policy oldPolicy = policy; + // edit existing policy only in case of minor change + if (isMinorChange) { + Policy oldPolicy = policyService.getPolicyByUid((Long) policyUid); + policy = oldPolicy; - //if the new policy has Active status then set the old one to Inactive - if (policyStateId.equals(Policy.STATUS_ACTIVE)) { - oldPolicy.setPolicyStateId(Policy.STATUS_INACTIVE); - oldPolicy.setLastModified(new Date()); - userManagementService.save(oldPolicy); - } + } else { + //if it's not a minor change - then instantiate a new child policy + policy = new Policy(); + //set policy's policyId + Long policyId; + if (policyUid != null && (Long) policyUid > 0) { + Policy oldPolicy = policyService.getPolicyByUid((Long) policyUid); + policyId = oldPolicy.getPolicyId(); + } else { + // generate Unique long ID + policyId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; + } + policy.setPolicyId(policyId); + + //set policy's version + if (policyUid != null && (Long) policyUid > 0) { + Policy oldPolicy = policyService.getPolicyByUid((Long) policyUid); //if version was not changed by the user - append current date if (oldPolicy.getVersion().equals(version)) { version += " " + currentDate; } + } - policy = new Policy(); - policy.setPolicyId(oldPolicy.getPolicyId()); + //take care about old policy/policies: if the new policy has Active status then set the old one(s) to Inactive + if (policyUid != null && (Long) policyUid > 0 && policyStateId.equals(Policy.STATUS_ACTIVE)) { + + if (isEditingPreviousVersion) { + List policyFamily = policyService.getPreviousVersionsPolicies(policyId); + for (Policy policyFromFamily : policyFamily) { + if (!policyFromFamily.getUid().equals(policyUid) + && Policy.STATUS_ACTIVE.equals(policyFromFamily.getPolicyStateId())) { + policyFromFamily.setPolicyStateId(Policy.STATUS_INACTIVE); + policyFromFamily.setLastModified(new Date()); + userManagementService.save(policyFromFamily); + } + } + + } else { + Policy oldPolicy = policyService.getPolicyByUid((Long) policyUid); + if (Policy.STATUS_ACTIVE.equals(oldPolicy.getPolicyStateId())) { + oldPolicy.setPolicyStateId(Policy.STATUS_INACTIVE); + oldPolicy.setLastModified(new Date()); + userManagementService.save(oldPolicy); + } + } } - - //create a new policy - } else { - policy = new Policy(); - // generate Unique long ID - Long policyId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; - policy.setPolicyId(policyId); + } - //set default version if it's empty + //set default version, if it's empty if (StringUtils.isEmpty(version)) { version = currentDate; } @@ -224,28 +236,44 @@ userManagementService.save(policy); return mapping.findForward("policyListMethod"); -// } - -// return mapping.findForward("editPolicy"); } - private ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, + private ActionForward displayUserConsents(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Long policyUid = WebUtil.readLongParam(request, "policyUid"); - if (policyUid != null && policyUid > 0) { - userManagementService.deleteById(Policy.class, policyUid); + Policy policy = policyService.getPolicyByUid(policyUid); + Set consents = policy.getConsents(); + request.setAttribute("policy", policy); + + List users = userManagementService.getAllUsers(); + LinkedList userPolicyConsents = new LinkedList(); + for (User user : users) { + UserPolicyConsentDTO userPolicyConsent = new UserPolicyConsentDTO(user.getUserId(), user.getFirstName(), user.getLastName(), user.getLogin()); + + for (PolicyConsent consent : consents) { + if (consent.getUser().getUserId().equals(user.getUserId())) { + userPolicyConsent.setConsentGivenByUser(true); + userPolicyConsent.setDateAgreedOn(consent.getDateAgreedOn()); + } + } + userPolicyConsents.add(userPolicyConsent); } + request.setAttribute("userPolicyConsents", userPolicyConsents); - return mapping.findForward("policyListMethod"); + return mapping.findForward("userConsents"); } private ActionForward viewPreviousVersions(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { long policyId = WebUtil.readLongParam(request, "policyId"); - List policies = policyService.getPreviousVersionsPolicies(policyId); - request.setAttribute("policies", policies); + List policyFamily = policyService.getPreviousVersionsPolicies(policyId); + //remove the first one from the list + if (policyFamily.size() > 1) { +// policyFamily.remove(policyFamily.size() - 1); + } + request.setAttribute("policies", policyFamily); int userCount = userManagementService.getCountUsers(); request.setAttribute("userCount", userCount); @@ -260,6 +288,6 @@ int newStatus = WebUtil.readIntParam(request, "newStatus"); policyService.changePolicyStatus(policyUid, newStatus); - return list(mapping, form, request, response); + return mapping.findForward("policyListMethod"); } } Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -62,7 +62,7 @@ links.add(new LinkBean("signupManagement.do", "admin.signup.title")); links.add(new LinkBean("serverlist.do", "sysadmin.maintain.external.servers")); links.add(new LinkBean("ltiConsumerManagement.do", "label.manage.tool.consumers")); - links.add(new LinkBean("policyManagement.do", "admin.policies.title")); + links.add(new LinkBean("policyManagement.do?method=list", "admin.policies.title")); links.add(new LinkBean("toolcontentlist.do", "sysadmin.tool.management")); links.add(new LinkBean("themeManagement.do", "admin.themes.title")); links.add(new LinkBean("sessionmaintain.do?method=list", "sysadmin.maintain.session")); Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/dto/UserPolicyConsentDTO.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/dto/UserPolicyConsentDTO.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/dto/UserPolicyConsentDTO.java (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -0,0 +1,37 @@ +package org.lamsfoundation.lams.admin.web.dto; + +import java.util.Date; + +import org.lamsfoundation.lams.usermanagement.dto.UserBasicDTO; + +/** + * Used for displaying which users consented to the policy. + * + * @author Andrey Balan + */ +public class UserPolicyConsentDTO extends UserBasicDTO { + private boolean isConsentGivenByUser; + + private Date dateAgreedOn; + + public UserPolicyConsentDTO(Integer userID, String firstName, String lastName, String login) { + super(userID, firstName, lastName, login); + } + + public void setConsentGivenByUser(boolean isConsentGivenByUser) { + this.isConsentGivenByUser = isConsentGivenByUser; + } + + public boolean isConsentGivenByUser() { + return isConsentGivenByUser; + } + + public Date getDateAgreedOn() { + return dateAgreedOn; + } + + public void setDateAgreedOn(Date dateAgreedOn) { + this.dateAgreedOn = dateAgreedOn; + } + +} Index: lams_admin/web/WEB-INF/struts-config.xml =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_admin/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_admin/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -170,6 +170,7 @@ + @@ -897,6 +898,11 @@ + Index: lams_admin/web/WEB-INF/tiles-defs.xml =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_admin/web/WEB-INF/tiles-defs.xml (.../tiles-defs.xml) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_admin/web/WEB-INF/tiles-defs.xml (.../tiles-defs.xml) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -252,13 +252,13 @@ - + - + Fisheye: Tag 4c134bb552fd30a24e610ddd532846ec38a3a51c refers to a dead (removed) revision in file `lams_admin/web/policies/edit.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/web/policies/editPolicy.jsp =================================================================== diff -u --- lams_admin/web/policies/editPolicy.jsp (revision 0) +++ lams_admin/web/policies/editPolicy.jsp (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -0,0 +1,143 @@ +<%@ include file="/taglibs.jsp"%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  *
: + + + + + + +
  * + + + +
  * + + + +
+   +
+   +
+ +
+
+ +
+ + + + + + + +
+ +
\ No newline at end of file Fisheye: Tag 4c134bb552fd30a24e610ddd532846ec38a3a51c refers to a dead (removed) revision in file `lams_admin/web/policies/list.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/web/policies/policies.jsp =================================================================== diff -u --- lams_admin/web/policies/policies.jsp (revision 0) +++ lams_admin/web/policies/policies.jsp (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -0,0 +1,164 @@ +<%@ include file="/taglibs.jsp"%> + + + + + + + + +

+ + + + + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${fn:length(policy.consents)}/${userCount} + + + + + + + + + + + + + + + + + + 2 + + + + 1 + + + +    + + + + + + + +    + + + + + + + + +
+ + + + + + Fisheye: Tag 4c134bb552fd30a24e610ddd532846ec38a3a51c refers to a dead (removed) revision in file `lams_admin/web/policies/previousVersionsList.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/web/policies/userConsents.jsp =================================================================== diff -u --- lams_admin/web/policies/userConsents.jsp (revision 0) +++ lams_admin/web/policies/userConsents.jsp (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -0,0 +1,82 @@ +<%@ include file="/taglibs.jsp"%> + + + + + + + + + + + +
+
+
+ +

+ +

+ + + + + + + + + + + + + + + +
+ : +

+ + + + + + + + + + + + + + +
 
+ + + + + + + + + + + + + + + + + - + + +
+ +
+
+
+ +
\ No newline at end of file Index: lams_central/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -r8f516ec9481b6ab34a5cd5e16fc3effc3115104e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_central/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 8f516ec9481b6ab34a5cd5e16fc3effc3115104e) +++ lams_central/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -804,6 +804,25 @@ authoring.error.application.exercise.not.blank.and.grade=Application Exercise {0} may not be blank and must have a grade. authoring.label.grade=Grade authoring.label.none=None + +label.policies.title=Policies +label.agree.to.policies.before.proceeding=Please agree to all the policies before proceeding +label.consent.required=Consent is required +label.agree.to.policy=I agree to the policy +label.policy.name =Policy name +label.policy.type =Policy type +label.policy.type.site =Site policy +label.policy.type.privacy =Privacy policy +label.policy.type.third.party =Third party policy +label.policy.type.other =Other policy +label.summary =Summary +label.full.policy =Full policy +label.consent =Consent +label.policies.consents =Policies and consents +label.version =Version +label.consented =Consented? +label.consented.on =Consented on + #=================== Specific to Team Based Learning (TBL) =========================# authoring.tbl.template.title=Team Based Learning Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java (.../IndexAction.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java (.../IndexAction.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -43,6 +43,7 @@ import org.lamsfoundation.lams.index.IndexLinkBean; import org.lamsfoundation.lams.integration.service.IIntegrationService; import org.lamsfoundation.lams.integration.service.IntegrationService; +import org.lamsfoundation.lams.policies.service.IPolicyService; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.Role; import org.lamsfoundation.lams.usermanagement.User; @@ -71,6 +72,7 @@ private static Logger log = Logger.getLogger(IndexAction.class); private static IUserManagementService userManagementService; private static IIntegrationService integrationService; + private static IPolicyService policyService; @Override @SuppressWarnings("unchecked") @@ -105,7 +107,7 @@ } // check if user needs to get his shared two-factor authorization secret - if (false) { + if (getPolicyService().isPolicyConsentRequiredForUser(loggedInUser.getUserId())) { return mapping.findForward("policyConsents"); } @@ -300,6 +302,14 @@ } return userManagementService; } + + private IPolicyService getPolicyService() { + if (policyService == null) { + policyService = (IPolicyService) WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()).getBean("policyService"); + } + return policyService; + } private static boolean isPedagogicalPlannerAvailable() { String lamsEarPath = Configuration.get(ConfigurationKeys.LAMS_EAR_DIR); Index: lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java =================================================================== diff -u -r6c8f36f8d99200afab3b0de708f89800cedea6f1 -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java (.../ProfileAction.java) (revision 6c8f36f8d99200afab3b0de708f89800cedea6f1) +++ lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java (.../ProfileAction.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -46,23 +46,27 @@ import org.lamsfoundation.lams.index.IndexOrgBean; import org.lamsfoundation.lams.learning.service.ICoreLearnerService; import org.lamsfoundation.lams.lesson.dto.LessonDTO; +import org.lamsfoundation.lams.policies.PolicyDTO; +import org.lamsfoundation.lams.policies.service.IPolicyService; import org.lamsfoundation.lams.themes.Theme; import org.lamsfoundation.lams.themes.service.IThemeService; import org.lamsfoundation.lams.timezone.Timezone; import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; import org.lamsfoundation.lams.timezone.service.ITimezoneService; -import org.lamsfoundation.lams.timezone.util.TimezoneDTOComparator; import org.lamsfoundation.lams.timezone.util.TimezoneIDComparator; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.OrganisationType; import org.lamsfoundation.lams.usermanagement.SupportedLocale; import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.IndexUtils; import org.lamsfoundation.lams.util.LanguageUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -82,6 +86,8 @@ private static IThemeService themeService; private static ITimezoneService timezoneService; + + private static IPolicyService policyService; public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -184,7 +190,17 @@ } return null; } + + public ActionForward policyConsents(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + Integer userId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); + List policyDtos = getPolicyService().getPolicyDtosByUser(userId); + request.setAttribute("policyDtos", policyDtos); + + return mapping.findForward("profilePolicyConsents"); + } + public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -289,4 +305,13 @@ } return timezoneService; } + + private IPolicyService getPolicyService() { + if (policyService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + policyService = (IPolicyService) wac.getBean("policyService"); + } + return policyService; + } } Index: lams_central/src/java/org/lamsfoundation/lams/web/action/PolicyConsentsAction.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_central/src/java/org/lamsfoundation/lams/web/action/PolicyConsentsAction.java (.../PolicyConsentsAction.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_central/src/java/org/lamsfoundation/lams/web/action/PolicyConsentsAction.java (.../PolicyConsentsAction.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -17,6 +17,8 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.PolicyConsent; +import org.lamsfoundation.lams.policies.PolicyDTO; import org.lamsfoundation.lams.policies.service.IPolicyService; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -33,7 +35,7 @@ import com.warrenstrange.googleauth.GoogleAuthenticatorQRGenerator; /** - * Shows policies user has to consent to. Also stores them once user agrees. + * Shows policies user has to consent to. Stores PolicyConsents once user agrees to them. * * @author Andrey Balan */ @@ -57,23 +59,36 @@ } String method = WebUtil.readStrParam(request, "method", true); - if (StringUtils.equals(method, "list") || isCancelled(request)) { + if (StringUtils.equals(method, "consent") || isCancelled(request)) { return consent(mapping, form, request, response); } - List policies = policyService.getActivePolicies(); - request.setAttribute("policies", policies); + Integer loggedUserId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); -// User loggedInUser = userManagementService.getUserByLogin(request.getRemoteUser()); + List policyDtos = policyService.getPolicyDtosByUser(loggedUserId); + request.setAttribute("policies", policyDtos); return mapping.findForward("policyConsents"); } private ActionForward consent(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + + UserDTO userDto = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + User user = userManagementService.getUserByLogin(userDto.getLogin()); + + List policyDtos = policyService.getPolicyDtosByUser(user.getUserId()); + //create all missing policy consents + for (PolicyDTO policyDto : policyDtos) { + if (!policyDto.isConsentedByUser()) { + PolicyConsent consent = new PolicyConsent(); + Policy policy = policyService.getPolicyByUid(policyDto.getUid()); + consent.setPolicy(policy); + consent.setUser(user); + userManagementService.save(consent); + } + } - DynaActionForm policyForm = (DynaActionForm) form; - // ActionMessages errors = new ActionMessages(); // // // validate @@ -88,66 +103,10 @@ // if (!errors.isEmpty()) { // saveErrors(request, errors); // } else { - Object policyUid = policyForm.get("policyUid"); - String version = policyForm.getString("version"); - Integer policyStateId = (Integer) policyForm.get("policyStateId"); - Boolean isMinorChange = (Boolean) policyForm.get("minorChange"); - Policy policy; - // edit existing policy -// if (policyUid != null && (Long) policyUid > 0) { -// policy = policyService.getPolicyByUid((Long) policyUid); -// -// //if it's not a minor change - then instantiate a new child policy -// if (!isMinorChange) { -// Policy oldPolicy = policy; -// -// //if the new policy has Active status then set the old one to Inactive -// if (policyStateId.equals(Policy.STATUS_ACTIVE)) { -// oldPolicy.setPolicyStateId(Policy.STATUS_INACTIVE); -// oldPolicy.setLastModified(new Date()); -// userManagementService.save(oldPolicy); -// } -// -// //if version was not changed by the user - append current date -// if (oldPolicy.getVersion().equals(version)) { -// version += " " + currentDate; -// } -// -// policy = new Policy(); -// policy.setPolicyId(oldPolicy.getPolicyId()); -// } -// -// //create a new policy -// } else { -// policy = new Policy(); -// // generate Unique long ID -// Long policyId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; -// policy.setPolicyId(policyId); -// } -// -// //set default version if it's empty -// if (StringUtils.isEmpty(version)) { -// version = currentDate; -// } -// policy.setVersion(version); -// policy.setSummary(policyForm.getString("summary")); -// policy.setFullPolicy(policyForm.getString("fullPolicy")); -// policy.setPolicyTypeId((Integer) policyForm.get("policyTypeId")); -// policy.setPolicyStateId(policyStateId); -// policy.setPolicyName(policyForm.getString("policyName")); -// //set created user -// Integer loggeduserId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); -// User createdBy = (User) userManagementService.findById(User.class, loggeduserId); -// policy.setCreatedBy(createdBy); -// policy.setLastModified(new Date()); -// userManagementService.save(policy); - return mapping.findForward("policyListMethod"); -// } - -// return mapping.findForward("editPolicy"); + return mapping.findForward("index"); } } Index: lams_central/web/WEB-INF/struts-config.xml =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_central/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_central/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -551,6 +551,11 @@ redirect="false" /> + + + +<%@ page contentType="text/html; charset=utf-8" language="java"%> +<%@ taglib uri="tags-html" prefix="html"%> +<%@ taglib uri="tags-core" prefix="c"%> +<%@ taglib uri="tags-bean" prefix="bean"%> +<%@ taglib uri="tags-logic" prefix="logic"%> +<%@ taglib uri="tags-fmt" prefix="fmt"%> +<%@ taglib uri="tags-lams" prefix="lams"%> - - - - - + + + <fmt:message key="label.policies.title" /> + + + + + + + + + + + + + +
+
+ +

+ +

+ + + + + +
+ + + + + + +
+
+ +
+ +
+ : + + + + + + + + + + + + + + +
+ + + +
+ + + + +
+ +
+
+
+ +
+ +
+ +
+ +
+ + + +
+
+ +
+
+ +
\ No newline at end of file Index: lams_central/web/profile.jsp =================================================================== diff -u -rc4604765c0116218e41964111ac33392757488b3 -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_central/web/profile.jsp (.../profile.jsp) (revision c4604765c0116218e41964111ac33392757488b3) +++ lams_central/web/profile.jsp (.../profile.jsp) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -86,6 +86,13 @@    + + + + +    + +<%@ page contentType="text/html; charset=utf-8" language="java"%> +<%@ taglib uri="tags-html" prefix="html"%> +<%@ taglib uri="tags-core" prefix="c"%> +<%@ taglib uri="tags-bean" prefix="bean"%> +<%@ taglib uri="tags-logic" prefix="logic"%> +<%@ taglib uri="tags-fmt" prefix="fmt"%> +<%@ taglib uri="tags-lams" prefix="lams"%> + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + + + + + + + + + + "> + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ " + onclick="javascript:document.location='index.do?method=profile'" /> +
+ +
+
+
+
+
+ +
Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/Policy.hbm.xml =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/Policy.hbm.xml (.../Policy.hbm.xml) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/Policy.hbm.xml (.../Policy.hbm.xml) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -50,7 +50,7 @@ name="consents" lazy="true" inverse="false" - cascade="all" + cascade="none" sort="unsorted" order-by="date_agreed_on asc" > Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20180528.sql =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20180528.sql (.../patch20180528.sql) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20180528.sql (.../patch20180528.sql) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -55,7 +55,6 @@ INSERT INTO lams_policy_state VALUES (1, 'ACTIVE'); INSERT INTO lams_policy_state VALUES (2, 'INACTIVE'); -INSERT INTO lams_policy_state VALUES (3, 'DRAFT'); INSERT INTO lams_policy_type VALUES (1, 'TYPE_SITE_POLICY'); INSERT INTO lams_policy_type VALUES (2, 'TYPE_PRIVACY_POLICY'); Index: lams_common/src/java/org/lamsfoundation/lams/policies/Policy.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_common/src/java/org/lamsfoundation/lams/policies/Policy.java (.../Policy.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_common/src/java/org/lamsfoundation/lams/policies/Policy.java (.../Policy.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -11,16 +11,14 @@ public static final Integer STATUS_ACTIVE = new Integer(1); /** inactive policy */ public static final Integer STATUS_INACTIVE = new Integer(2); - /** The state for draft policy */ - public static final Integer STATUS_DRAFT = new Integer(3); - /** active policy */ + /** site policy */ public static final Integer TYPE_SITE_POLICY = new Integer(1); - /** inactive policy */ + /** privacy policy */ public static final Integer TYPE_PRIVACY_POLICY = new Integer(2); - /** The state for draft policy */ + /** third party policy */ public static final Integer TYPE_THIRD_PARTIES_POLICY = new Integer(3); - /** The state for draft policy */ + /** other policy */ public static final Integer TYPE_OTHER = new Integer(4); /** identifier field */ @@ -59,6 +57,7 @@ // *************** NON Persistent Fields ******************** private boolean hasPreviousVersions; + private int userConsentsCount; /** default constructor */ public Policy() { @@ -161,4 +160,11 @@ return hasPreviousVersions; } + public void setUserConsentsCount(int userConsentsCount) { + this.userConsentsCount = userConsentsCount; + } + + public int getUserConsentsCount() { + return userConsentsCount; + } } Index: lams_common/src/java/org/lamsfoundation/lams/policies/PolicyDTO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/policies/PolicyDTO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/policies/PolicyDTO.java (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -0,0 +1,95 @@ +package org.lamsfoundation.lams.policies; + +import java.util.Date; + +public class PolicyDTO { + private Long uid; + + private String policyName; + + private String version; + + private Integer policyTypeId; + + private String summary; + + private String fullPolicy; + + private boolean isConsentedByUser; + + private Date dateAgreedOn; + + /** default constructor */ + public PolicyDTO(Policy policy) { + this.uid = policy.getUid(); + this.policyName = policy.getPolicyName(); + this.version = policy.getVersion(); + this.policyTypeId= policy.getPolicyTypeId(); + this.summary = policy.getSummary(); + this.fullPolicy= policy.getFullPolicy(); + } + + // --------------------------------------------------------------------- + // Getters and Setters + // --------------------------------------------------------------------- + public Long getUid() { + return uid; + } + + public void setUid(Long id) { + this.uid = id; + } + + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + + public Integer getPolicyTypeId() { + return this.policyTypeId; + } + + public void setPolicyTypeId(Integer policyTypeId) { + this.policyTypeId = policyTypeId; + } + + public String getSummary() { + return summary; + } + public void setSummary(String summary) { + this.summary = summary; + } + + public String getFullPolicy() { + return fullPolicy; + } + public void setFullPolicy(String fullPolicy) { + this.fullPolicy = fullPolicy; + } + + public void setConsentedByUser(boolean isConsentedByUser) { + this.isConsentedByUser = isConsentedByUser; + } + + public boolean isConsentedByUser() { + return isConsentedByUser; + } + + public Date getDateAgreedOn() { + return dateAgreedOn; + } + + public void setDateAgreedOn(Date dateAgreedOn) { + this.dateAgreedOn = dateAgreedOn; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/policies/dao/IPolicyDAO.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_common/src/java/org/lamsfoundation/lams/policies/dao/IPolicyDAO.java (.../IPolicyDAO.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_common/src/java/org/lamsfoundation/lams/policies/dao/IPolicyDAO.java (.../IPolicyDAO.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -26,17 +26,33 @@ import java.util.List; import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.PolicyConsent; +import org.lamsfoundation.lams.policies.PolicyDTO; public interface IPolicyDAO { Policy getPolicyByUid(Long uid); - List getPolicies(); + List getAllPoliciesWithUserConsentsCount(); - List getActivePolicies(); + List getPreviousVersionsPolicies(Long policyId); - List getActivePoliciesWithConsents(); + boolean isPolicyConsentRequiredForUser(Integer userId); - List getPreviousVersionsPolicies(Long policyId); + /** + * Return all active policies with indication which one of them has been consented by the user. + * + * @param userId + * @return + */ + List getPolicyDtosByUser(Integer userId); + + /** + * Return all consents user has given. + * + * @param userId + * @return + */ + List getConsentsByUserId(Integer userId); } Index: lams_common/src/java/org/lamsfoundation/lams/policies/dao/hibernate/PolicyDAO.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_common/src/java/org/lamsfoundation/lams/policies/dao/hibernate/PolicyDAO.java (.../PolicyDAO.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_common/src/java/org/lamsfoundation/lams/policies/dao/hibernate/PolicyDAO.java (.../PolicyDAO.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -1,12 +1,20 @@ package org.lamsfoundation.lams.policies.dao.hibernate; +import java.util.Date; +import java.util.LinkedList; import java.util.List; +import org.hibernate.Query; +import org.hibernate.SQLQuery; import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO; import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.PolicyConsent; +import org.lamsfoundation.lams.policies.PolicyDTO; import org.lamsfoundation.lams.policies.dao.IPolicyDAO; import org.springframework.stereotype.Repository; +import com.sun.webkit.PolicyClient; + @Repository public class PolicyDAO extends LAMSBaseDAO implements IPolicyDAO { @@ -16,25 +24,88 @@ } @Override - public List getPolicies() { - return super.findAll(Policy.class); + public List getAllPoliciesWithUserConsentsCount() { + final String LOAD_POLICIES_WITH_CONSENTS_COUNT = "SELECT policy.*, COUNT(policyConsent.uid) AS userConsentsCount " + + "FROM lams_policy AS policy " + + "LEFT JOIN lams_policy_consent AS policyConsent ON policyConsent.policy_uid = policy.uid " + + "GROUP BY policy.uid ORDER BY policy.last_modified ASC"; + + SQLQuery query = getSession().createSQLQuery(LOAD_POLICIES_WITH_CONSENTS_COUNT); + query.addEntity(Policy.class); + query.addScalar("userConsentsCount"); + List resultQuery = query.list(); + + // this map keeps the insertion order + LinkedList policies = new LinkedList(); + // make the result easier to process + for (Object[] entry : resultQuery) { + Policy policy = (Policy) entry[0]; + int userConsentsCount = ((Number) entry[1]).intValue(); + policy.setUserConsentsCount(userConsentsCount); + + policies.add(policy); + } + return policies; } @Override - public List getActivePolicies() { - String query = "from Policy p where p.policyStateId=1 GROUP BY p.policyId "; - return (List) doFind(query); + public List getPreviousVersionsPolicies(Long policyId) { + String query = "from Policy p where p.policyId=? ORDER BY p.lastModified ASC"; + return (List) doFind(query, policyId); } @Override - public List getActivePoliciesWithConsents() { - String query = "from Policy p where p.policyStateId=1 GROUP BY p.policyId "; - return (List) doFind(query); + public boolean isPolicyConsentRequiredForUser(Integer userId) { + String SQL = "SELECT count(*) FROM lams_policy as policy" + + " LEFT JOIN lams_policy_consent as policyConsent" + + " ON policy.uid = policyConsent.policy_uid AND policyConsent.user_id = :userId" + + " WHERE policyConsent.uid IS NULL AND policy.policy_state_id=1"; + + Query query = getSession().createSQLQuery(SQL); + query.setInteger("userId", userId); + Object value = query.uniqueResult(); + int result = ((Number) value).intValue(); + + return result > 0; } @Override - public List getPreviousVersionsPolicies(Long policyId) { - String query = "from Policy p where p.policyId=? and p.policyStateId=2"; - return (List) doFind(query, policyId); + public List getPolicyDtosByUser(Integer userId) { + final String LOAD_POLICIES_WITH_USER_CONSENTS = "SELECT policy.*, policyConsent.uid IS NOT NULL as isConsentedByUser, policyConsent.date_agreed_on as dateAgreedOn " + + "FROM lams_policy AS policy " + + "LEFT JOIN lams_policy_consent AS policyConsent ON policyConsent.policy_uid = policy.uid AND policyConsent.user_id = :userId " + + "WHERE policy.policy_state_id=1"; + + SQLQuery query = getSession().createSQLQuery(LOAD_POLICIES_WITH_USER_CONSENTS); + query.addEntity(Policy.class); + query.addScalar("isConsentedByUser"); + query.addScalar("dateAgreedOn"); + query.setInteger("userId", userId); + List resultQuery = query.list(); + + // this map keeps the insertion order + LinkedList policyDtos = new LinkedList(); + // make the result easier to process + for (Object[] entry : resultQuery) { + Policy policy = (Policy) entry[0]; + + PolicyDTO policyDto = new PolicyDTO(policy); + + boolean isConsentedByUser = ((Number) entry[1]).intValue() == 1; + policyDto.setConsentedByUser(isConsentedByUser); + + Date dateAgreedOn = (Date) entry[2]; + policyDto.setDateAgreedOn(dateAgreedOn); + + policyDtos.add(policyDto); + } + return policyDtos; } + + @Override + public List getConsentsByUserId(Integer userId) { + String query = "from PolicyConsent consent where consent.user.userId=? ORDER BY consent.dateAgreedOn ASC"; + return (List) doFind(query, userId); + } + } Index: lams_common/src/java/org/lamsfoundation/lams/policies/service/IPolicyService.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_common/src/java/org/lamsfoundation/lams/policies/service/IPolicyService.java (.../IPolicyService.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_common/src/java/org/lamsfoundation/lams/policies/service/IPolicyService.java (.../IPolicyService.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -26,18 +26,48 @@ import java.util.List; import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.PolicyConsent; +import org.lamsfoundation.lams.policies.PolicyDTO; public interface IPolicyService { void storeUserConsent(String login, Long policyUid); Policy getPolicyByUid(Long uid); - List getPolicies(); + /** + * Return all active policies together with how many users have consented to each of them + * + * @return + */ + List getAllPoliciesWithUserConsentsCount(); - List getActivePolicies(); - List getPreviousVersionsPolicies(Long policyId); + boolean isPolicyConsentRequiredForUser(Integer userId); + + /** + * Return all active policies together with indication which one of them has been consented by the user. + * + * @param userId + * @return + */ + List getPolicyDtosByUser(Integer userId); + + /** + * Return all consents user has given. + * + * @param userId + * @return + */ + List getConsentsByUserId(Integer userId); + + /** + * Changes policy status as set by the admin. In case of deactivating policy, it also removes all associated + * consents. + * + * @param policyUid + * @param newPolicyStatus + */ void changePolicyStatus(Long policyUid, Integer newPolicyStatus); } Index: lams_common/src/java/org/lamsfoundation/lams/policies/service/PolicyService.java =================================================================== diff -u -r52ed825cf80fc4c9f1b9e114c80b09913e86002e -r4c134bb552fd30a24e610ddd532846ec38a3a51c --- lams_common/src/java/org/lamsfoundation/lams/policies/service/PolicyService.java (.../PolicyService.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) +++ lams_common/src/java/org/lamsfoundation/lams/policies/service/PolicyService.java (.../PolicyService.java) (revision 4c134bb552fd30a24e610ddd532846ec38a3a51c) @@ -1,30 +1,19 @@ package org.lamsfoundation.lams.policies.service; -import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.util.Set; -import org.apache.commons.lang.StringUtils; -import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.service.ILessonService; import org.lamsfoundation.lams.policies.Policy; import org.lamsfoundation.lams.policies.PolicyConsent; +import org.lamsfoundation.lams.policies.PolicyDTO; import org.lamsfoundation.lams.policies.dao.IPolicyDAO; -import org.lamsfoundation.lams.signup.dao.ISignupDAO; -import org.lamsfoundation.lams.signup.model.SignupOrganisation; -import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; -import org.lamsfoundation.lams.usermanagement.Role; -import org.lamsfoundation.lams.usermanagement.SupportedLocale; +import org.lamsfoundation.lams.usermanagement.OrganisationState; +import org.lamsfoundation.lams.usermanagement.OrganisationType; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; -import org.lamsfoundation.lams.util.Configuration; -import org.lamsfoundation.lams.util.ConfigurationKeys; -import org.lamsfoundation.lams.util.LanguageUtil; public class PolicyService implements IPolicyService { @@ -52,23 +41,48 @@ public void changePolicyStatus(Long policyUid, Integer newPolicyStatus) { Policy policy = policyDAO.getPolicyByUid(policyUid); policy.setPolicyStateId(newPolicyStatus); + policy.setLastModified(new Date()); userManagementService.save(policy); + +// //remove according user consents +// if (Policy.STATUS_INACTIVE.equals(newPolicyStatus) || Policy.STATUS_DRAFT.equals(newPolicyStatus)) { +// HashMap properties = new HashMap(); +// properties.put("policy.uid", policyUid); +// List consents = userManagementService.findByProperties(PolicyConsent.class, properties); +// +// Iterator iter = consents.iterator(); +// while (iter.hasNext()) { +// PolicyConsent consent = iter.next(); +// userManagementService.delete(consent); +// iter.remove(); +// } +// } } @Override - public List getPolicies() { - return policyDAO.getPolicies(); + public List getAllPoliciesWithUserConsentsCount() { + return policyDAO.getAllPoliciesWithUserConsentsCount(); } @Override - public List getActivePolicies() { - return policyDAO.getActivePolicies(); + public List getPreviousVersionsPolicies(Long policyId) { + return policyDAO.getPreviousVersionsPolicies(policyId); } @Override - public List getPreviousVersionsPolicies(Long policyId) { - return policyDAO.getPreviousVersionsPolicies(policyId); + public boolean isPolicyConsentRequiredForUser(Integer userId) { + return policyDAO.isPolicyConsentRequiredForUser(userId); } + + @Override + public List getPolicyDtosByUser(Integer userId) { + return policyDAO.getPolicyDtosByUser(userId); + } + + @Override + public List getConsentsByUserId(Integer userId) { + return policyDAO.getConsentsByUserId(userId); + } public void setPolicyDAO(IPolicyDAO policyDAO) { this.policyDAO = policyDAO;