Skip to content

Commit

Permalink
Merge pull request OSGP#49 from OSGP/feature/FDP-2551-firmware
Browse files Browse the repository at this point in the history
FDP-2551: Firmware entities
  • Loading branch information
sanderv authored Sep 26, 2024
2 parents 4add4f5 + 972ac46 commit 41f5bfb
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 2 deletions.
2 changes: 2 additions & 0 deletions application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
implementation("org.springframework.kafka:spring-kafka")

implementation(project(":components:psk"))
implementation(project(":components:firmware"))

implementation(kotlin("reflect"))
implementation(libs.logging)
Expand Down Expand Up @@ -65,6 +66,7 @@ testing {
dependencies {
implementation(project())
implementation(project(":components:psk"))
implementation(project(":components:firmware"))
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation(libs.kafkaAvro)
implementation(libs.avro)
Expand Down
22 changes: 22 additions & 0 deletions application/src/main/resources/db/migration/V8__firmware.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE firmware
(
id uuid not null,
name varchar(255) not null,
hash varchar(255) not null,
previous_firmware_id uuid null,
PRIMARY KEY (id),
CONSTRAINT fk_previous_firmware
FOREIGN KEY (previous_firmware_id)
REFERENCES firmware (id)
);

CREATE TABLE firmware_packet
(
firmware_id uuid not null,
packet_number int not null,
packet varchar(1024),
PRIMARY KEY (firmware_id, packet_number),
CONSTRAINT fk_firmware
FOREIGN KEY (firmware_id)
REFERENCES firmware (id)
)
11 changes: 11 additions & 0 deletions components/firmware/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.security:spring-security-core")

implementation(libs.logging)

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation(libs.mockitoKotlin)

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
package org.gxf.crestdeviceservice.firmware.entity

import jakarta.annotation.Generated
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.OneToMany
import java.util.UUID
import org.hibernate.annotations.Cascade
import org.hibernate.annotations.CascadeType

@Entity
class Firmware(
@Id @Generated val id: UUID,
val name: String,
val hash: String,
val previousFirmwareId: UUID?,
@OneToMany @Cascade(CascadeType.ALL) val packets: List<FirmwarePacket>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
package org.gxf.crestdeviceservice.firmware.entity

import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.IdClass
import jakarta.persistence.ManyToOne

@Entity
@IdClass(FirmwarePacketCompositeKey::class)
class FirmwarePacket(
@ManyToOne @Id val firmware: Firmware,
@Id val packetNumber: Int,
val packet: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
package org.gxf.crestdeviceservice.firmware.entity

import java.io.Serializable

data class FirmwarePacketCompositeKey(val firmware: Firmware, val packetNumber: Int) : Serializable
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
package org.gxf.crestdeviceservice.firmware.repository

import org.gxf.crestdeviceservice.firmware.entity.FirmwarePacket
import org.gxf.crestdeviceservice.firmware.entity.FirmwarePacketCompositeKey
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository

@Repository
interface FirmwarePacketRepository : CrudRepository<FirmwarePacket, FirmwarePacketCompositeKey>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
package org.gxf.crestdeviceservice.firmware.repository

import org.gxf.crestdeviceservice.firmware.entity.Firmware
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository

@Repository
interface FirmwareRepository : CrudRepository<Firmware, Int> {
fun findByName(name: String): Firmware
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
package org.gxf.crestdeviceservice.firmware.service

import org.gxf.crestdeviceservice.firmware.repository.FirmwareRepository
import org.springframework.stereotype.Service

@Service class FirmwareService(private val firmwareRepository: FirmwareRepository)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ package org.gxf.crestdeviceservice.psk.entity

import java.io.Serializable

class PreSharedKeyCompositeKey(val identity: String?, val revision: Int?) : Serializable {
data class PreSharedKeyCompositeKey(val identity: String?, val revision: Int?) : Serializable {
constructor() : this(null, null)
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 2 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ echo "*********************************************************"
echo "Running git pre-commit hook. Running Spotless Apply... "
echo "*********************************************************"

[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"

# Gather the staged files - to make sure changes are saved only for these files.
stagedFiles=$(git diff --staged --name-only)

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rootProject.name = "sng-crest-device-service"

include("application")
include("components:psk")
include("components:firmware")

dependencyResolutionManagement {
versionCatalogs {
Expand Down

0 comments on commit 41f5bfb

Please sign in to comment.