Subversion Repositories SmartDukaan

Rev

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

Rev 395 Rev 449
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.serving.pages.PageContentKeys;
3
import in.shop2020.serving.pages.PageContentKeys;
4
import in.shop2020.serving.pages.PageEnum;
4
import in.shop2020.serving.pages.PageEnum;
5
import in.shop2020.serving.pages.PageManager;
5
import in.shop2020.serving.pages.PageManager;
-
 
6
import in.shop2020.serving.utils.Utils;
6
 
7
 
7
import java.io.UnsupportedEncodingException;
8
import java.io.UnsupportedEncodingException;
8
import java.util.HashMap;
9
import java.util.HashMap;
9
import java.util.Map;
10
import java.util.Map;
10
import java.util.StringTokenizer;
11
import java.util.StringTokenizer;
Line 20... Line 21...
20
import org.apache.struts2.util.ServletContextAware;
21
import org.apache.struts2.util.ServletContextAware;
21
 
22
 
22
 
23
 
23
 
24
 
24
 
25
 
25
public class MyresearchController extends BaseController implements ServletRequestAware{
26
public class MyresearchController extends BaseController{
26
	
27
	
27
	/**
28
	/**
28
	 * 
29
	 * 
29
	 */
30
	 */
30
	private static Log log = LogFactory.getLog(MyresearchController.class);
31
	private static Log log = LogFactory.getLog(MyresearchController.class);
31
	
32
	
32
	/**
-
 
33
	 * 
-
 
34
	 */
-
 
35
	private HttpServletRequest request;
-
 
36
 
33
 
-
 
34
 
37
	//id is in format xyz_zbc where xyz is customerid and abc is entityid
35
	//id is in format xyz where xyz is abc is entityid
38
	private String id;
36
	private String id;
39
	
37
	
40
	private String customer_id;
38
	//private String customer_id;
41
	
39
	
42
	private String entity_id;
40
	private String entity_id;
43
	
-
 
-
 
41
	private String htmlSnippet;
44
    // GET /test
42
    // GET /test
45
    public HttpHeaders index() throws UnsupportedEncodingException {
43
    public HttpHeaders index() throws UnsupportedEncodingException {
46
    	log.info("this.request=" + this.request);
44
    	log.info("this.request=" + this.request);
47
	
45
	
48
        return new DefaultHttpHeaders("show")
46
        return new DefaultHttpHeaders("show")
49
            .disableCaching();
47
            .disableCaching();
50
    }
48
    }
51
 
49
 
52
	
50
	
53
	//Handle /myresearch/{id}
51
	//Handle /myresearch/{id}
54
	public HttpHeaders show(){
52
	public HttpHeaders create(){
-
 
53
		log.info("list of item ids is " + this.request.getParameter("productid"));
-
 
54
		String itemIds = this.request.getParameter("productid");
-
 
55
		if(itemIds == null){
-
 
56
			itemIds = "1000008_1000005";
-
 
57
		}
-
 
58
    	//log.info("list of item ids is " + this.request.getParameter("productid"));
-
 
59
    	//String itemIds = this.reqparams.get("productid")[0];
-
 
60
		
-
 
61
    	
55
		getFields();
62
		//getFields();
56
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
63
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
57
		params.put(PageContentKeys.ENTITY_ID, entity_id);
64
		params.put(PageContentKeys.ENTITY_ID, itemIds);
58
		params.put(PageContentKeys.CUSTOMER_ID, customer_id);
65
		params.put(PageContentKeys.CUSTOMER_ID, userinfo.getUserId()+"");
59
		PageManager.getPageManager().getPageContents(PageEnum.MY_RESEARCH_PAGE, params);
66
		htmlSnippet = PageManager.getPageManager().getPageContents(PageEnum.MY_RESEARCH_PAGE, params).get("HTML");
60
		//return new DefaultHttpHeaders("index").disableCaching();
67
		//return new DefaultHttpHeaders("index").disableCaching();
61
		return new DefaultHttpHeaders("show");
68
		return new DefaultHttpHeaders("success");
-
 
69
	}
-
 
70
	
-
 
71
	public HttpHeaders destroy(){
-
 
72
		log.info("list of item ids is " + this.request.getParameter("productid"));
-
 
73
		String itemIds = this.request.getParameter("productid");
-
 
74
		if(itemIds == null){
-
 
75
			itemIds = "1000008_1000005";
-
 
76
		}
-
 
77
		long itemId = 0;
-
 
78
		StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
-
 
79
		while(tokenizer.hasMoreTokens()){
-
 
80
			itemId = Long.parseLong(tokenizer.nextToken());
-
 
81
			Utils.deleteFromMyResearch(userinfo.getUserId(), itemId);	
-
 
82
		}
-
 
83
		return new DefaultHttpHeaders("success");
-
 
84
	}
-
 
85
	
-
 
86
	public String getHtmlSnippet(){
-
 
87
		return htmlSnippet;
62
	}
88
	}
63
	
89
	
64
	private void getFields(){
90
	private void getFields(){
65
		StringTokenizer tokenizer = new StringTokenizer(id,"_");
91
		StringTokenizer tokenizer = new StringTokenizer(id,"_");
66
		customer_id = tokenizer.nextToken();
92
		//customer_id = tokenizer.nextToken();
67
		entity_id = tokenizer.nextToken();
93
		entity_id = tokenizer.nextToken();
68
	}
94
	}
69
	
95
	
70
    /**
96
    /**
71
     * 
97
     * 
72
     * @param id
98
     * @param id
73
     */
99
     */
74
    public void setId(String id) {
100
    public void setId(String id) {
75
        this.id = id;
101
        this.id = id;
76
    }
102
    }
77
 
-
 
78
 
-
 
79
    @Override
-
 
80
	public void setServletRequest(HttpServletRequest request) {
-
 
81
		this.request = request;
-
 
82
	}
-
 
83
 
-
 
84
	
103
	
85
}
104
}