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 4cad53fc34..931d2cf69a 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 27fae69615..2d66b0dab4 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