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

Commit c702df4

Browse files
committed
Removed UsagePointBuilder and added a new AdministratorController to
handle things like serverStatus and Registration
1 parent 6de27a3 commit c702df4

File tree

3 files changed

+164
-8
lines changed

3 files changed

+164
-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: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 javax.validation.Valid;
23+
24+
import org.energyos.espi.common.domain.ApplicationInformation;
25+
import org.energyos.espi.common.domain.Authorization;
26+
import org.energyos.espi.common.domain.RetailCustomer;
27+
import org.energyos.espi.common.domain.Routes;
28+
import org.energyos.espi.common.models.atom.EntryType;
29+
import org.energyos.espi.common.service.ImportService;
30+
import org.energyos.espi.common.service.ResourceService;
31+
import org.energyos.espi.common.service.RetailCustomerService;
32+
import org.energyos.espi.thirdparty.web.BaseController;
33+
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.beans.factory.annotation.Qualifier;
35+
import org.springframework.http.HttpEntity;
36+
import org.springframework.http.HttpHeaders;
37+
import org.springframework.http.HttpMethod;
38+
import org.springframework.security.access.prepost.PreAuthorize;
39+
import org.springframework.stereotype.Controller;
40+
import org.springframework.ui.ModelMap;
41+
import org.springframework.validation.BindingResult;
42+
import org.springframework.validation.Errors;
43+
import org.springframework.validation.ValidationUtils;
44+
import org.springframework.validation.Validator;
45+
import org.springframework.web.bind.WebDataBinder;
46+
import org.springframework.web.bind.annotation.InitBinder;
47+
import org.springframework.web.bind.annotation.ModelAttribute;
48+
import org.springframework.web.bind.annotation.PathVariable;
49+
import org.springframework.web.bind.annotation.RequestMapping;
50+
import org.springframework.web.bind.annotation.RequestMethod;
51+
import org.springframework.web.client.RestTemplate;
52+
53+
@Controller
54+
@PreAuthorize("hasRole('ROLE_CUSTODIAN')")
55+
public class AdministratorController extends BaseController {
56+
57+
@Autowired
58+
private RetailCustomerService service;
59+
60+
@Autowired
61+
@Qualifier("restTemplate")
62+
private RestTemplate restTemplate;
63+
64+
@Autowired
65+
private ResourceService resourceService;
66+
67+
@Autowired
68+
private ImportService importService;
69+
70+
public void setService(RetailCustomerService service) {
71+
this.service = service;
72+
}
73+
74+
@RequestMapping(value = Routes.ROOT_SERVICE_STATUS, method = RequestMethod.GET)
75+
public String showServiceStatus(ModelMap model) {
76+
77+
ApplicationInformation applicationInformation = resourceService.findById(1L, ApplicationInformation.class);
78+
String statusUri = applicationInformation.getAuthorizationServerAuthorizationEndpoint() + "/ReadServiceStatus";
79+
// not sure this will work w/o the right seed information
80+
//
81+
Authorization authorization = resourceService.findByResourceUri(statusUri, Authorization.class);
82+
RetailCustomer retailCustomer = authorization.getRetailCustomer();
83+
84+
String accessToken = authorization.getAccessToken();
85+
String serviceStatus = "OK";
86+
87+
try {
88+
89+
HttpHeaders requestHeaders = new HttpHeaders();
90+
requestHeaders.set("Authorization", "Bearer " + accessToken);
91+
@SuppressWarnings({ "unchecked", "rawtypes" })
92+
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
93+
94+
// get the subscription
95+
HttpEntity<String> httpResult = restTemplate.exchange(statusUri, HttpMethod.GET, requestEntity, String.class);
96+
97+
// import it into the repository
98+
ByteArrayInputStream bs = new ByteArrayInputStream(httpResult.getBody()
99+
.toString().getBytes());
100+
101+
importService.importData(bs, retailCustomer.getId());
102+
103+
List<EntryType> entries = importService.getEntries();
104+
105+
// not sure where the <feed> description is going to be ....
106+
107+
108+
} catch (Exception e) {
109+
// nothing there, so log the fact and move on. It will
110+
// get imported later.
111+
e.printStackTrace();
112+
}
113+
model.put("serviceStatus", serviceStatus);
114+
115+
return "/custodian/datacustodian/showservicestatus";
116+
}
117+
118+
}
119+
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)