Subversion Repositories SmartDukaan

Rev

Rev 8582 | Rev 8917 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8582 Rev 8590
Line 14... Line 14...
14
import org.apache.commons.io.FileUtils;
14
import org.apache.commons.io.FileUtils;
15
import org.apache.commons.lang.xwork.StringUtils;
15
import org.apache.commons.lang.xwork.StringUtils;
16
 
16
 
17
import in.shop2020.config.ConfigException;
17
import in.shop2020.config.ConfigException;
18
import in.shop2020.model.v1.catalog.Banner;
18
import in.shop2020.model.v1.catalog.Banner;
-
 
19
import in.shop2020.model.v1.catalog.BannerCongregate;
19
import in.shop2020.model.v1.catalog.BannerMap;
20
import in.shop2020.model.v1.catalog.BannerMap;
20
import in.shop2020.model.v1.catalog.BannerUriMapping;
21
import in.shop2020.model.v1.catalog.BannerUriMapping;
21
import in.shop2020.model.v1.catalog.Campaign;
22
import in.shop2020.model.v1.catalog.Campaign;
22
import in.shop2020.model.v1.catalog.CatalogService.Client;
23
import in.shop2020.model.v1.catalog.CatalogService.Client;
23
import in.shop2020.serving.services.ScpService;
24
import in.shop2020.serving.services.ScpService;
Line 85... Line 86...
85
			banner.setBannerName(bannerName);
86
			banner.setBannerName(bannerName);
86
			banner.setImageName(imageName);
87
			banner.setImageName(imageName);
87
			banner.setLink(link);
88
			banner.setLink(link);
88
			banner.setPriority(Long.parseLong(priority));
89
			banner.setPriority(Long.parseLong(priority));
89
			banner.setHasMap(Boolean.parseBoolean(hasMap));
90
			banner.setHasMap(Boolean.parseBoolean(hasMap));
90
			if (StringUtils.isNotEmpty(action)) {
-
 
91
				deleteBannerAndMap(action);
-
 
92
			}
-
 
93
			List<BannerMap> bannerMaps = new ArrayList<BannerMap>();
91
			List<BannerMap> bannerMaps = new ArrayList<BannerMap>();
94
			if(banner.isHasMap()) {
92
			if(banner.isHasMap()) {
95
				for(int i=0;i<mapLink.length;i++){
93
				for(int i=0;i<mapLink.length;i++){
96
					log.info("maplink"+mapLink[i]);
-
 
97
					log.info("maplink"+mapCoordinates[i]);
-
 
98
					if(mapLink[i].isEmpty()) {
94
					if(mapLink[i].isEmpty()) {
99
						continue;
95
						continue;
100
					}
96
					}
101
					BannerMap bannerMap = new BannerMap();
97
					BannerMap bannerMap = new BannerMap();
102
					bannerMap.setBannerName(bannerName);
98
					bannerMap.setBannerName(bannerName);
103
					bannerMap.setCoordinates(mapCoordinates[i]);
99
					bannerMap.setCoordinates(mapCoordinates[i]);
104
					bannerMap.setMapLink(mapLink[i]);
100
					bannerMap.setMapLink(mapLink[i]);
105
					bannerMaps.add(bannerMap);
101
					bannerMaps.add(bannerMap);
106
				}	
102
				}	
107
			}
103
			}
108
			Client CatalogClient = new CatalogClient().getClient();
-
 
109
			CatalogClient.addBanner(banner);
-
 
110
			if(bannerMaps.size()>0){
-
 
111
				addBannerMap(bannerMaps);
-
 
112
			}
-
 
113
			List<BannerUriMapping> bannerUriMappings = new ArrayList<BannerUriMapping>();
104
			List<BannerUriMapping> bannerUriMappings = new ArrayList<BannerUriMapping>();
114
			for (int i=0;i<uri.length;i++){
105
			for (int i=0;i<uri.length;i++){
115
				if(uri[i].isEmpty()) {
106
				if(uri[i].isEmpty()) {
116
					continue;
107
					continue;
117
				}
108
				}
Line 119... Line 110...
119
				bannerUriMapping.setBannerName(bannerName);
110
				bannerUriMapping.setBannerName(bannerName);
120
				bannerUriMapping.setUri(uri[i]);
111
				bannerUriMapping.setUri(uri[i]);
121
				bannerUriMapping.setIsActive(Boolean.valueOf(status[i]));
112
				bannerUriMapping.setIsActive(Boolean.valueOf(status[i]));
122
				bannerUriMappings.add(bannerUriMapping);
113
				bannerUriMappings.add(bannerUriMapping);
123
			}
114
			}
-
 
115
			BannerCongregate bannerCongregate = new BannerCongregate();
-
 
116
			bannerCongregate.setBanner(banner);
-
 
117
			bannerCongregate.setBannerMaps(bannerMaps);
124
			addBannerUriMapping(bannerUriMappings);
118
			bannerCongregate.setBannerUriMappings(bannerUriMappings);
-
 
119
			Client CatalogClient = new CatalogClient().getClient();
-
 
120
			CatalogClient.addBanner(bannerCongregate);
125
		} catch (Exception e) {   
121
		} catch (Exception e) {   
126
			log.error("Error while uploading/changing map",e);
122
			log.error("Error while uploading/changing map",e);
127
			addActionError("Failed To Do Changes");
123
			addActionError("Failed To Do Changes");
128
			return "redirect";
124
			return "redirect";
129
		}
125
		}
Line 131... Line 127...
131
		return "index";
127
		return "index";
132
	}
128
	}
133
 
129
 
134
	public String createNewsletter() throws IOException{
130
	public String createNewsletter() throws IOException{
135
		filePath = servletRequest.getSession().getServletContext().getRealPath("/images/campaignImages/");
131
		filePath = servletRequest.getSession().getServletContext().getRealPath("/images/campaignImages/");
-
 
132
		setUrl("/user-image!editNewsletter?newsletterName="+this.newsletterName);
136
		if (StringUtils.isNotEmpty(userImageFileName)) {
133
		if (StringUtils.isNotEmpty(userImageFileName)) {
137
			File fileToCreate = new File(filePath, imageName); 
134
			File fileToCreate = new File(filePath, imageName); 
138
			FileUtils.copyFile(this.userImage, fileToCreate);
135
			FileUtils.copyFile(this.userImage, fileToCreate);
139
			ScpService scp = new ScpService();
136
			ScpService scp = new ScpService();
140
			try {
137
			try {
141
				scp.scpFile("/var/lib/tomcat6/webapps/ROOT/images/campaignImages/"+imageName, filePath+"/"+imageName);
138
				scp.scpFile("/var/lib/tomcat6/webapps/ROOT/images/campaignImages/"+imageName, filePath+"/"+imageName);
142
			} catch (ConfigException e) {
139
			} catch (ConfigException e) {
143
				log.info("Unable to do scp "+e);
140
				log.info("Unable to do scp "+e);
144
				addActionError("Failed To Do Changes");
141
				addActionError("Image Failed To Upload");
145
				return "campaign-editNew";
142
				return "redirect";
146
			}
143
			}
147
			Campaign campaign = new Campaign();
144
			Campaign campaign = new Campaign();
148
			campaign.setCampaignName(this.newsletterName);
145
			campaign.setCampaignName(this.newsletterName);
149
			campaign.setImageName(imageName);
146
			campaign.setImageName(imageName);
150
			Client CatalogClient;
147
			Client CatalogClient;
Line 152... Line 149...
152
				CatalogClient = new CatalogClient().getClient();
149
				CatalogClient = new CatalogClient().getClient();
153
				CatalogClient.addCampaign(campaign);
150
				CatalogClient.addCampaign(campaign);
154
			} catch (Exception e) {
151
			} catch (Exception e) {
155
				log.info("Unable to add campaign "+e);
152
				log.info("Unable to add campaign "+e);
156
				addActionError("Failed To Do Changes");
153
				addActionError("Failed To Do Changes");
157
				return "campaign-editNew";
154
				return "redirect";
158
			}
155
			}
-
 
156
			addActionMessage("Changes Applied Successfully");
-
 
157
			return "redirect";
159
		}
158
		}
-
 
159
		else{
160
		addActionMessage("Changes Applied Successfully");
160
			addActionError("Image Missing");
161
		return "campaign-editNew";
161
			return "redirect";
-
 
162
		}
-
 
163
 
162
	}
164
	}
163
 
165
 
-
 
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
 
164
	public void addBannerUriMapping(List<BannerUriMapping> bannerUriMappings) throws TException{
182
	public void addBannerUriMapping(List<BannerUriMapping> bannerUriMappings) throws TException{
165
		Client CatalogClient = new CatalogClient().getClient();
183
		Client CatalogClient = new CatalogClient().getClient();
166
		CatalogClient.addBannerUri(bannerUriMappings);
184
		CatalogClient.addBannerUri(bannerUriMappings);
167
	}
185
	}
168
 
186
 
Line 219... Line 237...
219
	public List<BannerUriMapping> getUriMapping(String bannerName) throws TException{
237
	public List<BannerUriMapping> getUriMapping(String bannerName) throws TException{
220
		Client CatalogClient = new CatalogClient().getClient();
238
		Client CatalogClient = new CatalogClient().getClient();
221
		return CatalogClient.getUriMapping(bannerName);
239
		return CatalogClient.getUriMapping(bannerName);
222
	}
240
	}
223
 
241
 
224
	public void deleteBannerAndMap(String bannerName) throws TException{
-
 
225
		Client CatalogClient = new CatalogClient().getClient();
-
 
226
		CatalogClient.deleteBanner(bannerName);
-
 
227
	}
-
 
228
 
242
 
229
	public List<BannerUriMapping> getUriMapping() throws TException{
243
	public List<BannerUriMapping> getUriMapping() throws TException{
230
		Client CatalogClient = new CatalogClient().getClient();
244
		Client CatalogClient = new CatalogClient().getClient();
231
		return CatalogClient.getUriMapping(bannerName);
245
		return CatalogClient.getUriMapping(bannerName);
232
	}
246
	}
Line 234... Line 248...
234
	public List<Campaign> getCampaigns(String campaignName) throws TException{
248
	public List<Campaign> getCampaigns(String campaignName) throws TException{
235
		Client CatalogClient = new CatalogClient().getClient();
249
		Client CatalogClient = new CatalogClient().getClient();
236
		return CatalogClient.getCampaigns(campaignName);
250
		return CatalogClient.getCampaigns(campaignName);
237
	}
251
	}
238
 
252
 
239
	public void deleteCampaign() throws NumberFormatException, TException{
-
 
240
		Client CatalogClient = new CatalogClient().getClient();
-
 
241
		CatalogClient.deleteCampaign(Long.valueOf(campaignId));
-
 
242
	}
-
 
243
 
-
 
244
	public List<String> getAllCampaigns() throws TException{
253
	public List<String> getAllCampaigns() throws TException{
245
		Client CatalogClient = new CatalogClient().getClient();
254
		Client CatalogClient = new CatalogClient().getClient();
246
		log.info(CatalogClient.getAllCampaigns());
255
		log.info(CatalogClient.getAllCampaigns());
247
		return CatalogClient.getAllCampaigns();
256
		return CatalogClient.getAllCampaigns();
248
	}
257
	}
Line 406... Line 415...
406
 
415
 
407
	public void setImageName(String imageName) {
416
	public void setImageName(String imageName) {
408
		this.imageName = imageName;
417
		this.imageName = imageName;
409
	}
418
	}
410
 
419
 
411
}
-
 
412
420
}
-
 
421