Skip to content

Commit

Permalink
Merge pull request #20 from sensiflow/dev
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
TiagoJFil authored Jul 10, 2023
2 parents 6abce54 + 14699cc commit 9eb89e0
Show file tree
Hide file tree
Showing 55 changed files with 1,580 additions and 687 deletions.
20 changes: 10 additions & 10 deletions .ci/rabbit-init/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}
},
{
"name": "instance_ack_device_delete_test",
"name": "instance_scheduler_notification_test",
"vhost": "/",
"durable": true,
"auto_delete": false,
Expand All @@ -46,7 +46,7 @@
}
},
{
"name": "instance_ack_device_delete",
"name": "instance_scheduler_notification",
"vhost": "/",
"durable": true,
"auto_delete": false,
Expand Down Expand Up @@ -93,7 +93,7 @@
"arguments": {}
},
{
"name": "instance_ack_device_delete_test_exchange",
"name": "instance_scheduler_notification_test_exchange",
"vhost": "/",
"type": "direct",
"durable": true,
Expand All @@ -102,7 +102,7 @@
"arguments": {}
},
{
"name": "instance_ack_device_delete_exchange",
"name": "instance_scheduler_notification_exchange",
"vhost": "/",
"type": "direct",
"durable": true,
Expand Down Expand Up @@ -145,19 +145,19 @@
"arguments": {}
},
{
"source": "instance_ack_device_delete_test_exchange",
"source": "instance_scheduler_notification_test_exchange",
"vhost": "/",
"destination": "instance_ack_device_delete_test",
"destination": "instance_scheduler_notification_test",
"destination_type": "queue",
"routing_key": "instance_ack_device_delete_test",
"routing_key": "instance_scheduler_notification_test",
"arguments": {}
},
{
"source": "instance_ack_device_delete_exchange",
"source": "instance_scheduler_notification_exchange",
"vhost": "/",
"destination": "instance_ack_device_delete",
"destination": "instance_scheduler_notification",
"destination_type": "queue",
"routing_key": "instance_ack_device_delete",
"routing_key": "instance_scheduler_notification",
"arguments": {}
}
],
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run linter formatter
run: ./gradlew ktlintFormat
- name: Run Gradle Check (build, test, lint)
run: ./gradlew check
env:
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,39 @@ This is the repository housing the codebase for sensiflow's web api.

- [Documentation](https://docs.sensiflow.org/api/reference)
- [Project Report](https://github.com/sensiflow/main/blob/main/project-docs/Final_Report_V1.pdf).



### Possible Environment variables

##### General

- `PORT` - the port to run the server on

##### Database

- `JDBC_DATABASE_URL` - the url to the database containing the authentication information

##### SSL

- `SECURE` - whether to use SSL or not
- `KEYSTORE_PATH` - the path to the keystore
- `KEY_STORE_PASSWORD` - the password to the keystore
- `SSL_KEY_PASSWORD` - the password to the key in the keystore

##### RabbitMQ

- `RABBITMQ_HOST` - the host of the rabbitmq server
- `RABBITMQ_PORT` - the port of the rabbitmq server
- `RABBITMQ_USERNAME` - the username to the rabbitmq server
- `RABBITMQ_PASSWORD` - the password to the rabbitmq server
- `RABBITMQ_QUEUE` - the default queue to listen to
- `INSTANCE_CTL_QUEUE` - the queue to send instance control messages to
- `INSTANCE_ACK_DEVICE_STATE_QUEUE` - the queue to send instance ack device state messages to
- `INSTANCE_ACK_SCHEDULER_NOTIFICATION_QUEUE` - the queue to send instance ack scheduler notification messages to

### HTTPS

To use SSL, a keystore must be provided by providing its path and its password using the Environment variables above and the variable SECURE must be set to true
Keep in mind that the keystore type must be PKCS12.
The server port will be the same as the Environment variable PORT if it is set, otherwise it will be 8090.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.6.2")
implementation("junit:junit:4.13.1")

implementation("org.springframework.boot:spring-boot-starter-security")

developmentOnly("org.springframework.boot:spring-boot-devtools")

testImplementation("org.springframework.boot:spring-boot-starter-test")
Expand All @@ -61,6 +63,6 @@ tasks.withType<Test> {
"RABBITMQ_HOST" to "localhost",
"INSTANCE_CTL_QUEUE" to "instance_ctl_test",
"INSTANCE_ACK_QUEUE_DEVICE_STATE" to "instance_ack_device_state_test",
"INSTANCE_ACK_QUEUE_DEVICE_DELETE" to "instance_ack_device_delete_test"
"INSTANCE_ACK_QUEUE_DEVICE_DELETE" to "instance_scheduler_notification_test",
)
}
43 changes: 30 additions & 13 deletions src/main/kotlin/com/isel/sensiflow/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ package com.isel.sensiflow

object Constants {

const val API_VERSION = "v1"
const val CONTEXT_PATH = "/api/$API_VERSION"
const val API_PATH = "/api"

object Device {
const val PEOPLE_COUNT_RETRIEVAL_DELAY: Long = 1000 // 1 second
const val DEVICE_PROCESSING_STATE_RETRIEVAL_DELAY: Long = 3000 // 1 second
const val NAME_MAX_LENGTH = 20
const val PEOPLE_COUNT_RETRIEVAL_DELAY: Long = 1000 // 1 seconds
const val DEVICE_PROCESSING_STATE_RETRIEVAL_DELAY: Long = 3000 // 3 seconds
const val NAME_MAX_LENGTH = 35
const val NAME_MIN_LENGTH = 3
const val DESCRIPTION_MAX_LENGTH = 100
const val STREAM_URL_MAX_LENGTH = 200
const val NAME_MIN_LENGTH = 3
const val STREAM_URL_REGEX =
"(rtsp|rtsps):\\/\\/(?:([^\\s@\\/]+?)[@])?([^\\s\\/:]+)(?:[:]([0-9]+))?(?:(\\/[^\\s?#]+)?(?<!\\/)([?][^\\s#]+)?)"
}

object Group {
const val NAME_MAX_LENGTH = 35
const val NAME_MIN_LENGTH = 3
const val DESCRIPTION_MAX_LENGTH = 100
}

object User {
const val SESSION_EXPIRATION_TIME = 1000L * 60 * 60 * 24 // 1 day
const val AUTH_COOKIE_NAME = "SessionAuth"
Expand All @@ -38,7 +43,8 @@ object Constants {
const val NAME_MAX_LENGTH = 20
const val PASSWORD_MIN_SIZE = 5
const val PASSWORD_MAX_SIZE = 20
const val PASSWORD_REGEX = """^(?=.*[a-z])(?=.*[A-Z])(?=.*[*.!@$%^&(){}\[\]:;<>,.?/~_+-=|]).{$PASSWORD_MIN_SIZE,$PASSWORD_MAX_SIZE}$"""
const val PASSWORD_REGEX =
"""^(?=.*[a-z])(?=.*[A-Z])(?=.*[*.!@$%^&(){}\[\]:;<>,.?/~_+-=|]).{$PASSWORD_MIN_SIZE,$PASSWORD_MAX_SIZE}$"""
}

object Pagination {
Expand All @@ -56,14 +62,24 @@ object Constants {
const val EMAIL_NOT_FOUND = "User with email %s not found"
const val DEVICE_NAME_EMPTY = "Name cannot be empty"
const val DEVICE_STREAM_URL_EMPTY = "Stream URL cannot be empty"
const val USER_ROLE_NAME_INVALID_LENGTH = "Role name must be between ${Roles.ROLE_NAME_MIN_LENGTH} and ${Roles.ROLE_NAME_MAX_LENGTH} characters"
const val DEVICE_NAME_INVALID_LENGTH = "Name must be between 1 and ${Device.NAME_MAX_LENGTH} characters"
const val USER_ROLE_NAME_INVALID_LENGTH =
"Role name must be between ${Roles.ROLE_NAME_MIN_LENGTH} and ${Roles.ROLE_NAME_MAX_LENGTH} characters"
const val DEVICE_NAME_INVALID_LENGTH =
"name must be between ${Device.NAME_MIN_LENGTH} and ${Device.NAME_MAX_LENGTH} characters"
const val GROUP_NAME_INVALID_LENGTH =
"must be between ${Group.NAME_MIN_LENGTH} and ${Group.NAME_MAX_LENGTH} characters"
const val DEVICE_DESCRIPTION_INVALID_LENGTH =
"Description must be between 1 and ${Device.DESCRIPTION_MAX_LENGTH} characters"
const val GROUP_DESCRIPTION_INVALID_LENGTH =
"Description must be between 1 and ${Group.DESCRIPTION_MAX_LENGTH} characters"
const val DEVICE_STREAM_URL_INVALID_LENGTH =
"Stream URL must be between 1 and ${Device.STREAM_URL_MAX_LENGTH} characters"
const val PASSWORD_REGEX_MISMATCH = "Password must contain at least one uppercase letter, one lowercase letter, one digit and one special character"
const val PASSWORD_INVALID_LENGTH = "Password must be between ${InputValidation.PASSWORD_MIN_SIZE} and ${InputValidation.PASSWORD_MAX_SIZE} characters"
const val PASSWORD_REGEX_MISMATCH =
"Password must contain at least one uppercase letter, " +
"one lowercase letter, one digit and one special character"
const val PASSWORD_INVALID_LENGTH =
"Password must be between ${InputValidation.PASSWORD_MIN_SIZE}" +
" and ${InputValidation.PASSWORD_MAX_SIZE} characters"
const val EMAIL_INVALID_LENGTH = "Email must be between 1 and ${InputValidation.EMAIL_MAX_LENGTH} characters"
const val PASSWORD_EMPTY = "Password cannot be empty"
const val EMAIL_EMPTY = "Email cannot be empty"
Expand All @@ -74,13 +90,14 @@ object Constants {
const val DEVICE_STATE_REQUIRED = "Processing state is required"
const val DEVICE_STREAM_URL_INVALID = "Stream URL does not match the required format"
const val DEVICE_ID_MUST_BE_POSITVE = "Device id must be positive"
const val DEVICE_ALREADY_UPDATING = "A request to update this device has already been made, please wait for it to finish"
const val DEVICE_ALREADY_UPDATING =
"A request to update this device has already been made, please wait for it to finish"
}

object Problem {

object URI {
private const val BASE_URI = "https://docs.sensiflow.org/api/errors/general/"
private const val BASE_URI = "https://docs.sensiflow.net/api/errors/general/"

const val DEVICE_NOT_FOUND = "$BASE_URI#device-not-found"
const val USER_NOT_FOUND = "$BASE_URI#user-not-found"
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/isel/sensiflow/DbInit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.isel.sensiflow
import com.isel.sensiflow.http.entities.input.UserRegisterInput
import com.isel.sensiflow.model.repository.UserRepository
import com.isel.sensiflow.services.Role
import com.isel.sensiflow.services.UserService
import com.isel.sensiflow.services.beans.UserService
import jakarta.annotation.PostConstruct
import org.springframework.stereotype.Component

Expand Down
43 changes: 0 additions & 43 deletions src/main/kotlin/com/isel/sensiflow/amqp/Action.kt

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/kotlin/com/isel/sensiflow/amqp/DeleteDeviceMessage.kt

This file was deleted.

This file was deleted.

45 changes: 45 additions & 0 deletions src/main/kotlin/com/isel/sensiflow/amqp/ProcessingAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.isel.sensiflow.amqp

import com.isel.sensiflow.model.entities.DeviceProcessingState

/**
* Represents a possible action to be performed on a device.
*/
enum class ProcessingAction {
START,
RESUME,
STOP,
REMOVE,
PAUSE;

companion object {

fun fromString(value: String): ProcessingAction? {
return try {
ProcessingAction.valueOf(value.uppercase())
} catch (e: IllegalArgumentException) {
null
}
}
}
}

/**
* Returns the action that should be performed on the device to transition to the receiver state.
*/
val DeviceProcessingState.action: ProcessingAction get() = when (this) {
DeviceProcessingState.ACTIVE -> ProcessingAction.START
DeviceProcessingState.PAUSED -> ProcessingAction.PAUSE
DeviceProcessingState.INACTIVE -> ProcessingAction.STOP
}

/**
* Returns the state that the device should be in after performing the receiver action.
*/
val ProcessingAction.state: DeviceProcessingState get() = when (this) {
ProcessingAction.START -> DeviceProcessingState.ACTIVE
ProcessingAction.PAUSE -> DeviceProcessingState.PAUSED
ProcessingAction.STOP -> DeviceProcessingState.INACTIVE
ProcessingAction.REMOVE -> DeviceProcessingState.INACTIVE
ProcessingAction.RESUME -> DeviceProcessingState.ACTIVE
}
20 changes: 20 additions & 0 deletions src/main/kotlin/com/isel/sensiflow/amqp/SchedulerNotification.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.isel.sensiflow.amqp

/**
* Represents a possible action to be performed by the Instance Manager Scheduler on processor instances.
*/
enum class SchedulerNotification {
UPDATED_INSTANCE,
REMOVED_INSTANCE;

companion object {

fun fromString(value: String): SchedulerNotification? {
return try {
SchedulerNotification.valueOf(value.uppercase())
} catch (e: IllegalArgumentException) {
null
}
}
}
}
Loading

0 comments on commit 9eb89e0

Please sign in to comment.