130 lines
5.5 KiB
Java
130 lines
5.5 KiB
Java
|
package eu.dnetlib.data.mdstore;
|
||
|
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||
|
|
||
|
import eu.dnetlib.common.controller.AbstractDnetController;
|
||
|
import eu.dnetlib.dhp.schema.mdstore.MDStoreVersion;
|
||
|
import eu.dnetlib.dhp.schema.mdstore.MDStoreWithInfo;
|
||
|
import eu.dnetlib.errors.MDStoreManagerException;
|
||
|
import io.swagger.v3.oas.annotations.Operation;
|
||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||
|
|
||
|
public class AbstractMDStoreController extends AbstractDnetController {
|
||
|
|
||
|
@Autowired
|
||
|
protected MDStoreService service;
|
||
|
|
||
|
@Operation(summary = "Return all the mdstores")
|
||
|
@GetMapping("/")
|
||
|
public Iterable<MDStoreWithInfo> find() {
|
||
|
return service.listMdStores();
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Return a mdstores by id")
|
||
|
@GetMapping("/mdstore/{mdId}")
|
||
|
public MDStoreWithInfo getMdStore(@Parameter(name = "the mdstore identifier") @PathVariable final String mdId) throws MDStoreManagerException {
|
||
|
return service.findMdStore(mdId);
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Increase the read count of the current mdstore")
|
||
|
@GetMapping("/mdstore/{mdId}/startReading")
|
||
|
public MDStoreVersion startReading(@Parameter(name = "the mdstore identifier") @PathVariable final String mdId) throws MDStoreManagerException {
|
||
|
return service.startReading(mdId);
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Create a new mdstore")
|
||
|
@PostMapping("/new/{format}/{layout}/{interpretation}")
|
||
|
public MDStoreWithInfo createMDStore(
|
||
|
@Parameter(name = "mdstore format") @PathVariable final String format,
|
||
|
@Parameter(name = "mdstore layout") @PathVariable final String layout,
|
||
|
@Parameter(name = "mdstore interpretation") @PathVariable final String interpretation,
|
||
|
@Parameter(name = "datasource name") @RequestParam(required = true) final String dsName,
|
||
|
@Parameter(name = "datasource id") @RequestParam(required = true) final String dsId,
|
||
|
@Parameter(name = "api id") @RequestParam(required = true) final String apiId) throws MDStoreManagerException {
|
||
|
final String id = service.createMDStore(format, layout, interpretation, dsName, dsId, apiId);
|
||
|
return service.findMdStore(id);
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Delete a mdstore by id")
|
||
|
@DeleteMapping("/mdstore/{mdId}")
|
||
|
public StatusResponse delete(@Parameter(name = "the id of the mdstore that will be deleted") @PathVariable final String mdId)
|
||
|
throws MDStoreManagerException {
|
||
|
service.deleteMdStore(mdId);
|
||
|
|
||
|
return StatusResponse.DELETED;
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Return all the versions of a mdstore")
|
||
|
@GetMapping("/mdstore/{mdId}/versions")
|
||
|
public Iterable<MDStoreVersion> listVersions(@PathVariable final String mdId) throws MDStoreManagerException {
|
||
|
return service.listVersions(mdId);
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Create a new preliminary version of a mdstore")
|
||
|
@GetMapping("/mdstore/{mdId}/newVersion")
|
||
|
public MDStoreVersion prepareNewVersion(
|
||
|
@Parameter(name = "the id of the mdstore for which will be created a new version") @PathVariable final String mdId) {
|
||
|
return service.prepareMdStoreVersion(mdId);
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Promote a preliminary version to current")
|
||
|
@GetMapping("/version/{versionId}/commit/{size}")
|
||
|
public MDStoreVersion commitVersion(
|
||
|
@Parameter(name = "the id of the version that will be promoted to the current version") @PathVariable final String versionId,
|
||
|
@Parameter(name = "the size of the new current mdstore") @PathVariable final long size) throws MDStoreManagerException {
|
||
|
try {
|
||
|
return service.commitMdStoreVersion(versionId, size);
|
||
|
} finally {
|
||
|
service.deleteExpiredVersions();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Abort a preliminary version")
|
||
|
@GetMapping("/version/{versionId}/abort")
|
||
|
public StatusResponse commitVersion(@Parameter(name = "the id of the version to abort") @PathVariable final String versionId)
|
||
|
throws MDStoreManagerException {
|
||
|
|
||
|
service.deleteMdStoreVersion(versionId, true);
|
||
|
|
||
|
return StatusResponse.ABORTED;
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Return an existing mdstore version")
|
||
|
@GetMapping("/version/{versionId}")
|
||
|
public MDStoreVersion getVersion(@Parameter(name = "the id of the version that has to be deleted") @PathVariable final String versionId)
|
||
|
throws MDStoreManagerException {
|
||
|
return service.findVersion(versionId);
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Delete a mdstore version")
|
||
|
@DeleteMapping("/version/{versionId}")
|
||
|
public StatusResponse deleteVersion(@Parameter(name = "the id of the version that has to be deleted") @PathVariable final String versionId,
|
||
|
@Parameter(name = "if true, the controls on writing and readcount values will be skipped") @RequestParam(required = false, defaultValue = "false") final boolean force)
|
||
|
throws MDStoreManagerException {
|
||
|
|
||
|
service.deleteMdStoreVersion(versionId, force);
|
||
|
|
||
|
return StatusResponse.DELETED;
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Decrease the read count of a mdstore version")
|
||
|
@GetMapping("/version/{versionId}/endReading")
|
||
|
public MDStoreVersion endReading(@Parameter(name = "the id of the version that has been completely read") @PathVariable final String versionId)
|
||
|
throws MDStoreManagerException {
|
||
|
return service.endReading(versionId);
|
||
|
}
|
||
|
|
||
|
@Operation(summary = "Reset the read count of a mdstore version")
|
||
|
@GetMapping("/version/{versionId}/resetReading")
|
||
|
public MDStoreVersion resetReading(@Parameter(name = "the id of the version") @PathVariable final String versionId)
|
||
|
throws MDStoreManagerException {
|
||
|
return service.resetReading(versionId);
|
||
|
}
|
||
|
|
||
|
}
|