Subversion Repositories SmartDukaan

Rev

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

Rev 2672 Rev 2718
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.io.BufferedReader;
-
 
4
import java.io.File;
-
 
5
import java.io.FileInputStream;
-
 
6
import java.io.IOException;
-
 
7
import java.io.InputStreamReader;
-
 
8
import java.util.LinkedHashMap;
3
import java.util.List;
9
import java.util.List;
-
 
10
import java.util.Map;
4
 
11
 
5
import in.shop2020.model.v1.user.UserContextService;
12
import in.shop2020.model.v1.user.UserContextService;
6
import in.shop2020.model.v1.user.UserNote;
13
import in.shop2020.model.v1.user.UserNote;
-
 
14
import in.shop2020.serving.utils.Utils;
7
import in.shop2020.thrift.clients.UserContextServiceClient;
15
import in.shop2020.thrift.clients.UserContextServiceClient;
8
 
16
 
9
import org.apache.log4j.Logger;
17
import org.apache.log4j.Logger;
10
import org.apache.struts2.convention.annotation.Action;
18
import org.apache.struts2.convention.annotation.Action;
11
import org.apache.struts2.convention.annotation.InterceptorRef;
19
import org.apache.struts2.convention.annotation.InterceptorRef;
Line 21... Line 29...
21
 
29
 
22
    private String id;
30
    private String id;
23
 
31
 
24
	private static Logger logger = Logger.getLogger(Class.class);
32
	private static Logger logger = Logger.getLogger(Class.class);
25
	
33
	
26
	private List<UserNote> notes;
34
	private Map<String, String> slideNotes;
27
	
35
	
28
	public MyNotesController() {
36
	public MyNotesController() {
29
		super();
37
		super();
30
	}
38
	}
31
 
39
 
32
	@Action(value="my-notes",interceptorRefs={@InterceptorRef("myDefault")})
40
	@Action(value="my-notes",interceptorRefs={@InterceptorRef("myDefault")})
33
	public String show()	{
41
	public String show()	{
-
 
42
		String responseContentType = null;
-
 
43
		
34
        try {
44
        try {
-
 
45
        	String[] idParts = this.id.split("-");
-
 
46
        	
35
        	long entityId = Long.parseLong(this.id);
47
        	long entityId = Long.parseLong(idParts[0]);
-
 
48
        	responseContentType = idParts[1];
-
 
49
        	
-
 
50
        	this.slideNotes = getSlideNames(entityId);
-
 
51
        	
36
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
52
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
37
			this.notes = userClient.getUserNotes(userinfo.getUserId(), entityId);
53
			List<UserNote> userNotes = userClient.getUserNotes(userinfo.getUserId(), entityId);
-
 
54
			
-
 
55
			for (UserNote note: userNotes)	{
-
 
56
				slideNotes.put(note.getSlide(), note.getNote());
-
 
57
			}
38
		} catch (NumberFormatException e) {
58
		} catch (NumberFormatException e) {
39
			logger.error("Number Format Exception. String: " + this.id);
59
			logger.error("Number Format Exception. String: " + this.id);
40
		} catch (Exception e) {
60
		} catch (Exception e) {
41
			logger.error("Exception: " + e.getMessage());
61
			logger.error("Exception: " + e.getMessage());
42
		}
62
		}
43
 
63
 
44
		return "show";
64
		return responseContentType.equals("json") ? "json" : "show";
45
	}
65
	}
46
 
66
 
47
	// Handle POST /save-note/
67
	// Handle POST /save-note/
48
	@Action(value="save-note",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
68
	@Action(value="save-note",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
49
	public String create()	{
69
	public String create()	{
50
        
70
        
51
		try {
71
		try {
52
        	long entityId = Long.parseLong(request.getParameter("entity"));
72
        	long entityId = Long.parseLong(request.getParameter("entity"));
53
        	long slideId = Long.parseLong(request.getParameter("slide"));
73
        	String slide = request.getParameter("slide");
54
        	String note = request.getParameter("note");
74
        	String note = request.getParameter("note");
55
 
75
 
56
        	UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
76
        	UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
57
			userClient.putUserNote(userinfo.getUserId(), entityId, slideId, note);
77
			userClient.putUserNote(userinfo.getUserId(), entityId, slide, note);
58
			
78
			
59
		} catch (NumberFormatException e) {
79
		} catch (NumberFormatException e) {
60
			logger.error("Number Format Exception: " + e.getMessage());
80
			logger.error("Number Format Exception: " + e.getMessage());
61
		} catch (Exception e) {
81
		} catch (Exception e) {
62
			logger.error("Exception: " + e.getMessage());
82
			logger.error("Exception: " + e.getMessage());
63
		}
83
		}
64
		return "success";
84
		return "success";
65
	}
85
	}
66
	
86
	
67
	public List<UserNote> getNotes()	{
87
	public Map<String, String> getSlideNotes()	{
68
		return this.notes;
88
		return this.slideNotes;
69
	}
89
	}
70
	
90
	
-
 
91
    private Map<String, String> getSlideNames(long productId) {
-
 
92
    	Map<String, String> slides = new LinkedHashMap<String, String>();
-
 
93
        
-
 
94
        File f = new File(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideNamesSnippet.html");
-
 
95
        FileInputStream fis = null;
-
 
96
        try {
-
 
97
            fis = new FileInputStream(f);
-
 
98
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
-
 
99
            
-
 
100
            String line = br.readLine();	// Ignoring first line, which contains Product name and not Slide Label
-
 
101
            
-
 
102
            while((line = br.readLine()) != null){
-
 
103
                
-
 
104
                String[] parts = line.split("!!!");
-
 
105
                String slideName = parts[0];
-
 
106
                
-
 
107
                if(!slides.containsKey(slideName)){
-
 
108
                    slides.put(slideName, null);
-
 
109
                }
-
 
110
            }
-
 
111
        } catch (IOException e) {
-
 
112
            e.printStackTrace();
-
 
113
        }
-
 
114
        return slides;
-
 
115
    }
-
 
116
	
71
    public String getId() {
117
    public String getId() {
72
        return this.id;
118
        return this.id;
73
    }
119
    }
74
 
120
 
75
    /**
121
    /**