List of usage examples for org.joda.time DateTime withZone
public DateTime withZone(DateTimeZone newZone)
From source file:com.infotree.qliktest.admin.web.controller.ModuleProjectController.java
/** * This method is to save the modules list to the project *///w ww . j a va 2s .co m @RequestMapping(value = "/saveassignmodulelist", method = RequestMethod.POST) public String saveAssignedModules(@Valid ProjectModulePojo entity, BindingResult bindingResult, Model model, HttpServletRequest request) { try { //Deleting the existing records projectModuleService.deleteByProjectId(entity.getProjectId()); List<Integer> moduleId = entity.getModuleId(); Iterator<Integer> iterator = moduleId.iterator(); while (iterator.hasNext()) { ProjectModule md = new ProjectModule(); ProjectModuleComp modperComp = new ProjectModuleComp(); modperComp.setProjectId(entity.getProjectId()); modperComp.setModuleId(iterator.next()); md.setProjectModuleComp(modperComp); md.setCreatedBy(entity.getCreatedBy()); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata"); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); md.setCreatedDate(dateInIndia); md.setModifiedBy(entity.getModifiedBy()); md.setModifiedDate(dateInIndia); projectModuleService.save(md); } AuditLogRecord record = new AuditLogRecord(); record.setActionDate(new java.util.Date()); record.setActionType(AuditType.ASSIGN); Project p = projectService.getById(entity.getProjectId()); record.setActionData("Module and project name is" + p.getName()); record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString()); /*try { InetAddress inetAddress = InetAddress.getLocalHost(); record.setIpOrigin(inetAddress.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }*/ record.setUserId((Integer) request.getSession().getAttribute("userid")); record.setUserName(request.getSession().getAttribute("username").toString()); auditLogService.saveRecord(record); model.addAttribute("assignmodulestoproject", "assignmodulestoproject"); model.addAttribute("modulesassigned", "Modules Assigned For Project"); model.addAttribute("module_list", moduleService.list()); model.addAttribute("crudObj", new ProjectModulePojo()); model.addAttribute("project_list", projectService.getActiveProjects()); } catch (Exception e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.infotree.qliktest.admin.web.controller.ProjectController.java
/** * This method is to save the new projects *///w w w .j a v a 2 s . co m @RequestMapping(value = "/save", method = RequestMethod.POST) public String saveProject(@ModelAttribute("crudObj") @Valid Project entity, BindingResult bindingResult, Model model, HttpServletRequest request) { try { /*DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata"); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate();*/ Locale clientLocale = request.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); String clientZone = clientTimeZone.getID(); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID(clientZone); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); model.addAttribute("crudObj", getEntityInstance()); if (projectService.findByName(entity.getName()) != null) { model.addAttribute("createproject", "createproject"); model.addAttribute("project_list", projectService.list()); //model.addAttribute("active_project_list", projectService.getActiveProjects()); model.addAttribute("active_project_list", projectService.list()); model.addAttribute("projectalreadyexists", "'" + entity.getName() + "' already exists. Pl. enter a different Name."); } else { Notifications notifications = new Notifications(); Project p = new Project(); p.setName(entity.getName().trim()); p.setStartDate(entity.getStartDate()); p.setEndDate(entity.getEndDate()); p.setDisabled(false); p.setDescription(entity.getDescription()); p.setCreatedBy(entity.getCreatedBy()); p.setCreatedDate(dateInIndia); if (projectService.save(p) == null) { model.addAttribute("createproject", "createproject"); model.addAttribute("project_list", projectService.list()); model.addAttribute("projectsnotselected", "Error in creating Module. Pl. contact Sys Admin."); } else { /** * save the project to the tenant */ ProjectTenant projectTenant = new ProjectTenant(); ProjectTenantComp projectTenantComp = new ProjectTenantComp(); projectTenantComp.setProjectId(p.getId()); projectTenantComp.setTenantId(entity.getTenantId()); projectTenant.setProjectTenantComp(projectTenantComp); projectTenant.setCreatedBy(entity.getCreatedBy()); projectTenant.setCreatedDate(dateInIndia); projectTenant.setModifiedBy(entity.getModifiedBy()); projectTenant.setModifiedDate(dateInIndia); try { projectTenantService.insertNewProjectTenantEntity(projectTenant); } catch (Exception e1) { e1.printStackTrace(); } /** * assigning the modules to the project */ List<Integer> moduleList = entity.getModuleId(); if (moduleList != null) { Iterator<Integer> iterator = moduleList.iterator(); while (iterator.hasNext()) { ProjectModule projectModule = new ProjectModule(); ProjectModuleComp projectModuleComp = new ProjectModuleComp(); projectModuleComp.setProjectId(p.getId()); projectModuleComp.setModuleId(iterator.next()); projectModule.setProjectModuleComp(projectModuleComp); projectModule.setCreatedBy(entity.getCreatedBy()); projectModule.setCreatedDate(dateInIndia); projectModule.setModifiedBy(entity.getModifiedBy()); projectModule.setModifiedDate(dateInIndia); projectModuleService.save(projectModule); } } /** * Preparing the notification for the application admin */ UserTenant userTenant = userTenantService.findByTenantIdAndCreatedBy(entity.getTenantId(), (Integer) request.getSession().getAttribute("userid")); notifications.setId(notificationsDao.getMaxId() + 1); notifications.setAssignedBy((Integer) request.getSession().getAttribute("userid") + ""); notifications.setAssignedTo(userTenant.getUserTenantComp().getUserId() + ""); notifications.setAssignedData(p.getName() + " Assigned for you"); notifications.setStatus("UnRead"); notifications.setCreatedBy(entity.getCreatedBy()); notifications.setModifiedBy(entity.getModifiedBy()); notifications.setCreatedDate(dateInIndia); notifications.setModifiedDate(dateInIndia); notificationsDao.saveNotification(notifications); /** * preparing the audit record */ AuditLogRecord record = new AuditLogRecord(); record.setActionDate(dateInIndia); record.setActionType(AuditType.CREATE); record.setActionPerformed("Project Created with Name " + entity.getName()); record.setActionData("Project Name :" + entity.getName() + " start date is :" + entity.getStartDate() + " end date is" + entity.getEndDate()); record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString()); /*try { java.net.InetAddress inetAddress = java.net.InetAddress.getLocalHost(); record.setIpOrigin(inetAddress.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }*/ record.setUserId((Integer) request.getSession().getAttribute("userid")); record.setUserName(request.getSession().getAttribute("username").toString()); auditLogService.saveRecord(record); model.addAttribute("createproject", "createproject"); model.addAttribute("project_list", projectService.list()); model.addAttribute("module_list", moduleService.list()); model.addAttribute("tenant_list", tenantService.list()); //model.addAttribute("active_project_list", projectService.getActiveProjects()); model.addAttribute("active_project_list", projectService.list()); model.addAttribute("projectcreated", "'" + entity.getName() + "' created."); } } } catch (Exception e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.infotree.qliktest.admin.web.controller.ProjectController.java
/** * Thie method is to update the project/* w w w. ja v a2s . com*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String updateProject(@ModelAttribute("crudObj") @Valid Project entity, BindingResult bindingResult, Model model, HttpServletRequest request) { //System.out.println("Time in Project: "+entity.getCreatedDate()+" , @: "+entity.getModifiedDate()); try { /*DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata"); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate();*/ Locale clientLocale = request.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); String clientZone = clientTimeZone.getID(); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID(clientZone); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); Project p = projectService.getById(entity.getId()); if (p == null) { model.addAttribute("createproject", "createproject"); //model.addAttribute("project_list", projectService.getActiveProjects()); model.addAttribute("project_list", projectService.list()); model.addAttribute("projectcreated", "Data cannot be saved. Pl. try again."); } else { p.setName(entity.getName().trim()); p.setStartDate(entity.getStartDate()); p.setEndDate(entity.getEndDate()); p.setDisabled(false); p.setModifiedBy(entity.getModifiedBy()); p.setModifiedDate(dateInIndia); super.save(p, bindingResult, model); /** * preparing the audit log service */ AuditLogRecord record = new AuditLogRecord(); record.setActionDate(dateInIndia); record.setActionType(AuditType.MODIFY); record.setActionData("after updation Project Name :" + entity.getName() + "start date is :" + entity.getStartDate() + " end date is" + entity.getEndDate()); record.setActionPerformed("Project updated with name " + entity.getName()); record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString()); /*try { InetAddress inetAddress = InetAddress.getLocalHost(); record.setIpOrigin(inetAddress.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }*/ record.setUserId((Integer) request.getSession().getAttribute("userid")); record.setUserName(request.getSession().getAttribute("username").toString()); auditLogService.saveRecord(record); //delete the existing modules which were already assigned to the project projectModuleService.deleteByProjectId(entity.getId()); /** * assigning the licenses to the project */ List<Integer> moduleList = entity.getModuleId(); if (moduleList != null) { Iterator<Integer> iterator = moduleList.iterator(); while (iterator.hasNext()) { ProjectModule md = new ProjectModule(); ProjectModuleComp modperComp = new ProjectModuleComp(); modperComp.setProjectId(entity.getId()); modperComp.setModuleId(iterator.next()); md.setProjectModuleComp(modperComp); md.setCreatedBy(entity.getCreatedBy()); md.setCreatedDate(dateInIndia); md.setModifiedBy(entity.getModifiedBy()); md.setModifiedDate(dateInIndia); projectModuleService.save(md); } } model.addAttribute("editproject", "editproject"); model.addAttribute("projectupdated", "'" + entity.getName() + "' updated."); } //List<Project> projList = projectService.getActiveProjects(); List<Project> projList = projectService.list(); List<Project> projectsList = new ArrayList<Project>(); if (projList != null) { Iterator<Project> iterator = projList.iterator(); while (iterator.hasNext()) { Project proj = iterator.next(); if (proj.getModifiedBy() != null) { Integer id = Integer.parseInt(proj.getModifiedBy()); User u = userService.getById(id); proj.setCreatedName(u.getUserName()); } else { Integer id = Integer.parseInt(proj.getCreatedBy()); User u = userService.getById(id); proj.setCreatedName(u.getUserName()); } projectsList.add(proj); } } model.addAttribute("tenantname_list", tenantService.list()); model.addAttribute("project_list", projectsList); //model.addAttribute("projectname_list", projectService.getActiveProjects()); model.addAttribute("projectname_list", projectService.list()); model.addAttribute("crudObj", getEntityInstance()); entity.setEndDate(null); entity.setStartDate(null); } catch (NumberFormatException e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.infotree.qliktest.admin.web.controller.ReportsController.java
License:Open Source License
/** * This method returns the users related reports * projectService.getProjectsByUserId(userTenant.getUserTenantComp().getTenantId()) *//*from w w w . ja va2s . c om*/ @RequestMapping(value = "/userreports", method = RequestMethod.GET) public String userReports(Model model, HttpServletRequest request) { try { model.addAttribute("crudObj", new UserReports()); List<Project> projList = new ArrayList<Project>(); List<UserReports> userReports = new ArrayList<UserReports>(); List<User> userlist = userService .getUsersBasedOnCreatedBy((Integer) request.getSession().getAttribute("userid")); if (userlist != null) { Iterator<User> itr1 = userlist.iterator(); try { while (itr1.hasNext()) { User u = itr1.next(); UserReports reports = new UserReports(); reports.setFirstName(u.getFirstName()); reports.setLastName(u.getSurName()); if (u.getDisabled() == 0) { reports.setActive("Yes"); } else { reports.setActive("No"); } if (u.getImportedFromLdap() == 0) { reports.setImported("No"); } else if (u.getImportedFromLdap() == 1) { reports.setImported("Yes"); } List<UserRole> role = userRoleService.getByUserId(u.getId()); String userrole = ""; if (role != null) { Iterator<UserRole> itr = role.iterator(); while (itr.hasNext()) { UserRole userRole = itr.next(); String r = roleService.getNameById(userRole.getUserRoleComp().getRoleId()); if (userrole == "") { userrole = r; } else { userrole = userrole + "," + r; } } } reports.setRole(userrole); List<UserProject> userProject = userProjectService.getByUserId(u.getId()); String userprojects = ""; if (userProject != null) { Iterator<UserProject> userprojitr = userProject.iterator(); while (userprojitr.hasNext()) { UserProject projects = userprojitr.next(); Project proj = projectService.getById(projects.getUserProjectComp().getProjectId()); if (userprojects.equals("")) { userprojects = proj.getName(); } else { userprojects = userprojects + "," + proj.getName(); } } } reports.setProjects(userprojects); List<UserTeam> userTeamList = userTeamService.findByUserId(u.getId()); String userTeamReport = ""; if (userTeamList != null) { Iterator<UserTeam> userTeamItr = userTeamList.iterator(); while (userTeamItr.hasNext()) { UserTeam userTeam = userTeamItr.next(); Team team = teamService.getById(userTeam.getUserTeamComp().getTeamId()); if (userTeamReport.equals("") && team != null) { userTeamReport = team.getName(); } else if (team != null) { userTeamReport = userTeamReport + "," + team.getName(); } } } reports.setTeam(userTeamReport); userReports.add(reports); } } catch (Exception e) { e.printStackTrace(); } } model.addAttribute("user_list", userReports); List<UserProject> projects = userProjectService .getByUserId((Integer) request.getSession().getAttribute("userid")); if (projects != null) { Iterator<UserProject> itr = projects.iterator(); while (itr.hasNext()) { UserProject userProj = itr.next(); projList.add(projectService.getById(userProj.getUserProjectComp().getProjectId())); } } model.addAttribute("team_list", teamService.getTeamsById((Integer) request.getSession().getAttribute("userid") + "")); List<Role> list = roleService.list(); List<Role> rolelist = new ArrayList<Role>(); if (list != null) { Iterator<Role> itrRole = list.iterator(); while (itrRole.hasNext()) { Role r = itrRole.next(); if (!r.getName().equalsIgnoreCase("System Administrator")) { if (!r.getName().equalsIgnoreCase("Application Administrator")) { rolelist.add(r); } } } } HttpSession session = request.getSession(); Integer id = (Integer) session.getAttribute("userid"); UserTenant userTenant = userTenantService.findByUserId(id); model.addAttribute("project_list", projectService.getProjectsByUserId(userTenant.getUserTenantComp().getTenantId())); /*model.addAttribute("viewrole","viewrole");*/ model.addAttribute("role_list", rolelist); //model.addAttribute("project_list",projectService.list()); model.addAttribute("userreports", "userreports"); Locale clientLocale = request.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); String clientZone = clientTimeZone.getID(); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID(clientZone); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); AuditLogRecord record = new AuditLogRecord(); record.setActionDate(dateInIndia); record.setActionData("Viewed the users reports"); record.setActionType(AuditType.VIEW); record.setActionPerformed("Viewed the users reports"); record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString()); /*try { InetAddress inetAddress = InetAddress.getLocalHost(); record.setIpOrigin(inetAddress.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }*/ record.setUserId((Integer) request.getSession().getAttribute("userid")); record.setUserName(request.getSession().getAttribute("username").toString()); auditRecordService.saveRecord(record); } catch (Exception e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.infotree.qliktest.admin.web.controller.ReportsController.java
License:Open Source License
/** * This method returns the teams related reports *///from w ww . j av a2s . c om @RequestMapping(value = "/teamsreports", method = RequestMethod.GET) public String teamsReports(Model model, HttpServletRequest request) { try { model.addAttribute("crudObj", new TeamReports()); List<Project> projList = new ArrayList<Project>(); List<User> listusers = new ArrayList<User>(); List<TeamReports> teamReports = new ArrayList<TeamReports>(); List<Team> teamsList = teamService .getTeamsById((Integer) request.getSession().getAttribute("userid") + ""); if (teamsList != null) { Iterator<Team> teamsItr = teamsList.iterator(); while (teamsItr.hasNext()) { String users = ""; String projects = ""; TeamReports teams = new TeamReports(); Team team = teamsItr.next(); teams.setTeamName(team.getName()); int count = userTeamService.getNoOfUsers(team.getId()); if (count == 0) { teams.setTeamCount(count); users = "No Users Available"; } else { teams.setTeamCount(userTeamService.getNoOfUsers(team.getId())); } if (!(count == 0)) { listusers = userService.getUsersByTeamId(team.getId()); Iterator<User> iter = listusers.iterator(); while (iter.hasNext()) { User u = iter.next(); if (users == "") users = users + u.getFirstName(); else users = users + " " + "<br>" + u.getFirstName(); } } List<TeamProject> projectList = teamProjectService.getProjectsByTeamId(team.getId()); if (projectList != null) { Iterator<TeamProject> itr = projectList.iterator(); while (itr.hasNext()) { TeamProject teamproj = itr.next(); Project p = projectService.getById(teamproj.getTeamProjId().getProjectId()); if (projects.equals("")) { projects = projects + p.getName(); } else { projects = projects + "," + p.getName(); } } } Locale clientLocale = request.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); String clientZone = clientTimeZone.getID(); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID(clientZone); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); AuditLogRecord record = new AuditLogRecord(); record.setActionDate(dateInIndia); record.setActionData("Viewed the Teams Reports"); record.setActionType(AuditType.VIEW); record.setActionPerformed("Viewed the Teams Reports"); record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString()); /*try { InetAddress inetAddress = InetAddress.getLocalHost(); record.setIpOrigin(inetAddress.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }*/ record.setUserId((Integer) request.getSession().getAttribute("userid")); record.setUserName(request.getSession().getAttribute("username").toString()); auditRecordService.saveRecord(record); teams.setProjects(projects); teams.setUserName( "<center><table width=70% border=1><tr><th><center>User Names</center></th></tr><tr><td><center>" + users + "</center></td></tr></table></center>"); teamReports.add(teams); } } List<UserProject> projectList = userProjectService .getByUserId((Integer) request.getSession().getAttribute("userid")); if (projectList != null) { Iterator<UserProject> itr = projectList.iterator(); while (itr.hasNext()) { UserProject userProj = itr.next(); projList.add(projectService.getById(userProj.getUserProjectComp().getProjectId())); } } List<Role> rolelist = new ArrayList<Role>(); List<Role> list = roleService.list(); if (list != null) { Iterator<Role> itrRole = list.iterator(); while (itrRole.hasNext()) { Role r = itrRole.next(); Role r1 = new Role(); r1.setId(r.getId()); r1.setDescription(r.getDescription()); r1.setCreatedBy("1"); r1.setName(r.getName()); rolelist.add(r1); } } List<Project> projs = new ArrayList<Project>(); UserTenant ut = userTenantService.findByUserId((Integer) request.getSession().getAttribute("userid")); List<ProjectTenant> projTenant = projectTenantService .getByTenantId(ut.getUserTenantComp().getTenantId()); if (projTenant != null) { Iterator<ProjectTenant> projTenantItr = projTenant.iterator(); while (projTenantItr.hasNext()) { ProjectTenant pt = projTenantItr.next(); Project p = projectService.getById(pt.getProjectTenantComp().getProjectId()); projs.add(p); } } model.addAttribute("project_list", projs); List<Role> rolesList = roleService.list(); List<Role> newRoleList = new ArrayList<Role>(); for (Role role : rolesList) { if (!role.getName().equalsIgnoreCase("System Administrator")) { if (!role.getName().equalsIgnoreCase("Application Administrator")) { newRoleList.add(role); } } } model.addAttribute("role_list", newRoleList); model.addAttribute("team_list", teamReports); model.addAttribute("teamsreports", "teamsreports"); } catch (Exception e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.infotree.qliktest.admin.web.controller.ReportsController.java
License:Open Source License
/** * This method is used to save the other reports *///from ww w . j a va 2 s .c om @RequestMapping(value = "/savedashboardreports", method = RequestMethod.POST) public String save(@Valid DashBoardReports entity, BindingResult bindingResult, Model model, HttpServletRequest request) { try { /*DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata"); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate();*/ Locale clientLocale = request.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); String clientZone = clientTimeZone.getID(); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID(clientZone); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); DashBoardReports dashBoard = new DashBoardReports(); DashBoardReports report = reportsService.findByName(entity.getName()); Integer userid = (Integer) request.getSession().getAttribute("userid"); if (report != null) { model.addAttribute("reportupdated", "Report Name Already Exists"); } else { dashBoard.setId(entity.getId()); dashBoard.setName(entity.getName()); dashBoard.setDisplayname(entity.getDisplayname()); dashBoard.setDescription(entity.getDescription()); //dashBoard.setCreatedBy(entity.getCreatedBy()); dashBoard.setCreatedBy(userid.toString()); dashBoard.setCreatedDate(dateInIndia); dashBoard.setModifiedBy(entity.getModifiedBy()); dashBoard.setModifiedDate(dateInIndia); reportsService.save(dashBoard); if (reportsService.save(dashBoard) == null) { model.addAttribute("reportupdated", "Report Saved Successfully"); } else { model.addAttribute("reportupdated", "Report Saved Successfully"); } } model.addAttribute("crudObj", new DashBoardReports()); model.addAttribute("other_reports", reportsService.getOtherReports()); model.addAttribute("otherreports", "otherreports"); } catch (Exception e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.infotree.qliktest.admin.web.controller.RoleModuleController.java
/** * This method is used to save the roles to the modules *//* ww w. j a va2s . com*/ @RequestMapping(value = "/saveassignroletomodule", method = RequestMethod.POST) public String saveAssignRoleToModule(@Valid RoleModulePojo entity, BindingResult bindingResule, Model model, HttpServletRequest request) { String displayMessage = null; try { List<Integer> beforeAssignedRoleList = (List<Integer>) request.getSession().getAttribute("roleIds"); List<Integer> newlyAssignedRoleList = entity.getRoleIds(); //System.out.println("beforeAssignedUserList >>> "+beforeAssignedUserList); //System.out.println("newlyassignedUserList >>> "+newlyAssignedUserList); int beforeAssignedRoleSize = beforeAssignedRoleList.size(); int newlyAssignedRoleSize = 0; if (newlyAssignedRoleList != null) newlyAssignedRoleSize = newlyAssignedRoleList.size(); if (beforeAssignedRoleSize == 0 && newlyAssignedRoleSize == 0) { //System.out.println("No changes done...."); displayMessage = "Please assign atleast one role to the package"; //System.out.println("displayMessage : "+displayMessage); model.addAttribute("displayMessage", displayMessage); model.addAttribute("assignroletomodule", "assignroletomodule"); model.addAttribute("crudObj", new RoleModulePojo()); model.addAttribute("module_list", moduleService.list()); return "home"; } else if (beforeAssignedRoleSize > 0 && newlyAssignedRoleSize == 0) { if (beforeAssignedRoleSize == 1) displayMessage = "1 role is removed"; else displayMessage = beforeAssignedRoleSize + " roles are removed "; } else if (beforeAssignedRoleSize == 0 && newlyAssignedRoleSize > 0) { if (newlyAssignedRoleSize == 1) displayMessage = " 1 role is assigned"; else displayMessage = newlyAssignedRoleSize + " roles are assigned "; } else { int sameRoleAssigned = 0; if (newlyAssignedRoleList != null) { for (Integer roleId : newlyAssignedRoleList) { if (beforeAssignedRoleList != null) { for (Integer rid : beforeAssignedRoleList) { if (roleId.intValue() == rid.intValue()) { sameRoleAssigned++; break; } } } } } int removedRole = beforeAssignedRoleSize - sameRoleAssigned; if (removedRole == 0) displayMessage = ""; else if (removedRole == 1) displayMessage = " and 1 role is removed"; else displayMessage = " and " + removedRole + " roles are removed"; int assignedRole = newlyAssignedRoleSize - sameRoleAssigned; if (assignedRole == 0 && beforeAssignedRoleSize == newlyAssignedRoleSize) displayMessage = "No changes are made"; else if (assignedRole == 0) { if (removedRole == 0) displayMessage = ""; else if (removedRole == 1) displayMessage = " 1 role is removed"; else displayMessage = removedRole + " roles are removed"; } else if (assignedRole == 1) displayMessage = "1 role is assigned" + displayMessage; else displayMessage = assignedRole + " roles are assigned" + displayMessage; } //System.out.println(displayMessage); model.addAttribute("displayMessage", displayMessage); roleModuleService.deleteByModuleId(entity.getModuleId()); List<Integer> roleIds = entity.getRoleIds(); /*DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata"); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate();*/ Locale clientLocale = request.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); String clientZone = clientTimeZone.getID(); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID(clientZone); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); if (roleIds != null) { Iterator<Integer> iterator = roleIds.iterator(); while (iterator.hasNext()) { RoleModule roleModule = new RoleModule(); RoleModuleComp rolemodComp = new RoleModuleComp(); rolemodComp.setModuleId(entity.getModuleId()); rolemodComp.setRoleId(iterator.next()); roleModule.setRoleModuleComp(rolemodComp); roleModule.setCreatedBy(entity.getCreatedBy()); roleModule.setCreatedDate(dateInIndia); roleModule.setModifiedBy(entity.getModifiedBy()); roleModule.setModifiedDate(dateInIndia); roleModuleService.save(roleModule); } model.addAttribute("assignroletomodule", "assignroletomodule"); AuditLogRecord record = new AuditLogRecord(); record.setActionDate(dateInIndia); Module module = moduleService.getById(entity.getModuleId()); record.setActionData("Module name is " + module.getName()); record.setActionType(AuditType.ASSIGN); record.setActionPerformed("Module Assigned"); record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString()); /*try { InetAddress inetAddress = InetAddress.getLocalHost(); record.setIpOrigin(inetAddress.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }*/ record.setUserId((Integer) request.getSession().getAttribute("userid")); record.setUserName(request.getSession().getAttribute("username").toString()); auditRecordService.saveRecord(record); model.addAttribute("roleassigned", "Role(s) Assigned."); } else { model.addAttribute("roleassigned", "Role(s) Assigned."); } model.addAttribute("assignroletomodule", "assignroletomodule"); model.addAttribute("crudObj", new RoleModulePojo()); model.addAttribute("module_list", moduleService.list()); } catch (Exception e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.infotree.qliktest.admin.web.controller.RolePermissionsController.java
/** * This method is used to save the permissions to the role *///from w w w .j a v a 2 s . c om @RequestMapping(value = "/savepermissionstorole", method = RequestMethod.POST) public String saveLicenseAuth(@Valid RolePermissionsPojo entity, BindingResult bindingResult, Model model, HttpServletRequest request) { rolePermissionsService.deleteByRoleId(entity.getRoleId()); /*DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata"); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate();*/ Locale clientLocale = request.getLocale(); Calendar calendar = Calendar.getInstance(clientLocale); TimeZone clientTimeZone = calendar.getTimeZone(); String clientZone = clientTimeZone.getID(); DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID(clientZone); DateTime dtus = dt.withZone(dtZone); Date dateInIndia = dtus.toLocalDateTime().toDate(); try { int count = 0; String permissionName = ""; model.addAttribute("managerolesandpermissions", "managerolesandpermissions"); model.addAttribute("crudObj", new RolePermissionsPojo()); List<Integer> permissions = entity.getPermissionIds(); if (permissions != null) { Iterator<Integer> iterator = permissions.iterator(); while (iterator.hasNext()) { RolePermissions rolePerm = new RolePermissions(); RolePermissionsComp comp = new RolePermissionsComp(); Integer permId = iterator.next(); comp.setPermissionId(permId); comp.setRoleId(entity.getRoleId()); rolePerm.setUserPermissionsComp(comp); rolePerm.setCreatedBy(entity.getCreatedBy()); rolePerm.setCreatedDate(dateInIndia); rolePermissionsService.save(rolePerm); Permissions p = permissionsService.getById(permId); if (permissionName == "") { permissionName = p.getName(); } else { permissionName = permissionName + "," + p.getName(); } } } else { } AuditLogRecord record = new AuditLogRecord(); record.setActionDate(dateInIndia); record.setActionType(AuditType.ASSIGN); Role role = roleService.getById(entity.getRoleId()); record.setActionData("Permissions names " + permissionName + " and Role name is" + role.getName()); record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString()); /*try { InetAddress inetAddress = InetAddress.getLocalHost(); record.setIpOrigin(inetAddress.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); }*/ record.setUserId((Integer) request.getSession().getAttribute("userid")); record.setUserName(request.getSession().getAttribute("username").toString()); auditLogService.saveRecord(record); model.addAttribute("managerolesandpermissions", "managerolesandpermissions"); model.addAttribute("role_list", roleService.list()); model.addAttribute("permissions_list", permissionsService.list()); model.addAttribute("permissionsassigned", "Permissions Assigned "); if (count == 0) { model.addAttribute("permissionsassigned", "Permission(s) Assigned.'"); } else { model.addAttribute("permissionsassigned", "Permission(s) assigned.'" + "<font color='red'>" + count + "'Permission(s) not assigned(Already available.)</font>"); } } catch (Exception e) { LOG.error(e.toString()); e.printStackTrace(); } return "home"; }
From source file:com.inspireon.dragonfly.common.logging.ExtendedDailyRollingFileAppender.java
License:Apache License
int computeCheckPeriod() { RollingCalendar rollingCalendar = new RollingCalendar(GMT, Locale.ENGLISH); // set sate to 1970-01-01 00:00:00 GMT DateTime epoch = new DateTime(0); if (datePattern != null) { for (int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern); // simpleDateFormat.setTimeZone(GMT); // do all date // formatting in GMT epoch = epoch.withZone(DateTimeZone.forID(Constants.TIME_ZONE_GMT)); String r0 = epoch.toString(DateTimeFormat.forPattern(datePattern)); // String r0 = simpleDateFormat.format(epoch); rollingCalendar.setType(i);/*from w ww . j a v a 2 s . c o m*/ DateTime next = new DateTime(rollingCalendar.getNextCheckMillis(epoch.toDate())); next = next.withZone(DateTimeZone.forID(Constants.TIME_ZONE_GMT)); String r1 = next.toString(DateTimeFormat.forPattern(datePattern)); // String r1 = simpleDateFormat.format(next); if ((r0 != null) && (r1 != null) && !r0.equals(r1)) { return i; } } } return TOP_OF_TROUBLE; // Deliberately head for trouble... }
From source file:com.jbirdvegas.mgerrit.helpers.Tools.java
License:Apache License
public static DateTime parseDate(String dateStr, TimeZone serverTimeZone, TimeZone localTimeZone) { try {//from w ww . java2 s. co m DateTime d = DATE_TIME_FORMATTER.withZone(DateTimeZone.forTimeZone(serverTimeZone)) .parseDateTime(dateStr); return d.withZone(DateTimeZone.forTimeZone(localTimeZone)).withMillisOfDay(0); } catch (IllegalArgumentException e) { return new DateTime(0); } }