Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: decapodes data structures #2653

Merged
merged 9 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,115 @@ export interface TypingSemantics {
system: any;
}

export interface Configuration {
parameters: { [index: string]: ConfigurationParameter };
initialConditions: { [index: string]: ConfigurationCondition };
boundryConditions: { [index: string]: ConfigurationCondition };
datasets: { [index: string]: ConfigurationDataset };
}

export interface ConfigurationCondition {
_type: string;
type: string;
value: string;
domainMesh: string;
}

export interface ConfigurationDataset {
_type: string;
type: string;
name: string;
description: string;
file: ConfigurationDatasetFile;
}

export interface ConfigurationDatasetFile {
_type: string;
uri: string;
format: string;
shape: number[];
}

export interface ConfigurationHeader {
id: string;
description: string;
name: string;
parentContext: string;
}

export interface ConfigurationParameter {
_type: string;
type: string;
value: any;
}

export interface Context {
constants: { [index: string]: ContextConstant };
spatialConstraints: any;
temporalConstraints: any;
primalDualRelations: ContextPrimalDualRelation[];
meshSubmeshRelations: ContextMeshSubmeshRelation[];
meshes: ContextMesh[];
}

export interface ContextConstant {
_type: string;
value: any;
}

export interface ContextFile {
uri: string;
format: string;
}

export interface ContextHeader {
id: string;
description: string;
name: string;
parentContext: string;
}

export interface ContextMesh {
id: string;
description: string;
dimensionality: any;
vertexCount: number;
edgeCount: number;
faceCount: number;
volumeCount: number;
regions: any[];
checksum: string;
file: ContextFile;
}

export interface ContextMeshSubmeshRelation {
mesh: string;
submesh: string;
relation: any;
}

export interface ContextPrimalDualRelation {
primal: string;
dual: string;
method: any;
}

export interface DecapodesComponent {
modelInterface: string[];
model: DecapodesExpression;
_type: string;
}

export interface DecapodesConfiguration extends TerariumAsset {
header: ConfigurationHeader;
configuration: Configuration;
}

export interface DecapodesContext extends TerariumAsset {
header: ContextHeader;
context: Context;
}

export interface DecapodesEquation {
lhs: any;
rhs: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public record Index(
String notebookSessionRoot,
String simulationRoot,
String workflowRoot,
String externalPublicationRoot) {
String externalPublicationRoot,
String decapodesConfigurationRoot,
String decapodesContext) {
}

public String getCodeIndex() {
Expand Down Expand Up @@ -82,4 +84,12 @@ public String getWorkflowIndex() {
public String getExternalPublicationIndex() {
return String.join("_", index.prefix, index.externalPublicationRoot, index.suffix);
}

public String getDecapodesConfigurationIndex() {
return String.join("_", index.prefix, index.decapodesConfigurationRoot, index.suffix);
}

public String getDecapodesContextIndex() {
return String.join("_", index.prefix, index.decapodesContext, index.suffix);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package software.uncharted.terarium.hmiserver.controller.dataservice;

import java.io.IOException;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import software.uncharted.terarium.hmiserver.models.dataservice.ResponseDeleted;
import software.uncharted.terarium.hmiserver.models.dataservice.multiphysics.DecapodesConfiguration;
import software.uncharted.terarium.hmiserver.security.Roles;
import software.uncharted.terarium.hmiserver.service.data.DecapodesConfigurationService;

@RequestMapping("/decapodes-configurations")
@RestController
@Slf4j
@RequiredArgsConstructor
public class DecapodesConfigurationController {

final DecapodesConfigurationService decapodesConfigurationService;

@GetMapping("/{id}")
@Secured(Roles.USER)
@Operation(summary = "Gets a decapodes configuration by ID")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Decapodes configuration found.", content = @Content(mediaType = "application/json", schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = DecapodesConfiguration.class))),
@ApiResponse(responseCode = "204", description = "There was no decapodes configuration found", content = @Content),
@ApiResponse(responseCode = "500", description = "There was an issue retrieving the decapodes configuration from the data store", content = @Content)
})
ResponseEntity<DecapodesConfiguration> getDecapodesConfiguration(@PathVariable("id") UUID id) {

try {

// Fetch the decapodes configuration from the data-service
Optional<DecapodesConfiguration> configuration = decapodesConfigurationService.getDecapodesConfiguration(id);
if (configuration.isEmpty()) {
return ResponseEntity.noContent().build();
}

// Return the configuration
return ResponseEntity.ok(configuration.get());
} catch (IOException e) {
final String error = "Unable to get decapodes configuration";
log.error(error, e);
throw new ResponseStatusException(
org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR,
error);
}
}

@PutMapping("/{id}")
@Secured(Roles.USER)
@Operation(summary = "Update a decapodes configuration")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Decapodes configuraiton updated.", content = @Content(mediaType = "application/json", schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = DecapodesConfiguration.class))),
@ApiResponse(responseCode = "500", description = "There was an issue updating the decapodes configuration", content = @Content)
})
ResponseEntity<DecapodesConfiguration> updateDecapodesConfiguration(
@PathVariable("id") UUID id,
@RequestBody DecapodesConfiguration configuration) {

try {
configuration.setId(id);
final Optional<DecapodesConfiguration> updated = decapodesConfigurationService.updateDecapodesConfiguration(configuration);
if (updated.isEmpty()) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(updated.get());
} catch (IOException e) {
final String error = "Unable to update decapodes configuration";
log.error(error, e);
throw new ResponseStatusException(
org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR,
error);
}
}

@DeleteMapping("/{id}")
@Secured(Roles.USER)
@Operation(summary = "Deletes an decapodes configuration")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Deleted decapodes configuration", content = {
@Content(mediaType = "application/json", schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = ResponseDeleted.class)) }),
@ApiResponse(responseCode = "404", description = "DecapodesConfiguration could not be found", content = @Content),
@ApiResponse(responseCode = "500", description = "An error occurred while deleting", content = @Content)
})
ResponseEntity<ResponseDeleted> deleteDecapodesConfiguration(
@PathVariable("id") UUID id) {

try {
decapodesConfigurationService.deleteDecapodesConfiguration(id);
return ResponseEntity.ok(new ResponseDeleted("DecapodesConfiguration", id));
} catch (IOException e) {
final String error = "Unable to delete decapodes configuration";
log.error(error, e);
throw new ResponseStatusException(
org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR,
error);
}
}

@PostMapping
@Secured(Roles.USER)
@Operation(summary = "Create a new decapodes configuration")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Decapodes configuration created.", content = @Content(mediaType = "application/json", schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = DecapodesConfiguration.class))),
@ApiResponse(responseCode = "500", description = "There was an issue creating the decapodes configuration", content = @Content)
})
ResponseEntity<DecapodesConfiguration> createDecapodesConfiguration(
@RequestBody DecapodesConfiguration config) {

try {
config = decapodesConfigurationService.createDecapodesConfiguration(config);
return ResponseEntity.status(HttpStatus.CREATED).body(config);
} catch (IOException e) {
final String error = "Unable to create decapodes configuration";
log.error(error, e);
throw new ResponseStatusException(
org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR,
error);
}
}
}
Loading
Loading