2023-02-07 11:22:20 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
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}")
|
2023-02-08 12:23:53 +01:00
|
|
|
public MDStoreWithInfo getMdStore(@PathVariable final String mdId) throws MDStoreManagerException {
|
2023-02-07 11:22:20 +01:00
|
|
|
return service.findMdStore(mdId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Create a new mdstore")
|
|
|
|
@PostMapping("/new/{format}/{layout}/{interpretation}")
|
|
|
|
public MDStoreWithInfo createMDStore(
|
2023-02-08 12:23:53 +01:00
|
|
|
@PathVariable final String format,
|
|
|
|
@PathVariable final String layout,
|
|
|
|
@PathVariable final String interpretation,
|
|
|
|
@RequestParam(required = true) final String dsName,
|
|
|
|
@RequestParam(required = true) final String dsId,
|
|
|
|
@RequestParam(required = true) final String apiId) throws MDStoreManagerException {
|
2023-02-07 11:22:20 +01:00
|
|
|
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}")
|
2023-02-08 12:23:53 +01:00
|
|
|
public StatusResponse delete(@PathVariable final String mdId)
|
2023-02-07 11:22:20 +01:00
|
|
|
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(
|
2023-02-08 12:23:53 +01:00
|
|
|
@PathVariable final String mdId) {
|
2023-02-07 11:22:20 +01:00
|
|
|
return service.prepareMdStoreVersion(mdId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Promote a preliminary version to current")
|
|
|
|
@GetMapping("/version/{versionId}/commit/{size}")
|
|
|
|
public MDStoreVersion commitVersion(
|
2023-02-08 12:23:53 +01:00
|
|
|
@PathVariable final String versionId,
|
|
|
|
@PathVariable final long size) throws MDStoreManagerException {
|
2023-02-07 11:22:20 +01:00
|
|
|
try {
|
|
|
|
return service.commitMdStoreVersion(versionId, size);
|
|
|
|
} finally {
|
|
|
|
service.deleteExpiredVersions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Abort a preliminary version")
|
|
|
|
@GetMapping("/version/{versionId}/abort")
|
2023-02-08 12:23:53 +01:00
|
|
|
public StatusResponse commitVersion(@PathVariable final String versionId)
|
2023-02-07 11:22:20 +01:00
|
|
|
throws MDStoreManagerException {
|
|
|
|
|
|
|
|
service.deleteMdStoreVersion(versionId, true);
|
|
|
|
|
|
|
|
return StatusResponse.ABORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Return an existing mdstore version")
|
|
|
|
@GetMapping("/version/{versionId}")
|
2023-02-08 12:23:53 +01:00
|
|
|
public MDStoreVersion getVersion(@PathVariable final String versionId)
|
2023-02-07 11:22:20 +01:00
|
|
|
throws MDStoreManagerException {
|
|
|
|
return service.findVersion(versionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Delete a mdstore version")
|
|
|
|
@DeleteMapping("/version/{versionId}")
|
2023-02-08 12:23:53 +01:00
|
|
|
public StatusResponse deleteVersion(@PathVariable final String versionId,
|
|
|
|
@RequestParam(required = false, defaultValue = "false") final boolean force)
|
2023-02-07 11:22:20 +01:00
|
|
|
throws MDStoreManagerException {
|
|
|
|
|
|
|
|
service.deleteMdStoreVersion(versionId, force);
|
|
|
|
|
|
|
|
return StatusResponse.DELETED;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Decrease the read count of a mdstore version")
|
|
|
|
@GetMapping("/version/{versionId}/endReading")
|
2023-02-08 12:23:53 +01:00
|
|
|
public MDStoreVersion endReading(@PathVariable final String versionId) throws MDStoreManagerException {
|
2023-02-07 11:22:20 +01:00
|
|
|
return service.endReading(versionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Operation(summary = "Reset the read count of a mdstore version")
|
|
|
|
@GetMapping("/version/{versionId}/resetReading")
|
2023-02-08 12:23:53 +01:00
|
|
|
public MDStoreVersion resetReading(@PathVariable final String versionId) throws MDStoreManagerException {
|
2023-02-07 11:22:20 +01:00
|
|
|
return service.resetReading(versionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|