GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

README.md 2.98 KB
Newer Older
Athos Ribeiro's avatar
Athos Ribeiro committed
1
![Build Status](https://gitlab.com/smart-city-platform/resource-adaptor/badges/master/build.svg)
Athos Ribeiro's avatar
Athos Ribeiro committed
2

Arthur Del Esposte's avatar
Arthur Del Esposte committed
3
4
# README

Arthur Del Esposte's avatar
Arthur Del Esposte committed
5
6
The detailed documentation can be found in [Smart City Platform's Stoa page](https://social.stoa.usp.br/poo2016/forum-projeto-cidades-inteligentes/resource-adaptor).

Arthur Del Esposte's avatar
Arthur Del Esposte committed
7
8
## Environment Setup

Arthur Del Esposte's avatar
Arthur Del Esposte committed
9
10
11
* Install [PostgreSQL](https://www.postgresql.org/download/)
* Run on terminal: ```$ sudo -u postgres psql```
* Run on postgresql command line: ```$ create role resource_adaptor with createdb login password 'resource_adaptor';```
Arthur Del Esposte's avatar
Arthur Del Esposte committed
12
13
* Install RVM
* Run on terminal: ```$ rvm install 2.2.0```
Arthur Del Esposte's avatar
Arthur Del Esposte committed
14
* In the project directory, run:
Arthur Del Esposte's avatar
Arthur Del Esposte committed
15
  * ```$ gem install rails-api```
Arthur Del Esposte's avatar
Arthur Del Esposte committed
16
  * ```$ gem install bundle```
Arthur Del Esposte's avatar
Arthur Del Esposte committed
17
  * ```$ bundle install```
Arthur Del Esposte's avatar
Arthur Del Esposte committed
18
19
  * ```$ bundle exec rake db:create```
  * ```$ bundle exec rake db:migrate```
Arthur Del Esposte's avatar
Arthur Del Esposte committed
20
21
22
* Run the tests:
  * ```$ rspec```

Arthur Del Esposte's avatar
Arthur Del Esposte committed
23
24
You should see all tests passing =)

Arthur Del Esposte's avatar
Arthur Del Esposte committed
25
26
## Configuration

Arthur Del Esposte's avatar
Arthur Del Esposte committed
27
28
### Database

Arthur Del Esposte's avatar
Arthur Del Esposte committed
29
We use a relational database to store some important information about all components encapsulated by a resource.
Arthur Del Esposte's avatar
Arthur Del Esposte committed
30

Arthur Del Esposte's avatar
Arthur Del Esposte committed
31
By default, our [database config file](config/database.yml) use the adpater for postgresql.
Arthur Del Esposte's avatar
Arthur Del Esposte committed
32
33
34

### Services links

Arthur Del Esposte's avatar
Arthur Del Esposte committed
35
Basically, this app needs to know two external services:
Arthur Del Esposte's avatar
Arthur Del Esposte committed
36
37
38
39
40
* [Resources Catalog](https://gitlab.com/smart-city-platform/resources-catalog)
* [Data Collector](https://gitlab.com/smart-city-platform/data_collector)

The app also needs to know what its URL in order to properly register in the Smart City Platform.

Arthur Del Esposte's avatar
Arthur Del Esposte committed
41
To set the three required URL, edit the [services config file](config/services.yml).
Arthur Del Esposte's avatar
Arthur Del Esposte committed
42
43
44

### Resource and Components

45
46
47
In order to automatically populate the database with resource and components data we recommend that you use the one of the following methods:

* Create components data through [resource config file](config/resource.yml). See the [file](config/resource.yml) to undestand how to add data. After this, run the task to create components in database:
48

Arthur Del Esposte's avatar
Arthur Del Esposte committed
49
    * ```$ bundle exec rake component:create```
50

51
* Create components data through seed files. See the [existing seed files](lib/seeds/) to understand hot to create your own script. After this, run the task to create components in database:
Arthur Del Esposte's avatar
Arthur Del Esposte committed
52
53
    * To run all seed files: ```$ bundle exec rake component:seed```
    * To run a specific seed file: ```$ bundle exec rake component:seed[my_file_name.rb]```
Arthur Del Esposte's avatar
Arthur Del Esposte committed
54
55

You can also use alternative ways to populate the database with your informantion. You could add new fields or table by adding new migrations or create your own scripts to populate the database, for instance.
56

Arthur Del Esposte's avatar
Arthur Del Esposte committed
57
58
59
60
61
62
63
64
### Data collection

We create a thread to perform data collection by each of existing components in database. 
To properly start data collection, the following steps must be performed:

* Running rails server: The data collection starts when you make the first a request to Resource Adaptor's API
* Running rails console: You must start data collection by yourself on console with ```$ ComponentsManager.instance.start_all```
* **Deprecated** - Use the collect data script manager: Run on project root ```$ rails runner scripts/collect.rb```