Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.hotspotstore.controllers;


import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.hotspotstore.model.ContentPojo;
import com.hotspotstore.model.Snippet;
import com.hotspotstore.storage.Mongo;

@Results({
    @Result(name = "show", location = "entity-show.vm"),
    @Result(name = "redirect", location = "${redirectUrl}", type = "redirect", params={"statusCode", "301"})
})
public class EntityController extends BaseController{
        
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        private String id;
        private long productId;
        private ContentPojo cp;

        @Actions({
                @Action("/mobile-phones"),
                @Action("/cameras"),
                @Action("/mobile-accessories"),
                @Action("/tablets"),
                @Action("/laptops"),
                @Action("/laptop-accessories"),
                @Action("/entity"),
                @Action("/music-players"),
                @Action("/smart-watches"),
                @Action("/projectors"),
                @Action("/smart-watch-accessories")
        })
        public String show() throws Exception{
                Gson gson = new Gson();
                cp = gson.fromJson(Mongo.getEntityById(productId).toString(), ContentPojo.class);
                return "show";
        }
        
        public String getId() {
                return id;
        }
        
        public ContentPojo getCp() {
                return cp;
        }

        public void setCp(ContentPojo cp) {
                this.cp = cp;
        }

        public void setId(String id) {
                String[] tokens = id.split("-");
        this.id = tokens[tokens.length - 1];
        this.productId = Long.parseLong(this.id);
        }
        
}