git clone https://@opensourceprojects.eu/git/p/vfos/assets/enablers/nen/code vfos-assets-enablers-nen-code



File Date Author Commit
DB 2018-05-11 Miguel Rodrigues Miguel Rodrigues [c0fc31] Initial Commit - Ticket #1
backend 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
config 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
controllers 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
frontend 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
node_modules 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
.dockerignore 2018-05-11 Miguel Rodrigues Miguel Rodrigues [d8cb28] Create DockerFile - Ticket #2
Dockerfile 2018-05-11 Miguel Rodrigues Miguel Rodrigues [d8cb28] Create DockerFile - Ticket #2
constants.js 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
docker-compose.yml 2018-05-11 Miguel Rodrigues Miguel Rodrigues [09ee40] Update Docker-Compose - Ticket #3
package-lock.json 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
package.json 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1
readme.md 2018-05-11 Miguel Rodrigues Miguel Rodrigues [cfa3e2] Update ReadmeFile - Ticket #4
signature.js 2018-05-11 Miguel Rodrigues Miguel Rodrigues [60df53] Initial Commit - Ticket #1

Read Me

ERROR! The markdown supplied could not be parsed correctly. Did you forget to surround a code snippet with "~~~~"?

## Notification Enabler
### Read me

#### 1. Prerequisite

In order to run this enabler code on your local machine you should have installed:

**MySQL** should be installed and running at: `localhost:3306`


#### 2. Instalation

Clone the repository:

`git clone git clone https://<user>@bitbucket.org/miguelrodriguesKBZ/notification-enabler.git`

Install dependencies under the cloned folder execute:
`npm install`

Instal frontend dependencies:
`bower install`

Start:
`npm start`

Script:
`It is important to run the import.sh script in the DB folder for the creation of the database.`

Docker:
`Notification Enabler will be run from the docker. To be successful, the database is one container and the notification enabler will be in another container. In the Notification Enabler is present a dockerfile, which is defined the way to be executed and also is present a docker-compose in which will indicate the services to be executed successfully.`

To Execute:
`It is necessary to create a configuration in the configuration enabler where it will result a data.env file in which will contain the defined environment variables.`

For notification enabler run will need the following Environment Variables:
`PORT 
USEREMAIL 
USERPWD
DBUSER
DBPASSWORD
DATABASE`

#### 3. API

## vf-OS Enablers

### Enabler 2 - Get Rules

```http
GET /api/vf-os-enabler/v0/getRules/myawesomeappid
Accept: */*
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 11:04:31 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
	"success": true,
    "data": [
        {
            "rulesID": 11,
            "description": "New Rule",
            "parameters": "slumptest,corrigir",
            "parameter": "slumptest",
            "conditionValue": ">",
            "controlValue": "5",
            "notificationType": 5,
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```

Use this API call whenever is needed to retrieve all rules related to app.  

#### Request
`GET /api/vf-os-enabler/<api_version>/getRules/<app_id>`

#### URL Parameters

Resource Parameter | Description
---- | ----
api_version | Identifies the API version that will be used for the request
app_id | Identifies the APP


#### Query Parameters

Name | Required | Type | Description
---- | ---- | ---- | ----
appID | Yes | String | appID for identify which app will show the rules.


#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` with the rules of app (if found).

In the following Example it's queried all rules related to specific appID:


```json
{
    "success": true,
    "data": [
        {
            "rulesID": 11,
            "description": "New Rule",
            "parameters": "slumptest,corrigir",
            "parameter": "slumptest",
            "conditionValue": ">",
            "controlValue": "5",
            "notificationType": 5,
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```

#### Return Codes
Code | Description
--- | ---
200 | Data found
500 | Internal Server Error - There was an unexpected error at some point during the processing of the request.



### Enabler 2 - Get Notifications

```http
GET /api/vf-os-enabler/v0/getNotifications/myawesomeappid
Accept: */*
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 11:04:31 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true,
    "data": [
        {
            "emailTo": "raquel.melo@knowledgebiz.pt",
            "subject": "slumptest>10",
            "date": "2018-04-27 12:06:02",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```
Use this API call whenever is needed to retrieve all notifications of app.

#### Request
`GET /api/vf-os-enabler/<api_version>/getNotifications/<app_id>`


#### URL Parameters

Resource Parameter | Description
---- | ----
api_version | Identifies the API version that will be used for the request
app_id | Identifies the APP to show the notifications


#### Query Parameters

Name | Required | Type | Description
---- | ---- | ---- | ----
appID | Yes | String | appID for identify which app will show the rules.

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` with the notifications of app (if found).

In the following Example it's queried the all notifications of specific appID:

```json
{
    "success": true,
    "data": [
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 15:39:51",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:06:00",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:06:09",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:08:30",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        },
        {
            "emailTo": "miguel.rodrigues@knowledgebiz.pt",
            "subject": "slumptest=40",
            "date": "2018-04-27 16:09:51",
            "token": "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"
        }
    ]
}
```

#### Return Codes

Code | Description
---- | ----
200 | Configuration Found
500 | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Get Apps

```http
GET /api/vf-os-enabler/v0/getApps/david.aleixo@knowledgebiz.pt
Accept: */*
```


```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 13:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true,
    "data": [
        {
            "token": "Es5zfsco57fieoQcDJZuIZxFZWv4HQbBYgUXRgqodQp",
            "appID": "MiguelID",
            "developerID": "miguel.rodrigues@knowledgebiz.pt"
        }
    ]
}
```
Use this API call whenever is needed to retrieve all apps of developerid.

#### Request
`GET /api/vf-os-enabler/<api_version>/getApps/<developer_id>`


#### URL Parameters

Resource Parameter | Description
---- | ----
api_version | Identifies the API version that will be used for the request
developer_id | Identifies the Developer


#### Query Parameters

Name | Required | Type | Description
---- | ---- | ---- | ----
developerID | Yes | String | developerID for identify which developer will show the apps.

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` with the notifications of app (if found).

In the following Example it's queried the all Apps of specific developerID:

```json
{
    "success": true,
    "data": [
        {
            "token": "Es5zfsco57fieoQcDJZuIZxFZWv4HQbBYgUXRgqodQp",
            "appID": "MiguelID",
            "developerID": "painatal_vodka@hotmail.com"
        }
    ]
}
```

#### Return Codes
Code | Description
--- | ---
200 | Configuration Activated
500 | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Create Notifications

```http
POST http://localhost:8000/api/vf-os-enabler/v0/notifications
Accept: */*
Content-Type: application/json; charset=utf-8

{"body":[{"my_key":"my_value"},{"my_key":"my_value"},{"my_key":"my_value"}]}
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 15:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{"success": true}
```

Use this API call whenever is needed to create a new configuration version for one enabler.

#### Request
`POST /api/vf-os-enabler/<api_version>/enabler/notifications`

#### URL Parameters

Resource Parameter | Description
---- | ----
api_version | Identifies the API version that will be used for the request

#### JSON Body Payload

Name | Required | Type | Description
---- | ---- | ---- | ---
body | Yes | JSON | JSON document where the custom notification parameters are. Example: [{"emailTo" : "miguel.rodrigues@knowledgebiz.pt"},{"subject" : "slumptest=10"},{"token" : "fgTJAyuX0M4tpn1P2WXAJmRbDH7hwbVhZsL26Ca1Ecm"}]

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `reason` if the `success` became **false**.

Example:

```json
{
	 "success": true
}
```

#### Return Codes
Code | Description
---- | ----
200 | Configuration created successfully
500 | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Enabler 2 - Create App

```http
POST http://localhost:8000/api/vf-os-enabler/v0/register
Accept: */*
Content-Type: application/json; charset=utf-8

{"body":[{"my_key":"my_value"},{"my_key":"my_value"}]}
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 15:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

    "success": true,
    "data": {
        "token": "Z58oqMmXJJzC1KHAaPurgohg00xgklomu5DVXgcZwj4"
    }
```

Use this API call whenever is needed to create a new configuration version for one enabler.

#### Request
`POST /api/vf-os-enabler/<api_version>/enabler/register`

#### URL Parameters

Resource Parameter | Description
---- | ----
api_version | Identifies the API version that will be used for the request

#### JSON Body Payload

Name | Required | Type | Description
---- | ---- | ---- | ---
body | Yes | JSON | JSON document where the custom notification parameters are. Example: [{"appID" : "KBZ"},{"developerID" : "miguel.rodrigues@knowledgebiz.pt"}]

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `data` if the `success` became **false**.

Example:

```json
{
	"success": true,
    "data": {
        "token": "Z58oqMmXJJzC1KHAaPurgohg00xgklomu5DVXgcZwj4"
    }
}
```

#### Return Codes
Code | Description
---- | ----
200 | Configuration created successfully
500 | Internal Server Error - There was an unexpected error at some point during the processing of the request.

### Enabler 2 - Create Rules

```http
POST http://localhost:8000/api/vf-os-enabler/v0/notifications/rules
Accept: */*
Content-Type: application/json; charset=utf-8

{"body":[{"my_key":"my_value"},{"my_key":"my_value"},{"my_key":"my_value"},{"my_key":"my_value"},{"my_key":"my_value"},{"my_key":"my_value"},{"my_key":"my_value"]}
```

```http
HTTP/1.1 200 OK
Content-type: application/json
X-Powered-By: Express
Date: Tue, 29 Aug 2017 15:00:00 GMT
Connection: keep-alive
Transfer-Encondig: chunked

{
    "success": true
}
```

Use this API call whenever is needed to create a new configuration version for one enabler.

#### Request
`POST /api/vf-os-enabler/<api_version>/enabler/rules`

#### URL Parameters

Resource Parameter | Description
---- | ----
api_version | Identifies the API version that will be used for the request

#### JSON Body Payload

Name | Required | Type | Description
---- | ---- | ---- | ---
body | Yes | JSON | JSON document where the custom notification parameters are. Example: [{"appID" : "KBZ"},{"description" : "So many Tests"},{"parameters" : "Test,AnotherTest,Test3"},{"parameter" : "Test"},{"conditionValue" : ">"},{"controlValue" : "100"},{"notificationType" : "5"}]

#### Return Payload

The API response will contain a JSON document with the property `success`: **true**, **false** and the `reason` if the `success` became **false**.

Example:

```json
{
	 "success": true
}
```

#### Return Codes
Code | Description
---- | ----
200 | Configuration created successfully
500 | Internal Server Error - There was an unexpected error at some point during the processing of the request.


### Powered by:

![alt text](https://static.wixstatic.com/media/d65bd8_d460ab5a6ff54207a8ac3e7497af18c4~mv2_d_4201_2594_s_4_2.png "Notification Enabler")