dnet-applications/apps/dnet-is-application/src/main/java/eu/dnetlib/data/mdstore/AbstractMDStoreController.java

125 lines
4.4 KiB
Java
Raw Normal View History

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;
2023-02-10 10:27:09 +01:00
import eu.dnetlib.data.mdstore.model.MDStoreType;
import eu.dnetlib.data.mdstore.model.MDStoreVersion;
import eu.dnetlib.data.mdstore.model.MDStoreWithInfo;
2023-02-07 11:22:20 +01:00
import eu.dnetlib.errors.MDStoreManagerException;
import io.swagger.v3.oas.annotations.Operation;
public class AbstractMDStoreController extends AbstractDnetController {
@Autowired
2023-02-10 10:27:09 +01:00
protected MDStoreService service;
2023-02-07 11:22:20 +01:00
@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")
2023-02-10 10:27:09 +01:00
@PostMapping("/new/{format}/{layout}/{interpretation}/{type}")
2023-02-07 11:22:20 +01:00
public MDStoreWithInfo createMDStore(
2023-02-08 12:23:53 +01:00
@PathVariable final String format,
@PathVariable final String layout,
@PathVariable final String interpretation,
2023-02-10 10:27:09 +01:00
@PathVariable final String type,
2023-02-08 12:23:53 +01:00
@RequestParam(required = true) final String dsName,
@RequestParam(required = true) final String dsId,
@RequestParam(required = true) final String apiId) throws MDStoreManagerException {
2023-02-10 10:27:09 +01:00
final String id = service.createMDStore(format, layout, interpretation, MDStoreType.valueOf(type), dsName, dsId, apiId);
2023-02-07 11:22:20 +01:00
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-10 10:27:09 +01:00
@PathVariable final String mdId) throws MDStoreManagerException {
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);
}
}