/** * <b>Sample Code:</b><br> * <code>/wscontext/login-menu</code><br> * * @param inMessage * @return */ @SuppressWarnings("unchecked") @Secured({ RoleConstant.ROLE_SALESMAN, RoleConstant.ROLE_AREASALESMANAGER, RoleConstant.ROLE_NATIONALSALESMANAGER, RoleConstant.ROLE_ADMIN }) public Message<UserMenuTransferObject> getUserMenu(Message<?> inMessage) { UserMenuTransferObject userMenuTransferObject = new UserMenuTransferObject(); Map<String, Object> responseHeaderMap = new HashMap<String, Object>(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!(authentication instanceof AnonymousAuthenticationToken)) { this.currentUserName = authentication.getName(); GrantedAuthority grantedAuthority = authentication.getAuthorities().iterator().next(); this.currentRole = grantedAuthority.getAuthority(); } authentication = null; try { if (inMessage.getPayload() != null) { if (((String) inMessage.getPayload()).startsWith(ParameterConstant.VIEW_TYPE)) viewType = ((String) inMessage.getPayload()).replaceAll(ParameterConstant.VIEW_TYPE, ""); else { wsEndpointFault.setMessage(EResponseCode.RC_FAILURE.toString()); throw new WSEndpointFaultException( EResponseCode.RC_FAILURE.getResponseCode(), wsEndpointFault); } } List<User> userList = iGenericManagerJpa.loadObjectsJQLStatement( "FROM User WHERE username = ?", new Object[] {this.currentUserName}, null); if (userList != null) { List<UserData> userDatas = new ArrayList<UserData>(); userDatas.add(new UserData(userList.get(0))); userMenuTransferObject.setUserDatas(userDatas); userDatas = null; } else throw new Exception(); List<MenuData> menuDatas = new ArrayList<MenuData>(); switch (this.currentRole) { case RoleConstant.ROLE_ADMIN: if (ParameterConstant.VIEW_WEB.equals(this.viewType)) menuDatas = (List<MenuData>) context.getAttribute(ApplicationContextConstant.CONTEXT_MENU_ROLE_ADMIN_WEB); else menuDatas = (List<MenuData>) context.getAttribute(ApplicationContextConstant.CONTEXT_MENU_ROLE_ADMIN_MOBILE); break; case RoleConstant.ROLE_SALESMAN: if (ParameterConstant.VIEW_WEB.equals(this.viewType)) menuDatas = (List<MenuData>) context.getAttribute(ApplicationContextConstant.CONTEXT_MENU_ROLE_SALESMAN_WEB); else menuDatas = (List<MenuData>) context.getAttribute( ApplicationContextConstant.CONTEXT_MENU_ROLE_SALESMAN_MOBILE); break; case RoleConstant.ROLE_AREASALESMANAGER: if (ParameterConstant.VIEW_WEB.equals(this.viewType)) menuDatas = (List<MenuData>) context.getAttribute( ApplicationContextConstant.CONTEXT_MENU_ROLE_AREASALESMANAGER_WEB); else menuDatas = (List<MenuData>) context.getAttribute( ApplicationContextConstant.CONTEXT_MENU_ROLE_AREASALESMANAGER_MOBILE); break; case RoleConstant.ROLE_NATIONALSALESMANAGER: if (ParameterConstant.VIEW_WEB.equals(this.viewType)) menuDatas = (List<MenuData>) context.getAttribute( ApplicationContextConstant.CONTEXT_MENU_ROLE_NATIONALSALESMANAGER_WEB); else menuDatas = (List<MenuData>) context.getAttribute( ApplicationContextConstant.CONTEXT_MENU_ROLE_NATIONALSALESMANAGER_MOBILE); break; default: throw new Exception(); } if (menuDatas == null || menuDatas.isEmpty()) { List<Menu> menuList = iGenericManagerJpa.loadObjectsJQLStatement( "SELECT mn FROM Menu mn INNER JOIN mn.roles role WHERE role.code = ? AND (mn.viewType = ? OR mn.viewType = ?) ORDER BY mn.tree ASC", new Object[] {this.currentRole, this.viewType, ParameterConstant.VIEW_WEB_MOBILE}, null); if (menuList != null) { for (Menu menu : menuList) { MenuData menuData = new MenuData(menu); menuDatas.add(menuData); } } menuList = null; } userMenuTransferObject.setMenuDatas(menuDatas); userMenuTransferObject.setResponseCode(EResponseCode.RC_SUCCESS.getResponseCode()); userMenuTransferObject.setResponseMsg(ParameterConstant.RESPONSE_SUCCESS); userMenuTransferObject.setResponseDesc(EResponseCode.RC_SUCCESS.toString()); userList = null; menuDatas = null; } catch (WSEndpointFaultException e) { userMenuTransferObject.setResponseCode(e.getMessage()); userMenuTransferObject.setResponseMsg(ParameterConstant.RESPONSE_FAILURE); userMenuTransferObject.setResponseDesc(e.getFaultInfo().getMessage()); } catch (Exception e) { LOGGER.error("Login Menu System Error : " + e.getMessage(), e); userMenuTransferObject.setResponseCode(EResponseCode.RC_FAILURE.getResponseCode()); userMenuTransferObject.setResponseMsg(ParameterConstant.RESPONSE_FAILURE); userMenuTransferObject.setResponseDesc(EResponseCode.RC_FAILURE.toString() + e.getMessage()); } setReturnStatusAndMessage(userMenuTransferObject, responseHeaderMap); Message<UserMenuTransferObject> message = new GenericMessage<UserMenuTransferObject>(userMenuTransferObject, responseHeaderMap); userMenuTransferObject = null; this.currentUserName = null; this.currentRole = null; return message; }
/** * <b>Sample Code:</b><br> * <code>/wscontext/report/select</code><br> * * @param inMessage * @return */ @Secured({RoleConstant.ROLE_NATIONALSALESMANAGER, RoleConstant.ROLE_ADMIN}) public Message<byte[]> exportStreamReport(Message<GeneralReportTransferObject> inMessage) { outputStreamData = new ByteArrayOutputStream(); generalReportTransferObject = new GeneralReportTransferObject(); Map<String, Object> responseHeaderMap = new HashMap<String, Object>(); try { if (inMessage.getPayload() != null) { generalReportTransferObject = inMessage.getPayload(); params = generalReportTransferObject.getDataFilter(); if (params == null) params = new HashMap<String, Object>(); final TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManagerReport); transactionTemplate.execute( new TransactionCallback<Object>() { @Override public Object doInTransaction(TransactionStatus arg0) { try { if (generalReportTransferObject.getDataSelection() != null && !generalReportTransferObject.getDataSelection().isEmpty()) { JRDataSource dataSource = new JRBeanCollectionDataSource( generalReportTransferObject.getDataSelection()); params.put("beanCollectionDataSource", dataSource); reportGenerator.printReportToFile( generalReportTransferObject.getTemplateReportName(), dataSource, params, outputStreamData, EReportUtilConstant.getEnum(generalReportTransferObject.getTypeFile())); } else { Connection connection = dataSourceReport.getConnection(); params.put("dataSourceConnecion", connection); reportGenerator.printReportToFile( generalReportTransferObject.getTemplateReportName(), connection, params, outputStreamData, EReportUtilConstant.getEnum(generalReportTransferObject.getTypeFile())); } } catch (Exception e) { LOGGER.error("Generate Report System Error : " + e.getLocalizedMessage(), e); generalReportTransferObject.setResponseCode( EResponseCode.RC_FAILURE.getResponseCode()); generalReportTransferObject.setResponseMsg(ParameterConstant.RESPONSE_FAILURE); generalReportTransferObject.setResponseDesc( EResponseCode.RC_FAILURE.toString() + e.getLocalizedMessage()); } return null; } }); } generalReportTransferObject.setResponseCode(EResponseCode.RC_SUCCESS.getResponseCode()); generalReportTransferObject.setResponseMsg(ParameterConstant.RESPONSE_SUCCESS); generalReportTransferObject.setResponseDesc(EResponseCode.RC_SUCCESS.toString()); } catch (Exception e) { LOGGER.error("Generate Report System Error : " + e.getLocalizedMessage(), e); generalReportTransferObject.setResponseCode(EResponseCode.RC_FAILURE.getResponseCode()); generalReportTransferObject.setResponseMsg(ParameterConstant.RESPONSE_FAILURE); generalReportTransferObject.setResponseDesc( EResponseCode.RC_FAILURE.toString() + e.getLocalizedMessage()); } setReturnStatusAndMessage(generalReportTransferObject, responseHeaderMap); Message<byte[]> message = new GenericMessage<byte[]>(outputStreamData.toByteArray(), responseHeaderMap); generalReportTransferObject = null; outputStreamData = null; return message; }