From 2f79eb930a6e944a691c246da7e8e28cc0efd9d8 Mon Sep 17 00:00:00 2001 From: enricoottonello Date: Wed, 3 Apr 2019 16:03:44 +0200 Subject: [PATCH] added apidescriptor --- .../manager/controller/MDStoreController.java | 22 +++++++++++++++++++ .../collector/worker/model/ApiDescriptor.java | 0 dhp-workflows/dhp-collector-worker/pom.xml | 5 +++++ 3 files changed, 27 insertions(+) rename {dhp-workflows/dhp-collector-worker => dhp-common}/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java (100%) diff --git a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/MDStoreController.java b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/MDStoreController.java index 4cad53fc3..931d2cf69 100644 --- a/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/MDStoreController.java +++ b/dhp-applications/dhp-mdstore-manager-app/src/main/java/eu/dnetlib/data/mdstore/manager/controller/MDStoreController.java @@ -65,6 +65,18 @@ public class MDStoreController { return mdstoreWithInfoRepository.findById(mdId).orElseThrow(() -> new NoContentException("Missing mdstore: " + mdId)); } + @Transactional + @ApiOperation(value = "Increase the read count of the current mdstore") + @RequestMapping(value = "/mdstore/{mdId}/startReading", method = RequestMethod.GET) + public MDStoreVersion startReading(@ApiParam("the mdstore identifier") @PathVariable final String mdId) throws NoContentException { + final MDStoreCurrentVersion cv = mdstoreCurrentVersionRepository.findById(mdId).orElseThrow(() -> new NoContentException("Missing mdstore: " + mdId)); + final MDStoreVersion v = mdstoreVersionRepository.findById(cv.getCurrentVersion()) + .orElseThrow(() -> new NoContentException("Missing version: " + cv.getCurrentVersion())); + v.setReadCount(v.getReadCount() + 1); + mdstoreVersionRepository.save(v); + return v; + } + @ApiOperation(value = "Return the number of mdstores") @RequestMapping(value = "/count", method = RequestMethod.GET) public long count() { @@ -165,6 +177,16 @@ public class MDStoreController { _deleteVersion(versionId, force); } + @Transactional + @ApiOperation(value = "Decrease the read count of a mdstore version") + @RequestMapping(value = "/version/{versionId}/endReading", method = RequestMethod.GET) + public MDStoreVersion endReading(@ApiParam("the id of the version that has been completely read") @PathVariable final String versionId) + throws MDStoreManagerException { + final MDStoreVersion v = mdstoreVersionRepository.findById(versionId).orElseThrow(() -> new MDStoreManagerException("Version not found")); + v.setReadCount(v.getReadCount() - 1); + return v; + } + @Transactional @ApiOperation(value = "Delete multiple mdstore versions") @RequestMapping(value = "/versions/deleteList", method = RequestMethod.POST) diff --git a/dhp-workflows/dhp-collector-worker/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java b/dhp-common/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java similarity index 100% rename from dhp-workflows/dhp-collector-worker/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java rename to dhp-common/src/main/java/eu/dnetlib/collector/worker/model/ApiDescriptor.java diff --git a/dhp-workflows/dhp-collector-worker/pom.xml b/dhp-workflows/dhp-collector-worker/pom.xml index 27fae6961..2d66b0dab 100644 --- a/dhp-workflows/dhp-collector-worker/pom.xml +++ b/dhp-workflows/dhp-collector-worker/pom.xml @@ -29,6 +29,11 @@ + + eu.dnetlib.dhp + dhp-common + 1.0.0-SNAPSHOT + org.springframework.boot spring-boot-starter