Refactor the Datasets endpoint
This commit is contained in:
parent
8b77ab759a
commit
a6a7b2bdce
|
@ -41,15 +41,6 @@ public class DatasetProfileController extends BaseController {
|
|||
super(apiContext);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/datasetwizard/get/{id}"}, produces = "application/json")
|
||||
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getSingle(@PathVariable String id) {
|
||||
eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
||||
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(profile);
|
||||
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
||||
pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PagedDatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/save/{id}"}, consumes = "application/json", produces = "application/json")
|
||||
public ResponseEntity<Object> updateDataset(@PathVariable String id, @RequestBody PropertiesModel properties) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocom
|
|||
import eu.eudat.exceptions.datasetwizard.DatasetWizardCannotUnlockException;
|
||||
import eu.eudat.logic.managers.DatasetManager;
|
||||
import eu.eudat.logic.managers.DatasetWizardManager;
|
||||
import eu.eudat.logic.managers.UserManager;
|
||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||
|
@ -14,6 +15,7 @@ import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|||
import eu.eudat.models.data.dmp.AssociatedProfile;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -42,11 +44,13 @@ import static eu.eudat.types.Authorities.ANONYMOUS;
|
|||
public class DatasetWizardController extends BaseController {
|
||||
|
||||
private Environment environment;
|
||||
private DatasetManager datasetManager;
|
||||
|
||||
@Autowired
|
||||
public DatasetWizardController(ApiContext apiContext, Environment environment) {
|
||||
public DatasetWizardController(ApiContext apiContext, Environment environment, DatasetManager datasetManager) {
|
||||
super(apiContext);
|
||||
this.environment = environment;
|
||||
this.datasetManager = datasetManager;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/userDmps"}, produces = "application/json")
|
||||
|
@ -66,15 +70,23 @@ public class DatasetWizardController extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DatasetWizardModel>> getSingle(@PathVariable String id, @ClaimedAuthorities(claims = {ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException {
|
||||
DatasetWizardModel dataset = new DatasetManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatasetRepository(), id);
|
||||
DatasetWizardModel dataset = this.datasetManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatasetRepository(), id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/createOrUpdate"}, consumes = "application/json", produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> delete(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
||||
new DatasetWizardManager().delete(this.getApiContext(), id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted"));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) throws Exception {
|
||||
eu.eudat.data.entities.Dataset dataset = DatasetManager.createOrUpdate(this.getApiContext(), profile, principal);
|
||||
this.datasetManager.createOrUpdate(this.getApiContext(), profile, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(null));
|
||||
}
|
||||
|
||||
|
@ -119,6 +131,15 @@ public class DatasetWizardController extends BaseController {
|
|||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json")
|
||||
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getSingle(@PathVariable String id) {
|
||||
eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
||||
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(profile);
|
||||
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
||||
pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PagedDatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/{id}/unlock"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
|
@ -130,12 +151,4 @@ public class DatasetWizardController extends BaseController {
|
|||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Dataset>().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> delete(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
||||
new DatasetWizardManager().delete(this.getApiContext(), id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,33 +24,36 @@ import java.util.UUID;
|
|||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = {"/api"})
|
||||
@RequestMapping(value = {"/api/datasets/"})
|
||||
public class Datasets extends BaseController {
|
||||
|
||||
private DatasetManager datasetManager;
|
||||
|
||||
@Autowired
|
||||
public Datasets(ApiContext apiContext) {
|
||||
public Datasets(ApiContext apiContext, DatasetManager datasetManager) {
|
||||
super(apiContext);
|
||||
this.datasetManager = datasetManager;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/datasets/getPaged"}, consumes = "application/json", produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"paged"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
||||
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal);
|
||||
DataTableData<DatasetListingModel> dataTable = this.datasetManager.getPaged(this.getApiContext(), datasetTableRequest, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/datasets/public/paged"}, consumes = "application/json", produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPublicPaged(@RequestBody DatasetPublicTableRequest datasetTableRequest, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception {
|
||||
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal);
|
||||
DataTableData<DatasetListingModel> dataTable = this.datasetManager.getPaged(this.getApiContext(), datasetTableRequest, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/datasets/makepublic/{id}"}, produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/makepublic/{id}"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> makePublic(@PathVariable UUID id, Principal principal, Locale locale) throws Exception {
|
||||
DatasetManager.makePublic(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
|
||||
this.datasetManager.makePublic(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getHelpersService().getMessageSource().getMessage("dataset.public", new Object[]{}, locale)));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.springframework.core.env.Environment;
|
|||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
|
@ -42,7 +43,7 @@ import java.util.stream.Collectors;
|
|||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
||||
@Component
|
||||
public class DatasetManager {
|
||||
|
||||
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
||||
|
@ -239,7 +240,7 @@ public class DatasetManager {
|
|||
return newFile;
|
||||
}
|
||||
|
||||
public static eu.eudat.data.entities.Dataset createOrUpdate(ApiContext apiContext, DatasetWizardModel datasetWizardModel, Principal principal) throws Exception {
|
||||
public eu.eudat.data.entities.Dataset createOrUpdate(ApiContext apiContext, DatasetWizardModel datasetWizardModel, Principal principal) throws Exception {
|
||||
eu.eudat.data.entities.Dataset dataset = datasetWizardModel.toDataModel();
|
||||
propertiesModelToString(datasetWizardModel, dataset);
|
||||
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||
|
@ -252,7 +253,7 @@ public class DatasetManager {
|
|||
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
|
||||
}
|
||||
|
||||
private static void propertiesModelToString(DatasetWizardModel datasetWizardModel, eu.eudat.data.entities.Dataset dataset) {
|
||||
private void propertiesModelToString(DatasetWizardModel datasetWizardModel, eu.eudat.data.entities.Dataset dataset) {
|
||||
Map<String, Object> values = new HashMap();
|
||||
PagedDatasetProfile properties = datasetWizardModel.getDatasetProfileDefinition();
|
||||
properties.toMap(values);
|
||||
|
@ -260,7 +261,7 @@ public class DatasetManager {
|
|||
dataset.setProperties(jobject.toString());
|
||||
}
|
||||
|
||||
private static void updateTags(DatasetRepository datasetRepository, DatasetWizardModel datasetWizardModel) throws IOException {
|
||||
private void updateTags(DatasetRepository datasetRepository, DatasetWizardModel datasetWizardModel) throws IOException {
|
||||
if (datasetWizardModel.getTags() != null && !datasetWizardModel.getTags().isEmpty()) {
|
||||
eu.eudat.elastic.entities.Dataset dataset = new eu.eudat.elastic.entities.Dataset();
|
||||
dataset.setId(datasetWizardModel.getId().toString());
|
||||
|
@ -269,7 +270,7 @@ public class DatasetManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createRegistriesIfTheyDontExist(RegistryDao registryDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
private void createRegistriesIfTheyDontExist(RegistryDao registryDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
if (dataset.getRegistries() != null && !dataset.getRegistries().isEmpty()) {
|
||||
for (eu.eudat.data.entities.Registry registry : dataset.getRegistries()) {
|
||||
RegistryCriteria criteria = new RegistryCriteria();
|
||||
|
@ -281,7 +282,7 @@ public class DatasetManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createDataRepositoriesIfTheyDontExist(DataRepositoryDao dataRepositoryDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
private void createDataRepositoriesIfTheyDontExist(DataRepositoryDao dataRepositoryDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
Set<DatasetDataRepository> datasetDataRepositories = dataset.getDatasetDataRepositories();
|
||||
dataset.setDatasetDataRepositories(new HashSet<>());
|
||||
|
||||
|
@ -304,7 +305,7 @@ public class DatasetManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createServicesIfTheyDontExist(DatasetServiceDao datasetServiceDao, ServiceDao serviceDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
private void createServicesIfTheyDontExist(DatasetServiceDao datasetServiceDao, ServiceDao serviceDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
Set<DatasetService> services = dataset.getServices();
|
||||
dataset.setServices(new HashSet<>());
|
||||
if (services != null && !services.isEmpty()) {
|
||||
|
@ -325,7 +326,7 @@ public class DatasetManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void createExternalDatasetsIfTheyDontExist(DatasetExternalDatasetDao datasetExternalDatasetDao, ExternalDatasetDao externalDatasetDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
private void createExternalDatasetsIfTheyDontExist(DatasetExternalDatasetDao datasetExternalDatasetDao, ExternalDatasetDao externalDatasetDao, eu.eudat.data.entities.Dataset dataset) {
|
||||
Set<DatasetExternalDataset> externalDatasets = dataset.getDatasetExternalDatasets();
|
||||
dataset.setDatasetExternalDatasets(new HashSet<>());
|
||||
if (externalDatasets != null && !externalDatasets.isEmpty()) {
|
||||
|
@ -346,7 +347,7 @@ public class DatasetManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static void makePublic(DatasetDao datasetDao, UUID id) throws Exception {
|
||||
public void makePublic(DatasetDao datasetDao, UUID id) throws Exception {
|
||||
eu.eudat.data.entities.Dataset dataset = datasetDao.find(id);
|
||||
if (dataset.getStatus() != eu.eudat.data.entities.Dataset.Status.FINALISED.getValue())
|
||||
throw new Exception("You cannot make public a Dataset That Has not Been Finalised");
|
||||
|
|
|
@ -21,9 +21,9 @@ export class DatasetWizardService {
|
|||
this.actionUrl = environment.Server + 'datasetwizard/';
|
||||
}
|
||||
|
||||
public userDmps(criteria: RequestItem<DmpCriteria>): Observable<DmpModel[]> {
|
||||
return this.http.post<DmpModel[]>(this.actionUrl + 'userDmps', criteria, { headers: this.headers });
|
||||
}
|
||||
// public userDmps(criteria: RequestItem<DmpCriteria>): Observable<DmpModel[]> {
|
||||
// return this.http.post<DmpModel[]>(this.actionUrl + 'userDmps', criteria, { headers: this.headers });
|
||||
// }
|
||||
|
||||
public getAvailableProfiles(criteria: RequestItem<DatasetProfileCriteria>): Observable<DatasetProfileModel[]> {
|
||||
return this.http.post<DatasetProfileModel[]>(this.actionUrl + 'getAvailableProfiles/', criteria, { headers: this.headers });
|
||||
|
@ -34,11 +34,11 @@ export class DatasetWizardService {
|
|||
}
|
||||
|
||||
public delete(id: string): Observable<DatasetWizardModel> {
|
||||
return this.http.delete<DatasetWizardModel>(this.actionUrl + 'delete/' + id, { headers: this.headers });
|
||||
return this.http.delete<DatasetWizardModel>(this.actionUrl + id, { headers: this.headers });
|
||||
}
|
||||
|
||||
createDataset(datasetModel: DatasetWizardModel): Observable<DatasetWizardModel> {
|
||||
return this.http.post<DatasetWizardModel>(this.actionUrl + 'createOrUpdate', datasetModel, { headers: this.headers });
|
||||
return this.http.post<DatasetWizardModel>(this.actionUrl, datasetModel, { headers: this.headers });
|
||||
}
|
||||
|
||||
public downloadPDF(id: string): Observable<HttpResponse<Blob>> {
|
||||
|
|
|
@ -19,7 +19,7 @@ export class DatasetService {
|
|||
}
|
||||
|
||||
getPaged(dataTableRequest: DataTableRequest<DatasetCriteria>): Observable<DataTableData<DatasetListingModel>> {
|
||||
return this.http.post<DataTableData<DatasetListingModel>>(this.actionUrl + 'getPaged', dataTableRequest);
|
||||
return this.http.post<DataTableData<DatasetListingModel>>(this.actionUrl + 'paged', dataTableRequest);
|
||||
}
|
||||
|
||||
getPublicPaged(dataTableRequest: DataTableRequest<ExploreDatasetCriteriaModel>): Observable<DataTableData<DatasetListingModel>> {
|
||||
|
|
Loading…
Reference in New Issue