| 20424 |
kshitij.so |
1 |
package com.hotspotstore.controllers;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import java.io.File;
|
|
|
5 |
import java.io.IOException;
|
|
|
6 |
import java.util.ArrayList;
|
|
|
7 |
import java.util.Calendar;
|
|
|
8 |
import java.util.GregorianCalendar;
|
|
|
9 |
import java.util.HashMap;
|
|
|
10 |
import java.util.List;
|
|
|
11 |
import java.util.Map;
|
|
|
12 |
|
|
|
13 |
import com.hotspotstore.controllers.BaseController;
|
|
|
14 |
import com.hotspotstore.model.Banner;
|
|
|
15 |
import com.hotspotstore.storage.Mongo;
|
|
|
16 |
|
|
|
17 |
import org.apache.commons.io.FileUtils;
|
|
|
18 |
import org.apache.log4j.Logger;
|
|
|
19 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
20 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
21 |
|
|
|
22 |
@Results({
|
|
|
23 |
@Result(name = "redirect", location = "${url}", type = "redirect")
|
|
|
24 |
})
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
public class BannerController extends BaseController{
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
*/
|
|
|
32 |
private static final long serialVersionUID = 1L;
|
|
|
33 |
|
|
|
34 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
35 |
private String id;
|
|
|
36 |
private File userImage;
|
|
|
37 |
private String bannerName;
|
|
|
38 |
private String fileExtention;
|
|
|
39 |
private String link;
|
|
|
40 |
private String priority;
|
|
|
41 |
private Banner bannerObj;
|
|
|
42 |
private String sameWindowTarget;
|
|
|
43 |
private String url;
|
|
|
44 |
private String isActive;
|
|
|
45 |
private String[] mapLink;
|
|
|
46 |
|
|
|
47 |
public String[] getMapLink() {
|
|
|
48 |
return mapLink;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public void setMapLink(String[] mapLink) {
|
|
|
52 |
this.mapLink = mapLink;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
private String[] mapCoordinates;
|
|
|
56 |
|
|
|
57 |
public String[] getMapCoordinates() {
|
|
|
58 |
return mapCoordinates;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public void setMapCoordinates(String[] mapCoordinates) {
|
|
|
62 |
this.mapCoordinates = mapCoordinates;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public String getSameWindowTarget() {
|
|
|
66 |
return sameWindowTarget;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public void setSameWindowTarget(String sameWindowTarget) {
|
|
|
70 |
this.sameWindowTarget = sameWindowTarget;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public String create(){
|
|
|
74 |
try{
|
|
|
75 |
String filePath = request.getSession().getServletContext().getRealPath("/images/banners/");
|
|
|
76 |
String imageName = getImageName();
|
|
|
77 |
File fileToCreate = new File(filePath, imageName);
|
|
|
78 |
FileUtils.copyFile(this.userImage, fileToCreate);
|
|
|
79 |
|
|
|
80 |
Banner banner = new Banner();
|
|
|
81 |
banner.setBannerName(bannerName);
|
|
|
82 |
banner.setLink(link);
|
|
|
83 |
banner.setImageName(imageName);
|
|
|
84 |
banner.setPriority(Integer.valueOf(priority));
|
|
|
85 |
banner.setActive(false);
|
|
|
86 |
banner.setSameWindowTarget(Boolean.valueOf(sameWindowTarget));
|
|
|
87 |
banner.setFileExtention(fileExtention);
|
|
|
88 |
Mongo.addBanner(banner);
|
|
|
89 |
}
|
|
|
90 |
catch(Exception e){
|
|
|
91 |
log.error("Error while adding banner",e);
|
|
|
92 |
addActionError("Failed to do changes");
|
|
|
93 |
}
|
|
|
94 |
addActionMessage("Banner added successfully");
|
| 20428 |
kshitij.so |
95 |
return "index";
|
| 20424 |
kshitij.so |
96 |
}
|
|
|
97 |
|
|
|
98 |
public String update() throws NumberFormatException, Exception{
|
|
|
99 |
try{
|
|
|
100 |
bannerObj = Mongo.getBannerById(Long.valueOf(id));
|
|
|
101 |
if (userImage !=null){
|
|
|
102 |
bannerObj.setImageName(getImageName());
|
|
|
103 |
String filePath = request.getSession().getServletContext().getRealPath("/images/banners/");
|
|
|
104 |
File fileToCreate = new File(filePath, bannerObj.getImageName());
|
|
|
105 |
FileUtils.copyFile(this.userImage, fileToCreate);
|
|
|
106 |
}
|
|
|
107 |
bannerObj.setBannerName(bannerName);
|
|
|
108 |
bannerObj.setLink(link);
|
|
|
109 |
bannerObj.setPriority(Integer.valueOf(priority));
|
|
|
110 |
bannerObj.setActive(Boolean.valueOf(isActive));
|
|
|
111 |
bannerObj.setSameWindowTarget(Boolean.valueOf(sameWindowTarget));
|
|
|
112 |
bannerObj.setFileExtention(fileExtention);
|
|
|
113 |
ArrayList<Map<String, String>> bannerList = new ArrayList<Map<String, String>>();
|
|
|
114 |
if (mapLink!=null){
|
|
|
115 |
for(int i=0;i<mapLink.length;i++){
|
|
|
116 |
if(mapLink[i].isEmpty() || mapCoordinates[i].isEmpty()) {
|
|
|
117 |
continue;
|
|
|
118 |
}
|
|
|
119 |
Map<String, String> bannerMap = new HashMap<String, String>();
|
|
|
120 |
bannerMap.put("link", mapLink[i]);
|
|
|
121 |
bannerMap.put("coordinates", mapCoordinates[i]);
|
|
|
122 |
bannerList.add(bannerMap);
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
bannerObj.setBannerList(bannerList);
|
|
|
126 |
Mongo.updateBanner(bannerObj);
|
|
|
127 |
addActionMessage("Banner updated successfully");
|
|
|
128 |
}
|
|
|
129 |
catch(Exception e){
|
|
|
130 |
log.error("Unable to update banner ",e);
|
|
|
131 |
addActionMessage("Banner updation failed");
|
|
|
132 |
}
|
| 20428 |
kshitij.so |
133 |
return "index";
|
| 20424 |
kshitij.so |
134 |
}
|
|
|
135 |
|
|
|
136 |
public String destroy(){
|
|
|
137 |
try{
|
|
|
138 |
Mongo.deleteBanner(Long.valueOf(id));
|
|
|
139 |
addActionMessage("Banner deleted successfully");
|
|
|
140 |
}
|
|
|
141 |
catch(Exception e){
|
|
|
142 |
addActionError("Unable to delete banner");
|
|
|
143 |
}
|
| 20428 |
kshitij.so |
144 |
return "index";
|
| 20424 |
kshitij.so |
145 |
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
public ArrayList<Banner> getAllBanners(){
|
|
|
149 |
return Mongo.getAllBanners();
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
public String index() {
|
|
|
153 |
return "index";
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public String editNew() {
|
|
|
157 |
return "editNew";
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
public String edit() throws NumberFormatException, Exception {
|
|
|
161 |
bannerObj = Mongo.getBannerById(Long.valueOf(id));
|
|
|
162 |
return "edit";
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
public String getImageName() {
|
|
|
166 |
Calendar cal=GregorianCalendar.getInstance();
|
|
|
167 |
return String.valueOf(cal.getTimeInMillis())+"."+fileExtention;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
public String getId() {
|
|
|
171 |
return id;
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
public void setId(String id) {
|
|
|
175 |
this.id = id;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
public File getUserImage() {
|
|
|
180 |
return userImage;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
public void setUserImage(File userImage) {
|
|
|
184 |
this.userImage = userImage;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
public String getBannerName() {
|
|
|
188 |
return bannerName;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
public void setBannerName(String bannerName) {
|
|
|
192 |
this.bannerName = bannerName;
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
public String getFileExtention() {
|
|
|
196 |
return fileExtention;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public void setFileExtention(String fileExtention) {
|
|
|
200 |
this.fileExtention = fileExtention;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public String getLink() {
|
|
|
204 |
return link;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
public void setLink(String link) {
|
|
|
208 |
this.link = link;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public String getPriority() {
|
|
|
212 |
return priority;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
public void setPriority(String priority) {
|
|
|
216 |
this.priority = priority;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public void setBannerObj(Banner bannerObj) {
|
|
|
220 |
this.bannerObj = bannerObj;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
public Banner getBannerObj() {
|
|
|
224 |
return bannerObj;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
public void setUrl(String url) {
|
|
|
228 |
this.url = url;
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
public String getUrl() {
|
|
|
232 |
return url;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
public void setIsActive(String isActive) {
|
|
|
236 |
this.isActive = isActive;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
public String getIsActive() {
|
|
|
240 |
return isActive;
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
}
|