Coverage Report - no.sesat.search.util.TradeDoubler
 
Classes in this File Line Coverage Branch Coverage Complexity
TradeDoubler
0%
0/29
0%
0/10
1.727
 
 1  
 /* Copyright (2007) Schibsted Søk AS
 2  
  * This file is part of SESAT.
 3  
  *
 4  
  *   SESAT is free software: you can redistribute it and/or modify
 5  
  *   it under the terms of the GNU Affero General Public License as published by
 6  
  *   the Free Software Foundation, either version 3 of the License, or
 7  
  *   (at your option) any later version.
 8  
  *
 9  
  *   SESAT is distributed in the hope that it will be useful,
 10  
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
  *   GNU Affero General Public License for more details.
 13  
  *
 14  
  *   You should have received a copy of the GNU Affero General Public License
 15  
  *   along with SESAT.  If not, see <http://www.gnu.org/licenses/>.
 16  
  */
 17  
 package no.sesat.search.util;
 18  
 
 19  
 import java.security.MessageDigest;
 20  
 import java.security.NoSuchAlgorithmException;
 21  
 import java.util.UUID;
 22  
 import javax.servlet.http.Cookie;
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import org.apache.commons.codec.binary.Hex;
 25  
 
 26  
 
 27  
 
 28  
 /**
 29  
  * <b> Must be threadsafe </b>
 30  
  *
 31  
  * @version <tt>$Id$</tt>
 32  
  */
 33  
 public final class TradeDoubler {
 34  
 
 35  
     private final static String secretCode = "997";
 36  
     private final static String organization = "1064392";
 37  
     private final static String event = "46757";
 38  
     private final HttpServletRequest request;
 39  
 
 40  0
     public TradeDoubler(HttpServletRequest request) {
 41  0
         this.request = request;
 42  0
     }
 43  
 
 44  
     public String getChecksum(
 45  
             final String orderNumber,
 46  
             final String orderValue) throws RuntimeException {
 47  
 
 48  0
         MessageDigest digest = null;
 49  
         try {
 50  0
             digest = MessageDigest.getInstance("MD5");
 51  0
         } catch(NoSuchAlgorithmException e) {
 52  0
             throw new RuntimeException(e.getMessage());
 53  0
         }
 54  0
         final String s = new String(TradeDoubler.getSecretCode() + orderNumber + orderValue);
 55  0
         digest.update(s.getBytes());
 56  0
         return new String(Hex.encodeHex(digest.digest()));
 57  
     }
 58  
 
 59  
     public String getUUID() {
 60  0
         return UUID.randomUUID().toString();
 61  
     }
 62  
 
 63  
     public static String getEvent() {
 64  0
         return event;
 65  
     }
 66  
 
 67  
     public static String getOrganization() {
 68  0
         return organization;
 69  
     }
 70  
 
 71  
     public static String getSecretCode() {
 72  0
         return secretCode;
 73  
     }
 74  
 
 75  
     public String getCookieTDUID() {
 76  0
         return getCookie("TRADEDOUBLER");
 77  
     }
 78  
 
 79  
     public String getCookieOrderNumber(){
 80  0
         return getCookie("TRADEDOUBLER-onr");
 81  
     }
 82  
 
 83  
     public String getCookieChecksum(){
 84  0
         return getCookie("TRADEDOUBLER-cs");
 85  
     }
 86  
 
 87  
     public String getCookieReportInfo(){
 88  0
         return getCookie("TRADEDOUBLER-ri");
 89  
     }
 90  
 
 91  
     private String getCookie(String name){
 92  0
         if (this.request == null){
 93  0
             return "";
 94  
         }
 95  0
         String value = "";
 96  0
         final Cookie[] cookies = this.request.getCookies();
 97  0
         if (cookies != null){
 98  0
             for (int i = 0; i < cookies.length; i++) {
 99  0
                 if (cookies[i].getName().equals(name)) {
 100  0
                     if (cookies[i].getValue() != null) {
 101  0
                         value = cookies[i].getValue();
 102  
                     }
 103  
                 }
 104  
             }
 105  
         }
 106  0
         return value;
 107  
     }
 108  
 }