Oracle® Application Server Personalization Programmer's Guide
10g Release 2 (10.1.2) B14051-01 |
|
Previous |
Next |
This appendix contains ProxyTest.java
, a sample Java program that illustrates using REAPI.
Before you can execute this program, an appropriate model must be built and deployed to an RE. If no data is returned, it may indicate that the model is not sufficient for the data. The code is installed in ${ORACLE_HOME}/dmt/reapi/rt/
on the system where Oracle Application Server is installed.
Note: REAPI is installed on the system where Oracle Application Server is installed. It is simplest to run this program on that system. |
// Copyright (c) 2001, 2005 Oracle Corp /////////////////////////////////////////////////////////////////////// // // Test program exercises the functionality of // REAPI. // // Step 1 creates a unique session ID // Step 2 creates a proxy instance // Step 3 creates a session // Step 4 creates settings data (IdentificationData, TuningSettings, // FilteringSettings, hotPick list, item list) // Step 5 gets recomendations and ratings // Step 6 closes session // Step 7 destroys the proxy and flushes data cache //////////////////////////////////////////////////////////////////////// import oracle.dmt.op.re.base.DataItem; import oracle.dmt.op.re.base.Enum; import oracle.dmt.op.re.base.FilteringSettings; import oracle.dmt.op.re.base.TuningSettings; import oracle.dmt.op.re.reapi.rt.IdentificationData; import oracle.dmt.op.re.reapi.rt.REProxyManager; import oracle.dmt.op.re.reapi.rt.REProxyRT; import oracle.dmt.op.re.reapi.rt.RecommendationContent; import oracle.dmt.op.re.reapi.rt.RecommendationList; import oracle.dmt.op.re.reexception.BadDBConnectionException; import oracle.dmt.op.re.reexception.ErrorExecutingRE; import oracle.dmt.op.re.reexception.InvalidIDException; /** * Class ProxyTest * <P> * @author Oracle Corporation */ public class ProxyTest { static boolean bVerbose; static final String SESSIONEXISTS = ""; /** * Constructor */ public ProxyTest() { } /** * main * @param args */ public static void main(String[] args) { long lStart; long lTotal = 0; String sProxyName = "REP1"; String sdbURL = "jdbc:oracle:thin:@host:1521:sid"; // sdbURL must be correct // for your installation String sUser = "RE"; String sPass = "REPW"; int cSize = 3000; // Kbytes int interval = 10000; // in millisec REProxyRT proxy; // Step 1: Create a unique Session ID. String custID = "1"; java.util.Date tmp = new java.util.Date(); Long tmpInt = new Long(tmp.getTime()); String sessionID = tmpInt.toString(); String trace = null; lStart = System.currentTimeMillis(); try { // Step 2: Get a proxy instance. if ((proxy = REProxyManager.getProxy(sProxyName)) == null) proxy = REProxyManager.createProxy(sProxyName, sdbURL, sUser, sPass, cSize, interval); // Step 3: create OP session proxy.createCustomerSession(custID, sessionID); // Step 4: create settings data IdentificationData idData = IdentificationData.createSessionful( sessionID, Enum.User.CUSTOMER); TuningSettings tunings = new TuningSettings( Enum.DataSource.NAVIGATION, Enum.InterestDimension.NAVIGATION, Enum.PersonalizationIndex.LOW, Enum.ProfileDataBalance.BALANCED, Enum.ProfileUsage.INCLUDE); long[] hotPickGroups = {1,2,3,4,5,6,7,10,11}; long[] m_catList = {1,2,3,4,5,83,48,18,93,83}; int taxonomy=1; FilteringSettings filters = new FilteringSettings(taxonomy); filters.setItemFiltering( taxonomy, m_catList); RecommendationContent recContent = new RecommendationContent(Enum.Sorting.ASCENDING); try{ //Create list of items for testing DataItem[] items = new DataItem[4]; items[0] = new DataItem( "MOVIE", 449, Enum.DataSource.NAVIGATION, "1"); items[1] = new DataItem( "MOVIE", 282, Enum.DataSource.PURCHASING, "1"); items[2] = new DataItem( "MOVIE", 122, Enum.DataSource.NAVIGATION, "1"); items[3] = new DataItem( "MOVIE", 199, Enum.DataSource.NAVIGATION, "1"); // Step 5: Get recomendations and ratings and print them out. // Note use of toString. try{ System.out.println("\n################ 1 recommendBottomItems" + "################"); //Call recommendBottonItems RecommendationList es1 = proxy.recommendBottomItems( idData, 10, tunings, filters, recContent); System.out.println("Number of Recommendations: " + es1.getNumberOfRecommendations()); System.out.println(es1.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 2 rateItems ################"); //Call rateItems RecommendationList es2 = proxy.rateItems( idData, items, 1, tunings, recContent); System.out.println("Number of Recommendations: " + es2.getNumberOfRecommendations()); System.out.println(es2.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 3 selectFromHotPicks " + "################"); //call selectFromHotPicks RecommendationList es3 = proxy.selectFromHotPicks( idData, 6, hotPickGroups, tunings, filters, recContent); System.out.println(""); System.out.println("Number of Recommendations: " + es3.getNumberOfRecommendations()); System.out.println(es3.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 4 crossSellForItemFromHotPicks " + "################"); //Call crossSellForItemFromHotPicks RecommendationList es4 = proxy.crossSellForItemFromHotPicks( idData, items[3], 10, hotPickGroups, tunings, filters, recContent); System.out.println(""); System.out.println("Number of Recommendations: " + es4.getNumberOfRecommendations()); System.out.println(es4.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 5 recommendCrossSellForItem " + "################"); //Call recommendCrossSellForItem RecommendationList es5 = proxy.recommendCrossSellForItem( idData, items[0], 10, tunings, filters, recContent); System.out.println(""); System.out.println("Number of Recommendations: " + es5.getNumberOfRecommendations()); System.out.println(es5.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 6 recommendCrossSellForItems " + "################"); RecommendationList es6 = proxy.recommendCrossSellForItems( idData, items, 10, tunings, filters, recContent); System.out.println(""); System.out.println("Number of Recommendations: " + es6.getNumberOfRecommendations()); System.out.println(es6.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 7 crossSellForItemsFromHotPicks " + "################"); RecommendationList es7 = proxy.crossSellForItemsFromHotPicks( idData, items, 10, hotPickGroups, tunings, filters, recContent); System.out.println(""); System.out.println("Number of Recommendations: " + es7.getNumberOfRecommendations()); System.out.println(es7.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 8 rateItem ################"); float es9 = proxy.rateItem( idData, items[2], 1, tunings, recContent ); System.out.println(""); System.out.println("Result for recomend item: " + es9); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 9 recommendFromHotPicks " + "################"); RecommendationList es10 = proxy.recommendFromHotPicks( idData, 10, hotPickGroups, tunings, filters, recContent); System.out.println(""); System.out.println("Number of Recommendations: " + es10.getNumberOfRecommendations()); System.out.println(es10.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } try{ System.out.println("\n################ 10 recommendTopItems " + "################"); RecommendationList es11 = proxy.recommendTopItems( idData, 10, tunings, filters, recContent); System.out.println(""); System.out.println("Number of Recommendations: " + es11.getNumberOfRecommendations()); System.out.println(es11.toString()); } catch(ErrorExecutingRE e) { e.printStackTrace(); } } catch(BadDBConnectionException bdbe) { bdbe.printStackTrace(); } // Step 6: Close session proxy.closeSession(idData); // Step 7: Call destroy proxy (will flush data cache) REProxyManager.destroyProxy(sProxyName); } catch (ErrorExecutingRE se) { System.err.println(se); } catch (InvalidIDException iie) { System.err.println(iie); } catch(BadDBConnectionException bdbe) { bdbe.printStackTrace(); } catch (Exception e) { System.err.println(e); e.printStackTrace(); } } }