<%@page import="java.util.List"%> <%@page import="java.util.ArrayList"%> <%@page import="org.owasp.esapi.ESAPI"%> <%@page import="com.insightguru.giraffe.common.constant.UserProfileBitFlags"%> <%@page import="com.insightguru.giraffe.server.utils.TextUtil"%> <%@page import="com.insightguru.giraffe.server.database.HibernateUtil"%> <%@page import="com.insightguru.giraffe.server.dao.CompanyDAO"%> <%@page import="com.insightguru.giraffe.server.dao.MarketingSnippetDAO" %> <%@page import="com.insightguru.giraffe.server.dao.MarketingSnippetDAO.SectorSnippetCount"%> <%@page import="com.insightguru.giraffe.server.dao.MarketingSnippetDAO.CompanySnippetCount"%> <%@page import="com.insightguru.giraffe.server.domain.legacy.SankeyCompany"%> <%@page import="com.insightguru.giraffe.server.domain.Driver"%> <%@page import="com.insightguru.giraffe.server.domain.MarketingSnippet" %> <%@page import="com.insightguru.giraffe.server.domain.MarketingSnippet.MarketingSnippetType"%> <%@page import="com.insightguru.giraffe.server.domain.ModelId"%> <%@page import="com.insightguru.giraffe.server.domain.News"%> <%@page import="com.insightguru.giraffe.server.domain.Sector"%> <%@page import="com.insightguru.giraffe.server.utils.LinkUtil"%> <%@page import="com.insightguru.giraffe.server.controller.LoginController"%> <%!private String getHeaderRow(MarketingSnippetType type) { final String extra; if (type ==MarketingSnippetType.COMPANY) { extra = ""; } else if (type == MarketingSnippetType.SECTOR) { extra = "Sector"; } else{ extra = ""; } return "IDType"+extra+"TickerExample DriverSnippetAction"; }%> <%!private String getSnippetRow(MarketingSnippet snippet) { final String extra; final MarketingSnippetType type = snippet.getSnippetType(); if (type ==MarketingSnippetType.COMPANY) { extra = ""; } else if (type == MarketingSnippetType.SECTOR) { extra = ""+snippet.getExampleCompany().getSector().getName()+""; } else{ extra = ""; } return "" + snippet.getId() +"" + "" + snippet.getSnippetType().name() + "" + extra + ""+ snippet.getExampleCompany().getSymbol()+" ("+snippet.getExampleCompany().getCompanyName()+")" + ""+ (snippet.getExampleDriver()==null?"Null":snippet.getExampleDriver().getIdentifier()) +"" + "
" + snippet.getSnippet().replace("<", "<") +"
" + " Edit | " + " Delete " + ""; }%> <%!private String getAddlink(MarketingSnippetType snippet) { return "editsnippet.jsp?action=add&type="+snippet.ordinal(); }%> <%@ include file="components/contentType.jsp" %> Add or Edit Snippets <%@ include file="components/commonHead.jsp" %>
<% User loggedInUser = UserDAO.getCurrentUser(); if(loggedInUser == null || !UserProfileBitFlags.isAdmin(loggedInUser)) { %>

Admin Access Only

Logout and try again <% } else { %>

Add or Edit Snippets

<% if ("edit".equals(request.getParameter("action"))) { MarketingSnippet editable = MarketingSnippetDAO.getSnippetById(ServletUtil.getIntegerParameter(request,"id")); %> Editing snippet <%=editable.getId()%> of type <%=editable.getSnippetType().name()%>:
Example Ticker:
Example Driver: (Optional)
Snippets (one per line):

<% } else if ("delete".equals(request.getParameter("action"))) { %> Please email the following to dev@trefis.com:
Please delete snippet <%= request.getParameter("id") %>
ex: delete from marketing_snippet where id = <%= request.getParameter("id") %>;
Back <% } else if ("add".equals(request.getParameter("action"))) { MarketingSnippetType addType = MarketingSnippetType.values()[ServletUtil.getIntegerParameter(request,"type")]; %>

Adding snippet of type <%=addType.name()%>:

Example Ticker:
Example Driver: (Optional)
Snippets (one per line):

<% } else { %> <% if ("doEdit".equals(request.getParameter("action"))) { MarketingSnippet editable = MarketingSnippetDAO.getSnippetById(ServletUtil.getIntegerParameter(request,"id")); editable.setSnippet(request.getParameter("snippet")); editable.setExampleCompany(CompanyDAO.getCompany(request.getParameter("ticker"))); Driver driver = null; if (!TextUtil.NullOrEmpty(request.getParameter("driver"))) driver = MarketingSnippetDAO.getDriverByIdentifier(request.getParameter("driver")); editable.setExampleDriver(driver); HibernateUtil.getCurrentSession().flush(); %>

Saved edits for snippet id <%=editable.getId()%>

<%=getHeaderRow(editable.getSnippetType())%> <%=getSnippetRow(editable)%>
<% } else if ("doAdd".equals(request.getParameter("action"))) { MarketingSnippetType addType = MarketingSnippetType.values()[ServletUtil.getIntegerParameter(request,"type")]; MarketingSnippet newSnippet = new MarketingSnippet(); newSnippet.setSnippet(request.getParameter("snippet")); Driver driver = null; if (!TextUtil.NullOrEmpty(request.getParameter("driver"))) driver = MarketingSnippetDAO.getDriverByIdentifier(request.getParameter("driver")); newSnippet.setExampleCompany(CompanyDAO.getCompany(request.getParameter("ticker"))); newSnippet.setExampleDriver(driver); newSnippet.setSnippetType(addType); HibernateUtil.getCurrentSession().save(newSnippet); HibernateUtil.getCurrentSession().flush(); %>

Added new snippet with id <%=newSnippet.getId()%>

<%=getHeaderRow(newSnippet.getSnippetType())%> <%= getSnippetRow(newSnippet) %>
<% } %>

Default Snippet (Add):

<%=getHeaderRow(MarketingSnippetType.DEFAULT)%> <% for (MarketingSnippet snippet : MarketingSnippetDAO.getDefaultSnippets()) { %> <%=getSnippetRow(snippet)%> <% } %>

Sector Snippets (Add): <% List sectorSnippetCounts = MarketingSnippetDAO.getSectorSnippetCounts(); List sectorMissingSnippet = new ArrayList(); List sectorMultipleSnippet = new ArrayList(); for (MarketingSnippetDAO.SectorSnippetCount ssc : sectorSnippetCounts) { if (ssc.getCount() >1) { sectorMultipleSnippet.add(ssc.getSector()); } } %> <% if (sectorMissingSnippet.size() >0 ) { %>

The following restricted sectors are missing snippets:
<%= TextUtil.joinString(sectorMissingSnippet, ", ") %>
<% } // if (sectorMissingSnippet.size() >0 ) %> <% if (sectorMultipleSnippet.size() >0 ) { %>
The following restricted sectors have multiple snippets:
<%=getHeaderRow(MarketingSnippet.MarketingSnippetType.SECTOR)%> <% for (Sector sector : sectorMultipleSnippet) { for (MarketingSnippet snippet : MarketingSnippetDAO.getSnippetsForSector(sector)) { %> <%= getSnippetRow(snippet) %> <% } } %>
<% } // if (sectorMultipleSnippet.size() >0 ) %> <%=getHeaderRow(MarketingSnippetType.SECTOR)%> <% for (MarketingSnippet snippet : MarketingSnippetDAO.getSectorSnippets()) { %> <%=getSnippetRow(snippet)%> <% } %>

Company Snippets (Add): <% List companySnippetCounts = MarketingSnippetDAO.getCompanySnippetCounts(); List companyMissingSnippet = new ArrayList(); List companyMultipleSnippet = new ArrayList(); for (MarketingSnippetDAO.CompanySnippetCount ssc : companySnippetCounts) { Company company = ssc.getCompany(); if (ssc.getCount() >1) { companyMultipleSnippet.add(ssc.getCompany().getSymbol()); } } %> <% if (companyMissingSnippet.size() >0 ) { %>

The following companies from restricted sectors are missing snippets:
<%= TextUtil.joinString(companyMissingSnippet, ", ") %>
<% } // if (sectorMissingSnippet.size() >0 ) %> <% if (companyMultipleSnippet.size() >0 ) { %>
The following companies have multiple snippets:
<%=getHeaderRow(MarketingSnippet.MarketingSnippetType.COMPANY)%> <% for (String symbol : companyMultipleSnippet) { for (MarketingSnippet snippet : MarketingSnippetDAO.getSnippetsForSymbol(symbol)) { %> <%= getSnippetRow(snippet) %> <% } } %>
<% } // if (sectorMultipleSnippet.size() >0 ) %> <%=getHeaderRow(MarketingSnippetType.COMPANY)%> <% for (MarketingSnippet snippet : MarketingSnippetDAO.getCompanySnippets()) { %> <%= getSnippetRow(snippet) %> <% } %>

<% } %> <% } // end if admin %>