Skip to content

Commit 8d0e50d

Browse files
authored
feat(JAQPOT-478): send null if model too large (#144)
1 parent 3b98800 commit 8d0e50d

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

src/main/kotlin/org/jaqpot/api/mapper/ModelMapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fun ModelDto.toEntity(creatorId: String): Model {
103103
}
104104

105105
fun Model.toPredictionModelDto(
106-
rawModel: ByteArray,
106+
rawModel: ByteArray?,
107107
doas: List<PredictionDoaDto>,
108108
rawPreprocessor: ByteArray?
109109
): PredictionModelDto {
@@ -113,7 +113,7 @@ fun Model.toPredictionModelDto(
113113
independentFeatures = this.independentFeatures.map { it.toDto() },
114114
type = this.type.toDto(),
115115
task = this.task.toDto(),
116-
rawModel = this.encodeRawModel(rawModel),
116+
rawModel = rawModel?.let { this.encodeRawModel(rawModel) },
117117
rawPreprocessor = this.encodeRawPreprocessor(rawPreprocessor),
118118
doas = doas,
119119
selectedFeatures = this.selectedFeatures ?: emptyList(),

src/main/kotlin/org/jaqpot/api/service/model/ModelService.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class ModelService(
7878
ModelTypeDto.R_TREE_REGR,
7979
)
8080
private val logger = KotlinLogging.logger {}
81+
const val FIVE_MEGABYTES_IN_BYTES = 5e+6
8182

8283
fun storeRawModelToStorage(model: Model, storageService: StorageService, modelRepository: ModelRepository) {
8384
if (model.rawModel == null) {
@@ -321,7 +322,11 @@ class ModelService(
321322
val rawModel = if (model.isQsarToolboxModel()) {
322323
byteArrayOf()
323324
} else {
324-
storageService.readRawModel(model)
325+
if (storageService.readRawModelMetadata(model).contentLength() > FIVE_MEGABYTES_IN_BYTES) {
326+
null
327+
} else {
328+
storageService.readRawModel(model)
329+
}
325330
}
326331
val rawPreprocessor = storageService.readRawPreprocessor(model)
327332

src/main/kotlin/org/jaqpot/api/service/prediction/runtime/runtimes/RESTRuntime.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ abstract class RESTRuntime : RuntimeBase() {
111111

112112

113113
val legacyPredictionRequestDto = LegacyPredictionRequestDto(
114-
rawModel = arrayOf(predictionModelDto.rawModel),
114+
rawModel = arrayOf(predictionModelDto.rawModel!!),
115115
dataset = LegacyDatasetDto(
116116
LegacyDataEntryDto(values = values),
117117
features = predictionModelDto.independentFeatures.mapIndexed { index, it ->

src/main/resources/openapi.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,6 @@ components:
25202520
- dependentFeatures
25212521
- independentFeatures
25222522
- type
2523-
- rawModel
25242523
- task
25252524
properties:
25262525
id:

0 commit comments

Comments
 (0)