| 6848 |
kshitij.so |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import org.apache.log4j.Logger;
|
|
|
7 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
8 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
import org.apache.commons.io.FileUtils;
|
|
|
11 |
import org.apache.commons.lang.xwork.StringUtils;
|
|
|
12 |
import in.shop2020.model.v1.catalog.Banner;
|
|
|
13 |
import in.shop2020.model.v1.catalog.BannerMap;
|
|
|
14 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
15 |
import in.shop2020.serving.services.ScpService;
|
|
|
16 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
17 |
import org.apache.thrift.TException;
|
|
|
18 |
import org.apache.thrift.transport.TTransportException;
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
@SuppressWarnings("serial")
|
|
|
22 |
@Results({
|
|
|
23 |
@Result(name = "redirect", location = "${url}", type = "redirect") })
|
|
|
24 |
public class UserImageController extends BaseController {
|
|
|
25 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
26 |
private File userImage;
|
|
|
27 |
private String filePath;
|
|
|
28 |
private String userImageContentType;
|
|
|
29 |
private String userImageFileName;
|
|
|
30 |
private String url;
|
|
|
31 |
private HttpServletRequest servletRequest;
|
|
|
32 |
private String status;
|
|
|
33 |
private String bannerName;
|
|
|
34 |
private String link;
|
|
|
35 |
private String priority;
|
|
|
36 |
private String hasMap;
|
|
|
37 |
private String action;
|
|
|
38 |
private String imageName;
|
|
|
39 |
private String[] mapLink;
|
|
|
40 |
private String[] mapCoordinates;
|
|
|
41 |
public String create() {
|
|
|
42 |
try {
|
|
|
43 |
filePath = servletRequest.getSession().getServletContext().getRealPath("/images/banners/");
|
|
|
44 |
setUrl("/user-image");
|
|
|
45 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
46 |
if (StringUtils.isNotEmpty(action)) {
|
|
|
47 |
CatalogClient.deleteBanner(action);
|
|
|
48 |
CatalogClient.deleteBannerMap(action);
|
|
|
49 |
}
|
|
|
50 |
if (StringUtils.isNotEmpty(userImageFileName)) {
|
|
|
51 |
File fileToCreate = new File(filePath, this.userImageFileName);
|
|
|
52 |
FileUtils.copyFile(this.userImage, fileToCreate);
|
|
|
53 |
try {
|
|
|
54 |
ScpService scp = new ScpService();
|
| 6853 |
kshitij.so |
55 |
scp.scpFile("/var/lib/tomcat6/webapps/ROOT/images/banners/"+imageName, filePath+"/"+imageName);
|
| 6848 |
kshitij.so |
56 |
} catch (Exception e) {
|
|
|
57 |
addActionError("Image Failed To Upload");
|
|
|
58 |
return "redirect";
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
if (StringUtils.isEmpty(link)) {
|
|
|
62 |
this.link="#";
|
|
|
63 |
}
|
|
|
64 |
long rating = Long.parseLong(priority);
|
|
|
65 |
boolean state = Boolean.parseBoolean(status);
|
|
|
66 |
boolean containsMap = Boolean.parseBoolean(hasMap);
|
|
|
67 |
CatalogClient.addBanner(bannerName, imageName,link, rating, state, containsMap);
|
|
|
68 |
if(containsMap) {
|
|
|
69 |
for(int i=0;i<mapLink.length;i++){
|
|
|
70 |
log.info("maplink"+mapLink[i]);
|
|
|
71 |
log.info("maplink"+mapCoordinates[i]);
|
|
|
72 |
if(mapLink[i].isEmpty()) {
|
|
|
73 |
continue;
|
|
|
74 |
}
|
|
|
75 |
CatalogClient.addBannerMap(bannerName, mapLink[i], mapCoordinates[i]);
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
} catch (Exception e) {
|
|
|
79 |
addActionError("Failed To Do Changes");
|
|
|
80 |
return "redirect";
|
|
|
81 |
}
|
|
|
82 |
addActionMessage("Changes Applied Successfully");
|
|
|
83 |
return "redirect";
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
public List<String> getAllBanners() throws TException{
|
|
|
87 |
Client CatalogClient = null;
|
|
|
88 |
try {
|
|
|
89 |
CatalogClient = new CatalogClient().getClient();
|
|
|
90 |
} catch (TTransportException e) {
|
|
|
91 |
e.printStackTrace();
|
|
|
92 |
}
|
|
|
93 |
return CatalogClient.getAllBanners();
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public String destroy() throws TException {
|
|
|
97 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
98 |
CatalogClient.deleteBanner(bannerName);
|
|
|
99 |
CatalogClient.deleteBannerMap(bannerName);
|
|
|
100 |
setUrl("/user-image");
|
|
|
101 |
return "redirect";
|
|
|
102 |
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public Banner getUpdates() throws TException {
|
|
|
106 |
Client CatalogClient = null;
|
|
|
107 |
CatalogClient = new CatalogClient().getClient();
|
|
|
108 |
return CatalogClient.getBannerDetails(bannerName);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
public Banner getUpdates(String name) throws TException {
|
|
|
112 |
Client CatalogClient = null;
|
|
|
113 |
CatalogClient = new CatalogClient().getClient();
|
|
|
114 |
return CatalogClient.getBannerDetails(name);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
public List<BannerMap> getbannermapdetails() throws TException {
|
|
|
118 |
Client CatalogClient = null;
|
|
|
119 |
CatalogClient = new CatalogClient().getClient();
|
|
|
120 |
return CatalogClient.getBannerMapDetails(bannerName);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
public String index() {
|
|
|
124 |
return "index";
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public String show() {
|
|
|
128 |
return "show";
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
public String edit() {
|
|
|
132 |
return "edit";
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
public String editNew() {
|
|
|
137 |
return "editNew";
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
public File getUserImage() {
|
|
|
141 |
return userImage;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
public void setUserImage(File userImage) {
|
|
|
145 |
this.userImage = userImage;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
public String getUserImageContentType() {
|
|
|
149 |
return userImageContentType;
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
public void setUserImageContentType(String userImageContentType) {
|
|
|
153 |
this.userImageContentType = userImageContentType;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public String getUserImageFileName() {
|
|
|
157 |
return userImageFileName;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
public void setUserImageFileName(String userImageFileName) {
|
|
|
161 |
this.userImageFileName = userImageFileName;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
public void setUrl(String url) {
|
|
|
165 |
this.url = url;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
public String getUrl() {
|
|
|
169 |
return url;
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
public void setIsActive(String isActive) {
|
|
|
173 |
this.status=isActive;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
public String getIsActive() {
|
|
|
177 |
return status;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
public void setBannerName(String bannerName) {
|
|
|
182 |
this.bannerName=bannerName;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
public String getBannerName() {
|
|
|
186 |
return bannerName;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
public void setLink(String link) {
|
|
|
190 |
this.link=link;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public String getLink() {
|
|
|
194 |
return link;
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public void setAction(String action) {
|
|
|
198 |
this.action=action;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
public String getAction() {
|
|
|
202 |
return action;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
public void setPriority(String priority) {
|
|
|
206 |
this.priority=priority;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
public String getPriority() {
|
|
|
210 |
return priority;
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
public void setImageName(String imageName) {
|
|
|
214 |
this.imageName=imageName;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
public String getImageName() {
|
|
|
218 |
return imageName;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
public void setId(String id) {
|
|
|
222 |
this.bannerName = id;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
public String[] getMapLink() {
|
|
|
226 |
return mapLink;
|
|
|
227 |
}
|
|
|
228 |
public void setMapLink(String[] mapLink) {
|
|
|
229 |
this.mapLink = mapLink;
|
|
|
230 |
}
|
|
|
231 |
public String[] getReturnQty() {
|
|
|
232 |
return mapCoordinates;
|
|
|
233 |
}
|
|
|
234 |
public void setMapCoordinates(String[] mapCoordinates) {
|
|
|
235 |
this.mapCoordinates = mapCoordinates;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
public void setHasMap(String hasMap) {
|
|
|
239 |
this.hasMap=hasMap;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
public String getHasMap() {
|
|
|
243 |
return hasMap;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
@Override
|
|
|
248 |
public void setServletRequest(HttpServletRequest servletRequest) {
|
|
|
249 |
log.info("setservletrequest");
|
|
|
250 |
this.servletRequest = servletRequest;
|
|
|
251 |
|
|
|
252 |
}
|
|
|
253 |
}
|