Package dev.dokimos.server.service
Class DatasetService
java.lang.Object
dev.dokimos.server.service.DatasetService
Service for server-owned versioned datasets. Datasets are mutable shells; versions are immutable.
-
Constructor Summary
ConstructorsConstructorDescriptionDatasetService(DatasetRepository datasetRepository, DatasetVersionRepository versionRepository, DatasetItemRepository itemRepository, ItemResultRepository itemResultRepository) -
Method Summary
Modifier and TypeMethodDescriptioncreateDataset(String name, String description) Creates a dataset with a globally unique name.createVersion(String datasetName, String description, List<CreateVersionRequest.ItemPayload> items, String createdBy) Creates a new immutable version of the dataset and inserts all items in one transaction.voiddeleteDataset(String name) Deletes a dataset.getDataset(String name) Returns the dataset with the given name.getDatasetDetails(String name) Returns full dataset details including the version list, newest first.getLatestVersion(String datasetName) Returns the latest version of the dataset.getVersion(String datasetName, int version) Returns a specific version of the dataset.Returns dataset summaries with the latest version number and item count for each.org.springframework.data.domain.Page<DatasetItem> listItems(DatasetVersion version, org.springframework.data.domain.Pageable pageable) Overload for callers that have already resolved aDatasetVersion; avoids the double-fetch path throughgetVersion(java.lang.String, int).org.springframework.data.domain.Page<DatasetItem> Returns items for the given version ordered by ordinal, paginated.promote(PromoteRequest req, String createdBy) Promotes run item results into a new version of an existing dataset.
-
Constructor Details
-
DatasetService
public DatasetService(DatasetRepository datasetRepository, DatasetVersionRepository versionRepository, DatasetItemRepository itemRepository, ItemResultRepository itemResultRepository)
-
-
Method Details
-
createDataset
Creates a dataset with a globally unique name. Has no versions untilcreateVersion(java.lang.String, java.lang.String, java.util.List<dev.dokimos.server.dto.v1.CreateVersionRequest.ItemPayload>, java.lang.String)is called.- Throws:
IllegalStateException- if a dataset with the same name already exists (mapped to 409)
-
getDataset
Returns the dataset with the given name.- Throws:
IllegalArgumentException- if no such dataset exists (mapped to 404)
-
listDatasets
Returns dataset summaries with the latest version number and item count for each. Collapses to two queries (one for datasets, one for the latest version row per dataset) regardless of dataset count. -
getDatasetDetails
Returns full dataset details including the version list, newest first. -
deleteDataset
Deletes a dataset. The FK cascade removes its versions and items; runs that referenced any of those versions have theirdataset_version_idset to NULL via the SET NULL FK so the historical run is preserved unlinked.- Throws:
IllegalArgumentException- if no such dataset exists (mapped to 404)
-
createVersion
@Transactional public DatasetVersion createVersion(String datasetName, String description, List<CreateVersionRequest.ItemPayload> items, String createdBy) Creates a new immutable version of the dataset and inserts all items in one transaction. The pessimistic write lock on the parent dataset row serializes concurrent version creations so thenext = max(version) + 1read is consistent; the(dataset_id, version)unique constraint is the backstop if the lock is bypassed. Item ordinals follow the input order (0..N-1).- Throws:
IllegalArgumentException- if no such dataset exists or items is empty (the latter is also caught by bean validation, but the service enforces it for non-controller callers)
-
promote
Promotes run item results into a new version of an existing dataset. Each item's inputs become the new dataset item's inputs, its metadata is carried over, and its expected output is used unless the request supplies an override. Item order is preserved. Delegates tocreateVersion(java.lang.String, java.lang.String, java.util.List<dev.dokimos.server.dto.v1.CreateVersionRequest.ItemPayload>, java.lang.String)so the version-numbering and locking semantics are identical to a direct create.- Throws:
IllegalArgumentException- if any referenced item result or the dataset is missing (mapped to 404)
-
getVersion
Returns a specific version of the dataset.- Throws:
IllegalArgumentException- if the dataset or version is missing
-
getLatestVersion
Returns the latest version of the dataset.- Throws:
IllegalArgumentException- if the dataset has no versions
-
listItems
@Transactional(readOnly=true) public org.springframework.data.domain.Page<DatasetItem> listItems(String datasetName, int version, org.springframework.data.domain.Pageable pageable) Returns items for the given version ordered by ordinal, paginated. -
listItems
@Transactional(readOnly=true) public org.springframework.data.domain.Page<DatasetItem> listItems(DatasetVersion version, org.springframework.data.domain.Pageable pageable) Overload for callers that have already resolved aDatasetVersion; avoids the double-fetch path throughgetVersion(java.lang.String, int).
-