Subversion Repositories SmartDukaan

Rev

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

Rev 2867 Rev 2949
Line 23... Line 23...
23
import java.util.HashMap;
23
import java.util.HashMap;
24
import java.util.List;
24
import java.util.List;
25
import java.util.Map;
25
import java.util.Map;
26
import java.util.Properties;
26
import java.util.Properties;
27
 
27
 
-
 
28
import org.apache.log4j.Logger;
28
import org.apache.thrift.TException;
29
import org.apache.thrift.TException;
29
import org.apache.velocity.Template;
30
import org.apache.velocity.Template;
30
import org.apache.velocity.VelocityContext;
31
import org.apache.velocity.VelocityContext;
31
import org.apache.velocity.app.Velocity;
32
import org.apache.velocity.app.Velocity;
32
import org.apache.velocity.exception.MethodInvocationException;
33
import org.apache.velocity.exception.MethodInvocationException;
Line 34... Line 35...
34
import org.apache.velocity.exception.ResourceNotFoundException;
35
import org.apache.velocity.exception.ResourceNotFoundException;
35
 
36
 
36
 
37
 
37
public class PageLoaderHandler {
38
public class PageLoaderHandler {
38
 
39
 
-
 
40
    private static Logger logger = Logger.getLogger(PageLoaderHandler.class);
-
 
41
    
39
	public String getSlideGuideHtml(long productId) {
42
	public String getSlideGuideHtml(long productId) {
40
		StringBuilder htmlString = new StringBuilder();
43
		StringBuilder htmlString = new StringBuilder();
41
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
44
		String filename = Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "SlideGuide.html";
42
		File f = new File(filename);
45
		File f = new File(filename);
43
		
46
		
Line 49... Line 52...
49
			String line;
52
			String line;
50
			while((line = br.readLine()) != null){
53
			while((line = br.readLine()) != null){
51
				htmlString.append(line+"\n");
54
				htmlString.append(line+"\n");
52
			}
55
			}
53
		} catch (FileNotFoundException e) {
56
		} catch (FileNotFoundException e) {
54
			// TODO Auto-generated catch block
57
			logger.error("Unable to find the slide guide for " + productId, e);
55
			e.printStackTrace();
-
 
56
		} catch (IOException e) {
58
		} catch (IOException e) {
57
			// TODO Auto-generated catch block
59
		    logger.error("Unable to read the slide guide for " + productId, e);
58
			e.printStackTrace();
-
 
59
		}
60
		}
60
		finally {
61
		finally {
61
			if(fis != null) {
62
			if(fis != null) {
62
				try {
63
				try {
63
					fis.close();
64
					fis.close();
64
				} catch (IOException e) {
65
				} catch (IOException e) {
65
					// TODO Auto-generated catch block
66
				    logger.warn("Unable to close the slide guide for " + productId, e);
66
					e.printStackTrace();
-
 
67
				}
67
				}
68
			}
68
			}
69
		}
69
		}
70
		
70
		
71
		return htmlString.toString();
71
		return htmlString.toString();
Line 84... Line 84...
84
			String line;
84
			String line;
85
			while((line = br.readLine()) != null){
85
			while((line = br.readLine()) != null){
86
				htmlString.append(line+"\n");
86
				htmlString.append(line+"\n");
87
			}
87
			}
88
		} catch (FileNotFoundException e) {
88
		} catch (FileNotFoundException e) {
89
			// TODO Auto-generated catch block
89
			logger.error("Unable to find the product summary file", e);
90
			e.printStackTrace();
-
 
91
		} catch (IOException e) {
90
		} catch (IOException e) {
92
			// TODO Auto-generated catch block
91
			logger.error("Unable to read the product summary file", e);
93
			e.printStackTrace();
-
 
94
		}
92
		}
95
		finally {
93
		finally {
96
			if(fis != null) {
94
			if(fis != null) {
97
				try {
95
				try {
98
					fis.close();
96
					fis.close();
99
				} catch (IOException e) {
97
				} catch (IOException e) {
100
					// TODO Auto-generated catch block
98
					logger.error("Unable to close the product summary file", e);
101
					e.printStackTrace();
-
 
102
				}
99
				}
103
			}
100
			}
104
		}
101
		}
105
		
102
		
106
		return htmlString.toString();
103
		return htmlString.toString();
Line 119... Line 116...
119
			String line;
116
			String line;
120
			while((line = br.readLine()) != null){
117
			while((line = br.readLine()) != null){
121
				htmlString.append(line+"\n");
118
				htmlString.append(line+"\n");
122
			}
119
			}
123
		} catch (FileNotFoundException e) {
120
		} catch (FileNotFoundException e) {
124
			// TODO Auto-generated catch block
121
		    logger.error("Unable to find the product properties file", e);
125
			e.printStackTrace();
-
 
126
		} catch (IOException e) {
122
		} catch (IOException e) {
127
			// TODO Auto-generated catch block
123
			logger.error("Unable to read the product properties file", e);
128
			e.printStackTrace();
-
 
129
		}
-
 
130
		finally {
124
		} finally {
131
			if(fis != null) {
125
			if(fis != null) {
132
				try {
126
				try {
133
					fis.close();
127
					fis.close();
134
				} catch (IOException e) {
128
				} catch (IOException e) {
135
					// TODO Auto-generated catch block
129
					logger.error("Unable to close the product properties file", e);
136
					e.printStackTrace();
-
 
137
				}
130
				}
138
			}
131
			}
139
		}
132
		}
140
		
133
		
141
		return htmlString.toString();
134
		return htmlString.toString();
Line 222... Line 215...
222
			in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
215
			in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
223
			List<Provider> providers = logisticsClient.getAllProviders();
216
			List<Provider> providers = logisticsClient.getAllProviders();
224
			for(Provider provider: providers)
217
			for(Provider provider: providers)
225
				providerNames.put(provider.getId(), provider.getName());
218
				providerNames.put(provider.getId(), provider.getName());
226
		}catch (Exception e){
219
		}catch (Exception e){
227
			e.printStackTrace();
220
			logger.error("Unable to get order or provider details", e);
228
		}
221
		}
229
		List<String> orderDate = new ArrayList<String>();
222
		List<String> orderDate = new ArrayList<String>();
230
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
223
		SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
231
		if(orders!=null && !orders.isEmpty()){
224
		if(orders!=null && !orders.isEmpty()){
232
			for(Order order: orders){
225
			for(Order order: orders){
Line 261... Line 254...
261
		String email = " ";
254
		String email = " ";
262
		
255
		
263
		try {
256
		try {
264
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
257
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
265
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
258
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
266
			if(userClient.getUserById(userId).getEmail() != null){
259
			String userEmail = userClient.getUserById(userId).getEmail(); 
-
 
260
			if( userEmail != null){
267
				email = userClient.getUserById(userId).getEmail();
261
				email = userEmail;
268
			}
262
			}
269
		} catch (UserContextException e) {
263
		} catch (UserContextException e) {
270
			e.printStackTrace();
264
			logger.error("Unable to get the user for " + userId, e);
271
		} catch (TException e) {
265
		} catch (TException e) {
272
			e.printStackTrace();
266
		    logger.error("Unable to get the user for " + userId, e);
273
		} catch (Exception e) {
267
		} catch (Exception e) {
274
			e.printStackTrace();
268
		    logger.error("Unable to get the user for " + userId, e);
275
		}
269
		}
276
		return email; 
270
		return email; 
277
	}
271
	}
278
 
272
 
279
	
273
	
Line 297... Line 291...
297
			email = user.getCommunicationEmail();
291
			email = user.getCommunicationEmail();
298
			name = user.getName();
292
			name = user.getName();
299
			
293
			
300
			dateOfBirth = user.getDateOfBirth();
294
			dateOfBirth = user.getDateOfBirth();
301
		}catch (Exception e){
295
		}catch (Exception e){
302
			e.printStackTrace();
296
		    logger.error("Unable to get the user for " + userId, e);
303
		}
297
		}
304
		context.put("name", name);
298
		context.put("name", name);
305
		context.put("email", email);
299
		context.put("email", email);
306
		context.put("dateOfBirth", dateOfBirth+"");
300
		context.put("dateOfBirth", dateOfBirth+"");
307
		context.put("subscribe", subscribe);
301
		context.put("subscribe", subscribe);
Line 332... Line 326...
332
			userClient = userContextServiceClient.getClient();
326
			userClient = userContextServiceClient.getClient();
333
			
327
			
334
			addresses = userClient.getAllAddressesForUser(userId);
328
			addresses = userClient.getAllAddressesForUser(userId);
335
			defaultAddressId = userClient.getDefaultAddressId(userId);
329
			defaultAddressId = userClient.getDefaultAddressId(userId);
336
		} catch (Exception e) {
330
		} catch (Exception e) {
337
			e.printStackTrace();
331
		    logger.error("Unable to get either the user for " + userId + " or his address", e);
338
		}
332
		}
339
		context.put("defaultAddressId", defaultAddressId+"");
333
		context.put("defaultAddressId", defaultAddressId+"");
340
		context.put("addresses", addresses);
334
		context.put("addresses", addresses);
341
		context.put("errorMsg", errorMsg);
335
		context.put("errorMsg", errorMsg);
342
		
336
		
Line 349... Line 343...
349
		p.setProperty("resource.loader", "class");
343
		p.setProperty("resource.loader", "class");
350
		p.setProperty("class.resource.loader.class",
344
		p.setProperty("class.resource.loader.class",
351
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
345
		"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
352
		p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"); 
346
		p.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem"); 
353
		
347
		
354
		try {
348
        try {
355
			Velocity.init(p);
349
            Velocity.init(p);
356
			//Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
350
            // Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, value)
357
			Template template = Velocity.getTemplate(templateFile);
351
            Template template = Velocity.getTemplate(templateFile);
358
			if(template != null) {
352
            if (template != null) {
359
				StringWriter writer = new StringWriter();
353
                StringWriter writer = new StringWriter();
360
				template.merge(context, writer);
354
                template.merge(context, writer);
361
				writer.flush();
355
                writer.flush();
362
				writer.close();
356
                writer.close();
363
				return writer.toString();
357
                return writer.toString();
364
			}
358
            }
365
	
359
 
366
			} catch (ResourceNotFoundException e) {
360
        } catch (ResourceNotFoundException e) {
367
				// TODO Auto-generated catch block
361
            logger.error("Unable to find the template file " + templateFile, e);
368
				e.printStackTrace();
-
 
369
			} catch (ParseErrorException e) {
362
        } catch (ParseErrorException e) {
370
				// TODO Auto-generated catch block
363
            logger.error("Unable to parse the template file " + templateFile, e);
371
				e.printStackTrace();
-
 
372
			} catch (MethodInvocationException e) {
364
        } catch (MethodInvocationException e) {
373
				// TODO Auto-generated catch block
365
            logger.error("Unable to invoke methods for the velocity template file " + templateFile, e);
374
				e.printStackTrace();
-
 
375
			} catch (IOException e) {
366
        } catch (IOException e) {
376
				// TODO Auto-generated catch block
367
            logger.error("Unable to read the template file " + templateFile, e);
377
				e.printStackTrace();
-
 
378
			} catch (Exception e) {
368
        } catch (Exception e) {
379
				// TODO Auto-generated catch block
369
            logger.error("Unable to generate the HTML from the template file " + templateFile, e);
380
				e.printStackTrace();
-
 
381
			}
370
        }
382
	
371
	
383
		return null;
372
		return null;
384
	}
373
	}
385
}
374
}