Skip to content

Commit 86595ab

Browse files
authored
Merge pull request #1189 from cambridge-cares/1716-dev-ceavisualisationagent
1716 dev ceavisualisationagent
2 parents 9018dfe + 1dff22f commit 86595ab

File tree

16 files changed

+945
-0
lines changed

16 files changed

+945
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<settingsSecurity>
2+
<master>MASTER_PASSWORD</master>
3+
</settingsSecurity>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<settings>
2+
<!-- The path to the local repository Maven will use to store artifacts -->
3+
<localRepository>${user.home}/.m2/repository</localRepository>
4+
5+
<!-- Will Maven prompt you when it needs input? If false, Maven will use a sensible default -->
6+
<interactiveMode>false</interactiveMode>
7+
8+
<!-- Should Maven use the plugin-registry.xml to manage plugin version? -->
9+
<usePluginRegistry>false</usePluginRegistry>
10+
11+
<!-- Should Maven operate in offline mode? -->
12+
<offline>false</offline>
13+
14+
<!-- Server credentials -->
15+
<servers>
16+
<server>
17+
<id>repo</id>
18+
<username>REPO_USERNAME</username>
19+
<password>REPO_PASSWORD</password>
20+
</server>
21+
</servers>
22+
23+
<profiles>
24+
<profile>
25+
<id>Default Profile</id>
26+
<properties></properties>
27+
<repositories>
28+
<repository>
29+
<id>repo</id>
30+
<url>https://maven.pkg.github.com/cambridge-cares/TheWorldAvatar/</url>
31+
<layout>default</layout>
32+
<releases>
33+
<enabled>true</enabled>
34+
</releases>
35+
<snapshots>
36+
<enabled>true</enabled>
37+
</snapshots>
38+
</repository>
39+
</repositories>
40+
</profile>
41+
</profiles>
42+
43+
<!-- List of profiles that are active for all builds. -->
44+
<activeProfiles>
45+
<activeProfile>Default Profile</activeProfile>
46+
</activeProfiles>
47+
</settings>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# First stage: build war file
2+
#==================================================================================================
3+
FROM maven:3.6-openjdk-11-slim as builder
4+
5+
# Copy all files into root's home, including the source, pom file, ./m2 directory and credentials
6+
ADD . /root
7+
8+
# Populate settings templates with credentials, repo name
9+
WORKDIR /root/.m2
10+
# (Note that | rather than / is used as the sed delimiter, since encrypted passwords can contain the former, but not the latter
11+
RUN sed -i "s|MASTER_PASSWORD|$(mvn --encrypt-master-password master_password)|" settings-security.xml
12+
RUN sed -i "s|REPO_USERNAME|$(cat ../credentials/repo_username.txt)|;s|REPO_PASSWORD|$(cat ../credentials/repo_password.txt|xargs mvn --encrypt-password)|" settings.xml
13+
14+
# Build
15+
WORKDIR /root/ceavisualisation-agent
16+
RUN --mount=type=cache,target=/root/.m2/repository mvn package
17+
#==================================================================================================
18+
19+
# Second stage: copy the downloaded dependency into a new image and build into an app
20+
#==================================================================================================
21+
FROM tomcat:9.0 as agent
22+
23+
WORKDIR /app
24+
25+
COPY --from=builder /root/ceavisualisation-agent/output/ceavisualisation-agent##0.1.0.war $CATALINA_HOME/webapps/
26+
27+
# Start the Tomcat server
28+
ENTRYPOINT ["catalina.sh", "run"]
29+
#==================================================================================================
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Agent purpose
2+
The CEAVisualisationAgent is intended to create the necessary PostgreSQL table and GeoServer layer, as well as relevant set up, for the visualisation of CEA agent results within TWA-VF.
3+
In the resulting TWA-VF visualisation, it is intended that the buildings are visualised with a color scale representing their energy demand and solar potential results from the CEA agent.
4+
5+
# Agent logic
6+
The agent is designed to receive a POST request with the CEA agent outputs as annual values for energy demands and solar potentials and the solar suitable areas, together with the building IRI.
7+
After receiving the request, the agent will create (if the table does not exist before) or update the table that with the building IRI and its corresponding annual values and solar suitable areas.
8+
The agent will also create a GeoServer layer based on the aforementioned PostgreSQL table.
9+
A `data.json` has been included in `./stack-manager-input/data/webspace` which uses the GeoServer layer that the agent created to visualise CEA results in TWA-VF.
10+
11+
# What has been implemented
12+
- The main classes to receive the request, and to parse the data into PostgreSQL table and GeoServer layer.
13+
- Stack manager configurations
14+
- `data.json` for TWA-VF
15+
16+
# TODO
17+
- Automatic creation of legends for TWA-VF
18+
- Integration with the CEA agent
19+
- Unit tests
20+
- Testing that everything works together
21+
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>uk.ac.cam.cares.jps.agent</groupId>
8+
<artifactId>ceavisualisation-agent</artifactId>
9+
<version>0.1.0</version>
10+
<packaging>war</packaging>
11+
12+
<!-- Project properties -->
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>11</maven.compiler.source>
16+
<maven.compiler.target>11</maven.compiler.target>
17+
18+
<!-- Version of the JPS Base Library to use -->
19+
<jps.base.version>1.35.0</jps.base.version>
20+
</properties>
21+
22+
<!-- Parent POM -->
23+
<parent>
24+
<groupId>uk.ac.cam.cares.jps</groupId>
25+
<artifactId>jps-parent-pom</artifactId>
26+
<version>2.2.0</version>
27+
</parent>
28+
29+
<!-- Profiles are used to switch between building for development and production
30+
environments. Use "-P profile-id" within an mvn command to build with a profile -->
31+
<profiles>
32+
<!-- This profile should be used for development builds. -->
33+
<profile>
34+
<id>dev-profile</id>
35+
<activation>
36+
<activeByDefault>true</activeByDefault>
37+
</activation>
38+
<properties>
39+
<!-- Set property to download development logging config -->
40+
<log.artifact>java-logging-dev</log.artifact>
41+
</properties>
42+
</profile>
43+
44+
<!-- This profile should be used for production builds. -->
45+
<profile>
46+
<id>prod-profile</id>
47+
<properties>
48+
<!-- Set property to download production logging config -->
49+
<log.artifact>java-logging-prod</log.artifact>
50+
</properties>
51+
</profile>
52+
</profiles>
53+
54+
<build>
55+
<plugins>
56+
57+
<!-- Compile and build with Java 11 -->
58+
<plugin>
59+
<groupId>org.apache.maven.plugins</groupId>
60+
<artifactId>maven-compiler-plugin</artifactId>
61+
<version>3.7.0</version>
62+
<configuration>
63+
<source>11</source>
64+
<target>11</target>
65+
</configuration>
66+
</plugin>
67+
68+
<!-- Allows maven executions -->
69+
<plugin>
70+
<groupId>org.codehaus.mojo</groupId>
71+
<artifactId>exec-maven-plugin</artifactId>
72+
<version>1.6.0</version>
73+
</plugin>
74+
75+
<!-- Used to execute unit tests -->
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-surefire-plugin</artifactId>
79+
<!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
80+
<version>2.22.0</version>
81+
</plugin>
82+
83+
<!-- Used to build into a WAR file and ensures everything in ./WEB-INF
84+
gets copied into the final WAR file's internal WEB-INF directory. -->
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-war-plugin</artifactId>
88+
<!-- Version, configuration, and executions should be pulled from the
89+
parent POM unless overridden here. -->
90+
</plugin>
91+
92+
<!-- Downloads and extracts ZIP archives from Maven repository -->
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-dependency-plugin</artifactId>
96+
<!-- Version, configuration, and executions should be pulled from the
97+
parent POM unless overridden here. -->
98+
</plugin>
99+
100+
</plugins>
101+
</build>
102+
103+
<!-- Dependencies -->
104+
<dependencies>
105+
106+
<!-- JPS Base Library -->
107+
<dependency>
108+
<groupId>uk.ac.cam.cares.jps</groupId>
109+
<artifactId>jps-base-lib</artifactId>
110+
<version>${jps.base.version}</version>
111+
</dependency>
112+
113+
<dependency>
114+
<groupId>com.cmclinnovations</groupId>
115+
<artifactId>stack-clients</artifactId>
116+
<version>1.10.2</version>
117+
</dependency>
118+
119+
<!-- Java servlet API, version pulled from parent -->
120+
<dependency>
121+
<groupId>javax.servlet</groupId>
122+
<artifactId>javax.servlet-api</artifactId>
123+
</dependency>
124+
125+
<!-- JSON handling -->
126+
<dependency>
127+
<groupId>org.json</groupId>
128+
<artifactId>json</artifactId>
129+
<version>20180813</version>
130+
<type>jar</type>
131+
</dependency>
132+
133+
<!-- Logging, versions pulled from parent -->
134+
<dependency>
135+
<groupId>org.apache.logging.log4j</groupId>
136+
<artifactId>log4j-api</artifactId>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.apache.logging.log4j</groupId>
140+
<artifactId>log4j-core</artifactId>
141+
</dependency>
142+
<dependency>
143+
<groupId>org.apache.logging.log4j</groupId>
144+
<artifactId>log4j-web</artifactId>
145+
</dependency>
146+
147+
<!-- Testing, versions pulled from parent -->
148+
<dependency>
149+
<groupId>org.junit.jupiter</groupId>
150+
<artifactId>junit-jupiter</artifactId>
151+
<version>5.4.2</version>
152+
<scope>test</scope>
153+
</dependency>
154+
<dependency>
155+
<groupId>org.mockito</groupId>
156+
<artifactId>mockito-core</artifactId>
157+
<version>3.11.2</version>
158+
<scope>test</scope>
159+
</dependency>
160+
<dependency>
161+
<groupId>org.mockito</groupId>
162+
<artifactId>mockito-inline</artifactId>
163+
<version>3.11.2</version>
164+
<scope>test</scope>
165+
</dependency>
166+
<dependency>
167+
<groupId>org.testcontainers</groupId>
168+
<artifactId>testcontainers</artifactId>
169+
<version>1.16.2</version>
170+
<scope>test</scope>
171+
</dependency>
172+
<dependency>
173+
<groupId>org.testcontainers</groupId>
174+
<artifactId>junit-jupiter</artifactId>
175+
<version>1.16.2</version>
176+
<scope>test</scope>
177+
</dependency>
178+
<dependency>
179+
<groupId>org.testcontainers</groupId>
180+
<artifactId>postgresql</artifactId>
181+
<version>1.16.2</version>
182+
<scope>test</scope>
183+
</dependency>
184+
</dependencies>
185+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package uk.ac.cam.cares.jps.agent.ceavisualisation;
2+
3+
import org.apache.commons.lang3.tuple.Pair;
4+
5+
enum Annual {
6+
GRID("grid","grid_per_gfa"),
7+
ELECTRICITY("electricity","electricity_per_gfa"),
8+
HEATING("heating","heating_per_gfa"),
9+
COOLING("cooling","cooling_per_gfa"),
10+
PV_ROOF("pv_roof","pv_roof_per_area"),
11+
PV_NORTH("pv_north","pv_north_per_area"),
12+
PV_SOUTH("pv_south","pv_south_per_area"),
13+
PV_WEST("pv_west","pv_west_per_area"),
14+
PV_EAST("pv_east","pv_east_per_area"),
15+
PVT_PLATE_Q_ROOF("pvt_plate_q_roof","pvt_plate_q_roof_per_area"),
16+
PVT_PLATE_Q_NORTH("pvt_plate_q_north","pvt_plate_q_north_per_area"),
17+
PVT_PLATE_Q_SOUTH("pvt_plate_q_south","pvt_plate_q_south_per_area"),
18+
PVT_PLATE_Q_WEST("pvt_plate_q_west","pvt_plate_q_west_per_area"),
19+
PVT_PLATE_Q_EAST("pvt_plate_q_east","pvt_plate_q_east_per_area"),
20+
PVT_PLATE_E_ROOF("pvt_plate_e_roof","pvt_plate_e_roof_per_area"),
21+
PVT_PLATE_E_NORTH("pvt_plate_e_north","pvt_plate_e_north_per_area"),
22+
PVT_PLATE_E_SOUTH("pvt_plate_e_south","pvt_plate_e_south_per_area"),
23+
PVT_PLATE_E_WEST("pvt_plate_e_west","pvt_plate_e_west_per_area"),
24+
PVT_PLATE_E_EAST("pvt_plate_e_east","pvt_plate_e_east_per_area"),
25+
PVT_TUBE_Q_ROOF("pvt_tube_q_roof","pvt_tube_q_roof_per_area"),
26+
PVT_TUBE_Q_NORTH("pvt_tube_q_north","pvt_tube_q_north_per_area"),
27+
PVT_TUBE_Q_SOUTH("pvt_tube_q_south","pvt_tube_q_south_per_area"),
28+
PVT_TUBE_Q_WEST("pvt_tube_q_west","pvt_tube_q_west_per_area"),
29+
PVT_TUBE_Q_EAST("pvt_tube_q_east","pvt_tube_q_east_per_area"),
30+
PVT_TUBE_E_ROOF("pvt_tube_e_roof","pvt_tube_e_roof_per_area"),
31+
PVT_TUBE_E_NORTH("pvt_tube_e_north","pvt_tube_e_north_per_area"),
32+
PVT_TUBE_E_SOUTH("pvt_tube_e_south","pvt_tube_e_south_per_area"),
33+
PVT_TUBE_E_WEST("pvt_tube_e_west","pvt_tube_e_west_per_area"),
34+
PVT_TUBE_E_EAST("pvt_tube_e_east","pvt_tube_e_east_per_area"),
35+
SC_PLATE_ROOF("sc_plate_roof","sc_plate_roof_per_area"),
36+
SC_PLATE_NORTH("sc_plate_north","sc_plate_north_per_area"),
37+
SC_PLATE_SOUTH("sc_plate_south","sc_plate_south_per_area"),
38+
SC_PLATE_WEST("sc_plate_west","sc_plate_west_per_area"),
39+
SC_PLATE_EAST("sc_plate_east","sc_plate_east_per_area"),
40+
SC_TUBE_ROOF("sc_tube_roof","sc_tube_roof_per_area"),
41+
SC_TUBE_NORTH("sc_tube_north","sc_tube_north_per_area"),
42+
SC_TUBE_SOUTH("sc_tube_south","sc_tube_south_per_area"),
43+
SC_TUBE_WEST("sc_tube_west","sc_tube_west_per_area"),
44+
SC_TUBE_EAST("sc_tube_east","sc_tube_east_per_area");
45+
46+
private final Pair<String, String> value;
47+
Annual(String annual, String annualPerArea) {
48+
this.value = Pair.of(annual, annualPerArea);
49+
}
50+
51+
public String getAnnual() {
52+
return this.value.getKey();
53+
}
54+
55+
public String getAnnualPerArea() {
56+
return this.value.getValue();
57+
}
58+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package uk.ac.cam.cares.jps.agent.ceavisualisation;
2+
3+
enum Area {
4+
GFA("gfa"),
5+
ROOF_AREA("roof_area"),
6+
NORTH_AREA("north_area"),
7+
SOUTH_AREA("south_area"),
8+
WEST_AREA("west_area"),
9+
EAST_AREA("east_area");
10+
11+
private final String value;
12+
13+
Area(String value) {
14+
this.value = value;
15+
}
16+
17+
public String getValue() {
18+
return value;
19+
}
20+
}

0 commit comments

Comments
 (0)