1+ /*
2+ * Copyright 2013,2014,2015 EnergyOS.org
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .energyos .espi .thirdparty .web ;
18+
19+ import java .io .IOException ;
20+ import java .util .Map ;
21+
22+ import javax .servlet .http .HttpServletResponse ;
23+
24+ import org .energyos .espi .common .domain .Routes ;
25+ import org .energyos .espi .common .service .ExportService ;
26+ import org .energyos .espi .common .utils .ExportFilter ;
27+ import org .springframework .beans .factory .annotation .Autowired ;
28+ import org .springframework .http .MediaType ;
29+ import org .springframework .security .access .prepost .PreAuthorize ;
30+ import org .springframework .stereotype .Controller ;
31+ import org .springframework .web .bind .annotation .PathVariable ;
32+ import org .springframework .web .bind .annotation .RequestMapping ;
33+ import org .springframework .web .bind .annotation .RequestMethod ;
34+ import org .springframework .web .bind .annotation .RequestParam ;
35+
36+ import com .sun .syndication .io .FeedException ;
37+
38+ @ Controller
39+ @ PreAuthorize ("hasRole('ROLE_USER')" )
40+ public class CustomerDownloadMyDataController extends BaseController {
41+
42+ @ Autowired
43+ private ExportService exportService ;
44+
45+ @ RequestMapping (value = Routes .RETAIL_CUSTOMER_DOWNLOAD_MY_DATA , method = RequestMethod .GET )
46+ public void downloadMyData (HttpServletResponse response ,
47+ @ PathVariable Long retailCustomerId ,
48+ @ PathVariable Long usagePointId ,
49+ @ RequestParam Map <String , String > params ) throws IOException ,
50+ FeedException {
51+ response .setContentType (MediaType .TEXT_HTML_VALUE );
52+ response .addHeader ("Content-Disposition" ,
53+ "attachment; filename=GreenButtonDownload.xml" );
54+ try {
55+
56+ exportService .exportUsagePointFull (0L , retailCustomerId ,
57+ usagePointId , response .getOutputStream (), new ExportFilter (
58+ params ));
59+
60+ } catch (Exception e ) {
61+ response .setStatus (HttpServletResponse .SC_BAD_REQUEST );
62+ }
63+ }
64+
65+ @ RequestMapping (value = Routes .RETAIL_CUSTOMER_DOWNLOAD_MY_DATA_COLLECTION , method = RequestMethod .GET )
66+ public void downloadMyDataCollection (HttpServletResponse response ,
67+ @ PathVariable Long retailCustomerId ,
68+ @ RequestParam Map <String , String > params ) throws IOException ,
69+ FeedException {
70+
71+ response .setContentType (MediaType .TEXT_HTML_VALUE );
72+ response .addHeader ("Content-Disposition" ,
73+ "attachment; filename=GreenButtonDownload.xml" );
74+ try {
75+ // TODO -- need authorization hook
76+ exportService .exportUsagePointsFull (0L , retailCustomerId ,
77+ response .getOutputStream (), new ExportFilter (params ));
78+
79+ } catch (Exception e ) {
80+ response .setStatus (HttpServletResponse .SC_BAD_REQUEST );
81+ }
82+ }
83+
84+ public void setExportService (ExportService exportService ) {
85+ this .exportService = exportService ;
86+ }
87+
88+ public ExportService getExportService () {
89+ return this .exportService ;
90+ }
91+ }
0 commit comments