Subversion Repositories SmartDukaan

Rev

Rev 2768 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2276 rajveer 1
package in.shop2020.creation.controllers;
2
import java.util.List;
3
import java.util.Map;
4
import java.util.StringTokenizer;
5
 
6
import in.shop2020.metamodel.core.Helpdoc;
7
import in.shop2020.metamodel.util.CreationUtils;
8
 
9
import org.apache.commons.lang.StringUtils;
10
import org.apache.juli.logging.Log;
11
import org.apache.juli.logging.LogFactory;
12
import org.apache.struts2.convention.annotation.InterceptorRef;
13
import org.apache.struts2.convention.annotation.InterceptorRefs;
14
import org.apache.struts2.convention.annotation.Result;
15
import org.apache.struts2.convention.annotation.Results;
16
 
17
@InterceptorRefs({
18
    @InterceptorRef("myDefault"),
19
    @InterceptorRef("login")
20
})
21
 
22
@Results({
23
    @Result(name="success", type="redirectAction", 
24
    		params = {"actionName" , "helpdoc"}),
25
    @Result(name="redirect", location="${url}", type="redirect")
26
})
27
 
28
public class HelpdocController extends BaseController {
29
	private static final long serialVersionUID = 1L;
30
	private static Log log = LogFactory.getLog(MediaController.class);
31
 
32
	private String id;
33
	private String helpdocId;
34
	private String name;
35
	private String content;
36
	private String terms;
37
	private String helpdocIds;
38
 
39
	public String index(){
40
		return "index";
41
	}
42
 
43
	public String show(){
44
		return "show";
45
	}
46
 
47
	public String create() throws Exception{
48
		//long id = Long.parseLong(this.getHelpdocId());
49
		long id = CreationUtils.getNewHelpdocId();
50
		String name = this.getName();
51
		Helpdoc helpdoc = new Helpdoc(id, name);
52
		if(name==null){
53
			addActionError("Name cannot be empty");
54
			return "index";	
55
		}
56
		if(this.getContent() != null){
57
			helpdoc.setContent(this.getContent());
58
		}
59
		if(this.getTerms() != null){
60
			StringTokenizer tokenizer = new StringTokenizer(this.getTerms(), ",");
61
			while(tokenizer.hasMoreTokens()){
62
				helpdoc.addTerm(tokenizer.nextToken().trim());
63
			}
64
		}
65
		if(this.getHelpdocIds() != null){
66
			StringTokenizer tokenizer = new StringTokenizer(this.getHelpdocIds(), ",");
67
			while(tokenizer.hasMoreTokens()){
68
				helpdoc.addrelatedDocId(Long.parseLong(tokenizer.nextToken().trim()));
69
			}
70
		}
71
		log.info(helpdoc);
72
		CreationUtils.storeHelpdoc(helpdoc);
73
		return "index";
74
	}
75
 
76
	public  Map<Long, Helpdoc> getHelpdocs() throws Exception{
77
		return CreationUtils.getHelpdocs();
78
	}
79
 
80
	public  Helpdoc getHelpdoc() throws Exception{
81
		return CreationUtils.getHelpdoc(Long.parseLong(this.getId()));
82
	}
83
 
84
	public String edit(){
85
 
86
		return "edit";
87
	}
88
 
89
	public String editNew() {
90
        return "editNew";
91
    }
92
 
93
 
94
	public String destroy(){
95
		return "index";
96
	}
97
 
98
	public String update() throws Exception {
99
		long id = Long.parseLong(this.getId());
100
		String name = this.getName();
101
		Helpdoc helpdoc = CreationUtils.getHelpdoc(id);
102
		helpdoc.setName(name);
103
		helpdoc.setContent(this.getContent());
104
		helpdoc.setTerms(null);
105
		helpdoc.setRelatedDocIds(null);
106
		if(this.getTerms() != null){
107
			StringTokenizer tokenizer = new StringTokenizer(this.getTerms(), ",");
108
			while(tokenizer.hasMoreTokens()){
109
				helpdoc.addTerm(tokenizer.nextToken().trim());
110
			}
111
		}
112
		if(this.getHelpdocIds() != null){
113
			StringTokenizer tokenizer = new StringTokenizer(this.getHelpdocIds(), ",");
114
			while(tokenizer.hasMoreTokens()){
115
				helpdoc.addrelatedDocId(Long.parseLong(tokenizer.nextToken().trim()));
116
			}
117
		}
118
		log.info(helpdoc);
119
		CreationUtils.storeHelpdoc(helpdoc);
120
		return "index";
121
 
122
	}
123
 
124
	/**
125
	 * @param id the id to set
126
	 */
127
	public void setId(String id) {
128
		this.id = id;
129
	}
130
 
131
	/**
132
	 * @return the id
133
	 */
134
	public String getId() {
135
		return id;
136
	}
137
 
138
	/**
139
	 * @param helpdocId the helpdocId to set
140
	 */
141
	public void setHelpdocId(String helpdocId) {
142
		this.helpdocId = helpdocId;
143
	}
144
 
145
	/**
146
	 * @return the helpdocId
147
	 */
148
	public String getHelpdocId() {
149
		return helpdocId;
150
	}
151
 
152
	/**
153
	 * @param terms the terms to set
154
	 */
155
	public void setTerms(String terms) {
156
		this.terms = terms;
157
	}
158
 
159
	/**
160
	 * @return the terms
161
	 */
162
	public String getTerms() {
163
		return terms;
164
	}
165
 
166
	/**
167
	 * @param content the content to set
168
	 */
169
	public void setContent(String content) {
170
		this.content = content;
171
	}
172
 
173
	/**
174
	 * @return the content
175
	 */
176
	public String getContent() {
177
		return content;
178
	}
179
 
180
	/**
181
	 * @param helpdocIds the helpdocIds to set
182
	 */
183
	public void setHelpdocIds(String helpdocIds) {
184
		this.helpdocIds = helpdocIds;
185
	}
186
 
187
	/**
188
	 * @return the helpdocIds
189
	 */
190
	public String getHelpdocIds() {
191
		return helpdocIds;
192
	}
193
 
194
	/**
195
	 * @param name the name to set
196
	 */
197
	public void setName(String name) {
198
		this.name = name;
199
	}
200
 
201
	/**
202
	 * @return the name
203
	 */
204
	public String getName() {
205
		return name;
206
	}
207
 
208
	public String getTerms(List<String> terms){
209
		return StringUtils.join(terms, ",");
210
	}
211
}
212