Skip to content

Commit ed34732

Browse files
authored
Merge pull request #193 from ptidejteam/develop
Pre-release checks
2 parents b73a599 + 2a329d7 commit ed34732

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+25329
-289
lines changed

.github/workflows/maven.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ name: Ptidej Middleware CI with Maven
1010

1111
on:
1212
push:
13-
branches: [ "master" ]
13+
branches: [ "master", "develop" ]
1414
paths-ignore:
1515
- 'docs/**'
1616
- '*.md'
1717
pull_request:
18-
branches: [ "master" ]
18+
branches: [ "master", "develop" ]
1919
paths-ignore:
2020
- 'docs/**'
2121
- '*.md'
@@ -37,9 +37,9 @@ jobs:
3737
- name: Generate keypair for authentication (in correct location)
3838
working-directory: Middleware
3939
run: |
40-
mkdir -p src/main/resources/certs
41-
openssl genpkey -algorithm RSA -out src/main/resources/certs/private.pem -pkeyopt rsa_keygen_bits:2048
42-
openssl rsa -pubout -in src/main/resources/certs/private.pem -out src/main/resources/certs/public.pem
40+
mkdir -p src/main/resources/scripts/certs/
41+
openssl genpkey -algorithm RSA -out src/main/resources/scripts/certs/private.pem -pkeyopt rsa_keygen_bits:2048
42+
openssl rsa -pubout -in src/main/resources/scripts/certs/private.pem -out src/main/resources/scripts/certs/public.pem
4343
4444
- name: Clean and test with Maven
4545
working-directory: Middleware
@@ -52,4 +52,3 @@ jobs:
5252
- name: Build with Maven
5353
run: mvn install
5454
working-directory: Middleware
55-

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,6 @@ cython_debug/
235235
#########
236236
.DS_Store
237237

238-
certs/
238+
certs/
239+
240+
credentials/

Middleware/.classpath

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,16 @@
4848
<attribute name="test" value="true"/>
4949
</attributes>
5050
</classpathentry>
51+
<classpathentry kind="src" path=".apt_generated">
52+
<attributes>
53+
<attribute name="optional" value="true"/>
54+
</attributes>
55+
</classpathentry>
56+
<classpathentry kind="src" output="target/test-classes" path=".apt_generated_tests">
57+
<attributes>
58+
<attribute name="optional" value="true"/>
59+
<attribute name="test" value="true"/>
60+
</attributes>
61+
</classpathentry>
5162
<classpathentry kind="output" path="target/classes"/>
5263
</classpath>

Middleware/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ build/
5151
!.mvn/wrapper/maven-wrapper.jar
5252
!**/src/main/**/target/
5353
!**/src/test/**
54+
!META-INF/**
55+
56+
## Ignore JWT certs/keys
57+
Middleware/src/main/resources/scripts/certs/
58+
59+
## Ignore user credentials
60+
Middleware/src/main/resources/scripts/credentials/
61+
Middleware/src/main/resources/credentials/
62+
5463

Middleware/.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.jdt.core.javabuilder</name>
1015
<arguments>
@@ -19,6 +24,7 @@
1924
<natures>
2025
<nature>org.eclipse.m2e.core.maven2Nature</nature>
2126
<nature>org.eclipse.jdt.core.javanature</nature>
27+
<nature>org.python.pydev.pythonNature</nature>
2228
</natures>
2329
<filteredResources>
2430
<filter>

Middleware/DATA_SOURCES.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Dataset Catalog
2+
3+
## Overview
4+
This document provides a comprehensive catalog of datasets available for research and analysis, covering building information, transportation, energy consumption, and urban infrastructure in Montreal and surrounding areas. Currently, these datasets are not in the repository, they will be added in coming days.
5+
6+
---
7+
8+
## Datasets
9+
10+
11+
| ID | Dataset Names | Description | Format |
12+
|---|---|---|---|
13+
| DS1 | Montreal Districts/Boroughs | Polygons of Montreal districts and boroughs sourced from City of Montreal. | GeoJSON |
14+
| DS2 | Montreal Building Geometry (LoD2) | 3D building footprints extruded by average height, represented as GeoJSON feature‑collection. | RAR (GeoJSON) |
15+
| DS3 | Montreal Buildings (LoD1) | 2D polygons and metadata of Montreal buildings derived from property assessment rolls. | SHP |
16+
| DS4 | Canadian Building Footprints | ~2.5M building footprints for Quebec, generated and licensed by Microsoft. | ZIP / GeoJSON |
17+
| DS5 | MTL Trajet_routes | Mobile-phone trip trajectories in Montreal collected in 2016–17. | ZIP |
18+
| DS6 | Transportation in Montreal Tweets | Tweets about transportation in Montreal, with multiple tweet attributes. | CSV |
19+
| DS7 | Census tract boundaries | Geometric boundaries of Canadian census tract units. | CSV / ZIP / PDF |
20+
| DS8 | Varennes Digital Surface Model (DSM) | DSM .tif of Varennes area used for data cleaning around Varennes Public Library. | TIFF |
21+
| DS9 | Varennes Digital Terrain Model (DTM) | DTM .tif used in the same context. | TIFF |
22+
| DS10 | Varennes Boundary Shape File | Shapefile boundary covering ~5,229 buildings around Varennes Public Library. | SHP |
23+
| DS11 | Geoindex shape file clipped for Varennes | Shapefile clipped based on a defined Varennes boundary using PyQGIS. | SHP |
24+
| DS12 | Whole building LCA | Harmonized North America-wide whole-building life-cycle assessment dataset (first release). | ZIP / XLSX |
25+
| DS13 | Concordia Building Blueprints | Blueprints of all Concordia campus buildings (SGW + Loyola) Campus | DWG, PDF, PNG/JPG |
26+
| DS14 | Hydro Quebec Energy Metering Data | Comprehensive dataset containing energy metering data of Hydro Quebec users | Parquet |
27+
| DS15 | Building Elecricity Data | Comes from Concordia Facilities Management - Weekly basis | CSV |
28+
| DS16 | General Transit Feed Specification | The General Transit Feed Specification (GTFS) is a standardized open data portal that offers information about transit systems. | TXT files |
29+
| DS17 | Lot boundaries of Montreal Chinatown 2014 | Buildings' lot boundaries and associated metadata for Chinatown, Montreal. This dataset pertains to the year 2014. | JSON |
30+
| DS18 | Montreal Chinatown buildings footprints | Polygon footprints of buildings in Montreal's Chinatown. | GeoJSON |
31+
| DS19 | Montreal Chinatown points of interests | Locations and information about Points of Interest in Montreal's Chinatown. | JSON |
32+
| DS20 | Public trees in Montreal chinatown | Positions and information of trees planted in Montreal's Chinatown. | JSON |
33+
| DS21 | Public Parking Meters Montreal Chinatown | Geographical information and details about parking meter spaces available in Montreal's Chinatown. | GeoJSON |
34+
| DS22 | Chinatown Polygon Boundary 2022 | Data on Montreal's Chinatown boundary polygon declared in 2022. | JSON |
35+
| DS23 | CERC CMM | This is the first version of the CERC's Communauté métropolitaine de Montréal (CMM). The map was developed based on different datasets. | ZIP |
36+
| DS24 | CERC CMM: One feature for each building | This is the second version of the CERC's Communauté métropolitaine de Montréal (CMM). This data layer (in GeoJSON format) is composed in a way that each feature represents one building. | CKAN | GEOJSON |
37+
| DS25 | Property assessment units | Property Assessment Units (Unités d'évaluation foncière" ) contains Vector geospatial data of property divisions within the Montreal agglomeration, providing general information on property assessment units. This includes codification (CUBF), approximate dimensions, and registration numbers. | JSON/CSV |
38+
| DS26 | BIXI Stations | "BIXI Stations" lists stations within the BIXI Montréal self-service bicycle network, providing information on their geographic positions, available bicycles, and terminals. BIXI Montréal has published the dataset. | CKAN | CSV |
39+
| DS27 | BIXI Trips History (2021, 2022) | BIXI trip history contains detailed information about trips taken using the BIXI Montréal self-service bicycle network in 2021. BIXI is a popular bike-sharing system that offers a convenient and eco-friendly mode of transportation for residents and visitors. | ZIP |
40+
| DS28 | Load data by a load generator tool | Information missing | XLSX |
41+
| DS29 | Montreal downtown buildings (SGW campus) | This data includes 188 buildings in Montreal downtown. All of the SGW campus building of Concordia University is included. | GeoJSON |
42+
| DS30 | Varennes shp files | This .tif file is a Digital Surface Model (DSM) of Varennes. It is being used for a data cleaning and updating project focused on buildings around the Varennes Public Library. Metadata can also be found in the .rar file. High-Resolution Digital Elevation Model (HRDEM) - CanElevation Series | RAR/PDF |
43+
| DS31 | Varennes-Clipped Quebec Property Assessment Rolls 2022 | This shape file is from Quebec property assessment rolls 2022 data. It has been clipped based on buildings around Varennes Public Library. | RAR |
44+
| DS32 | Comptages Vehicules Cyclistes Pietons | Count of Motor Vehicles, Cyclists, and Pedestrians at Montreal Intersections Counts of vehicles, cyclists, and pedestrians are available for most intersections equipped with traffic lights and specific intersections where the installation of lights was under study. | CSV |
45+
| DS33 | Hydro Quebec Dataset for Concordia Buildings | Yearly bills - SGW and Loyola Campus | CSV |
46+
| DS34 | Monthly billing data | Monthly billing consumption data - several swimming poola arenas and fire station in Montreal | CSV |
47+
| DS35 | Some dataset | Some csv files - a lot of them | CSV |
48+
| DS36 | Occupancy Data | Occupancy sensors data - 14th floor - EV building (4 10 9) | API Call/CSV |
49+
| DS37 | GENOME Project 2 dataset | Data Genome Project 2 - Clean version of electricity consumption - 1630 institutional buildings across north america | CSV |
50+
| DS38 | Commuters Survey | Commuters survey | Concordia sustainability office | Information missing |
51+
| DS39 | Synthetic population dataset | The dataset represents a synthetic population developed by Polytechnique Montréal. Based on Home Travel Survey data. Covers 100% of the population of Montreal, capturing detailed travel behavior. | XML |
52+
| DS40 | PECAN Street Residential Building Dataset in the California Region | Historical time series load data recorded from the real-world PECAN street in the California region. | CSV |
53+
| DS41 | Data Ontology CIMNE-CERC | Information missing | Information missing |
54+
| DS42 | Buildings demands energy generation from Solar PV systems | Net electricity load, and net demand (load -PV). The data also includes blueprints of architectural drawings, road maps, and types of electrical demands and their specifications. Data of 5 buildings. | DWG, PDF, PNG/JPG, CSV |

Middleware/README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To collaborate with CITYdata, you can use the Java IDE of your choice. The CITYd
3636

3737
Before generating the public and private keys, ensure you have `openssl` installed in your machine!
3838

39-
- Step 1: Create a folder named `certs` inside the `src/main/resources` directory.
39+
- Step 1: Create a folder named `certs` inside the `src/main/resources/scripts/certs` directory.
4040
- Step 2: Navigate to the `certs` folder and run the following commands to generate your public and private keys:
4141

4242
```bash
@@ -46,6 +46,28 @@ openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in keypair.pem -out priv
4646
```
4747
- Step 3: Once public and private keys are generated, you can delete the keypair.pem
4848

49+
## Adding Users
50+
51+
Before proceeding, ensure the following prerequisites are met:
52+
* `Python` is installed and added to your system's environment variables.
53+
* The `bcrypt` package is installed. If not, open your terminal (Bash) and run:
54+
55+
pip install bcrypt
56+
57+
Once the above requirements are fulfilled, follow these steps to add, remove, or update users:
58+
59+
- Open `Bash` and navigate to the following directory in the `citydata` project:
60+
61+
cd src/main/resources/scripts
62+
63+
- Run the credentials manager script:
64+
65+
./credentials-manager.sh
66+
67+
- An interactive menu will appear, allowing you to add, remove, or update users in `citydata`.
68+
69+
- If you wish to use the instance of CITYdata hosted at the NGCI, please contact us for user creation.
70+
4971
## How do I set it up?
5072

5173
- Install Java and Maven in your operating system
@@ -79,7 +101,7 @@ java -jar ./target/Middleware-0.0.1-SNAPSHOT.jar --server.port=8080
79101
## How do I use it?
80102

81103
- CITYdata is a REST API which receives queries as input and generates data as output.
82-
- A query is a JSON file where you specify which data you want and which transformations you wish to apply to the data. You can see query examples in the folder /docs/examples.
104+
- A query is a JSON file where you specify which data you want and which transformations you wish to apply to the data. You can see query examples in the folder `/docs/examples/queries`.
83105
- You can call CITYdata routes using your favourite programming language. For example, you can use the requests package in [Python](https://www.geeksforgeeks.org/get-post-requests-using-python/) or the fetch API in [JavaScript](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch).
84106
- If you are familiar with Postman, you can use our Postman collection [here](https://github.com/ptidejteam/citydata/blob/master/Middleware/docs/citydata_collection.json) to send your queries, no need to write code.
85107

@@ -97,10 +119,59 @@ The following routes are available:
97119

98120
For now, the number of Producers, Operations and parameters is quite limited, but we intend to expand it in the future and also document it better. Your suggestions are more than welcome!
99121

122+
123+
## Accessing Private/Protected Routes
124+
125+
To access the private or protected routes, follow these steps
126+
127+
- Create a User Account:
128+
* Follow the instructions in the "Adding Users" section above to create a username and password
129+
130+
- Authenticate the User:
131+
* Run the application and send a `POST` request to the following endpoint
132+
133+
http://localhost:8080/authenticate
134+
135+
Include your username and password in the request body as JSON, for example
136+
137+
```json
138+
{
139+
"username": "yourUsername",
140+
"password": "yourPassword"
141+
}
142+
```
143+
144+
- Receive Authentication Token:
145+
* Upon successful authentication, a token will be returned in the response
146+
147+
- Copy the Token:
148+
* Copy the token from the response. You'll use this to access protected routes
149+
150+
- Access Protected Routes:
151+
* Use one of the following endpoints:
152+
153+
POST http://localhost:8080/apply/sync
154+
POST http://localhost:8080/apply/async
155+
156+
- Add Authorization Header in Postman:
157+
* In Postman (or any API client)
158+
* Go to the Authorization tab
159+
* Set Type to Bearer Token
160+
* Paste the token into the Token field
161+
162+
- Access Granted:
163+
* If the token is valid, Spring Boot will authorize your request and grant access to the protected route
164+
165+
## Available Data Sources
166+
167+
- [Dataset Catalog](DATA_SOURCES.md) - Complete list of all available datasets
168+
169+
100170
## Who do I talk to?
101171

102172
Project manager: gabriel.cavalheiroullmann at concordia.ca
103173

174+
104175
## Development Guidelines
105176
- The develop branch is the working branch for CityData middleware developers. To integrate your changes, please create a new branch based on develop, apply your changes, then open a **pull request** and set develop as a target.
106177
- One or more members of the CityData development team will **review every pull request** and provide improvement suggestions to the PR authors, if necessary.

Middleware/docs/examples/code/HttpAuthenticate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import requests
22
import json
33

4-
url = "http://localhost:8082/authenticate"
4+
url = "https://ngci.encs.concordia.ca/citydata/authenticate"
55

66
payload = json.dumps({
77
"username": "citydata",

Middleware/docs/examples/code/HttpGetAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class HttpGetAsync {
1212

1313
public static void main(String[] args) throws Exception {
1414
String runnerId = "d593c930-7fed-4c7b-ac52-fff946b78c32";
15-
String requestUrl = "http://localhost:8082/apply/async/" + runnerId;
15+
String requestUrl = "https://ngci.encs.concordia.ca/citydata/home" + runnerId;
1616

1717
URL url = new URL(requestUrl);
1818
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.net.URI;
2+
import java.net.http.HttpClient;
3+
import java.net.http.HttpRequest;
4+
import java.net.http.HttpResponse;
5+
6+
import java.io.BufferedReader;
7+
import java.io.InputStreamReader;
8+
import java.net.HttpURLConnection;
9+
import java.net.URL;
10+
11+
public class HttpGetAsyncWithJWT {
12+
13+
public static void main(String[] args) throws Exception {
14+
15+
String token = getJwtToken();
16+
17+
// This runnerId is just an example; the user should use an actually existing runnerId from a Runner they created.
18+
19+
String runnerId = "d593c930-7fed-4c7b-ac52-fff946b78c32";
20+
String requestUrl = "http://localhost:8082/apply/async/" + runnerId;
21+
22+
URL url = new URL(requestUrl);
23+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
24+
connection.setRequestMethod("GET");
25+
connection.setRequestProperty("Authorization", "Bearer " + token);
26+
27+
int responseCode = connection.getResponseCode();
28+
System.out.println("GET Response Code: " + responseCode);
29+
30+
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
31+
StringBuilder response = new StringBuilder();
32+
String responseLine;
33+
while ((responseLine = br.readLine()) != null) {
34+
response.append(responseLine.trim());
35+
}
36+
System.out.println(response.toString());
37+
}
38+
}
39+
40+
private static String getJwtToken() throws Exception {
41+
URL url = new URL("http://localhost:8082/authenticate");
42+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
43+
connection.setRequestMethod("POST");
44+
connection.setRequestProperty("Content-Type", "application/json");
45+
connection.setDoOutput(true);
46+
47+
String json = "{\"username\":\"citydata\",\"password\":\"citydata\"}";
48+
connection.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
49+
50+
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
51+
return reader.readLine(); // JWT token returned directly as string
52+
}
53+
}

0 commit comments

Comments
 (0)