Skip to content

Commit

Permalink
Feature/add UUID to 3rd party configs to allow multiple configs for m…
Browse files Browse the repository at this point in the history
…anufatcturer (#205)
  • Loading branch information
saschadoemer authored May 21, 2024
1 parent 65fe3ab commit 4eef629
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.app.fivegla.business;

import de.app.fivegla.api.Manufacturer;
import de.app.fivegla.persistence.ThirdPartyApiConfigurationRepository;
import de.app.fivegla.persistence.entity.ThirdPartyApiConfiguration;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,31 +19,48 @@ public class ThirdPartyApiConfigurationService {
* Creates a third-party API configuration and adds it to the system.
*
* @param configuration The third-party API configuration to be created and added.
* @return The created third-party API configuration.
*/
public void createThirdPartyApiConfiguration(ThirdPartyApiConfiguration configuration) {
public ThirdPartyApiConfiguration createThirdPartyApiConfiguration(ThirdPartyApiConfiguration configuration) {
log.info("Creating third-party API configuration.");
thirdPartyApiConfigurationRepository.addThirdPartyApiConfiguration(configuration);
return thirdPartyApiConfigurationRepository.addThirdPartyApiConfiguration(configuration);
}

/**
* Gets all third-party API configurations.
*
* @param tenantId The tenantId of the third-party API configuration.
* @param uuid The uuid of the third-party API configuration.
* @return A list of third-party API configurations.
*/
public List<ThirdPartyApiConfiguration> getThirdPartyApiConfigurations(String tenantId) {
public List<ThirdPartyApiConfiguration> getThirdPartyApiConfigurations(String tenantId, String uuid) {
log.info("Getting third-party API configurations.");
return thirdPartyApiConfigurationRepository.getThirdPartyApiConfigurations(tenantId);
return thirdPartyApiConfigurationRepository.getThirdPartyApiConfigurations(tenantId, uuid);
}

/**
* Deletes a third-party API configuration.
*
* @param tenantId The tenantId of the third-party API configuration.
* @param manufacturer The manufacturer of the third-party API configuration.
* @param tenantId The tenantId of the third-party API configuration.
* @param uuid The uuid of the third-party API configuration.
*/
public void deleteThirdPartyApiConfiguration(String tenantId, Manufacturer manufacturer) {
public void deleteThirdPartyApiConfiguration(String tenantId, String uuid) {
log.info("Deleting third-party API configuration.");
thirdPartyApiConfigurationRepository.deleteThirdPartyApiConfiguration(tenantId, manufacturer);
thirdPartyApiConfigurationRepository.deleteThirdPartyApiConfiguration(tenantId, uuid);
}

/**
* Gets all third-party API configurations.
*
* @param tenantId The tenantId of the third-party API configuration.
* @return A list of third-party API configurations.
*/
public List<ThirdPartyApiConfiguration> getThirdPartyApiConfigurations(String tenantId) {
return thirdPartyApiConfigurationRepository.getThirdPartyApiConfigurations(tenantId);
}

public void addMissingUuidForThirdPartyApiConfigurations() {
log.info("Adding missing UUIDs for third-party API configurations.");
thirdPartyApiConfigurationRepository.addMissingUuidForThirdPartyApiConfigurations();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.app.fivegla.controller.dto.response;

import de.app.fivegla.api.Response;
import de.app.fivegla.controller.dto.response.inner.ThirdPartyApiConfiguration;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Builder
@Schema(description = "Response wrapper.")
public class CreateThirdPartyApiConfigurationResponse extends Response {

/**
* The third-party API configuration.
*/
@Schema(description = "The third-party API configuration.")
private ThirdPartyApiConfiguration thirdPartyApiConfiguration;

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Setter
@Builder
@Schema(name = "Response for finding all tenants.")
public class FindAllTenantsResponse extends Response {
public class ReadTenantsResponse extends Response {

/**
* The list of tenants.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Setter
@Builder
@Schema(name = "Response for finding all third API responses.")
public class FindAllThirdPartyApiConfigurationsResponse extends Response {
public class ReadThirdPartyApiConfigurationsResponse extends Response {

/**
* The list of third-party API configurations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ThirdPartyApiConfiguration {
/**
* Represents the tenant.
*/
@Schema(description = "The tenant.")
@Schema(description = "The tenant ID.")
private String tenantId;

/**
Expand All @@ -24,10 +24,27 @@ public class ThirdPartyApiConfiguration {
@Schema(description = "The manufacturer.")
private Manufacturer manufacturer;

/**
* Represents the prefix used for FIWARE integration.
*/
@Schema(description = "The FIWARE prefix.")
private String fiwarePrefix;

/**
* Indicator if the configuration is enabled.
*/
@Schema(description = "Indicator if the configuration is enabled.")
@Schema(description = "The enabled status.")
private boolean enabled;

/**
* Represents the URL of the third-party API.
*/
@Schema(description = "The URL of the third-party API.")
private String url;

/**
* Represents the UUID of the third-party API. Will be set automatically to a random UUID.
*/
@Schema(description = "The UUID of the third-party API.")
private String uuid;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import de.app.fivegla.api.Response;
import de.app.fivegla.business.ThirdPartyApiConfigurationService;
import de.app.fivegla.config.security.marker.ApiKeyApiAccess;
import de.app.fivegla.controller.api.BaseMappings;
import de.app.fivegla.scheduled.DataImportScheduler;
Expand Down Expand Up @@ -32,6 +33,7 @@
public class MaintenanceController implements ApiKeyApiAccess {

private final DataImportScheduler dataImportScheduler;
private final ThirdPartyApiConfigurationService thirdPartyApiConfigurationService;

/**
* Run the import.
Expand All @@ -55,4 +57,23 @@ public ResponseEntity<? extends Response> runAllImports() {
return ResponseEntity.ok().body(new Response());
}

@Operation(
operationId = "add-uuid-for-3rd-party-api",
description = "Add UUID for 3rd party API configurations.",
tags = BaseMappings.MAINTENANCE
)
@ApiResponse(
responseCode = "200",
description = "The UUID has been added for 3rd party API configurations.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = Response.class)
)
)
@PostMapping(value = "/add-missing-uuid-for-3rd-party-api-cfg", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<? extends Response> addUuidForThirdPartyApiConfigurations() {
thirdPartyApiConfigurationService.addMissingUuidForThirdPartyApiConfigurations();
return ResponseEntity.ok().body(new Response());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import de.app.fivegla.controller.dto.request.CreateTenantRequest;
import de.app.fivegla.controller.dto.request.UpdateTenantRequest;
import de.app.fivegla.controller.dto.response.CreateTenantResponse;
import de.app.fivegla.controller.dto.response.FindAllTenantsResponse;
import de.app.fivegla.controller.dto.response.ReadTenantsResponse;
import de.app.fivegla.controller.dto.response.UpdateTenantResponse;
import de.app.fivegla.controller.dto.response.inner.Tenant;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -118,7 +118,7 @@ public ResponseEntity<? extends Response> update(@Valid @RequestBody UpdateTenan
description = "The tenants are found successfully. The response contains a list of tenants.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = FindAllTenantsResponse.class)
schema = @Schema(implementation = ReadTenantsResponse.class)
)
)
@ApiResponse(
Expand All @@ -133,7 +133,7 @@ public ResponseEntity<? extends Response> findAll() {
.tenantId(tenant.getTenantId())
.description(tenant.getDescription())
.build()).toList();
return ResponseEntity.ok(FindAllTenantsResponse.builder().tenants(tenants).build());
return ResponseEntity.ok(ReadTenantsResponse.builder().tenants(tenants).build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import de.app.fivegla.controller.api.BaseMappings;
import de.app.fivegla.controller.dto.request.CreateGroupRequest;
import de.app.fivegla.controller.dto.request.UpdateGroupRequest;
import de.app.fivegla.controller.dto.response.*;
import de.app.fivegla.controller.dto.response.ReadGroupsResponse;
import de.app.fivegla.controller.dto.response.SensorAddedToGroupResponse;
import de.app.fivegla.controller.dto.response.UpdateGroupResponse;
import de.app.fivegla.persistence.entity.Group;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -23,6 +25,7 @@
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;
import java.util.Optional;

@Slf4j
Expand All @@ -44,7 +47,7 @@ public class GroupController implements TenantCredentialApiAccess {
description = "The group was created successfully.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = GroupResponse.class)
schema = @Schema(implementation = ReadGroupsResponse.class)
)
)
@ApiResponse(
Expand Down Expand Up @@ -72,7 +75,7 @@ public ResponseEntity<? extends Response> createGroup(@Valid @RequestBody Create
description = "The group was read successfully.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ReadGroupResponse.class)
schema = @Schema(implementation = ReadGroupsResponse.class)
)
)
@ApiResponse(
Expand Down Expand Up @@ -230,7 +233,7 @@ public ResponseEntity<? extends Response> assignSensorToExistingGroup(@PathVaria
description = "The sensor was unassigned from the group successfully.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = GroupResponse.class)
schema = @Schema(implementation = ReadGroupsResponse.class)
)
)
@ApiResponse(
Expand All @@ -254,15 +257,15 @@ private static ResponseEntity<? extends Response> createGroupResponse(Optional<G
if (group.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new Response());
}
return ResponseEntity.status(HttpStatus.OK).body(GroupResponse.builder()
.group(de.app.fivegla.controller.dto.response.inner.Group.builder()
return ResponseEntity.status(HttpStatus.OK).body(ReadGroupsResponse.builder()
.groups(List.of(de.app.fivegla.controller.dto.response.inner.Group.builder()
.groupId(group.get().getGroupId())
.name(group.get().getName())
.description(group.get().getDescription())
.createdAt(group.get().getCreatedAt().toString())
.updatedAt(group.get().getUpdatedAt().toString())
.sensorIdsAssignedToGroup(group.get().getSensorIdsAssignedToGroup())
.build())
.build()))
.build()
);
}
Expand All @@ -277,7 +280,7 @@ private static ResponseEntity<? extends Response> createGroupResponse(Optional<G
description = "The sensor was reassigned to the group successfully.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = GroupResponse.class)
schema = @Schema(implementation = ReadGroupsResponse.class)
)
)
@ApiResponse(
Expand All @@ -289,7 +292,9 @@ private static ResponseEntity<? extends Response> createGroupResponse(Optional<G
)
)
@PutMapping(value = "/{groupId}/reassign-sensor/{sensorId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<? extends Response> reAssignSensorToExistingGroup(String groupId, String sensorId, Principal principal) {
public ResponseEntity<? extends Response> reAssignSensorToExistingGroup(@PathVariable("groupId") @Parameter(description = "The unique ID of the group.") String groupId,
@PathVariable("sensorId") @Parameter(description = "The unique ID of the sensor.") String sensorId,
Principal principal) {
var tenant = validateTenant(tenantService, principal);
var group = groupService.reAssignSensorToExistingGroup(tenant, groupId, sensorId);
return createGroupResponse(group);
Expand Down
Loading

0 comments on commit 4eef629

Please sign in to comment.