| 6848 |
kshitij.so |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
| 8578 |
kshitij.so |
4 |
import java.io.IOException;
|
|
|
5 |
import java.util.ArrayList;
|
|
|
6 |
import java.util.Calendar;
|
|
|
7 |
import java.util.GregorianCalendar;
|
| 6848 |
kshitij.so |
8 |
import java.util.List;
|
|
|
9 |
|
|
|
10 |
import org.apache.log4j.Logger;
|
|
|
11 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
12 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
import org.apache.commons.io.FileUtils;
|
|
|
15 |
import org.apache.commons.lang.xwork.StringUtils;
|
| 8578 |
kshitij.so |
16 |
|
|
|
17 |
import in.shop2020.config.ConfigException;
|
| 6848 |
kshitij.so |
18 |
import in.shop2020.model.v1.catalog.Banner;
|
| 8590 |
kshitij.so |
19 |
import in.shop2020.model.v1.catalog.BannerCongregate;
|
| 6848 |
kshitij.so |
20 |
import in.shop2020.model.v1.catalog.BannerMap;
|
| 8578 |
kshitij.so |
21 |
import in.shop2020.model.v1.catalog.BannerUriMapping;
|
|
|
22 |
import in.shop2020.model.v1.catalog.Campaign;
|
| 6848 |
kshitij.so |
23 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
24 |
import in.shop2020.serving.services.ScpService;
|
|
|
25 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
26 |
import org.apache.thrift.TException;
|
|
|
27 |
import org.apache.thrift.transport.TTransportException;
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
@SuppressWarnings("serial")
|
| 8582 |
kshitij.so |
31 |
|
| 6848 |
kshitij.so |
32 |
@Results({
|
| 8578 |
kshitij.so |
33 |
@Result(name = "redirect", location = "${url}", type = "redirect"),
|
|
|
34 |
@Result(name = "newCampaign", location = "campaign-editNew.vm"),
|
| 8582 |
kshitij.so |
35 |
@Result(name = "campaignEdit", location = "campaignEdit.vm")
|
| 8578 |
kshitij.so |
36 |
})
|
| 8582 |
kshitij.so |
37 |
|
| 8578 |
kshitij.so |
38 |
public class UserImageController extends BaseController {
|
| 6848 |
kshitij.so |
39 |
private static Logger log = Logger.getLogger(Class.class);
|
| 8578 |
kshitij.so |
40 |
private File userImage;
|
|
|
41 |
private String filePath;
|
|
|
42 |
private String userImageContentType;
|
|
|
43 |
private String userImageFileName;
|
|
|
44 |
private String url;
|
|
|
45 |
private HttpServletRequest servletRequest;
|
|
|
46 |
private String[] status;
|
|
|
47 |
private String bannerName;
|
|
|
48 |
private String link;
|
|
|
49 |
private String priority;
|
|
|
50 |
private String hasMap;
|
|
|
51 |
private String action;
|
|
|
52 |
private String[] mapLink;
|
|
|
53 |
private String[] mapCoordinates;
|
|
|
54 |
private String[] uri;
|
|
|
55 |
private String id;
|
|
|
56 |
private String newsletterName;
|
|
|
57 |
private String imageName;
|
|
|
58 |
private String campaignId;
|
|
|
59 |
public String create() {
|
| 6848 |
kshitij.so |
60 |
try {
|
| 8578 |
kshitij.so |
61 |
filePath = servletRequest.getSession().getServletContext().getRealPath("/images/banners/");
|
|
|
62 |
setUrl("/user-image");
|
|
|
63 |
String imageName = null;
|
|
|
64 |
if (StringUtils.isNotEmpty(userImageFileName)) {
|
|
|
65 |
imageName = getImageName();
|
|
|
66 |
File fileToCreate = new File(filePath, imageName);
|
|
|
67 |
FileUtils.copyFile(this.userImage, fileToCreate);
|
|
|
68 |
try {
|
|
|
69 |
ScpService scp = new ScpService();
|
|
|
70 |
scp.scpFile("/var/lib/tomcat6/webapps/ROOT/images/banners/"+imageName, filePath+"/"+imageName);
|
|
|
71 |
} catch (Exception e) {
|
|
|
72 |
log.error("Scp To Servers Failed",e);
|
|
|
73 |
addActionError("Image Failed To Upload");
|
|
|
74 |
return "redirect";
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
else{
|
|
|
78 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
79 |
imageName =CatalogClient.getBannerDetails(action).getImageName();
|
|
|
80 |
}
|
|
|
81 |
if (StringUtils.isEmpty(link)) {
|
|
|
82 |
log.info("Empty Link Field");
|
|
|
83 |
this.link="#";
|
|
|
84 |
}
|
|
|
85 |
Banner banner = new Banner();
|
|
|
86 |
banner.setBannerName(bannerName);
|
|
|
87 |
banner.setImageName(imageName);
|
|
|
88 |
banner.setLink(link);
|
|
|
89 |
banner.setPriority(Long.parseLong(priority));
|
|
|
90 |
banner.setHasMap(Boolean.parseBoolean(hasMap));
|
|
|
91 |
List<BannerMap> bannerMaps = new ArrayList<BannerMap>();
|
|
|
92 |
if(banner.isHasMap()) {
|
|
|
93 |
for(int i=0;i<mapLink.length;i++){
|
|
|
94 |
if(mapLink[i].isEmpty()) {
|
|
|
95 |
continue;
|
|
|
96 |
}
|
|
|
97 |
BannerMap bannerMap = new BannerMap();
|
|
|
98 |
bannerMap.setBannerName(bannerName);
|
|
|
99 |
bannerMap.setCoordinates(mapCoordinates[i]);
|
|
|
100 |
bannerMap.setMapLink(mapLink[i]);
|
|
|
101 |
bannerMaps.add(bannerMap);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
List<BannerUriMapping> bannerUriMappings = new ArrayList<BannerUriMapping>();
|
|
|
105 |
for (int i=0;i<uri.length;i++){
|
|
|
106 |
if(uri[i].isEmpty()) {
|
|
|
107 |
continue;
|
|
|
108 |
}
|
|
|
109 |
BannerUriMapping bannerUriMapping = new BannerUriMapping();
|
|
|
110 |
bannerUriMapping.setBannerName(bannerName);
|
|
|
111 |
bannerUriMapping.setUri(uri[i]);
|
|
|
112 |
bannerUriMapping.setIsActive(Boolean.valueOf(status[i]));
|
|
|
113 |
bannerUriMappings.add(bannerUriMapping);
|
|
|
114 |
}
|
| 8590 |
kshitij.so |
115 |
BannerCongregate bannerCongregate = new BannerCongregate();
|
|
|
116 |
bannerCongregate.setBanner(banner);
|
|
|
117 |
bannerCongregate.setBannerMaps(bannerMaps);
|
|
|
118 |
bannerCongregate.setBannerUriMappings(bannerUriMappings);
|
|
|
119 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
120 |
CatalogClient.addBanner(bannerCongregate);
|
| 8578 |
kshitij.so |
121 |
} catch (Exception e) {
|
|
|
122 |
log.error("Error while uploading/changing map",e);
|
|
|
123 |
addActionError("Failed To Do Changes");
|
|
|
124 |
return "redirect";
|
|
|
125 |
}
|
|
|
126 |
addActionMessage("Changes Applied Successfully");
|
|
|
127 |
return "index";
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
public String createNewsletter() throws IOException{
|
|
|
131 |
filePath = servletRequest.getSession().getServletContext().getRealPath("/images/campaignImages/");
|
| 8590 |
kshitij.so |
132 |
setUrl("/user-image!editNewsletter?newsletterName="+this.newsletterName);
|
| 8578 |
kshitij.so |
133 |
if (StringUtils.isNotEmpty(userImageFileName)) {
|
|
|
134 |
File fileToCreate = new File(filePath, imageName);
|
|
|
135 |
FileUtils.copyFile(this.userImage, fileToCreate);
|
|
|
136 |
ScpService scp = new ScpService();
|
|
|
137 |
try {
|
|
|
138 |
scp.scpFile("/var/lib/tomcat6/webapps/ROOT/images/campaignImages/"+imageName, filePath+"/"+imageName);
|
|
|
139 |
} catch (ConfigException e) {
|
|
|
140 |
log.info("Unable to do scp "+e);
|
| 8590 |
kshitij.so |
141 |
addActionError("Image Failed To Upload");
|
|
|
142 |
return "redirect";
|
| 8578 |
kshitij.so |
143 |
}
|
|
|
144 |
Campaign campaign = new Campaign();
|
|
|
145 |
campaign.setCampaignName(this.newsletterName);
|
|
|
146 |
campaign.setImageName(imageName);
|
|
|
147 |
Client CatalogClient;
|
|
|
148 |
try {
|
|
|
149 |
CatalogClient = new CatalogClient().getClient();
|
|
|
150 |
CatalogClient.addCampaign(campaign);
|
|
|
151 |
} catch (Exception e) {
|
|
|
152 |
log.info("Unable to add campaign "+e);
|
|
|
153 |
addActionError("Failed To Do Changes");
|
| 8590 |
kshitij.so |
154 |
return "redirect";
|
| 8578 |
kshitij.so |
155 |
}
|
| 8590 |
kshitij.so |
156 |
addActionMessage("Changes Applied Successfully");
|
|
|
157 |
return "redirect";
|
| 8578 |
kshitij.so |
158 |
}
|
| 8590 |
kshitij.so |
159 |
else{
|
|
|
160 |
addActionError("Image Missing");
|
|
|
161 |
return "redirect";
|
|
|
162 |
}
|
|
|
163 |
|
| 8578 |
kshitij.so |
164 |
}
|
|
|
165 |
|
| 8590 |
kshitij.so |
166 |
public String deleteCampaign() {
|
|
|
167 |
setUrl("/user-image!editNewsletter?newsletterName="+this.newsletterName);
|
|
|
168 |
try {
|
|
|
169 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
170 |
CatalogClient.deleteCampaign(Long.valueOf(campaignId));
|
|
|
171 |
addActionMessage("Image deleted");
|
|
|
172 |
return "redirect";
|
|
|
173 |
}
|
|
|
174 |
catch (Exception e) {
|
|
|
175 |
log.info("Unable to delete campaign "+e);
|
|
|
176 |
addActionError("Unable to delete image");
|
|
|
177 |
return "redirect";
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
| 8578 |
kshitij.so |
182 |
public void addBannerUriMapping(List<BannerUriMapping> bannerUriMappings) throws TException{
|
|
|
183 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
184 |
CatalogClient.addBannerUri(bannerUriMappings);
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
public void addBannerMap(List<BannerMap> bannerMaps) throws TException{
|
|
|
188 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
189 |
CatalogClient.addBannerMap(bannerMaps);
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public List<Banner> getAllBanners() {
|
|
|
193 |
Client CatalogClient = null;
|
|
|
194 |
List<Banner> banners = null;
|
|
|
195 |
try {
|
| 6848 |
kshitij.so |
196 |
CatalogClient = new CatalogClient().getClient();
|
| 8578 |
kshitij.so |
197 |
banners = CatalogClient.getAllBanners();
|
| 6848 |
kshitij.so |
198 |
} catch (TTransportException e) {
|
| 8578 |
kshitij.so |
199 |
log.info("Unable to fetch all banners "+e);
|
|
|
200 |
} catch (TException ex) {
|
|
|
201 |
log.info("Unable to fetch all banners "+ex);
|
| 6848 |
kshitij.so |
202 |
}
|
| 8578 |
kshitij.so |
203 |
return banners;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
public String destroy() throws TException {
|
|
|
207 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
208 |
CatalogClient.deleteBanner(bannerName);
|
|
|
209 |
setUrl("/user-image");
|
|
|
210 |
return "redirect";
|
|
|
211 |
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
public Banner getUpdates() throws TException {
|
|
|
215 |
Client CatalogClient = null;
|
| 6848 |
kshitij.so |
216 |
CatalogClient = new CatalogClient().getClient();
|
|
|
217 |
return CatalogClient.getBannerDetails(bannerName);
|
| 8578 |
kshitij.so |
218 |
}
|
|
|
219 |
|
|
|
220 |
public Banner getUpdates(String name) throws TException {
|
|
|
221 |
Client CatalogClient = null;
|
| 6848 |
kshitij.so |
222 |
CatalogClient = new CatalogClient().getClient();
|
|
|
223 |
return CatalogClient.getBannerDetails(name);
|
| 8578 |
kshitij.so |
224 |
}
|
| 6848 |
kshitij.so |
225 |
|
| 8578 |
kshitij.so |
226 |
public List<BannerMap> getbannermapdetails() throws TException {
|
|
|
227 |
Client CatalogClient = null;
|
|
|
228 |
CatalogClient = new CatalogClient().getClient();
|
|
|
229 |
return CatalogClient.getBannerMapDetails(bannerName);
|
|
|
230 |
}
|
| 6848 |
kshitij.so |
231 |
|
| 8578 |
kshitij.so |
232 |
public String getImageName() {
|
|
|
233 |
Calendar cal=GregorianCalendar.getInstance();
|
|
|
234 |
return String.valueOf(cal.getTimeInMillis())+".jpg";
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
public List<BannerUriMapping> getUriMapping(String bannerName) throws TException{
|
|
|
238 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
239 |
return CatalogClient.getUriMapping(bannerName);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
public List<BannerUriMapping> getUriMapping() throws TException{
|
|
|
244 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
245 |
return CatalogClient.getUriMapping(bannerName);
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
public List<Campaign> getCampaigns(String campaignName) throws TException{
|
|
|
249 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
250 |
return CatalogClient.getCampaigns(campaignName);
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
public List<String> getAllCampaigns() throws TException{
|
|
|
254 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
255 |
log.info(CatalogClient.getAllCampaigns());
|
|
|
256 |
return CatalogClient.getAllCampaigns();
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
public String index() {
|
|
|
260 |
return "index";
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
public String show() {
|
|
|
264 |
if (StringUtils.equals(id, "newCampaign")){
|
|
|
265 |
log.info("Returing camapign edit new");
|
|
|
266 |
return "newCampaign";
|
|
|
267 |
}
|
|
|
268 |
return "show";
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
public String editNewsletter(){
|
|
|
272 |
return "campaignEdit";
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
public String edit() {
|
|
|
276 |
return "edit";
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
public String editNew() {
|
|
|
281 |
return "editNew";
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
public File getUserImage() {
|
|
|
285 |
return userImage;
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
public void setUserImage(File userImage) {
|
|
|
289 |
log.info("set file"+userImage.toString());
|
|
|
290 |
this.userImage = userImage;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
public String getUserImageContentType() {
|
|
|
294 |
return userImageContentType;
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
public void setUserImageContentType(String userImageContentType) {
|
|
|
298 |
this.userImageContentType = userImageContentType;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
public String getUserImageFileName() {
|
|
|
302 |
return userImageFileName;
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
public void setUserImageFileName(String userImageFileName) {
|
|
|
306 |
log.info("userimage file name set"+userImageFileName);
|
|
|
307 |
this.userImageFileName = userImageFileName;
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
public void setUrl(String url) {
|
| 6848 |
kshitij.so |
311 |
this.url = url;
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
public String getUrl() {
|
|
|
315 |
return url;
|
|
|
316 |
}
|
| 8578 |
kshitij.so |
317 |
|
|
|
318 |
public void setIsActive(String[] isActive) {
|
| 6848 |
kshitij.so |
319 |
this.status=isActive;
|
|
|
320 |
}
|
| 8578 |
kshitij.so |
321 |
|
|
|
322 |
public String[] getIsActive() {
|
| 6848 |
kshitij.so |
323 |
return status;
|
|
|
324 |
}
|
| 8578 |
kshitij.so |
325 |
|
|
|
326 |
|
| 6848 |
kshitij.so |
327 |
public void setBannerName(String bannerName) {
|
|
|
328 |
this.bannerName=bannerName;
|
|
|
329 |
}
|
| 8578 |
kshitij.so |
330 |
|
| 6848 |
kshitij.so |
331 |
public String getBannerName() {
|
|
|
332 |
return bannerName;
|
|
|
333 |
}
|
| 8578 |
kshitij.so |
334 |
|
| 6848 |
kshitij.so |
335 |
public void setLink(String link) {
|
|
|
336 |
this.link=link;
|
|
|
337 |
}
|
| 8578 |
kshitij.so |
338 |
|
| 6848 |
kshitij.so |
339 |
public String getLink() {
|
|
|
340 |
return link;
|
|
|
341 |
}
|
| 8578 |
kshitij.so |
342 |
|
| 6848 |
kshitij.so |
343 |
public void setAction(String action) {
|
|
|
344 |
this.action=action;
|
|
|
345 |
}
|
| 8578 |
kshitij.so |
346 |
|
| 6848 |
kshitij.so |
347 |
public String getAction() {
|
|
|
348 |
return action;
|
|
|
349 |
}
|
| 8578 |
kshitij.so |
350 |
|
| 6848 |
kshitij.so |
351 |
public void setPriority(String priority) {
|
|
|
352 |
this.priority=priority;
|
|
|
353 |
}
|
| 8578 |
kshitij.so |
354 |
|
| 6848 |
kshitij.so |
355 |
public String getPriority() {
|
|
|
356 |
return priority;
|
|
|
357 |
}
|
| 8578 |
kshitij.so |
358 |
|
|
|
359 |
public void setId(String id) {
|
|
|
360 |
log.info("set id banner "+id);
|
|
|
361 |
this.id = id;
|
|
|
362 |
this.bannerName = id;
|
| 6848 |
kshitij.so |
363 |
}
|
| 8578 |
kshitij.so |
364 |
|
| 6848 |
kshitij.so |
365 |
public String[] getMapLink() {
|
|
|
366 |
return mapLink;
|
|
|
367 |
}
|
|
|
368 |
public void setMapLink(String[] mapLink) {
|
|
|
369 |
this.mapLink = mapLink;
|
|
|
370 |
}
|
| 8578 |
kshitij.so |
371 |
public String[] getMapCoordinates() {
|
| 6848 |
kshitij.so |
372 |
return mapCoordinates;
|
|
|
373 |
}
|
|
|
374 |
public void setMapCoordinates(String[] mapCoordinates) {
|
|
|
375 |
this.mapCoordinates = mapCoordinates;
|
|
|
376 |
}
|
| 8578 |
kshitij.so |
377 |
|
|
|
378 |
public void setUri(String[] uri) {
|
|
|
379 |
this.uri = uri;
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
public String[] getUri() {
|
|
|
383 |
return uri;
|
|
|
384 |
}
|
|
|
385 |
|
| 6848 |
kshitij.so |
386 |
public void setHasMap(String hasMap) {
|
|
|
387 |
this.hasMap=hasMap;
|
|
|
388 |
}
|
| 8578 |
kshitij.so |
389 |
|
| 6848 |
kshitij.so |
390 |
public String getHasMap() {
|
|
|
391 |
return hasMap;
|
|
|
392 |
}
|
| 8578 |
kshitij.so |
393 |
|
|
|
394 |
public void setNewsletterName(String newsletterName) {
|
|
|
395 |
this.newsletterName = newsletterName;
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
public String getNewsletterName() {
|
|
|
399 |
return newsletterName;
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
public void setCampaignId(String campaignId) {
|
|
|
403 |
this.campaignId = campaignId;
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
public String getCampaignId() {
|
|
|
407 |
return campaignId;
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
@Override
|
|
|
411 |
public void setServletRequest(HttpServletRequest servletRequest) {
|
|
|
412 |
this.servletRequest = servletRequest;
|
|
|
413 |
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
public void setImageName(String imageName) {
|
|
|
417 |
this.imageName = imageName;
|
|
|
418 |
}
|
|
|
419 |
|
| 8590 |
kshitij.so |
420 |
}
|