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

Commit 865f3d3

Browse files
committed
Merge pull request #62 from jateeter/master
DeadCode Removal
2 parents 2321cca + d4ea961 commit 865f3d3

File tree

3 files changed

+154
-8
lines changed

3 files changed

+154
-8
lines changed

src/main/java/org/energyos/espi/thirdparty/repository/impl/UsagePointRESTRepositoryImpl.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.energyos.espi.common.service.ImportService;
3030
import org.energyos.espi.common.service.RetailCustomerService;
3131
import org.energyos.espi.common.service.UsagePointService;
32-
import org.energyos.espi.common.utils.UsagePointBuilder;
3332
import org.energyos.espi.thirdparty.repository.UsagePointRESTRepository;
3433
import org.springframework.beans.factory.annotation.Autowired;
3534
import org.springframework.beans.factory.annotation.Qualifier;
@@ -45,9 +44,6 @@ public class UsagePointRESTRepositoryImpl implements UsagePointRESTRepository {
4544
@Qualifier("restTemplate")
4645
private RestTemplate template;
4746

48-
@Autowired
49-
UsagePointBuilder builder;
50-
5147
@Autowired
5248
private AuthorizationService authorizationService;
5349

@@ -84,10 +80,6 @@ public void setTemplate(RestTemplate template) {
8480
this.template = template;
8581
}
8682

87-
public void setBuilder(UsagePointBuilder builder) {
88-
this.builder = builder;
89-
}
90-
9183
public void setAuthorizationService(AuthorizationService authorizationService) {
9284
this.authorizationService = authorizationService;
9385
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2013, 2014 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.custodian;
18+
19+
import java.io.ByteArrayInputStream;
20+
import java.util.List;
21+
22+
import org.energyos.espi.common.domain.ApplicationInformation;
23+
import org.energyos.espi.common.domain.Authorization;
24+
import org.energyos.espi.common.domain.RetailCustomer;
25+
import org.energyos.espi.common.domain.Routes;
26+
import org.energyos.espi.common.models.atom.EntryType;
27+
import org.energyos.espi.common.service.ImportService;
28+
import org.energyos.espi.common.service.ResourceService;
29+
import org.energyos.espi.common.service.RetailCustomerService;
30+
import org.energyos.espi.thirdparty.web.BaseController;
31+
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.beans.factory.annotation.Qualifier;
33+
import org.springframework.http.HttpEntity;
34+
import org.springframework.http.HttpHeaders;
35+
import org.springframework.http.HttpMethod;
36+
import org.springframework.security.access.prepost.PreAuthorize;
37+
import org.springframework.stereotype.Controller;
38+
import org.springframework.ui.ModelMap;
39+
import org.springframework.web.bind.annotation.RequestMapping;
40+
import org.springframework.web.bind.annotation.RequestMethod;
41+
import org.springframework.web.client.RestTemplate;
42+
43+
@Controller
44+
@PreAuthorize("hasRole('ROLE_CUSTODIAN')")
45+
public class AdministratorController extends BaseController {
46+
47+
@Autowired
48+
private RetailCustomerService service;
49+
50+
@Autowired
51+
@Qualifier("restTemplate")
52+
private RestTemplate restTemplate;
53+
54+
@Autowired
55+
private ResourceService resourceService;
56+
57+
@Autowired
58+
private ImportService importService;
59+
60+
public void setService(RetailCustomerService service) {
61+
this.service = service;
62+
}
63+
64+
@RequestMapping(value = Routes.ROOT_SERVICE_STATUS, method = RequestMethod.GET)
65+
public String showServiceStatus(ModelMap model) {
66+
67+
ApplicationInformation applicationInformation = resourceService.findById(1L, ApplicationInformation.class);
68+
String statusUri = applicationInformation.getAuthorizationServerAuthorizationEndpoint() + "/ReadServiceStatus";
69+
// not sure this will work w/o the right seed information
70+
//
71+
Authorization authorization = resourceService.findByResourceUri(statusUri, Authorization.class);
72+
RetailCustomer retailCustomer = authorization.getRetailCustomer();
73+
74+
String accessToken = authorization.getAccessToken();
75+
String serviceStatus = "OK";
76+
77+
try {
78+
79+
HttpHeaders requestHeaders = new HttpHeaders();
80+
requestHeaders.set("Authorization", "Bearer " + accessToken);
81+
@SuppressWarnings({ "unchecked", "rawtypes" })
82+
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
83+
84+
// get the subscription
85+
HttpEntity<String> httpResult = restTemplate.exchange(statusUri, HttpMethod.GET, requestEntity, String.class);
86+
87+
// import it into the repository
88+
ByteArrayInputStream bs = new ByteArrayInputStream(httpResult.getBody()
89+
.toString().getBytes());
90+
91+
importService.importData(bs, retailCustomer.getId());
92+
93+
List<EntryType> entries = importService.getEntries();
94+
95+
// not sure where the <feed> description is going to be ....
96+
97+
98+
} catch (Exception e) {
99+
// nothing there, so log the fact and move on. It will
100+
// get imported later.
101+
e.printStackTrace();
102+
}
103+
model.put("serviceStatus", serviceStatus);
104+
105+
return "/custodian/datacustodian/showservicestatus";
106+
}
107+
108+
}
109+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2+
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
3+
<%--
4+
~ Copyright 2013 EnergyOS.org
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
--%>
18+
19+
<!DOCTYPE html>
20+
<html lang="en">
21+
22+
<jsp:include page="/WEB-INF/jsp/tiles/head.jsp"/>
23+
24+
<body>
25+
26+
<jsp:include page="/WEB-INF/jsp/tiles/custodian/header.jsp"/>
27+
28+
<div class="container">
29+
30+
<div class="row">
31+
<div class="span12">
32+
33+
<h2>Service Status: - <c:out value="${serviceStatus}"/></h2>
34+
35+
</div>
36+
</div>
37+
38+
<hr>
39+
40+
<jsp:include page="/WEB-INF/jsp/tiles/footer.jsp"/>
41+
42+
</div>
43+
44+
</body>
45+
</html>

0 commit comments

Comments
 (0)