<%@ page import="oracle.jsp.webutil.personalization.Item" errorPage="error.jsp" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/personalization.tld" prefix="op" %>

<html>
<head><title>Personalization Demo</title></head>
<body>
<b><font size=+1>evaluateItems Tag</font></b>
<p>
<%
   String inputItemList = request.getParameter("inputItemList");
   String forItem = request.getParameter("forItem");
   String taxonomyID = request.getParameter("taxonomyID");
   String itemType = request.getParameter("itemType");
   String itemListIDStrs[] = request.getParameterValues("itemListID");
   String forItemIDStrs[] = request.getParameterValues("forItemID");
   String tuningName = request.getParameter("tuningName");
   String tuningMeth = request.getParameter("tuningMeth");
   String dfltTuning = request.getParameter("dfltTuning");
   String sortOrder = request.getParameter("sortOrder");

   long[] itemIDs = null;
   Item[] items  = null;
   if( itemListIDStrs != null ) {
       itemIDs = new long[itemListIDStrs.length];
       for( int i=0; i<itemListIDStrs.length;i++) {
          try {
              itemIDs[i] = Long.parseLong(itemListIDStrs[i]);
          } catch(Exception e) {}
       }
   }

   if( inputItemList != null || forItem != null ) {
      if( inputItemList != null ) {
         items = new Item[2];
         for(int i=0; i<2; i++) {
            items[i] = new Item(itemType, itemIDs[i]);
         }
  
%>
<font color="#FF0000">Using inputItemList:
<%=items[0].getID()%>; <%=items[1].getID()%>
</font><br>
<%
      }

      if( forItem != null ) {
         if( forItemIDStrs != null ) {
           itemIDs = new long[forItemIDStrs.length];
           for( int i=0; i<forItemIDStrs.length;i++) {
              try {
                itemIDs[i] = Long.parseLong(forItemIDStrs[i]);
              } catch(Exception e) {}
           }
         }
%>
<font color="#FF0000">Using forItem tags, items:
<% for(int i=0; i<itemIDs.length; i++) { %>
<%=itemIDs[i]%>;&nbsp;
<% } %>
</font><br>
<%}%>
</p>
<% if(tuningMeth.equals("Dflt")) { %>
<font color="#FF0000">Using Default Tuning (not using forItem tags)</font><br>
<% if( inputItemList != null) { %>
<op:evaluateItems inputItemList="<%=items%>"
                  storeResultsIn="results"
                  taxonomyID="<%=taxonomyID%>"
                  sortOrder="<%=sortOrder%>">
</op:evaluateItems>
<%  items = results;
} else { %>
<op:evaluateItems 
                  storeResultsIn="results"
                  taxonomyID="<%=taxonomyID%>"
                  sortOrder="<%=sortOrder%>">
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:evaluateItems>
<% items = results; }
} else  if(tuningMeth.equals("Name")){ %>
<font color="#FF0000">Using Tuning from Config file</font><br>
<% if( inputItemList != null) { %>
<op:evaluateItems inputItemList="<%=items%>"
                  storeResultsIn="results"
                  taxonomyID="<%=taxonomyID%>"
                  tuningName="<%=tuningName%>"
                  sortOrder="<%=sortOrder%>">
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:evaluateItems>
<%  items = results; } else { %>
<op:evaluateItems 
                  storeResultsIn="results"
                  taxonomyID="<%=taxonomyID%>"
                  tuningName="<%=tuningName%>"
                  sortOrder="<%=sortOrder%>">
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:evaluateItems>
<%  items = results; }
} else { /* deliberately allow null itemList */%>
<font color="#FF0000">Using Tuning attributes</font><br>
<op:evaluateItems inputItemList="<%=items%>"
                  storeResultsIn="results"
                  taxonomyID="<%=taxonomyID%>"
                  tuningDataSource="<%=request.getParameter(\"tuningDS\")%>"
                  tuningInterestDimension="<%=request.getParameter(\"tuningID\")%>"
                  tuningPersonalizationIndex="<%=request.getParameter(\"tuningPI\")%>"
                  tuningProfileDataBalance="<%=request.getParameter(\"tuningPDB\")%>"
                  tuningProfileUsage="<%=request.getParameter(\"tuningPU\")%>"
                  sortOrder="<%=sortOrder%>">
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:evaluateItems>
<%  items = results;
} %>
<p>Your items were rated as follows :</p>
<table border=1>
<tr><td>Type</td><td>ID</td><td>Rating</td></tr>
<%
for(int i=0; i<items.length; i++) {
%>
<tr><td><%=items[i].getType()%></td><td><%=items[i].getID()%></td>
     <td><%=items[i].getPrediction()%></td></tr>
<%
}
%>
</table>
<hr>
<table?
<tr>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><form action="tagdemodriver.jsp" method="post">
<input type="hidden" name="target" value="Return"/>
<input type="submit" name="Choose another tag" value="Choose another tag"/>
</form></td></tr></table>

<% } 
%>
<p>
<form action="evaluateitem.jsp" method="post">
<table>
<tr><td><b>Use inputItemList:</b> </td><td><input type="checkbox" name="inputItemList" value="true" checked/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="itemListID"/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="itemListID"/></td></tr>
<tr><td><b>Use forItem:</b> </td><td><input type="checkbox" name="forItem" value="true"/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="forItemID"/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="forItemID"/></td></tr>
<tr><td><b>Taxonomy ID:</b> </td><td><input type="text" name="taxonomyID"/></td></tr>
<tr><td><b>Item Type:</b> </td><td><input type="text" name="itemType"/></td></tr>
<tr><td><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tuning </b></td> </tr>
<tr><td><label><input type="radio" name="tuningMeth" value="Attr" checked>Use Attributes </label></td>
<td><label><input type="radio" name="tuningMeth" value="Name" >Use Tuning Name <input type="text" name="tuningName"/></label></td>
<td><label><input type="radio" name="tuningMeth" value="Dflt" >Use Default Tuning </label></td>
</tr>
<tr><td><b>Tuning Data Source:</b> </td><td><input type="text" name="tuningDS"/></td></tr>
<tr><td><b>Tuning Interest Dimension:</b> </td><td><input type="text" name="tuningID"/></td></tr>
<tr><td><b>Tuning Personalization Index:</b> </td><td><input type="text" name="tuningPI"/></td></tr>
<tr><td><b>Tuning Profile Data Balance:</b> </td><td><input type="text" name="tuningPDB"/></td></tr>
<tr><td><b>Tuning Profile Usage:</b> </td><td><input type="text" name="tuningPU"/></td></tr>
<tr><td><b>sortOrder:</b> </td><td><select name="sortOrder">
<option value="NONE">NONE</option>
<option value="">no value</option>
<option value="DESCEND">DESCEND</option>
<option value="ASCEND">ASCEND</option>
</select></td>
</tr>
</table>
<input type="submit" name="submit" value="Evaluate"/>
</form>
</body>
</html>
