Skip to content

Commit

Permalink
Release v2.1
Browse files Browse the repository at this point in the history
Release v2.1
  • Loading branch information
Rashair authored Jan 25, 2021
2 parents 1b47120 + 2068cfa commit 0c7880a
Show file tree
Hide file tree
Showing 277 changed files with 4,272 additions and 1,800 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SmartCity-build/
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM openjdk:14-oraclelinux7

# install nodejs
RUN yum install -y curl
ENV NODE_VERSION=14.15.1
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version && npm --version
RUN npm install serve -g

# copy SmartCity-build
COPY SmartCity-build ./SmartCity

# automatically start app
CMD ["sh","-c","cd SmartCity && ./run.sh"]
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Introduction

Welcome in SmartCity!
We hope, you will have a nice journey.


![image](https://user-images.githubusercontent.com/33404585/102254512-fce3ae00-3f08-11eb-8b6e-897cd7f48b52.png)


## Build guide

To run `build.sh \ build.ps1` script following dependencies are required:

1. Maven >= 3.6.0:
Download link: https://maven.apache.org/download.cgi
Download maven archive from provided website, unpack it and add its `bin` directory to system PATH variable.
See also: https://maven.apache.org/install.html
Check by `mvn --version`

2. Java >= 14
Download link: https://jdk.java.net/java-se-ri/14
Check by `"$JAVA_HOME/bin/java" --version` for bash
Check by `& "$Env:JAVA_HOME\bin\java.exe" --version` for powershell

3. Node.js >= 14.15.1
Download link: https://nodejs.org/en/download/
Check by `node --version`

## Run guide

To run `run.sh \ run.ps1` script following dependencies are required:

1. Java >= 14
2. Node.js >= 14.15.1
3. Serve ( `npm install -g serve`)

See above for instructions.

Run `run.sh \ run.ps1` script to boot the application.
By default it will be present on address: `localhost:5000` - it should open in your browser automatically.

### Browser
See https://create-react-app.dev/docs/supported-browsers-features/ for browser compatibility guide.
It is not guaranteed that app will work in IE 11, 10, 9 or older.


## Docker
To use in docker:
```
docker build -t smart_city-image .
docker run -dit -p 4000:4000 -p 9000:9000 -p 5000:5000
--name smartCity smart_city-image:latest
```
Then open your browser on `localhost:5000`.
4 changes: 4 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ MTPs-Main-Container.txt
smartCity.eml
.settings/
.classpath

## Other
package/**
docs/
2 changes: 2 additions & 0 deletions backend/.idea/dictionaries/przem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion backend/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions backend/.idea/runConfigurations/Boot_w__SmartCity.xml

This file was deleted.

55 changes: 40 additions & 15 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>agent.systems</groupId>
<artifactId>smartCity</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>2.0</version>
<repositories>
<repository>
<id>jade-repo</id>
Expand All @@ -20,8 +20,15 @@
<slf4j.version>1.7.21</slf4j.version>
<java.version>14</java.version>
<resourceFolder>src/main/resources/</resourceFolder>
<packageFolder>${project.basedir}/package</packageFolder>
</properties>
<build>
<resources>
<resource>
<directory>${resourceFolder}</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<!-- For build -->
<plugin>
Expand All @@ -34,37 +41,61 @@
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- For copying dependencies -->
<!-- For copying folders -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<outputDirectory>${packageFolder}</outputDirectory>
<resources>
<resource>
<directory>${resourceFolder}</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- For executable JAR -->
<!-- For assembly JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<outputDirectory>${packageFolder}</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>SmartCity</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
<plugin>
Expand Down Expand Up @@ -103,17 +134,11 @@
<artifactId>graphhopper-reader-osm</artifactId>
<version>0.8.2</version>
</dependency>

<dependency>
<groupId>org.javatuples</groupId>
<artifactId>javatuples</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.tilab.jade</groupId>
<artifactId>jade</artifactId>
Expand Down
3 changes: 0 additions & 3 deletions backend/smartCity.iml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
<orderEntry type="library" name="Maven: org.openstreetmap.osmosis:osmosis-osm-binary:0.44.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.10" level="project" />
<orderEntry type="library" name="Maven: org.javatuples:javatuples:1.2" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: com.tilab.jade:jade:4.5.0" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.3" level="project" />
<orderEntry type="library" name="Maven: org.java-websocket:Java-WebSocket:1.5.1" level="project" />
Expand Down
65 changes: 56 additions & 9 deletions backend/src/main/java/SmartCity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
import org.slf4j.LoggerFactory;
import osmproxy.OsmModule;
import osmproxy.buses.BusModule;
import osmproxy.routes.OsmRoutesModule;
import routing.RoutingModule;
import smartcity.SmartCityModule;
import smartcity.config.ConfigProperties;
import smartcity.lights.core.LightsModule;
import web.WebModule;

import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.Properties;

/**
Expand All @@ -34,32 +41,69 @@ public static void main(String[] args) {
new WebModule(),
new BusModule(),
new OsmModule(),
new OsmRoutesModule(),
new RoutingModule(),
new SmartCityModule()
);
}

private static void setupProperties() {
URL configFile = SmartCity.class.getClassLoader().getResource("config.properties");
var uriLocation = getURILocation();
if (uriLocation.isEmpty()) {
return;
}

var uriLocationPath = Paths.get(uriLocation.get()).toString();
var configFile = Paths.get(uriLocationPath, "config.properties").toFile();
if (!configFile.exists()) {
logger.warn("Did not find config.properties: " + configFile.getAbsolutePath());
return;
}

var props = new Properties();
if (configFile != null) {
try (InputStream configFileStream = new FileInputStream(configFile)) {
props.load(configFileStream);
props.forEach((key, value) -> setStatic((String) key, value));
} catch (Exception e) {
logger.warn("Unable to read properties", e);
}
}

private static Optional<URI> getURILocation() {
URL location = SmartCity.class.getProtectionDomain().getCodeSource().getLocation();
if (location == null) {
logger.warn("Unable to get code source location to read properties");
return Optional.empty();
}

if (!location.getPath().endsWith("/")) {
try {
InputStream configFileStream = configFile.openStream();
props.load(configFileStream);
configFileStream.close();
} catch (Exception e) {
logger.warn("Unable to read properties", e);
var locationString = location.toString();
var lastIndexOfSlash = locationString.lastIndexOf("/");
location = new URL(locationString.substring(0, lastIndexOfSlash + 1));
} catch (MalformedURLException e) {
logger.warn("Unable to get path for location: " + location.toString(), e);
return Optional.empty();
}
}

props.forEach((key, value) -> setFinalStatic((String) key, value));
URI uriLocation;
try {
uriLocation = location.toURI();
} catch (URISyntaxException e) {
logger.warn("Unable to convert to URI", e);
return Optional.empty();
}

return Optional.of(uriLocation);
}

private static void setFinalStatic(String fieldName, Object newValue) {
private static void setStatic(String fieldName, Object newValue) {
try {
var field = ConfigProperties.class.getField(fieldName);
var parsedValue = getParsedValue(field, newValue);
field.set(null, parsedValue);
logger.debug("Successfully set " + fieldName + " to " + newValue.toString());
} catch (IllegalAccessException | NoSuchFieldException e) {
logger.warn("Error trying to setup config for: " + fieldName, e);
}
Expand All @@ -74,6 +118,9 @@ private static Object getParsedValue(Field field, Object newValue) {
else if (type == int.class) {
return Integer.parseInt(stringValue);
}
else if (type == String[].class) {
return stringValue.split(",");
}

return newValue;
}
Expand Down
Loading

0 comments on commit 0c7880a

Please sign in to comment.