Subversion Repositories SmartDukaan

Rev

Rev 2276 | Go to most recent revision | 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
 
93
	public String destroy(){
94
		return "index";
95
	}
96
 
97
	public String update() throws Exception {
98
		long id = Long.parseLong(this.getId());
99
		String name = this.getName();
100
		Helpdoc helpdoc = CreationUtils.getHelpdoc(id);
101
		helpdoc.setName(name);
102
		helpdoc.setContent(this.getContent());
103
		helpdoc.setTerms(null);
104
		helpdoc.setRelatedDocIds(null);
105
		if(this.getTerms() != null){
106
			StringTokenizer tokenizer = new StringTokenizer(this.getTerms(), ",");
107
			while(tokenizer.hasMoreTokens()){
108
				helpdoc.addTerm(tokenizer.nextToken().trim());
109
			}
110
		}
111
		if(this.getHelpdocIds() != null){
112
			StringTokenizer tokenizer = new StringTokenizer(this.getHelpdocIds(), ",");
113
			while(tokenizer.hasMoreTokens()){
114
				helpdoc.addrelatedDocId(Long.parseLong(tokenizer.nextToken().trim()));
115
			}
116
		}
117
		log.info(helpdoc);
118
		CreationUtils.storeHelpdoc(helpdoc);
119
		return "index";
120
 
121
	}
122
 
123
	/**
124
	 * @param id the id to set
125
	 */
126
	public void setId(String id) {
127
		this.id = id;
128
	}
129
 
130
	/**
131
	 * @return the id
132
	 */
133
	public String getId() {
134
		return id;
135
	}
136
 
137
	/**
138
	 * @param terms the terms to set
139
	 */
140
	public void setTerms(String terms) {
141
		this.terms = terms;
142
	}
143
 
144
	/**
145
	 * @return the terms
146
	 */
147
	public String getTerms() {
148
		return terms;
149
	}
150
 
151
	/**
152
	 * @param content the content to set
153
	 */
154
	public void setContent(String content) {
155
		this.content = content;
156
	}
157
 
158
	/**
159
	 * @return the content
160
	 */
161
	public String getContent() {
162
		return content;
163
	}
164
 
165
	/**
166
	 * @param helpdocIds the helpdocIds to set
167
	 */
168
	public void setHelpdocIds(String helpdocIds) {
169
		this.helpdocIds = helpdocIds;
170
	}
171
 
172
	/**
173
	 * @return the helpdocIds
174
	 */
175
	public String getHelpdocIds() {
176
		return helpdocIds;
177
	}
178
 
179
	/**
180
	 * @param name the name to set
181
	 */
182
	public void setName(String name) {
183
		this.name = name;
184
	}
185
 
186
	/**
187
	 * @return the name
188
	 */
189
	public String getName() {
190
		return name;
191
	}
192
 
193
	public String getTerms(List<String> terms){
194
		return StringUtils.join(terms, ",");
195
	}
196
}
197