Skip to content

Commit

Permalink
Merge pull request #1 from FundacionParaguaya/project-startup
Browse files Browse the repository at this point in the history
Thank you! Looking forward for the clean up.
  • Loading branch information
danicricco authored Aug 8, 2017
2 parents 43d7daa + 897c1cf commit 64e152e
Show file tree
Hide file tree
Showing 22 changed files with 602 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.classpath
.idea/*
.project
.settings
.settings/*
target/
*.iml
**/*.iml
/build/
out.txt
*.lck
*.log
*.script
*.out
139 changes: 138 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,138 @@
FP-SPS-SERVER
## Poverty Stoplight
Fundación Paraguaya (FP from now on) has developed a methodology called
“Poverty Stoplight”. The Poverty Stoplight seeks to eliminate the
multidimensional poverty that affects many families. It allows families to
trace their own poverty map and develop and implement a clear plan to
overcome it.

Through a visual survey that shows photographs, families self-assess their
level of poverty with 50 indicators. These indicators are in turn grouped
into 6 different dimensions of poverty.

##Poverty Stoplight Platform
The PSP (Poverty Stoplight Platform) is a set of components that assist
people in the process of acquiring data, analyzing and helping the families
with solution to overcome his poverty.

The PSP-server is a Spring Boot application that expose a REST API to
diferent components (i.e. an Andorid Application)

##Status of the project
The project is just starting and we expect to have a running version by the
end of the year.

The platform is currently being developed by a group of developers
from FP and SODEP. We welcome help from other developers, but we understand
that the project is still in its early days.

Since we have a comprise to remain an open source project, we decided to push
it to github and let everybody know our progress.

##Code of conduct
Under development

##Test environment
Under development

##Issue Tracking
We've decided to use our internal issue tracking for fastest communication in
the development team. We are going to use pull requests from day one and we are
planning to move to github tickets once we reach a stable version.

##Building from source
The PSP-server used a Maven-based build system and liquibase for the database
evolution.

The directory "scripts" contains some custom scripts on top of maven and
liquibase that assist a developer during the development lifecyle.

Under the directory "conf" you will find examples of configuration file to
customize your installation.
### Prerequisites

[Git][] and [JDK 8 update 20 or later][JDK8 build]

###Basic setup
These are steps that you will only need to perform the first time you are
configuring the PSP-server.
####Step 1) Create /opt/psp-server diretory
Create the directory /opt/psp-server. This is the recommended path, but you
are free to change it.

####Step 2) Configure development.vars
Copy the file "conf/development.vars" to /opt/psp-server/
Edit the content of the file. You will find to variables
```
# The maven setting
export MVN_SETTINGS=$HOME/.m2/settings.xml
# The profile directory. It is passed to maven to read the application.properties from theres.
export PROFILE_DIR=/opt/psp-server/dev
```
####Step 3) Create your dev directory
Create the directory /opt/psp-server/dev

Copy the file conf/application.properties to /opt/psp-server/dev

Note: You can have many "profile" directory. For example /opt/psp-server/test
or /opt/psp-server/prod, each with its own configuration

####Step 4) Configure the application.properties
Probably you will need to configure the database properties. Please take a
look at the following properties:
```
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc\:postgresql\://localhost\:5432/poverty_stoplight_platform
spring.datasource.username=postgres
spring.datasource.password=postgres
```

###Creating the Database
#### Step 1) Setup the ENV_VARS variable
Setup a environment variable that points to your development.vars file.

`export ENV_VARS=/opt/psp-server/development.vars`

Note: You can have several *.vars files. For example production.vars, testing
.vars. Each pointing to a different configuration file.

#### Step 2) Create the DB
If this is your first time, or you just want a new fresh DB please execute
the following command.

`scripts/updater fresh`

It will create the DB and update it to the latest version.

#### Step 3) Update the DB
If you just want to update the DB, you can execute the following command:

`scripts/updater update`

###Compile the server

```
mvn -Dext.prop.dir=/opt/psp-server/dev -Dspring.config
.location=file:/opt/psp-server/dev/application.properties test
```

###Starting the server
The PSP-server is build on top of Spring Boot, therefore you can just run it
as any other Spring Boot App. However, we recommend to have the application
.properties file on an external directory, as mentioned on the previous
section.

If you follow our recommendation, the following line should start a new server.

```
cd target
java -jar spring.config.location=file:/opt/psp-server/dev/application
.properties psp-server-0.0.1-SNAPSHOT.jar
```

## License
The Spring Framework is released under version 2.0 of the [Apache License][]

[Git]: http://help.github.com/set-up-git-redirect
[JDK8 build]: http://www.oracle.com/technetwork/java/javase/downloads
[Apache License]: http://www.apache.org/licenses/LICENSE-2.0
31 changes: 31 additions & 0 deletions conf/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# [ Database Configuration Section ]
#
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc\:postgresql\://localhost\:5432/poverty_stoplight_platform
spring.datasource.username=postgres
spring.datasource.password=postgres

spring.datasource.min-pool-size=6
spring.datasource.max-pool-size=15

spring.jpa.database=POSTGRESQL
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
#spring.jpa.hibernate.ddl-auto=create-drop


#web server
server.port=${port:8080}
server.contextPath=/psp

#Application specific
authentication.oauth.clientid=client
authentication.oauth.secret=secret
authentication.oauth.tokenValidityInSeconds=18000

# mp resolver
multipart.enabled=true

spring.http.multipart.max-file-size=20Mb
spring.http.multipart.max-request-size=20Mb
5 changes: 5 additions & 0 deletions conf/development.vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The maven setting
export MVN_SETTINGS=$HOME/.m2/settings.xml

# The profile directory. It is passed to maven to read the application.properties from theres.
export PROFILE_DIR=/opt/psp-server/dev
107 changes: 107 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>py.org.fundacionparaguaya</groupId>
<artifactId>psp-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>psp-server</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1205-jdbc41</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<!-- este plugin suele dar un error dentro del Eclipse porque no está
disponbile en el marketplace -->
<!-- no afecta al desarrollo ni a la ejecución, se utiliza para el empaquetado
por línea de comando -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<configuration>
<outputFile />
<properties />
<files>
<file>${ext.prop.dir}/application.properties</file>
</files>
</configuration>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<changeLogFile>src/main/resources/db/liquibase/db-changelog.xml</changeLogFile>
<driver>${spring.datasource.driver-class-name}</driver>
<url>${spring.datasource.url}</url>
<username>${spring.datasource.username}</username>
<password>${spring.datasource.password}</password>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
</plugins>
</build>


</project>
9 changes: 9 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# DEMO DB SCRIPT
TITLE='\033[34m'
TEXT='\033[33m'
NC='\033[0m' # No Color
echo -e " ${TITLE}CLEANING :D${TEXT}"

mvn -s ~/.m2/devtools-settings.xml -Dext.prop.dir=/opt/finhealth/ -Dspring.config.location=file:///opt/finhealth/application.properties -DskipTests -U clean install

echo -e " ${TITLE}FINISHED${NC}"
15 changes: 15 additions & 0 deletions scripts/demo_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# DEMO DB SCRIPT
echo -e "33[33m DEMO DB SCRIPT :D"

export ENV_VARS="/opt/finhealth/development.vars"

./scripts/updater fresh

./scripts/updater seed src/main/resources/db/sql/seed-data.sql

./scripts/updater seed src/main/resources/db/sql/seed-demo.sql

./scripts/updater seed src/main/resources/db/sql/seed-demo-sprint-11.sql
./scripts/updater seed src/main/resources/db/sql/seed-demo-sprint-12.sql


53 changes: 53 additions & 0 deletions scripts/lib/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

function check_status() {
status=$1
if [ ${status} -ne 0 ]; then
echo "Program exited with code: $status"
_EXIT_STATUS=${status}
exit_handler
fi
}

function exit_handler(){
exit $_EXIT_STATUS
}

[ -z "${ENV_VARS}" ] && echo "ERROR: No environment variable ENV_VARS defined. Aborting" && exit 1
[ ! -f "${ENV_VARS}" ] && echo "ERROR: The ENV_VARS does not exist or is not pointing to a file. Aborting." && exit 1
type mvn >/dev/null 2>&1 || { echo >&2 "ERROR: I require 'mvn' but it's not installed. Aborting."; exit 1; }

source ${ENV_VARS}

[ -z "$PROFILE_DIR" ] && echo "ERROR: PROFILE_DIR not defined in ${ENV_VARS}. Aborting" && exit 1

#[ $# -eq 0 ] && echo "ERROR: No parameter provided" && exit 2

sys=$(uname);
if [ $sys != "MINGW32_NT-6.2" ]; then
MY_IP="`/sbin/ifconfig | awk '$1 == "inet" { print $2 }'|head -1 | awk -F\: '{print $2}'`";
else
MY_IP="unknown";
fi
# si estamos dentro de sodep
for i in `scripts/lib/get-ip.sh`; do
if [[ "$i" =~ ^10\.1\.* || "$MY_IP" =~ ^10\.0\.* ]]; then
SODEP="si";
else
SODEP="";
fi
done
PROP_FILE=${PROFILE_DIR}/application.properties

URL=$(grep ^spring.datasource.url $PROP_FILE | cut -d '=' -f 2)
HOSTPORT=$(echo $URL | cut -d '/' -f 3)
PORT=$(echo $HOSTPORT | cut -d ':' -f 2)
HOST=$(echo $HOSTPORT | cut -d '\' -f 1)
DB=$(echo $URL | cut -d '/' -f 4)

USERNAME=$(grep ^spring.datasource.username $PROP_FILE | cut -d '=' -f 2)
PASSWORD=$(grep ^spring.datasource.password $PROP_FILE | cut -d '=' -f 2)

export PGPASSWORD=$PASSWORD
export MY_IP

11 changes: 11 additions & 0 deletions scripts/lib/drop-create-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. scripts/lib/common.sh

echo "[PGSQL] Dropping DB: $DB"
psql -h $HOST -p $PORT -U $USERNAME -d template1 -c "drop database if exists $DB"
check_status $?
echo "[PGSQL] Creating DB: $DB"
psql -h $HOST -p $PORT -U $USERNAME -d template1 -c "create database $DB"
check_status $?

Loading

0 comments on commit 64e152e

Please sign in to comment.