| 2768 |
mandeep.dh |
1 |
package in.shop2020.creation.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.core.Brand;
|
|
|
4 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
5 |
|
|
|
6 |
import java.util.List;
|
|
|
7 |
import java.util.Map;
|
|
|
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 |
/**
|
|
|
18 |
* Action class for brand page in CMS. Delete operation is not supported.
|
|
|
19 |
*
|
|
|
20 |
* @author mandeep
|
|
|
21 |
*/
|
|
|
22 |
@InterceptorRefs({ @InterceptorRef("myDefault"), @InterceptorRef("login") })
|
|
|
23 |
@Results({
|
|
|
24 |
@Result(name = "success", type = "redirectAction", params = {
|
|
|
25 |
"actionName", "brand" }),
|
|
|
26 |
@Result(name = "redirect", location = "${url}", type = "redirect") })
|
|
|
27 |
public class BrandController extends BaseController {
|
|
|
28 |
private static final long serialVersionUID = 1L;
|
|
|
29 |
private static Log log = LogFactory.getLog(BrandController.class);
|
|
|
30 |
|
|
|
31 |
// Brand attributes set by Struts2
|
|
|
32 |
private String id;
|
|
|
33 |
private String displayName;
|
|
|
34 |
private String description;
|
|
|
35 |
private String primeURL;
|
|
|
36 |
private String saholicURL;
|
|
|
37 |
private String searchQuery;
|
|
|
38 |
private String pageTitle;
|
|
|
39 |
private String metaKeywords;
|
|
|
40 |
private String metaDescription;
|
|
|
41 |
|
|
|
42 |
// Index page
|
|
|
43 |
public String index() {
|
|
|
44 |
return "index";
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
// Display page for a single brand
|
|
|
48 |
public String show() {
|
|
|
49 |
return "show";
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Handles creation of a new brand
|
|
|
54 |
*/
|
|
|
55 |
public String create() throws Exception {
|
|
|
56 |
long id = CreationUtils.getNewBrandId();
|
|
|
57 |
if (displayName == null) {
|
|
|
58 |
addActionError("Display Name cannot be empty");
|
|
|
59 |
return "index";
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
Brand brand = new Brand(id, displayName);
|
|
|
63 |
brand.setDescription(description);
|
|
|
64 |
brand.setPrimeURL(primeURL);
|
|
|
65 |
brand.setSaholicURL(saholicURL);
|
|
|
66 |
brand.setPageTitle(pageTitle);
|
|
|
67 |
brand.setMetaDescription(metaDescription);
|
|
|
68 |
brand.setMetaKeywords(metaKeywords);
|
|
|
69 |
brand.setSearchQuery(searchQuery);
|
|
|
70 |
|
|
|
71 |
log.info(brand);
|
|
|
72 |
CreationUtils.storeBrand(brand);
|
|
|
73 |
return "index";
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Used in index view to display all brands
|
|
|
78 |
*/
|
|
|
79 |
public Map<Long, Brand> getBrands() throws Exception {
|
|
|
80 |
return CreationUtils.getBrands();
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Used in UI to display other attributes given brand Id
|
|
|
85 |
*/
|
|
|
86 |
public Brand getBrand() throws Exception {
|
|
|
87 |
return CreationUtils.getBrand(Long.parseLong(id));
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public String edit() {
|
|
|
91 |
return "edit";
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public String editNew() {
|
|
|
95 |
return "editNew";
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* Delete is not supported yet. Index is refreshed on its call
|
|
|
100 |
*/
|
|
|
101 |
public String destroy() {
|
|
|
102 |
return "index";
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Handles updates done on brand through UI
|
|
|
107 |
*/
|
|
|
108 |
public String update() throws Exception {
|
|
|
109 |
Brand brand = CreationUtils.getBrand(Long.parseLong(id));
|
|
|
110 |
brand.setDisplayName(displayName);
|
|
|
111 |
brand.setDescription(description);
|
|
|
112 |
brand.setPrimeURL(primeURL);
|
|
|
113 |
brand.setSaholicURL(saholicURL);
|
|
|
114 |
brand.setPageTitle(pageTitle);
|
|
|
115 |
brand.setMetaDescription(metaDescription);
|
|
|
116 |
brand.setMetaKeywords(metaKeywords);
|
|
|
117 |
brand.setSearchQuery(searchQuery);
|
|
|
118 |
|
|
|
119 |
CreationUtils.storeBrand(brand);
|
|
|
120 |
return "index";
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
public String getSearchQuery(List<String> searchQuery) {
|
|
|
124 |
return StringUtils.join(searchQuery, ",");
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public String getId() {
|
|
|
128 |
return id;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
public void setId(String id) {
|
|
|
132 |
this.id = id;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public String getDisplayName() {
|
|
|
136 |
return displayName;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public void setDisplayName(String displayName) {
|
|
|
140 |
this.displayName = displayName;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public String getPrimeURL() {
|
|
|
144 |
return primeURL;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
public void setPrimeURL(String primeURL) {
|
|
|
148 |
this.primeURL = primeURL;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
public String getSaholicURL() {
|
|
|
152 |
return saholicURL;
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
public void setSaholicURL(String saholicURL) {
|
|
|
156 |
this.saholicURL = saholicURL;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
public String getSearchQuery() {
|
|
|
160 |
return searchQuery;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
public void setSearchQuery(String searchQuery) {
|
|
|
164 |
this.searchQuery = searchQuery;
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
public String getDescription() {
|
|
|
168 |
return description;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
public void setDescription(String description) {
|
|
|
172 |
this.description = description;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
public String getPageTitle() {
|
|
|
176 |
return pageTitle;
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
public void setPageTitle(String pageTitle) {
|
|
|
180 |
this.pageTitle = pageTitle;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
public String getMetaKeywords() {
|
|
|
184 |
return metaKeywords;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
public void setMetaKeywords(String metaKeywords) {
|
|
|
188 |
this.metaKeywords = metaKeywords;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
public String getMetaDescription() {
|
|
|
192 |
return metaDescription;
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
public void setMetaDescription(String metaDescription) {
|
|
|
196 |
this.metaDescription = metaDescription;
|
|
|
197 |
}
|
|
|
198 |
}
|