Subversion Repositories SmartDukaan

Rev

Rev 2768 | Details | Compare with Previous | 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 name;
34
	private String content;
35
	private String terms;
36
	private String helpdocIds;
37
 
38
	public String index(){
39
		return "index";
40
	}
41
 
42
	public String show(){
43
		return "show";
44
	}
45
 
46
	public String create() throws Exception{
47
		//long id = Long.parseLong(this.getHelpdocId());
48
		long id = CreationUtils.getNewHelpdocId();
49
		String name = this.getName();
50
		Helpdoc helpdoc = new Helpdoc(id, name);
51
		if(name==null){
52
			addActionError("Name cannot be empty");
53
			return "index";	
54
		}
55
		if(this.getContent() != null){
56
			helpdoc.setContent(this.getContent());
57
		}
58
		if(this.getTerms() != null){
59
			StringTokenizer tokenizer = new StringTokenizer(this.getTerms(), ",");
60
			while(tokenizer.hasMoreTokens()){
61
				helpdoc.addTerm(tokenizer.nextToken().trim());
62
			}
63
		}
64
		if(this.getHelpdocIds() != null){
65
			StringTokenizer tokenizer = new StringTokenizer(this.getHelpdocIds(), ",");
66
			while(tokenizer.hasMoreTokens()){
67
				helpdoc.addrelatedDocId(Long.parseLong(tokenizer.nextToken().trim()));
68
			}
69
		}
70
		log.info(helpdoc);
71
		CreationUtils.storeHelpdoc(helpdoc);
72
		return "index";
73
	}
74
 
75
	public  Map<Long, Helpdoc> getHelpdocs() throws Exception{
76
		return CreationUtils.getHelpdocs();
77
	}
78
 
79
	public  Helpdoc getHelpdoc() throws Exception{
80
		return CreationUtils.getHelpdoc(Long.parseLong(this.getId()));
81
	}
82
 
83
	public String edit(){
84
 
85
		return "edit";
86
	}
87
 
88
	public String editNew() {
89
        return "editNew";
90
    }
91
 
92
 
3485 rajveer 93
	public String destroy() throws Exception{
94
		long id = Long.parseLong(this.getId());
95
		CreationUtils.getHelpdoc(id);
2276 rajveer 96
		return "index";
97
	}
98
 
99
	public String update() throws Exception {
100
		long id = Long.parseLong(this.getId());
101
		String name = this.getName();
102
		Helpdoc helpdoc = CreationUtils.getHelpdoc(id);
103
		helpdoc.setName(name);
104
		helpdoc.setContent(this.getContent());
105
		helpdoc.setTerms(null);
106
		helpdoc.setRelatedDocIds(null);
107
		if(this.getTerms() != null){
108
			StringTokenizer tokenizer = new StringTokenizer(this.getTerms(), ",");
109
			while(tokenizer.hasMoreTokens()){
110
				helpdoc.addTerm(tokenizer.nextToken().trim());
111
			}
112
		}
113
		if(this.getHelpdocIds() != null){
114
			StringTokenizer tokenizer = new StringTokenizer(this.getHelpdocIds(), ",");
115
			while(tokenizer.hasMoreTokens()){
116
				helpdoc.addrelatedDocId(Long.parseLong(tokenizer.nextToken().trim()));
117
			}
118
		}
119
		log.info(helpdoc);
120
		CreationUtils.storeHelpdoc(helpdoc);
121
		return "index";
122
 
123
	}
124
 
125
	/**
126
	 * @param id the id to set
127
	 */
128
	public void setId(String id) {
129
		this.id = id;
130
	}
131
 
132
	/**
133
	 * @return the id
134
	 */
135
	public String getId() {
136
		return id;
137
	}
138
 
139
	/**
140
	 * @param terms the terms to set
141
	 */
142
	public void setTerms(String terms) {
143
		this.terms = terms;
144
	}
145
 
146
	/**
147
	 * @return the terms
148
	 */
149
	public String getTerms() {
150
		return terms;
151
	}
152
 
153
	/**
154
	 * @param content the content to set
155
	 */
156
	public void setContent(String content) {
157
		this.content = content;
158
	}
159
 
160
	/**
161
	 * @return the content
162
	 */
163
	public String getContent() {
164
		return content;
165
	}
166
 
167
	/**
168
	 * @param helpdocIds the helpdocIds to set
169
	 */
170
	public void setHelpdocIds(String helpdocIds) {
171
		this.helpdocIds = helpdocIds;
172
	}
173
 
174
	/**
175
	 * @return the helpdocIds
176
	 */
177
	public String getHelpdocIds() {
178
		return helpdocIds;
179
	}
180
 
181
	/**
182
	 * @param name the name to set
183
	 */
184
	public void setName(String name) {
185
		this.name = name;
186
	}
187
 
188
	/**
189
	 * @return the name
190
	 */
191
	public String getName() {
192
		return name;
193
	}
194
 
195
	public String getTerms(List<String> terms){
196
		return StringUtils.join(terms, ",");
197
	}
198
}
199