<%@ page import="java.text.DateFormat" %> <%@ page import="java.text.SimpleDateFormat" %> <%@ page import="java.util.Date" %> <%@ page import="java.util.Calendar" %> <%@ page import="java.util.List" %> <%@ page import="java.util.Collections" %> <%@ page import="java.util.Comparator" %> <%@ page import="java.util.regex.Pattern" %> <%@ page import="java.util.regex.Matcher" %> <%@page import="com.insightguru.giraffe.common.model.texteditor.AnalystCommentaryType"%> <%@page import="com.insightguru.giraffe.common.constant.UserProfileBitFlags"%> <%@page import="com.insightguru.giraffe.server.domain.FeaturedCompany"%> <%@page import="com.insightguru.giraffe.server.domain.Company"%> <%@page import="com.insightguru.giraffe.server.domain.User"%> <%@page import="com.insightguru.giraffe.server.domain.AnalystCommentaryText"%> <%@page import="com.insightguru.giraffe.server.dao.CompanyDAO"%> <%@page import="com.insightguru.giraffe.server.dao.UserDAO"%> <%@page import="com.insightguru.giraffe.server.dao.GetAnalystText"%> <%@page import="com.insightguru.giraffe.server.utils.FeaturedCompanyUtil"%> <%@page import="com.insightguru.giraffe.server.utils.ServletUtil"%> <%@page import="com.insightguru.giraffe.server.controller.LoginController"%> <%@page import="com.insightguru.giraffe.server.service.ClearCacheService"%> <%@page import="com.insightguru.giraffe.server.service.ClearCacheService.CacheType"%> <%@ page import="org.owasp.esapi.ESAPI" %> <%@ page import="org.owasp.esapi.Encoder" %> <%@page import="org.json.JSONObject"%> <%@page import="java.util.ArrayList"%> <%! DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT); %> Add a Featured Company <%@ include file="components/commonHead.jsp" %>
<% User loggedInUser = UserDAO.getCurrentUser(); if(loggedInUser == null || !UserProfileBitFlags.isAdmin(loggedInUser)) { %>

Admin Access Only

Logout and try again <% } else { %> <% if("submit".equals(request.getParameter("do"))) { boolean editing = request.getParameter("id") != null; FeaturedCompany featuredCompany; if(editing) featuredCompany = CompanyDAO.getFeaturedCompany(Integer.parseInt(request.getParameter("id"))); else featuredCompany = new FeaturedCompany(); featuredCompany.setCompany(CompanyDAO.loadCompany(request.getParameter("symbol"))); featuredCompany.setSnippet(request.getParameter("snippet")); featuredCompany.setDay(dateFormat.parse(request.getParameter("day"))); CompanyDAO.saveFeaturedCompany(featuredCompany); ClearCacheService.clear(CacheType.FEATURED_COMPANIES); %>

Featured Company <%= editing ? "edited" : "added" %>!

<% } %> <% if("delete".equals(request.getParameter("do"))) { CompanyDAO.deleteFeaturedCompany(Integer.parseInt(request.getParameter("id"))); ClearCacheService.clear(CacheType.FEATURED_COMPANIES); %>

Featurd Company deleted!

<% } %> <% if("add".equals(request.getParameter("do")) || "edit".equals(request.getParameter("do"))) { FeaturedCompany toEdit = null; if("edit".equals(request.getParameter("do"))) toEdit = CompanyDAO.getFeaturedCompany(Integer.parseInt(request.getParameter("id"))); List companies = CompanyDAO.getCompanies(false); Collections.sort(companies, new Comparator() { public int compare(Company company1, Company company2) { return company1.getSymbol().compareToIgnoreCase(company2.getSymbol()); } }); %>
Date:
Company:
Snippet: Use Default Snippet
Cancel
<% if(toEdit != null) { %> <% } %>
<% JSONObject defaultSnippets = new JSONObject(); List companyRootIdentifiers = new ArrayList(companies.size()); for(Company company : companies) { companyRootIdentifiers.add("root" + company.getSymbol()); } List companyOverviews = GetAnalystText.getAnalystCommentaryText(companyRootIdentifiers, AnalystCommentaryType.COMPANY_OVERVIEW); final Pattern firstBulletPattern = Pattern.compile("
  • (.*?)
  • "); for(AnalystCommentaryText companyOverview : companyOverviews) { Matcher matcher = firstBulletPattern.matcher(companyOverview.getContent()); if(matcher.find()) { defaultSnippets.put( companyOverview.getIdentifier().getCompany().getSymbol(), ESAPI.encoder().encodeForHTML(matcher.group(1))); } } %> <%@ include file="/components/commonJS.jsp" %> <% } else {%> Add a new Featured Company <% final List featuredCompanies; if (request.getParameter("showAll") == null) { Calendar fiveDaysAgo = Calendar.getInstance(); fiveDaysAgo.add(Calendar.DATE, -5); featuredCompanies = CompanyDAO.getAllFeaturedCompaniesAfter(fiveDaysAgo.getTime()); %> | Show All

    Recent and Future Featured Companies

    <% } else { featuredCompanies = CompanyDAO.getAllFeaturedCompanies(); %> | Show Recent

    All Featured Companies

    <% } %> <% for(FeaturedCompany featuredCompany : featuredCompanies) { %> <% } %>
    Date Company Preview
    <%= dateFormat.format(featuredCompany.getDay()) %> <%= ESAPI.encoder().encodeForHTML(featuredCompany.getCompany().getCompanyName()) %>
    <%= FeaturedCompanyUtil.getAugmentedEscapedSnippet(featuredCompany) %>
    Edit Delete
    <% } %> <% } %>