Subversion Repositories SmartDukaan

Rev

Rev 2620 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2620 Rev 2699
Line 14... Line 14...
14
 * limitations under the License.
14
 * limitations under the License.
15
 */
15
 */
16
 
16
 
17
package in.shop2020.web.mappers;
17
package in.shop2020.web.mappers;
18
 
18
 
-
 
19
import java.util.List;
19
import java.util.logging.Logger;
20
import java.util.logging.Logger;
20
 
21
 
21
import org.apache.hadoop.io.NullWritable;
22
import org.apache.hadoop.io.NullWritable;
22
 
23
 
23
import com.google.appengine.api.datastore.Entity;
24
import com.google.appengine.api.datastore.Entity;
Line 59... Line 60...
59
 
60
 
60
    // This is a silly mapper that's intended to show some of the capabilities
61
    // This is a silly mapper that's intended to show some of the capabilities
61
    // of the API.
62
    // of the API.
62
    @Override
63
    @Override
63
    public void map(Key key, Entity value, Context context) {
64
    public void map(Key key, Entity value, Context context) {
64
        log.warning("Mapping key: " + key);
65
        countItemEvent("ADD_TO_CART", key, value, context);
-
 
66
        countItemEvent("DELETE_FROM_CART", key, value, context);
-
 
67
        countProductEvent("PRODUCT_VIEW", key, value, context);
-
 
68
        countItemEvent("PRODUCT_COMPARE", key, value, context);
-
 
69
        countItemEvent("RESEARCH_ADD", key, value, context);
-
 
70
        countItemEvent("RESEARCH_DELETE", key, value, context);
-
 
71
    }
-
 
72
 
-
 
73
    private void countProductEvent(String eventType, Key key, Entity value, Context context) {
-
 
74
        if (value.hasProperty("eventType") && value.getProperty("eventType")!=null) {
-
 
75
            if (value.getProperty("eventType").toString().equals(eventType)) {
-
 
76
                    String productName = value.getProperty("productName").toString();
65
        context.getCounter("event", "count").increment(1);
77
                    context.getCounter(productName, eventType).increment(1);
-
 
78
            }
-
 
79
        }
-
 
80
    }
-
 
81
 
-
 
82
    @SuppressWarnings("unchecked")
-
 
83
    private void countItemEvent(String eventType, Key key, Entity value,
-
 
84
            Context context) {
66
        if (value.hasProperty("eventType") && value.getProperty("eventType")!=null) {
85
        if (value.hasProperty("eventType") && value.getProperty("eventType")!=null) {
67
            context.getCounter("eventType", value.getProperty("eventType").toString()).increment(1);
86
            if (value.getProperty("eventType").toString().equals(eventType)) {
-
 
87
                try {
-
 
88
                    List<Long> entityIds = (List<Long>)value.getProperty("itemIds");
-
 
89
                    for (Long entityId : entityIds) {
-
 
90
                        context.getCounter(entityId.toString(), eventType).increment(1);
-
 
91
                    }
-
 
92
                }
-
 
93
                catch (ClassCastException e) {
-
 
94
                    try {
-
 
95
                        Long entityId = (Long) value.getProperty("itemIds");
-
 
96
                        context.getCounter(entityId.toString(), eventType).increment(1);
-
 
97
                    }
-
 
98
                    catch (ClassCastException e1) {
-
 
99
                        log.warning("Unable to cast entityIds to List of long or long.");
-
 
100
                    }
-
 
101
                }
-
 
102
            }
68
        }
103
        }
69
    }
104
    }
70
}
105
}
71
106