@Override protected Field<?> onCreateField(final Object propertyId) { String value = ""; if (propertyId.equals("email")) { return new DefaultFormViewFieldFactory.FormEmailLinkViewField( PreviewForm.this.user.getEmail()); } else if (propertyId.equals("dateofbirth")) { value = AppContext.formatDate(PreviewForm.this.user.getDateofbirth()); return new DefaultFormViewFieldFactory.FormViewField(value); } else if (propertyId.equals("timezone")) { value = TimezoneMapper.getTimezone(PreviewForm.this.user.getTimezone()).getDisplayName(); return new DefaultFormViewFieldFactory.FormViewField(value); } else if (propertyId.equals("website")) { value = PreviewForm.this.user.getWebsite(); return new DefaultFormViewFieldFactory.FormUrlLinkViewField(value); } else if (propertyId.equals("facebookaccount")) { return new DefaultFormViewFieldFactory.FormUrlSocialNetworkLinkViewField( PreviewForm.this.user.getFacebookaccount(), "https://www.facebook.com/" + PreviewForm.this.user.getFacebookaccount()); } else if (propertyId.equals("twitteraccount")) { return new DefaultFormViewFieldFactory.FormUrlSocialNetworkLinkViewField( PreviewForm.this.user.getTwitteraccount(), "https://www.twitter.com/" + PreviewForm.this.user.getTwitteraccount()); } else if (propertyId.equals("skypecontact")) { return new DefaultFormViewFieldFactory.FormUrlSocialNetworkLinkViewField( PreviewForm.this.user.getSkypecontact(), "skype:" + PreviewForm.this.user.getSkypecontact() + "?chat"); } return null; }
@Override protected Field<?> onCreateField(final Object propertyId) { if (propertyId.equals("roleid")) { return new AdminRoleSelectionField(); } else if (propertyId.equals("firstname") || propertyId.equals("lastname") || propertyId.equals("email")) { final TextField tf = new TextField(); tf.setNullRepresentation(""); tf.setRequired(true); tf.setRequiredError("This field must be not null"); return tf; } else if (propertyId.equals("dateofbirth")) { return new DateComboboxSelectionField(); } else if (propertyId.equals("timezone")) { TimeZoneSelectionField cboTimezone = new TimeZoneSelectionField(false); if (UserAddViewImpl.this.user.getTimezone() != null) { cboTimezone.setTimeZone( TimezoneMapper.getTimezoneExt(UserAddViewImpl.this.user.getTimezone())); } else { if (AppContext.getSession().getTimezone() != null) { cboTimezone.setTimeZone( TimezoneMapper.getTimezoneExt(AppContext.getSession().getTimezone())); } } return cboTimezone; } else if (propertyId.equals("country")) { final CountryComboBox cboCountry = new CountryComboBox(); cboCountry.addValueChangeListener( new Property.ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(final Property.ValueChangeEvent event) { UserAddViewImpl.this.user.setCountry((String) cboCountry.getValue()); } }); return cboCountry; } return null; }
public void migrate(JdbcTemplate jdbcTemplate) throws Exception { LOG.info("Set up initial values"); LOG.debug("Insert default billing plan"); SimpleJdbcInsert billingJdbcInsert = new SimpleJdbcInsert(jdbcTemplate) .withTableName("s_billing_plan") .usingColumns( "billingType", "numUsers", "volume", "numProjects", "pricing", "hasBugEnable", "hasStandupMeetingEnable", "hasTimeTracking") .usingGeneratedKeyColumns("id"); Map<String, Object> billingParameters = new HashMap<>(); billingParameters.put("billingType", "Community"); billingParameters.put("numUsers", 99999999); billingParameters.put("volume", 999999999999L); billingParameters.put("numProjects", 999999); billingParameters.put("pricing", 0); billingParameters.put("hasBugEnable", Boolean.TRUE); billingParameters.put("hasStandupMeetingEnable", Boolean.TRUE); billingParameters.put("hasTimeTracking", Boolean.TRUE); Number billingPlanId = billingJdbcInsert.executeAndReturnKey(billingParameters); LOG.debug("Insert default account"); SimpleJdbcInsert accountJdbcInsert = new SimpleJdbcInsert(jdbcTemplate) .withTableName("s_account") .usingColumns("status", "billingPlanId", "paymentMethod", "subdomain") .usingGeneratedKeyColumns("id"); Map<String, Object> accountParameters = new HashMap<>(); accountParameters.put("status", "Active"); accountParameters.put("billingPlanId", billingPlanId); accountParameters.put("paymentMethod", "None"); accountParameters.put("subdomain", ""); Number accountId = accountJdbcInsert.executeAndReturnKey(accountParameters); LOG.debug("Insert default users"); SimpleJdbcInsert userJdbcInsert = new SimpleJdbcInsert(jdbcTemplate) .withTableName("s_user") .usingColumns( "username", "firstname", "lastname", "email", "status", "registeredTime", "password", "timezone"); Date nowDate = DateTimeUtils.convertDateTimeToUTC(new GregorianCalendar().getTime()); String timezoneDbId = TimezoneMapper.getTimezoneDbId(TimeZone.getDefault()); Map<String, Object> userParameters = new HashMap<>(); userParameters.put("username", "*****@*****.**"); userParameters.put("firstname", ""); userParameters.put("lastname", "admin"); userParameters.put("email", "*****@*****.**"); userParameters.put("status", "Active"); userParameters.put("registeredTime", nowDate); userParameters.put("password", PasswordEncryptHelper.encryptSaltPassword("admin123")); userParameters.put("timezone", timezoneDbId); userJdbcInsert.execute(userParameters); LOG.debug("Insert default user avatar"); LOG.debug("Create associate between user and billing plan"); SimpleJdbcInsert userAccountJdbcInsert = new SimpleJdbcInsert(jdbcTemplate) .withTableName("s_user_account") .usingColumns( "username", "accountId", "isAccountOwner", "registeredTime", "registerStatus") .usingGeneratedKeyColumns("id"); Map<String, Object> userAccountParameters = new HashMap<>(); userAccountParameters.put("username", "*****@*****.**"); userAccountParameters.put("accountId", accountId); userAccountParameters.put("isAccountOwner", Boolean.TRUE); userAccountParameters.put("registeredTime", nowDate); userAccountParameters.put("registerStatus", "Active"); userAccountJdbcInsert.executeAndReturnKey(userAccountParameters); LOG.debug("Insert default roles"); SimpleJdbcInsert roleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate) .withTableName("s_roles") .usingColumns("rolename", "description", "sAccountId", "isSystemRole") .usingGeneratedKeyColumns("id"); LOG.debug("Create default admin role"); SqlParameterSource adminRoleParameters = new MapSqlParameterSource() .addValue("rolename", "Administrator") .addValue("description", "Admin Role") .addValue("sAccountId", accountId) .addValue("isSystemRole", Boolean.TRUE); Number adminRoleId = roleJdbcInsert.executeAndReturnKey(adminRoleParameters); LOG.debug("Create default employee role"); SqlParameterSource employeeRoleParameters = new MapSqlParameterSource() .addValue("rolename", "Employee") .addValue("description", "Employee Role") .addValue("sAccountId", accountId) .addValue("isSystemRole", Boolean.TRUE); Number employeeRoleId = roleJdbcInsert.executeAndReturnKey(employeeRoleParameters); LOG.debug("Create default guest role"); SqlParameterSource guestRoleParameters = new MapSqlParameterSource() .addValue("rolename", "Guest") .addValue("description", "Guest Role") .addValue("sAccountId", accountId) .addValue("isSystemRole", Boolean.TRUE); Number guestRoleId = roleJdbcInsert.executeAndReturnKey(guestRoleParameters); LOG.debug("Associate permission with admin role"); SimpleJdbcInsert rolePermissionJdbcInsert = new SimpleJdbcInsert(jdbcTemplate) .withTableName("s_role_permission") .usingColumns("roleid", "roleVal") .usingGeneratedKeyColumns("id"); SqlParameterSource adminRolePermissionParameters = new MapSqlParameterSource() .addValue("roleid", adminRoleId) .addValue("roleVal", PermissionMap.buildAdminPermissionCollection().toJsonString()); rolePermissionJdbcInsert.execute(adminRolePermissionParameters); LOG.debug("Associate permission with employee role"); SqlParameterSource employeeRolePermissionParameters = new MapSqlParameterSource() .addValue("roleid", employeeRoleId) .addValue("roleVal", PermissionMap.buildEmployeePermissionCollection().toJsonString()); rolePermissionJdbcInsert.execute(employeeRolePermissionParameters); LOG.debug("Associate permission with guest role"); SqlParameterSource guestRolePermissionParameters = new MapSqlParameterSource() .addValue("roleid", guestRoleId) .addValue("roleVal", PermissionMap.buildGuestPermissionCollection().toJsonString()); rolePermissionJdbcInsert.execute(guestRolePermissionParameters); }
@Override protected void onHandleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String type = request.getParameter("type"); String typeId = request.getParameter("typeId"); Integer sAccountId = Integer.parseInt(request.getParameter("sAccountId")); String siteURL = request.getParameter("siteURL"); String timeZoneId = request.getParameter("timeZone"); TimeZone timeZone = TimezoneMapper.getTimezone(timeZoneId); String username = request.getParameter("username"); String localeParam = request.getParameter("locale"); Locale locale = LocaleHelper.toLocale(localeParam); String html = ""; if (ProjectTypeConstants.PROJECT.equals(type)) { ProjectService service = ApplicationContextUtil.getSpringBean(ProjectService.class); SimpleProject project = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipProject(locale, project, siteURL, timeZone); } else if (ProjectTypeConstants.MESSAGE.equals(type)) { MessageService service = ApplicationContextUtil.getSpringBean(MessageService.class); SimpleMessage message = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipMessage(locale, message, siteURL, timeZone); } else if (ProjectTypeConstants.MILESTONE.equals(type)) { MilestoneService service = ApplicationContextUtil.getSpringBean(MilestoneService.class); SimpleMilestone mileStone = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipMilestone(locale, mileStone, siteURL, timeZone); } else if (ProjectTypeConstants.BUG.equals(type)) { BugService service = ApplicationContextUtil.getSpringBean(BugService.class); SimpleBug bug = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipBug(locale, bug, siteURL, timeZone); } else if (ProjectTypeConstants.TASK.equals(type)) { ProjectTaskService service = ApplicationContextUtil.getSpringBean(ProjectTaskService.class); SimpleTask task = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipTask(locale, task, siteURL, timeZone); } else if (ProjectTypeConstants.RISK.equals(type)) { RiskService service = ApplicationContextUtil.getSpringBean(RiskService.class); SimpleRisk risk = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipRisk(locale, risk, siteURL, timeZone); } else if (ProjectTypeConstants.PROBLEM.equals(type)) { ProblemService service = ApplicationContextUtil.getSpringBean(ProblemService.class); SimpleProblem problem = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipProblem(locale, problem, siteURL, timeZone); } else if (ProjectTypeConstants.BUG_VERSION.equals(type)) { VersionService service = ApplicationContextUtil.getSpringBean(VersionService.class); SimpleVersion version = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipVersion(locale, version, siteURL, timeZone); } else if (ProjectTypeConstants.BUG_COMPONENT.equals(type)) { ComponentService service = ApplicationContextUtil.getSpringBean(ComponentService.class); SimpleComponent component = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipComponent(locale, component, siteURL, timeZone); } else if (ProjectTypeConstants.PAGE.equals(type)) { ProjectPageService pageService = ApplicationContextUtil.getSpringBean(ProjectPageService.class); Page page = pageService.getPage(typeId, username); html = ProjectTooltipGenerator.generateToolTipPage(locale, page, siteURL, timeZone); } else if (ProjectTypeConstants.STANDUP.equals(type)) { StandupReportService service = ApplicationContextUtil.getSpringBean(StandupReportService.class); SimpleStandupReport standup = service.findById(Integer.parseInt(typeId), sAccountId); html = ProjectTooltipGenerator.generateToolTipStandUp(locale, standup, siteURL, timeZone); } else if (CrmTypeConstants.ACCOUNT.equals(type)) { AccountService service = ApplicationContextUtil.getSpringBean(AccountService.class); SimpleAccount account = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateToolTipAccount(locale, account, siteURL); } else if (CrmTypeConstants.CONTACT.equals(type)) { ContactService service = ApplicationContextUtil.getSpringBean(ContactService.class); SimpleContact contact = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateToolTipContact(locale, contact, siteURL, timeZone); } else if (CrmTypeConstants.CAMPAIGN.equals(type)) { CampaignService service = ApplicationContextUtil.getSpringBean(CampaignService.class); SimpleCampaign account = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateTooltipCampaign(locale, account, siteURL, timeZone); } else if (CrmTypeConstants.LEAD.equals(type)) { LeadService service = ApplicationContextUtil.getSpringBean(LeadService.class); SimpleLead lead = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateTooltipLead(locale, lead, siteURL, timeZone); } else if (CrmTypeConstants.OPPORTUNITY.equals(type)) { OpportunityService service = ApplicationContextUtil.getSpringBean(OpportunityService.class); SimpleOpportunity opportunity = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateTooltipOpportunity(locale, opportunity, siteURL, timeZone); } else if (CrmTypeConstants.CASE.equals(type)) { CaseService service = ApplicationContextUtil.getSpringBean(CaseService.class); SimpleCase cases = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateTooltipCases(locale, cases, siteURL, timeZone); } else if (CrmTypeConstants.MEETING.equals(type)) { MeetingService service = ApplicationContextUtil.getSpringBean(MeetingService.class); SimpleMeeting meeting = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateToolTipMeeting(locale, meeting, siteURL, timeZone); } else if (CrmTypeConstants.CALL.equals(type)) { CallService service = ApplicationContextUtil.getSpringBean(CallService.class); SimpleCall call = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateToolTipCall(locale, call, siteURL, timeZone); } else if (CrmTypeConstants.TASK.equals(type)) { TaskService service = ApplicationContextUtil.getSpringBean(TaskService.class); com.esofthead.mycollab.module.crm.domain.SimpleTask crmTask = service.findById(Integer.parseInt(typeId), sAccountId); html = CrmTooltipGenerator.generateToolTipCrmTask(locale, crmTask, siteURL, timeZone); } else if ("User".equals(type)) { UserService service = ApplicationContextUtil.getSpringBean(UserService.class); SimpleUser user = service.findUserByUserNameInAccount(username, sAccountId); html = CommonTooltipGenerator.generateTooltipUser(locale, user, siteURL, timeZone); } else { LOG.error("Can not generate tooltip for item has type " + type); } response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(html); return; } catch (Exception e) { LOG.error("Error while get html tooltip attachForm TooltipGeneratorServletRequestHandler", e); String html = null; PrintWriter out = response.getWriter(); out.println(html); return; } }
public static String generateTooltipUser( Locale locale, SimpleUser user, String siteURL, TimeZone timeZone) { try { if (user == null) { return generateTolltipNull(locale); } Div div = new Div(); H3 userFullName = new H3() .setStyle( "font: 12px Arial, Verdana, Helvetica, sans-serif !important;line-height: normal;"); userFullName.setStyle("padding-left:10px;").appendText(user.getDisplayName()); div.appendChild(userFullName); Table table = new Table(); table.setStyle("padding-left:10px; width :380px; color: #5a5a5a; font-size:11px;"); Tr trRow1 = new Tr() .appendChild( new Td() .setStyle("width: 110px; vertical-align: top; text-align: right;") .appendText(LocalizationHelper.getMessage(locale, UserI18nEnum.FORM_EMAIL))) .appendChild( new Td() .setStyle("vertical-align: top;") .appendChild( new A() .setHref("mailto:" + user.getEmail()) .appendText(StringUtils.trimHtmlTags(user.getEmail())))); Td trRow1_value = new Td() .setStyle("width:150px;text-align: right; vertical-align: top;") .appendChild( new Img("", StorageFactory.getInstance().getAvatarPath(user.getAvatarid(), 100))); trRow1_value.setAttribute("rowspan", "5"); trRow1.appendChild( new Td() .setStyle("width: 0px; vertical-align: top; text-align: right;") .appendChild(trRow1_value)); Tr trRow2 = new Tr() .appendChild( new Td() .setStyle("width: 110px; vertical-align: top; text-align: right;") .appendText( LocalizationHelper.getMessage(locale, UserI18nEnum.FORM_TIMEZONE))) .appendChild( new Td() .setStyle("vertical-align: top;") .appendText( TimezoneMapper.getTimezoneExt(user.getTimezone()).getDisplayName())); Tr trRow3 = new Tr() .appendChild( new Td() .setStyle("width: 110px; vertical-align: top; text-align: right;") .appendText(LocalizationHelper.getMessage(locale, UserI18nEnum.FORM_COUNTRY))) .appendChild( new Td() .setStyle("vertical-align: top;") .appendText(StringUtils.trimHtmlTags(user.getCountry()))); Tr trRow4 = new Tr() .appendChild( new Td() .setStyle("width: 110px; vertical-align: top; text-align: right;") .appendText( LocalizationHelper.getMessage(locale, UserI18nEnum.FORM_WORK_PHONE))) .appendChild( new Td() .setStyle("vertical-align: top;") .appendText(StringUtils.trimHtmlTags(user.getWorkphone()))); Tr trRow5 = new Tr() .appendChild( new Td() .setStyle("width: 110px; vertical-align: top; text-align: right;") .appendText( LocalizationHelper.getMessage( locale, GenericI18Enum.FORM_LAST_ACCESSED_TIME))) .appendChild( new Td() .setStyle( "word-wrap: break-word; white-space: normal;vertical-align: top; word-break: break-all;") .appendText( DateTimeUtils.getPrettyDateValue(user.getLastaccessedtime(), locale))); table.appendChild(trRow1, trRow2, trRow3, trRow4, trRow5); div.appendChild(table); return div.write(); } catch (Exception e) { LOG.error("Error while generate tooltip for servlet project-task tooltip", e); return null; } }