Subversion Repositories SmartDukaan

Rev

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

Rev 6903 Rev 6915
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.nio.ByteBuffer;
3
import java.text.SimpleDateFormat;
4
import java.text.SimpleDateFormat;
4
import java.util.ArrayList;
5
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.Arrays;
6
import java.util.Calendar;
7
import java.util.Calendar;
7
import java.util.Collections;
8
import java.util.Collections;
8
import java.util.Date;
9
import java.util.Date;
9
import java.util.HashMap;
10
import java.util.HashMap;
10
import java.util.List;
11
import java.util.List;
11
import java.util.Map;
12
import java.util.Map;
12
 
13
 
-
 
14
import javax.servlet.ServletOutputStream;
-
 
15
 
13
import in.shop2020.model.v1.catalog.CatalogService.Client;
16
import in.shop2020.model.v1.catalog.CatalogService.Client;
14
import in.shop2020.model.v1.catalog.CatalogServiceException;
17
import in.shop2020.model.v1.catalog.CatalogServiceException;
15
import in.shop2020.model.v1.order.Order;
18
import in.shop2020.model.v1.order.Order;
16
import in.shop2020.model.v1.order.OrderStatus;
19
import in.shop2020.model.v1.order.OrderStatus;
-
 
20
import in.shop2020.model.v1.order.TransactionService;
17
import in.shop2020.serving.utils.FormattingUtils;
21
import in.shop2020.serving.utils.FormattingUtils;
18
import in.shop2020.thrift.clients.CatalogClient;
22
import in.shop2020.thrift.clients.CatalogClient;
19
import in.shop2020.thrift.clients.TransactionClient;
23
import in.shop2020.thrift.clients.TransactionClient;
20
 
24
 
21
import org.apache.log4j.Logger;
25
import org.apache.log4j.Logger;
Line 49... Line 53...
49
    private FormattingUtils formattingUtils = new FormattingUtils();
53
    private FormattingUtils formattingUtils = new FormattingUtils();
50
 
54
 
51
    Map<Long, String> providerNames = new HashMap<Long, String>();
55
    Map<Long, String> providerNames = new HashMap<Long, String>();
52
    List<Order> orders = null;
56
    List<Order> orders = null;
53
    List<String> orderDate = new ArrayList<String>();
57
    List<String> orderDate = new ArrayList<String>();
-
 
58
    
-
 
59
    private String orderId;
54
	
60
	
55
    CatalogClient csc = null;
61
    CatalogClient csc = null;
56
    Client client = null;
62
    Client client = null;
57
	public MyPurchasesController() {
63
	public MyPurchasesController() {
58
		super();
64
		super();
Line 75... Line 81...
75
        } catch (Exception e)   {
81
        } catch (Exception e)   {
76
        	logger.error("Not able to get order information from service.");
82
        	logger.error("Not able to get order information from service.");
77
        }
83
        }
78
		return "index";
84
		return "index";
79
    }
85
    }
-
 
86
	
-
 
87
	public String downloadPolicyDoc() {
-
 
88
	    ByteBuffer buffer = null;
-
 
89
        try {
-
 
90
            if (orderId == null || orderId.isEmpty()) {
-
 
91
                logger.error("Order Id is null or empty");
-
 
92
                return "index";
-
 
93
            }
-
 
94
            TransactionClient transactionServiceClient = new TransactionClient();
-
 
95
            TransactionService.Client orderClient = transactionServiceClient.getClient();
-
 
96
            buffer = orderClient.getDocument(1, Long.parseLong(orderId));
-
 
97
            if(!buffer.hasArray()) {
-
 
98
                logger.error("The policy doc is not backed by an accessible byte buffer");
-
 
99
            }
-
 
100
        } catch (Exception e) {
-
 
101
            System.out.println(e.getMessage());
-
 
102
        }
-
 
103
        response.setHeader("Content-disposition", "inline; filename=" + orderId + "-policy.pdf");
-
 
104
 
-
 
105
        ServletOutputStream sos;
-
 
106
        try {
-
 
107
            sos = response.getOutputStream();
-
 
108
            sos.write(buffer.array());
-
 
109
            sos.flush();
-
 
110
        } catch (Exception e) {
-
 
111
            System.out.println("Unable to stream the manifest file");
-
 
112
        }
-
 
113
        return "index";
-
 
114
	}
80
    
115
    
81
	public String formatPrice(double price)    {
116
	public String formatPrice(double price)    {
82
        return formattingUtils.formatPrice(price);
117
        return formattingUtils.formatPrice(price);
83
    }
118
    }
84
	
119
	
Line 129... Line 164...
129
        int addition = 12;
164
        int addition = 12;
130
        cd.add(Calendar.MONTH, addition);
165
        cd.add(Calendar.MONTH, addition);
131
        SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
166
        SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
132
        return dateformat.format(cd.getTime());
167
        return dateformat.format(cd.getTime());
133
    }
168
    }
-
 
169
 
-
 
170
    public String getOrderId() {
-
 
171
        return orderId;
-
 
172
    }
-
 
173
 
-
 
174
    public void setOrderId(String orderId) {
-
 
175
        this.orderId = orderId;
-
 
176
    }
134
}
177
}
135
178