Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit b74797d

Browse files
committed
1 parent 425b2cc commit b74797d

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

src/main/webapp/WEB-INF/jsp/customer/usagepoints/index.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<div style="margin-left: 40px;">
3131
<table><tr><td>
32-
<a id = "downloadMyData" class="brand" href="<c:url value='/espi/1_1/resource/Batch/RetailCustomer/${currentCustomer.id}/UsagePoint'/>">
32+
<a id = "downloadMyData" class="brand" href="<c:url value='/RetailCustomer/${currentCustomer.id}/DownloadMyData/UsagePoint'/>">
3333
<img src="<c:url value='/resources/img/Green_Download_265.png'/>" width="150"/></a>
3434
&nbsp;&nbsp;</td><td>
3535

src/main/webapp/WEB-INF/jsp/customer/usagepoints/show.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<div style="margin-left: 40px;">
2828
<table><tr><td>
2929

30-
<a id = "downloadMyData" class="brand" href="<c:url value='/espi/1_1/resource/Batch/RetailCustomer/${currentCustomer.id}/UsagePoint/${displayBag.get("usagePointId")}'/>">
30+
<a id = "downloadMyData" class="brand" href="<c:url value='/RetailCustomer/${currentCustomer.id}/DownloadMyData/UsagePoint/${displayBag.get("usagePointId")}'/>">
3131
<img src="<c:url value='/resources/img/Green_Download_265.png'/>" width="150"/></a>
3232
&nbsp;&nbsp;</td><td>
3333

0 commit comments

Comments
 (0)