Subversion Repositories SmartDukaan

Rev

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

Rev 8917 Rev 9155
Line 5... Line 5...
5
import in.shop2020.model.v1.catalog.BannerCongregate;
5
import in.shop2020.model.v1.catalog.BannerCongregate;
6
import in.shop2020.model.v1.catalog.BannerMap;
6
import in.shop2020.model.v1.catalog.BannerMap;
7
import in.shop2020.model.v1.catalog.BannerUriMapping;
7
import in.shop2020.model.v1.catalog.BannerUriMapping;
8
import in.shop2020.model.v1.catalog.Campaign;
8
import in.shop2020.model.v1.catalog.Campaign;
9
import in.shop2020.model.v1.catalog.CatalogService.Client;
9
import in.shop2020.model.v1.catalog.CatalogService.Client;
-
 
10
import in.shop2020.model.v1.catalog.BannerType;
10
import in.shop2020.serving.services.ScpService;
11
import in.shop2020.serving.services.ScpService;
11
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.thrift.clients.CatalogClient;
12
 
13
 
13
import java.io.File;
14
import java.io.File;
14
import java.io.IOException;
15
import java.io.IOException;
Line 58... Line 59...
58
	private String id;
59
	private String id;
59
	private String newsletterName;
60
	private String newsletterName;
60
	private String imageName;
61
	private String imageName;
61
	private String campaignId;
62
	private String campaignId;
62
	private String fileExtention;
63
	private String fileExtention;
-
 
64
	private String bannerType;
-
 
65
	private String actionType;
-
 
66
 
63
	public String create() {
67
	public String create() {
64
		try {
68
		try {
65
			filePath = servletRequest.getSession().getServletContext().getRealPath("/images/banners/");
69
			filePath = servletRequest.getSession().getServletContext().getRealPath("/images/banners/");
66
			setUrl("/user-image");
70
			setUrl("/user-image");
67
			String imageName = null;
71
			String imageName = null;
-
 
72
			Banner antecedent = new Banner();
68
			if (StringUtils.isNotEmpty(userImageFileName)) {
73
			if (StringUtils.isNotEmpty(userImageFileName)) {
69
				imageName = getImageName();
74
				imageName = getImageName();
70
				File fileToCreate = new File(filePath, imageName); 
75
				File fileToCreate = new File(filePath, imageName); 
71
				FileUtils.copyFile(this.userImage, fileToCreate);
76
				FileUtils.copyFile(this.userImage, fileToCreate);
72
				try {
77
				try {
Line 78... Line 83...
78
					return "redirect";
83
					return "redirect";
79
				}
84
				}
80
			}
85
			}
81
			else{
86
			else{
82
				Client CatalogClient = new CatalogClient().getClient();
87
				Client CatalogClient = new CatalogClient().getClient();
83
				imageName =CatalogClient.getBannerDetails(action).getImageName(); 
88
				imageName =CatalogClient.getBannerDetails(action,BannerType.valueOf(actionType)).getImageName();
-
 
89
				antecedent.setBannerName(action);
-
 
90
				antecedent.setBannerType(BannerType.valueOf(actionType));
84
			}
91
			}
85
			if (StringUtils.isEmpty(link)) {
92
			if (StringUtils.isEmpty(link)) {
86
				log.info("Empty Link Field");
93
				log.info("Empty Link Field");
87
				this.link="#";
94
				this.link="#";
88
			}
95
			}
Line 90... Line 97...
90
			banner.setBannerName(bannerName);
97
			banner.setBannerName(bannerName);
91
			banner.setImageName(imageName);
98
			banner.setImageName(imageName);
92
			banner.setLink(link);
99
			banner.setLink(link);
93
			banner.setHasMap(Boolean.parseBoolean(hasMap));
100
			banner.setHasMap(Boolean.parseBoolean(hasMap));
94
			banner.setPriority(Long.valueOf(priority));
101
			banner.setPriority(Long.valueOf(priority));
95
			banner.setOldBanner(action);
102
			banner.setBannerType(BannerType.valueOf(bannerType));
96
			List<BannerMap> bannerMaps = new ArrayList<BannerMap>();
103
			List<BannerMap> bannerMaps = new ArrayList<BannerMap>();
97
			if(banner.isHasMap()) {
104
			if(banner.isHasMap()) {
98
				for(int i=0;i<mapLink.length;i++){
105
				for(int i=0;i<mapLink.length;i++){
99
					if(mapLink[i].isEmpty()) {
106
					if(mapLink[i].isEmpty()) {
100
						continue;
107
						continue;
Line 119... Line 126...
119
			}
126
			}
120
			BannerCongregate bannerCongregate = new BannerCongregate();
127
			BannerCongregate bannerCongregate = new BannerCongregate();
121
			bannerCongregate.setBanner(banner);
128
			bannerCongregate.setBanner(banner);
122
			bannerCongregate.setBannerMaps(bannerMaps);
129
			bannerCongregate.setBannerMaps(bannerMaps);
123
			bannerCongregate.setBannerUriMappings(bannerUriMappings);
130
			bannerCongregate.setBannerUriMappings(bannerUriMappings);
-
 
131
			bannerCongregate.setAntecedent(antecedent);
124
			Client CatalogClient = new CatalogClient().getClient();
132
			Client CatalogClient = new CatalogClient().getClient();
125
			CatalogClient.addBanner(bannerCongregate);
133
			CatalogClient.addBanner(bannerCongregate);
126
		} catch (Exception e) {   
134
		} catch (Exception e) {   
127
			log.error("Error while uploading/changing map",e);
135
			log.error("Error while uploading/changing map",e);
128
			addActionError("Failed To Do Changes");
136
			addActionError("Failed To Do Changes");
Line 134... Line 142...
134
 
142
 
135
	public String createNewsletter() throws IOException{
143
	public String createNewsletter() throws IOException{
136
		filePath = servletRequest.getSession().getServletContext().getRealPath("/images/campaignImages/");
144
		filePath = servletRequest.getSession().getServletContext().getRealPath("/images/campaignImages/");
137
		setUrl("/user-image!editNewsletter?newsletterName="+this.newsletterName);
145
		setUrl("/user-image!editNewsletter?newsletterName="+this.newsletterName);
138
		if (StringUtils.isNotEmpty(userImageFileName)) {
146
		if (StringUtils.isNotEmpty(userImageFileName)) {
139
			imageName = getTimeInMilliseconds()+"_"+imageName.replace(' ', '_');
147
			imageName = getImageName();
140
			File fileToCreate = new File(filePath, imageName); 
148
			File fileToCreate = new File(filePath, imageName); 
141
			FileUtils.copyFile(this.userImage, fileToCreate);
149
			FileUtils.copyFile(this.userImage, fileToCreate);
142
			ScpService scp = new ScpService();
150
			ScpService scp = new ScpService();
143
			try {
151
			try {
144
				scp.scpFile("/var/lib/tomcat6/webapps/ROOT/images/campaignImages/"+imageName, filePath+"/"+imageName);
152
				scp.scpFile("/var/lib/tomcat6/webapps/ROOT/images/campaignImages/"+imageName, filePath+"/"+imageName);
Line 208... Line 216...
208
		return banners;	
216
		return banners;	
209
	}
217
	}
210
 
218
 
211
	public String destroy() throws TException {
219
	public String destroy() throws TException {
212
		Client CatalogClient = new CatalogClient().getClient();
220
		Client CatalogClient = new CatalogClient().getClient();
213
		CatalogClient.deleteBanner(bannerName);
221
		CatalogClient.deleteBanner(bannerName,BannerType.valueOf(bannerType));
214
		setUrl("/user-image");
222
		setUrl("/user-image");
215
		return "redirect";
223
		return "redirect";
216
 
224
 
217
	}
225
	}
218
 
226
 
219
	public Banner getUpdates() throws TException {
227
	public Banner getUpdates(String bannerType) throws TException {
220
		Client CatalogClient = null;
228
		Client CatalogClient = null;
221
		CatalogClient = new CatalogClient().getClient();
229
		CatalogClient = new CatalogClient().getClient();
222
		Banner banner = CatalogClient.getBannerDetails(bannerName);
230
		Banner banner = CatalogClient.getBannerDetails(bannerName,BannerType.valueOf(bannerType));
223
		try{
231
		try{
224
			setFileExtention(banner.getImageName().split("[.]")[1]);
232
			setFileExtention(banner.getImageName().split("[.]")[1]);
225
		}
233
		}
226
		catch (Exception e){
234
		catch (Exception e){
227
			log.error("Split image name error "+e);
235
			log.error("Split image name error "+e);
228
		}
236
		}
229
		return banner;
237
		return banner;
230
	} 
238
	} 
231
 
239
 
232
	public Banner getUpdates(String name) throws TException {
240
	public Banner getUpdates(String name,String bannerType) throws TException {
233
		Client CatalogClient = null;
241
		Client CatalogClient = null;
234
		CatalogClient = new CatalogClient().getClient();
242
		CatalogClient = new CatalogClient().getClient();
235
		return CatalogClient.getBannerDetails(name);
243
		return CatalogClient.getBannerDetails(name,BannerType.valueOf(bannerType));
236
	} 
244
	} 
237
 
245
 
238
	public List<BannerMap> getbannermapdetails() throws TException {
246
	public List<BannerMap> getbannermapdetail(String bannerType) throws TException {
239
		Client CatalogClient = null;
247
		Client CatalogClient = null;
240
		CatalogClient = new CatalogClient().getClient();
248
		CatalogClient = new CatalogClient().getClient();
241
		return CatalogClient.getBannerMapDetails(bannerName);
249
		return CatalogClient.getBannerMapDetails(bannerName,BannerType.valueOf(bannerType));
242
	}
250
	}
243
 
251
 
244
	public String getImageName() {
252
	public String getImageName() {
245
		Calendar cal=GregorianCalendar.getInstance();
253
		Calendar cal=GregorianCalendar.getInstance();
246
		return String.valueOf(cal.getTimeInMillis())+"."+fileExtention;
254
		return String.valueOf(cal.getTimeInMillis())+"."+fileExtention;
Line 249... Line 257...
249
	public String getTimeInMilliseconds(){
257
	public String getTimeInMilliseconds(){
250
		Calendar cal=GregorianCalendar.getInstance();
258
		Calendar cal=GregorianCalendar.getInstance();
251
		return String.valueOf(cal.getTimeInMillis());
259
		return String.valueOf(cal.getTimeInMillis());
252
	}
260
	}
253
 
261
 
254
	public List<BannerUriMapping> getUriMapping(String bannerName) throws TException{
262
	public List<BannerUriMapping> getUriMapping(String bannerName,BannerType bannerType) throws TException{
255
		Client CatalogClient = new CatalogClient().getClient();
263
		Client CatalogClient = new CatalogClient().getClient();
256
		return CatalogClient.getUriMapping(bannerName);
264
		return CatalogClient.getUriMapping(bannerName,bannerType);
257
	}
265
	}
258
 
266
 
259
 
-
 
260
	public List<BannerUriMapping> getUriMapping() throws TException{
267
	public List<BannerUriMapping> getUriMapping(String bannerType) throws TException{
261
		Client CatalogClient = new CatalogClient().getClient();
268
		Client CatalogClient = new CatalogClient().getClient();
262
		return CatalogClient.getUriMapping(bannerName);
269
		return CatalogClient.getUriMapping(bannerName,BannerType.valueOf(bannerType));
263
	}
270
	}
264
 
271
 
265
	public List<Campaign> getCampaigns(String campaignName) throws TException{
272
	public List<Campaign> getCampaigns(String campaignName) throws TException{
266
		Client CatalogClient = new CatalogClient().getClient();
273
		Client CatalogClient = new CatalogClient().getClient();
267
		return CatalogClient.getCampaigns(campaignName);
274
		return CatalogClient.getCampaigns(campaignName);
268
	}
275
	}
269
 
276
 
270
	public List<String> getAllCampaigns() throws TException{
277
	public List<String> getAllCampaigns() throws TException{
271
		Client CatalogClient = new CatalogClient().getClient();
278
		Client CatalogClient = new CatalogClient().getClient();
272
		log.info(CatalogClient.getAllCampaigns());
-
 
273
		return CatalogClient.getAllCampaigns();
279
		return CatalogClient.getAllCampaigns();
274
	}
280
	}
275
 
281
 
276
	public String index() {
282
	public String index() {
277
		return "index";
283
		return "index";
Line 446... Line 452...
446
 
452
 
447
	public String getFileExtention() {
453
	public String getFileExtention() {
448
		return fileExtention;
454
		return fileExtention;
449
	}
455
	}
450
 
456
 
-
 
457
	public void setBannerType(String bannerType) {
-
 
458
		this.bannerType = bannerType;
-
 
459
	}
-
 
460
 
-
 
461
	public String getBannerType() {
-
 
462
		return bannerType;
-
 
463
	}
-
 
464
 
-
 
465
	public void setActionType(String actionType) {
-
 
466
		this.actionType = actionType;
-
 
467
	}
-
 
468
 
-
 
469
	public String getActionType() {
-
 
470
		return actionType;
-
 
471
	}
-
 
472
 
451
}
473
}