1
0
Fork 0

added swagger comments to input parameters

This commit is contained in:
Enrico Ottonello 2019-03-22 10:11:46 +01:00
parent 042d477878
commit 639483090a
4 changed files with 65 additions and 41 deletions

View File

@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.google.common.collect.Lists;
import eu.dnetlib.data.mdstore.manager.exceptions.MDStoreManagerException;
import eu.dnetlib.data.mdstore.manager.exceptions.NoContentException;
import eu.dnetlib.data.mdstore.manager.model.MDStore;
@ -25,9 +27,13 @@ import eu.dnetlib.data.mdstore.manager.repository.MDStoreCurrentVersionRepositor
import eu.dnetlib.data.mdstore.manager.repository.MDStoreRepository;
import eu.dnetlib.data.mdstore.manager.repository.MDStoreVersionRepository;
import eu.dnetlib.data.mdstore.manager.repository.MDStoreWithInfoRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@RestController
@RequestMapping("/mdstores")
@Api(tags = { "Metadata Stores" })
public class MDStoreController {
@Autowired
@ -41,33 +47,38 @@ public class MDStoreController {
@Autowired
private JdbcTemplate jdbcTemplate;
@ApiOperation(value = "Return all the mdstores")
@RequestMapping(value = "/", method = RequestMethod.GET)
public Iterable<MDStoreWithInfo> find() {
return mdstoreWithInfoRepository.findAll();
public List<MDStoreWithInfo> find() {
return Lists.newArrayList(mdstoreWithInfoRepository.findAll());
}
@ApiOperation(value = "Return all the mdstore identifiers")
@RequestMapping(value = "/ids", method = RequestMethod.GET)
public List<String> findIdentifiers() {
return mdstoreRepository.findAll().stream().map(MDStore::getId).collect(Collectors.toList());
}
@ApiOperation(value = "Return a mdstores by id")
@RequestMapping(value = "/mdstore/{mdId}", method = RequestMethod.GET)
public MDStoreWithInfo get(@PathVariable final String mdId) throws NoContentException {
public MDStoreWithInfo get(@ApiParam("the mdstore identifier") @PathVariable final String mdId) throws NoContentException {
return mdstoreWithInfoRepository.findById(mdId).orElseThrow(() -> new NoContentException("Missing mdstore: " + mdId));
}
@ApiOperation(value = "Return the number of mdstores")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public long count() {
return mdstoreRepository.count();
}
@ApiOperation(value = "Create a new mdstore")
@RequestMapping(value = "/new/{format}/{layout}/{interpretation}", method = RequestMethod.PUT)
public MDStoreWithInfo createMDStore(
@PathVariable final String format,
@PathVariable final String layout,
@PathVariable final String interpretation,
@RequestParam(required = false) final String dsId,
@RequestParam(required = false) final String apiId) throws MDStoreManagerException {
@ApiParam("mdstore format") @PathVariable final String format,
@ApiParam("mdstore layout") @PathVariable final String layout,
@ApiParam("mdstore interpretation") @PathVariable final String interpretation,
@ApiParam("datasource id") @RequestParam(required = false) final String dsId,
@ApiParam("api id") @RequestParam(required = false) final String apiId) throws MDStoreManagerException {
final String id = _createMDStore(format, layout, interpretation, dsId, apiId);
return mdstoreWithInfoRepository.findById(id).orElseThrow(() -> new MDStoreManagerException("MDStore not found"));
}
@ -86,8 +97,9 @@ public class MDStoreController {
}
@Transactional
@ApiOperation(value = "Delete a mdstore by id")
@RequestMapping(value = "/mdstore/{mdId}", method = RequestMethod.DELETE)
public void delete(@PathVariable final String mdId) throws MDStoreManagerException {
public void delete(@ApiParam("the id of the mdstore that will be deleted") @PathVariable final String mdId) throws MDStoreManagerException {
if (!mdstoreRepository.existsById(mdId)) { throw new NoContentException("On delete MDStore not found " + "[" + mdId + "]"); }
if (mdstoreVersionRepository.countByMdstoreAndReadCountGreaterThan(mdId,
@ -102,16 +114,19 @@ public class MDStoreController {
}
@Transactional
@ApiOperation(value = "Create a new preliminary version of a mdstore")
@RequestMapping(value = "/mdstore/{mdId}/newVersion", method = RequestMethod.GET)
public MDStoreVersion prepareNewVersion1(@PathVariable final String mdId) {
public MDStoreVersion prepareNewVersion(@ApiParam("the id of the mdstore for which will be created a new version") @PathVariable final String mdId) {
final MDStoreVersion v = MDStoreVersion.newInstance(mdId, true);
mdstoreVersionRepository.save(v);
return v;
}
@Transactional
@ApiOperation(value = "Promote a preliminary version to current")
@RequestMapping(value = "/version/{versionId}/commit/{size}", method = RequestMethod.GET)
public void commitVersion(@PathVariable final String versionId, @PathVariable final int size) throws NoContentException {
public void commitVersion(@ApiParam("the id of the version that will be promoted to the current version") @PathVariable final String versionId,
@ApiParam("the size of the new current mdstore") @PathVariable final int size) throws NoContentException {
final MDStoreVersion v = mdstoreVersionRepository.findById(versionId).orElseThrow(() -> new NoContentException("Invalid version: " + versionId));
mdstoreCurrentVersionRepository.save(MDStoreCurrentVersion.newInstance(v));
v.setWriting(false);
@ -120,6 +135,7 @@ public class MDStoreController {
mdstoreVersionRepository.save(v);
}
@ApiOperation(value = "Return all the expired versions of all the mdstores")
@RequestMapping(value = "/versions/expired", method = RequestMethod.GET)
public List<String> listExpiredVersions() {
return jdbcTemplate.queryForList(
@ -128,27 +144,36 @@ public class MDStoreController {
}
@Transactional
@ApiOperation(value = "Delete a mdstore version")
@RequestMapping(value = "/version/{versionId}", method = RequestMethod.DELETE)
public void deleteVersion(@PathVariable final String versionId) throws MDStoreManagerException {
_deleteVersion(versionId);
public void deleteVersion(@ApiParam("the id of the version that has to be deleted") @PathVariable final String versionId,
@ApiParam("if true, the controls on writing and readcount values will be skipped") @RequestParam(required = false, defaultValue = "false") final boolean force)
throws MDStoreManagerException {
_deleteVersion(versionId, force);
}
@Transactional
@ApiOperation(value = "Delete multiple mdstore versions")
@RequestMapping(value = "/versions/deleteList", method = RequestMethod.POST)
public void deleteVersions(@RequestBody final List<String> versions) throws MDStoreManagerException {
public void deleteVersions(@ApiParam("the list of ids of the versions that have to be deleted") @RequestBody final List<String> versions,
@ApiParam("if true, the controls on writing and readcount values will be skipped") @RequestParam(required = false, defaultValue = "false") final boolean force)
throws MDStoreManagerException {
for (final String v : versions) {
_deleteVersion(v);
_deleteVersion(v, force);
}
}
private void _deleteVersion(final String versionId) throws MDStoreManagerException {
private void _deleteVersion(final String versionId, final boolean force) throws MDStoreManagerException {
final MDStoreVersion v = mdstoreVersionRepository.findById(versionId).orElseThrow(() -> new MDStoreManagerException("Version not found"));
if (v.isWriting()) { throw new MDStoreManagerException("I cannot delete this version because it is in write mode"); }
if (v.getReadCount() > 0) { throw new MDStoreManagerException("I cannot delete this version because it is in read mode"); }
if (mdstoreCurrentVersionRepository
.countByCurrentVersion(versionId) > 0) { throw new MDStoreManagerException("I cannot delete this version because it is the current version"); }
if (!force) {
if (v.isWriting()) { throw new MDStoreManagerException("I cannot delete this version because it is in write mode"); }
if (v.getReadCount() > 0) { throw new MDStoreManagerException("I cannot delete this version because it is in read mode"); }
}
mdstoreVersionRepository.delete(v);
}

View File

@ -37,9 +37,9 @@ public class MDStoreVersion implements Serializable {
private Date lastUpdate;
@Column(name = "size")
private int size;
private long size;
public static MDStoreVersion newInstance(final String mdId, boolean writing) {
public static MDStoreVersion newInstance(final String mdId, final boolean writing) {
final MDStoreVersion t = new MDStoreVersion();
t.setId(mdId + "-" + new Date().getTime());
t.setMdstore(mdId);
@ -54,7 +54,7 @@ public class MDStoreVersion implements Serializable {
return id;
}
public void setId(String id) {
public void setId(final String id) {
this.id = id;
}
@ -62,7 +62,7 @@ public class MDStoreVersion implements Serializable {
return mdstore;
}
public void setMdstore(String mdstore) {
public void setMdstore(final String mdstore) {
this.mdstore = mdstore;
}
@ -70,7 +70,7 @@ public class MDStoreVersion implements Serializable {
return writing;
}
public void setWriting(boolean writing) {
public void setWriting(final boolean writing) {
this.writing = writing;
}
@ -78,7 +78,7 @@ public class MDStoreVersion implements Serializable {
return readCount;
}
public void setReadCount(int readCount) {
public void setReadCount(final int readCount) {
this.readCount = readCount;
}
@ -86,15 +86,15 @@ public class MDStoreVersion implements Serializable {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
public void setLastUpdate(final Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public int getSize() {
public long getSize() {
return size;
}
public void setSize(int size) {
public void setSize(final long size) {
this.size = size;
}

View File

@ -46,13 +46,13 @@ public class MDStoreWithInfo implements Serializable {
private Date lastUpdate;
@Column(name = "size")
private int size;
private long size;
public String getId() {
return id;
}
public void setId(String id) {
public void setId(final String id) {
this.id = id;
}
@ -60,7 +60,7 @@ public class MDStoreWithInfo implements Serializable {
return format;
}
public void setFormat(String format) {
public void setFormat(final String format) {
this.format = format;
}
@ -68,7 +68,7 @@ public class MDStoreWithInfo implements Serializable {
return layout;
}
public void setLayout(String layout) {
public void setLayout(final String layout) {
this.layout = layout;
}
@ -76,7 +76,7 @@ public class MDStoreWithInfo implements Serializable {
return interpretation;
}
public void setInterpretation(String interpretation) {
public void setInterpretation(final String interpretation) {
this.interpretation = interpretation;
}
@ -84,7 +84,7 @@ public class MDStoreWithInfo implements Serializable {
return datasourceId;
}
public void setDatasourceId(String datasourceId) {
public void setDatasourceId(final String datasourceId) {
this.datasourceId = datasourceId;
}
@ -92,7 +92,7 @@ public class MDStoreWithInfo implements Serializable {
return apiId;
}
public void setApiId(String apiId) {
public void setApiId(final String apiId) {
this.apiId = apiId;
}
@ -100,7 +100,7 @@ public class MDStoreWithInfo implements Serializable {
return currentVersion;
}
public void setCurrentVersion(String currentVersion) {
public void setCurrentVersion(final String currentVersion) {
this.currentVersion = currentVersion;
}
@ -108,17 +108,16 @@ public class MDStoreWithInfo implements Serializable {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
public void setLastUpdate(final Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public int getSize() {
public long getSize() {
return size;
}
public void setSize(int size) {
public void setSize(final long size) {
this.size = size;
}
}

View File

@ -18,7 +18,7 @@ CREATE TABLE mdstore_versions (
writing boolean,
readcount int,
lastupdate timestamp,
size int
size bigint
);
CREATE TABLE mdstore_current_versions (