From 68fc268344122e9b40453f0f863ce08509709a7c Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Thu, 10 Oct 2024 11:32:15 -0400 Subject: [PATCH 1/4] Remove model framework --- .../dataservice/FrameworkController.java | 125 ------------------ .../src/main/resources/application.properties | 21 ++- .../dataservice/FrameworkControllerTests.java | 112 ---------------- 3 files changed, 10 insertions(+), 248 deletions(-) delete mode 100644 packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkController.java delete mode 100644 packages/server/src/test/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkControllerTests.java diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkController.java deleted file mode 100644 index 5dfe900047..0000000000 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkController.java +++ /dev/null @@ -1,125 +0,0 @@ -package software.uncharted.terarium.hmiserver.controller.dataservice; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import jakarta.transaction.Transactional; -import java.util.Optional; -import java.util.UUID; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import software.uncharted.terarium.hmiserver.models.dataservice.ResponseDeleted; -import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelFramework; -import software.uncharted.terarium.hmiserver.security.Roles; -import software.uncharted.terarium.hmiserver.service.data.FrameworkService; - -@RequestMapping("/models") -@RestController -@RequiredArgsConstructor -public class FrameworkController { - - final FrameworkService frameworkService; - - final ObjectMapper objectMapper; - - @PostMapping("/frameworks") - @Secured(Roles.USER) - @Operation(summary = "Create a new model framework") - @ApiResponses( - value = { - @ApiResponse( - responseCode = "201", - description = "Model framework created.", - content = @Content( - mediaType = "application/json", - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ModelFramework.class) - ) - ) - } - ) - ResponseEntity createFramework(@RequestBody final ModelFramework framework) { - final ModelFramework modelFramework = frameworkService.createFramework(framework); - - return ResponseEntity.status(HttpStatus.CREATED).body(modelFramework); - } - - @GetMapping("/frameworks/{id}") - @Secured(Roles.USER) - @Operation(summary = "Gets a model framework by ID") - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Model framework found.", - content = @Content( - mediaType = "application/json", - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ModelFramework.class) - ) - ), - @ApiResponse(responseCode = "404", description = "There was no framework found", content = @Content) - } - ) - ResponseEntity getFramework(@PathVariable("id") final UUID id) { - final Optional framework = frameworkService.getFramework(id); - if (framework.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Framework %s not found", id)); - } - return ResponseEntity.ok(framework.get()); - } - - @PutMapping("/frameworks/{id}") - @Secured(Roles.USER) - @Operation(summary = "Update a model framework") - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Model framework updated.", - content = @Content( - mediaType = "application/json", - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ModelFramework.class) - ) - ), - @ApiResponse(responseCode = "404", description = "There was no framework found", content = @Content) - } - ) - ResponseEntity updateFramework( - @PathVariable("id") final UUID id, - @RequestBody final ModelFramework framework - ) { - framework.setId(id); - final Optional updated = frameworkService.updateFramework(framework); - if (updated.isEmpty()) { - return ResponseEntity.notFound().build(); - } - return ResponseEntity.ok(updated.get()); - } - - @DeleteMapping("/frameworks/{id}") - @Secured(Roles.USER) - @Operation(summary = "Deletes an model framework") - @ApiResponses( - value = { - @ApiResponse( - responseCode = "200", - description = "Deleted framework", - content = { - @Content( - mediaType = "application/json", - schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ResponseDeleted.class) - ) - } - ) - } - ) - ResponseEntity deleteFramework(@PathVariable("id") final UUID id) { - frameworkService.deleteFramework(id); - return ResponseEntity.ok(new ResponseDeleted("ModelFramework", id)); - } -} diff --git a/packages/server/src/main/resources/application.properties b/packages/server/src/main/resources/application.properties index 98c38bbb01..58c2dc8ea8 100644 --- a/packages/server/src/main/resources/application.properties +++ b/packages/server/src/main/resources/application.properties @@ -77,17 +77,16 @@ terarium.serviceRequestPatterns[1]=/concepts/** terarium.serviceRequestPatterns[2]=/datasets/** terarium.serviceRequestPatterns[3]=/document-asset/** terarium.serviceRequestPatterns[4]=/equations/** -terarium.serviceRequestPatterns[5]=/models/frameworks/** -terarium.serviceRequestPatterns[6]=/model-configurations/** -terarium.serviceRequestPatterns[7]=/models/** -terarium.serviceRequestPatterns[8]=/sessions/** -terarium.serviceRequestPatterns[9]=/projects/** -terarium.serviceRequestPatterns[10]=/provenance/** -terarium.serviceRequestPatterns[11]=/simulations/** -terarium.serviceRequestPatterns[12]=/code-asset/** -terarium.serviceRequestPatterns[13]=/workflows/** -terarium.serviceRequestPatterns[14]=/interventions/** -terarium.serviceRequestPatterns[15]=/knowledge/** +terarium.serviceRequestPatterns[5]=/model-configurations/** +terarium.serviceRequestPatterns[6]=/models/** +terarium.serviceRequestPatterns[7]=/sessions/** +terarium.serviceRequestPatterns[8]=/projects/** +terarium.serviceRequestPatterns[9]=/provenance/** +terarium.serviceRequestPatterns[10]=/simulations/** +terarium.serviceRequestPatterns[11]=/code-asset/** +terarium.serviceRequestPatterns[12]=/workflows/** +terarium.serviceRequestPatterns[13]=/interventions/** +terarium.serviceRequestPatterns[14]=/knowledge/** terarium.extractionService.poolSize=10 terarium.cacheHeadersMaxAge=86400 management.endpoints.web.exposure.include=health,prometheus diff --git a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkControllerTests.java b/packages/server/src/test/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkControllerTests.java deleted file mode 100644 index af94b6e657..0000000000 --- a/packages/server/src/test/java/software/uncharted/terarium/hmiserver/controller/dataservice/FrameworkControllerTests.java +++ /dev/null @@ -1,112 +0,0 @@ -package software.uncharted.terarium.hmiserver.controller.dataservice; - -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.test.context.support.WithUserDetails; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import software.uncharted.terarium.hmiserver.TerariumApplicationTests; -import software.uncharted.terarium.hmiserver.configuration.MockUser; -import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelFramework; -import software.uncharted.terarium.hmiserver.models.dataservice.project.Project; -import software.uncharted.terarium.hmiserver.service.data.FrameworkService; -import software.uncharted.terarium.hmiserver.service.data.ProjectSearchService; -import software.uncharted.terarium.hmiserver.service.data.ProjectService; - -public class FrameworkControllerTests extends TerariumApplicationTests { - - @Autowired - private ObjectMapper objectMapper; - - @Autowired - private FrameworkService frameworkService; - - @Autowired - private ProjectService projectService; - - @Autowired - private ProjectSearchService projectSearchService; - - Project project; - - @BeforeEach - public void setup() throws IOException { - projectSearchService.setupIndexAndAliasAndEnsureEmpty(); - project = projectService.createProject( - (Project) new Project().setPublicAsset(true).setName("test-project-name").setDescription("my description") - ); - } - - @AfterEach - public void teardown() throws IOException { - projectSearchService.teardownIndexAndAlias(); - } - - @Test - @WithUserDetails(MockUser.URSULA) - public void testItCanCreateFramework() throws Exception { - final ModelFramework framework = new ModelFramework() - .setName("test-framework") - .setVersion("0.1.2") - .setSemantics("test-semantics"); - - mockMvc - .perform( - MockMvcRequestBuilders.post("/models/frameworks") - .with(csrf()) - .contentType("application/json") - .content(objectMapper.writeValueAsString(framework)) - ) - .andExpect(status().isCreated()); - } - - @Test - @WithUserDetails(MockUser.URSULA) - public void testItCanUpdateFramework() throws Exception { - final ModelFramework framework = frameworkService.createFramework( - new ModelFramework().setName("test-framework").setVersion("0.1.2").setSemantics("test-semantics") - ); - - mockMvc - .perform( - MockMvcRequestBuilders.put("/models/frameworks/" + framework.getId()) - .with(csrf()) - .contentType("application/json") - .content(objectMapper.writeValueAsString(framework)) - ) - .andExpect(status().isOk()); - } - - @Test - @WithUserDetails(MockUser.URSULA) - public void testItCanGetFramework() throws Exception { - final ModelFramework framework = frameworkService.createFramework( - new ModelFramework().setName("test-framework").setVersion("0.1.2").setSemantics("test-semantics") - ); - - mockMvc - .perform(MockMvcRequestBuilders.get("/models/frameworks/" + framework.getId()).with(csrf())) - .andExpect(status().isOk()); - } - - @Test - @WithUserDetails(MockUser.URSULA) - public void testItCanDeleteFramework() throws Exception { - final ModelFramework framework = frameworkService.createFramework( - new ModelFramework().setName("test-framework").setVersion("0.1.2").setSemantics("test-semantics") - ); - - mockMvc - .perform(MockMvcRequestBuilders.delete("/models/frameworks/" + framework.getId()).with(csrf())) - .andExpect(status().isOk()); - - Assertions.assertTrue(frameworkService.getFramework(framework.getId()).isEmpty()); - } -} From 653c8413e3cec3a0cd50343831dd85426945ae6e Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Tue, 15 Oct 2024 09:42:25 -0400 Subject: [PATCH 2/4] Delete FrameworkService.java --- .../service/data/FrameworkService.java | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/FrameworkService.java diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/FrameworkService.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/FrameworkService.java deleted file mode 100644 index fcad083783..0000000000 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/data/FrameworkService.java +++ /dev/null @@ -1,57 +0,0 @@ -package software.uncharted.terarium.hmiserver.service.data; - -import io.micrometer.observation.annotation.Observed; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelFramework; -import software.uncharted.terarium.hmiserver.repository.data.FrameworkRepository; - -@Service -@RequiredArgsConstructor -public class FrameworkService { - - final FrameworkRepository frameworkRepository; - - @Observed(name = "function_profile") - public List getFrameworks() { - return frameworkRepository.findAllByDeletedOnIsNull(); - } - - @Observed(name = "function_profile") - public List getFrameworks(final List ids) { - return frameworkRepository.findAllByIdInAndDeletedOnIsNull(ids); - } - - @Observed(name = "function_profile") - public Optional getFramework(final UUID id) { - return frameworkRepository.getByIdAndDeletedOnIsNull(id); - } - - @Observed(name = "function_profile") - public ModelFramework createFramework(final ModelFramework framework) { - return frameworkRepository.save(framework); - } - - @Observed(name = "function_profile") - public Optional updateFramework(final ModelFramework framework) { - if (!frameworkRepository.existsById(framework.getId())) { - return Optional.empty(); - } - return Optional.of(frameworkRepository.save(framework)); - } - - @Observed(name = "function_profile") - public void deleteFramework(final UUID id) { - final Optional framework = frameworkRepository.findById(id); - if (framework.isEmpty()) { - return; - } - framework.get().setDeletedOn(Timestamp.from(Instant.now())); - frameworkRepository.save(framework.get()); - } -} From 408590096dc5f37a917e65638541f59c195808da Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Tue, 15 Oct 2024 09:52:28 -0400 Subject: [PATCH 3/4] Removing model framework --- .../dataservice/model/ModelFramework.java | 26 ------------------- .../PSCrudSoftDeleteRepository.java | 3 --- .../repository/data/FrameworkRepository.java | 9 ------- 3 files changed, 38 deletions(-) delete mode 100644 packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/ModelFramework.java delete mode 100644 packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/data/FrameworkRepository.java diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/ModelFramework.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/ModelFramework.java deleted file mode 100644 index 4953ceee5c..0000000000 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/ModelFramework.java +++ /dev/null @@ -1,26 +0,0 @@ -package software.uncharted.terarium.hmiserver.models.dataservice.model; - -import jakarta.persistence.Entity; -import java.io.Serial; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -import software.uncharted.terarium.hmiserver.annotations.TSModel; -import software.uncharted.terarium.hmiserver.models.TerariumAssetThatSupportsAdditionalProperties; - -@EqualsAndHashCode(callSuper = true) -@Entity -@Data -@Accessors(chain = true) -@TSModel -public class ModelFramework extends TerariumAssetThatSupportsAdditionalProperties { - - @Serial - private static final long serialVersionUID = -2375250471839320328L; - - private String name; - - private String version; - - private String semantics; -} diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java index a302fcefac..8b5d428947 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/PSCrudSoftDeleteRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.NoRepositoryBean; -import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelFramework; @NoRepositoryBean public interface PSCrudSoftDeleteRepository extends PSCrudRepository { @@ -14,6 +13,4 @@ public interface PSCrudSoftDeleteRepository extends PSCrudRepository getByIdAndDeletedOnIsNull(final ID id); Page findAllByPublicAssetIsTrueAndTemporaryIsFalseAndDeletedOnIsNull(final Pageable pageable); - - List findAllByDeletedOnIsNull(); } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/data/FrameworkRepository.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/data/FrameworkRepository.java deleted file mode 100644 index 0a39aaec70..0000000000 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/repository/data/FrameworkRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package software.uncharted.terarium.hmiserver.repository.data; - -import java.util.UUID; -import org.springframework.stereotype.Repository; -import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelFramework; -import software.uncharted.terarium.hmiserver.repository.PSCrudSoftDeleteRepository; - -@Repository -public interface FrameworkRepository extends PSCrudSoftDeleteRepository {} From 9a2f4fc4707a7afb2f21f16475274151c8d8d4e0 Mon Sep 17 00:00:00 2001 From: YohannParis Date: Tue, 15 Oct 2024 13:53:33 +0000 Subject: [PATCH 4/4] chore: update generated types --- packages/client/hmi-client/src/types/Types.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/client/hmi-client/src/types/Types.ts b/packages/client/hmi-client/src/types/Types.ts index 3bb2fb504e..5a22c20daf 100644 --- a/packages/client/hmi-client/src/types/Types.ts +++ b/packages/client/hmi-client/src/types/Types.ts @@ -224,12 +224,6 @@ export interface ModelDescription { userId?: string; } -export interface ModelFramework extends TerariumAssetThatSupportsAdditionalProperties { - name: string; - version: string; - semantics: string; -} - export interface InferredParameterSemantic extends Semantic { referenceId: string; distribution: ModelDistribution;