2017-12-15 00:01:26 +01:00
package eu.eudat.controllers ;
2017-10-04 11:48:21 +02:00
2018-03-21 11:57:56 +01:00
import eu.eudat.data.entities.Dataset ;
2020-07-15 11:33:10 +02:00
import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest ;
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest ;
2018-10-02 16:33:58 +02:00
import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest ;
2018-03-21 13:11:02 +01:00
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest ;
2019-06-12 11:10:46 +02:00
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem ;
2020-07-15 11:33:10 +02:00
import eu.eudat.exceptions.datasetwizard.DatasetWizardCannotUnlockException ;
2020-07-03 15:11:54 +02:00
import eu.eudat.exceptions.security.UnauthorisedException ;
2018-08-30 13:09:36 +02:00
import eu.eudat.logic.managers.DatasetManager ;
2020-07-03 15:11:54 +02:00
import eu.eudat.logic.managers.DatasetWizardManager ;
2022-03-16 11:14:08 +01:00
import eu.eudat.logic.managers.FileManager ;
2020-07-15 11:33:10 +02:00
import eu.eudat.logic.managers.UserManager ;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader ;
2018-08-30 13:09:36 +02:00
import eu.eudat.logic.security.claims.ClaimedAuthorities ;
import eu.eudat.logic.services.ApiContext ;
2020-07-15 11:33:10 +02:00
import eu.eudat.logic.services.forms.VisibilityRuleService ;
2022-02-09 14:23:16 +01:00
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl ;
2020-07-15 11:33:10 +02:00
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope ;
2021-10-12 17:17:16 +02:00
import eu.eudat.logic.utilities.documents.pdf.PDFUtils ;
2020-07-03 15:11:54 +02:00
import eu.eudat.models.data.dataset.DatasetOverviewModel ;
2019-06-12 11:10:46 +02:00
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel ;
2020-07-15 11:33:10 +02:00
import eu.eudat.models.data.datasetwizard.DataManagentPlanListingModel ;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel ;
import eu.eudat.models.data.dmp.AssociatedProfile ;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.helpers.common.DataTableData ;
import eu.eudat.models.data.helpers.responses.ResponseItem ;
2020-07-15 11:33:10 +02:00
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel ;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.listingmodels.DatasetListingModel ;
import eu.eudat.models.data.security.Principal ;
2020-07-15 11:33:10 +02:00
import eu.eudat.models.data.user.composite.PagedDatasetProfile ;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode ;
2018-08-30 13:09:36 +02:00
import eu.eudat.types.Authorities ;
2020-07-15 11:33:10 +02:00
import org.apache.poi.util.IOUtils ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2017-10-04 11:48:21 +02:00
import org.springframework.beans.factory.annotation.Autowired ;
2020-07-15 11:33:10 +02:00
import org.springframework.core.env.Environment ;
import org.springframework.http.HttpHeaders ;
2017-10-04 11:48:21 +02:00
import org.springframework.http.HttpStatus ;
2020-07-15 11:33:10 +02:00
import org.springframework.http.MediaType ;
2017-10-04 11:48:21 +02:00
import org.springframework.http.ResponseEntity ;
2018-02-16 11:34:02 +01:00
import org.springframework.web.bind.annotation.* ;
2020-07-15 11:33:10 +02:00
import org.springframework.web.multipart.MultipartFile ;
2018-02-16 11:34:02 +01:00
2020-07-15 11:33:10 +02:00
import javax.persistence.NoResultException ;
2021-11-23 13:05:57 +01:00
import javax.transaction.Transactional ;
2020-07-15 11:33:10 +02:00
import java.io.File ;
import java.io.FileInputStream ;
import java.io.IOException ;
import java.io.InputStream ;
import java.nio.file.Files ;
import java.util.List ;
2018-02-16 11:34:02 +01:00
import java.util.Locale ;
import java.util.UUID ;
2017-10-04 11:48:21 +02:00
2020-07-15 11:33:10 +02:00
import static eu.eudat.types.Authorities.ANONYMOUS ;
2017-10-04 11:48:21 +02:00
@RestController
@CrossOrigin
2019-01-31 16:53:37 +01:00
@RequestMapping ( value = { " /api/datasets/ " } )
2018-01-12 09:05:44 +01:00
public class Datasets extends BaseController {
2020-07-15 11:33:10 +02:00
private static final Logger logger = LoggerFactory . getLogger ( Datasets . class ) ;
2017-12-15 13:25:21 +01:00
2020-07-15 11:33:10 +02:00
private Environment environment ;
2019-01-31 16:53:37 +01:00
private DatasetManager datasetManager ;
2020-07-15 11:33:10 +02:00
private ConfigLoader configLoader ;
private UserManager userManager ;
2022-03-16 11:14:08 +01:00
private FileManager fileManager ;
2019-01-31 16:53:37 +01:00
2018-01-12 09:05:44 +01:00
@Autowired
2022-03-16 11:14:08 +01:00
public Datasets ( ApiContext apiContext , Environment environment , DatasetManager datasetManager , ConfigLoader configLoader , UserManager userManager ,
FileManager fileManager ) {
2018-01-12 09:05:44 +01:00
super ( apiContext ) ;
2020-07-15 11:33:10 +02:00
this . environment = environment ;
2019-01-31 16:53:37 +01:00
this . datasetManager = datasetManager ;
2020-07-15 11:33:10 +02:00
this . configLoader = configLoader ;
this . userManager = userManager ;
2022-03-16 11:14:08 +01:00
this . fileManager = fileManager ;
2018-01-12 09:05:44 +01:00
}
2017-12-15 13:25:21 +01:00
2020-07-15 11:33:10 +02:00
/ *
* Data Retrieval
* * /
2019-01-31 16:53:37 +01:00
@RequestMapping ( method = RequestMethod . POST , value = { " paged " } , consumes = " application/json " , produces = " application/json " )
2018-01-24 15:11:09 +01:00
public @ResponseBody
2020-03-16 17:50:29 +01:00
ResponseEntity < ResponseItem < DataTableData < DatasetListingModel > > > getPaged ( @RequestBody DatasetTableRequest datasetTableRequest , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
2019-03-05 16:33:59 +01:00
DataTableData < DatasetListingModel > dataTable = this . datasetManager . getPaged ( datasetTableRequest , principal ) ;
2018-10-02 16:33:58 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataTableData < DatasetListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataTable ) ) ;
}
2019-01-31 16:53:37 +01:00
@RequestMapping ( method = RequestMethod . POST , value = { " /public/paged " } , consumes = " application/json " , produces = " application/json " )
2018-10-02 16:33:58 +02:00
public @ResponseBody
2019-09-26 17:33:41 +02:00
ResponseEntity < ResponseItem < DataTableData < DatasetListingModel > > > getPublicPaged ( @RequestBody DatasetPublicTableRequest datasetTableRequest ,
@ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
2019-03-05 16:33:59 +01:00
DataTableData < DatasetListingModel > dataTable = this . datasetManager . getPaged ( datasetTableRequest , principal ) ;
2018-08-31 16:12:31 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataTableData < DatasetListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataTable ) ) ;
2018-01-12 09:05:44 +01:00
}
2017-12-15 13:25:21 +01:00
2020-07-03 15:11:54 +02:00
@RequestMapping ( method = RequestMethod . GET , value = { " /overview/{id} " } )
public @ResponseBody
ResponseEntity getOverviewSingle ( @PathVariable String id , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) {
try {
DatasetOverviewModel dataset = this . datasetManager . getOverviewSingle ( id , principal , false ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DatasetOverviewModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataset ) ) ;
} catch ( Exception e ) {
if ( e instanceof UnauthorisedException ) {
return ResponseEntity . status ( HttpStatus . FORBIDDEN ) . body ( new ResponseItem < DatasetOverviewModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
} else {
return ResponseEntity . status ( HttpStatus . NOT_FOUND ) . body ( new ResponseItem < DatasetOverviewModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
}
}
}
@RequestMapping ( method = RequestMethod . GET , value = { " /publicOverview/{id} " } )
public @ResponseBody
ResponseEntity getOverviewSinglePublic ( @PathVariable String id , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
// try {
DatasetOverviewModel dataset = this . datasetManager . getOverviewSingle ( id , principal , true ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DatasetOverviewModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataset ) ) ;
// } catch (Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
// }
}
2021-11-23 13:05:57 +01:00
@Transactional
2020-07-15 11:33:10 +02:00
@RequestMapping ( method = RequestMethod . GET , value = { " {id} " } , produces = " application/json " )
public @ResponseBody
ResponseEntity getSingle ( @PathVariable String id , @RequestHeader ( " Content-Type " ) String contentType , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws IllegalAccessException , IOException , InstantiationException {
try {
2022-02-09 14:23:16 +01:00
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl ( ) ;
2020-07-15 11:33:10 +02:00
if ( contentType . equals ( " application/xml " ) ) {
return this . datasetManager . getDocument ( id , visibilityRuleService , contentType , principal ) ;
} else if ( contentType . equals ( " application/msword " ) ) {
2022-02-09 14:23:16 +01:00
FileEnvelope file = datasetManager . getWordDocumentFile ( this . configLoader , id , visibilityRuleService , principal ) ;
2020-07-15 11:33:10 +02:00
InputStream resource = new FileInputStream ( file . getFile ( ) ) ;
HttpHeaders responseHeaders = new HttpHeaders ( ) ;
responseHeaders . setContentLength ( file . getFile ( ) . length ( ) ) ;
responseHeaders . setContentType ( MediaType . APPLICATION_OCTET_STREAM ) ;
2021-11-02 13:50:20 +01:00
String fileName = file . getFilename ( ) . replace ( " " , " _ " ) . replace ( " , " , " _ " ) ;
responseHeaders . set ( " Content-Disposition " , " attachment;filename= " + fileName ) ;
2020-07-15 11:33:10 +02:00
responseHeaders . set ( " Access-Control-Expose-Headers " , " Content-Disposition " ) ;
responseHeaders . get ( " Access-Control-Expose-Headers " ) . add ( " Content-Type " ) ;
byte [ ] content = IOUtils . toByteArray ( resource ) ;
resource . close ( ) ;
Files . deleteIfExists ( file . getFile ( ) . toPath ( ) ) ;
return new ResponseEntity < > ( content ,
responseHeaders ,
HttpStatus . OK ) ;
} else {
DatasetWizardModel dataset = this . datasetManager . getSingle ( id , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DatasetWizardModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataset ) ) ;
}
} catch ( Exception e ) {
2020-07-21 15:05:34 +02:00
logger . error ( e . getMessage ( ) , e ) ;
2020-07-15 11:33:10 +02:00
if ( e instanceof UnauthorisedException ) {
2020-07-21 15:05:34 +02:00
return ResponseEntity . status ( HttpStatus . FORBIDDEN ) . body ( new ResponseItem < DataManagementPlanOverviewModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
} else if ( e instanceof NoResultException ) {
return ResponseEntity . status ( HttpStatus . NOT_FOUND ) . body ( new ResponseItem < DataManagementPlanOverviewModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
} else {
return ResponseEntity . status ( HttpStatus . INTERNAL_SERVER_ERROR ) . body ( new ResponseItem < DataManagementPlanOverviewModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
2020-07-15 11:33:10 +02:00
}
}
}
@RequestMapping ( method = RequestMethod . POST , value = { " /datasetProfilesUsedByDatasets/paged " } , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < DataTableData < DatasetProfileListingModel > > > getUsingDatasetProfilesPaged ( @RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem , Principal principal ) {
DataTableData < DatasetProfileListingModel > datasetProfileTableData = this . datasetManager . getDatasetProfilesUsedByDatasets ( datasetProfileTableRequestItem , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataTableData < DatasetProfileListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( datasetProfileTableData ) ) ;
}
@RequestMapping ( method = RequestMethod . POST , value = { " /userDmps " } , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < List < DataManagentPlanListingModel > > > getUserDmps ( @RequestBody DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest , Principal principal ) throws IllegalAccessException , InstantiationException {
List < DataManagentPlanListingModel > dataManagementPlans = DatasetWizardManager . getUserDmps ( this . getApiContext ( ) . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) , datasetWizardAutocompleteRequest , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < List < DataManagentPlanListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataManagementPlans ) ) ;
}
@RequestMapping ( method = RequestMethod . POST , value = { " /getAvailableProfiles " } , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < List < AssociatedProfile > > > getAvailableProfiles ( @RequestBody DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest , @ClaimedAuthorities ( claims = { ANONYMOUS } ) Principal principal ) throws IllegalAccessException , InstantiationException {
2021-07-20 11:55:52 +02:00
List < AssociatedProfile > dataManagementPlans = DatasetWizardManager . getAvailableProfiles ( this . getApiContext ( ) . getOperationsContext ( ) . getDatabaseRepository ( ) . getDmpDao ( ) , this . getApiContext ( ) . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetProfileDao ( ) , datasetProfileWizardAutocompleteRequest ) ;
2020-07-15 11:33:10 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < List < AssociatedProfile > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataManagementPlans ) ) ;
}
@RequestMapping ( method = RequestMethod . GET , value = { " /public/{id} " } , produces = " application/json " )
public @ResponseBody
ResponseEntity getSinglePublic ( @PathVariable String id ) throws Exception {
try {
DatasetWizardModel dataset = this . datasetManager . getSinglePublic ( id ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DatasetWizardModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataset ) ) ;
}
catch ( Exception ex ) {
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < DatasetWizardModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . message ( ex . getMessage ( ) ) ) ;
}
}
@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 ) ) ;
}
@RequestMapping ( method = RequestMethod . GET , value = { " profile/{id} " } , produces = " application/json " )
public @ResponseBody
ResponseEntity getSingleProfileUpdate ( @PathVariable String id , @ClaimedAuthorities ( claims = { ANONYMOUS } ) Principal principal ) throws IllegalAccessException , IOException , InstantiationException {
DatasetWizardModel dataset = this . datasetManager . datasetUpdateProfile ( id ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DatasetWizardModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataset ) ) ;
}
/ *
* Data Export
* * /
@RequestMapping ( method = RequestMethod . GET , value = { " /getPDF/{id} " } )
public @ResponseBody
ResponseEntity < byte [ ] > getPDFDocument ( @PathVariable String id , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws IllegalAccessException , IOException , InstantiationException , InterruptedException {
2022-02-09 14:23:16 +01:00
FileEnvelope file = datasetManager . getWordDocumentFile ( this . configLoader , id , new VisibilityRuleServiceImpl ( ) , principal ) ;
2021-11-02 13:50:20 +01:00
String fileName = file . getFilename ( ) . replace ( " " , " _ " ) . replace ( " , " , " _ " ) ;
2020-07-15 11:33:10 +02:00
if ( fileName . endsWith ( " .docx " ) ) {
fileName = fileName . substring ( 0 , fileName . length ( ) - 5 ) ;
}
2021-10-12 17:17:16 +02:00
File pdffile = PDFUtils . convertToPDF ( file , environment ) ;
2020-07-15 11:33:10 +02:00
InputStream resource = new FileInputStream ( pdffile ) ;
HttpHeaders responseHeaders = new HttpHeaders ( ) ;
responseHeaders . setContentLength ( pdffile . length ( ) ) ;
responseHeaders . setContentType ( MediaType . APPLICATION_OCTET_STREAM ) ;
responseHeaders . set ( " Content-Disposition " , " attachment;filename= " + fileName + " .pdf " ) ;
responseHeaders . set ( " Access-Control-Expose-Headers " , " Content-Disposition " ) ;
responseHeaders . get ( " Access-Control-Expose-Headers " ) . add ( " Content-Type " ) ;
byte [ ] content = IOUtils . toByteArray ( resource ) ;
resource . close ( ) ;
Files . deleteIfExists ( file . getFile ( ) . toPath ( ) ) ;
Files . deleteIfExists ( pdffile . toPath ( ) ) ;
return new ResponseEntity < > ( content ,
responseHeaders ,
HttpStatus . OK ) ;
}
/ *
* Data Management
* * /
2021-11-23 13:05:57 +01:00
@Transactional
2020-07-15 11:33:10 +02:00
@RequestMapping ( method = RequestMethod . POST , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
2020-10-29 16:12:59 +01:00
ResponseEntity < ResponseItem < DatasetWizardModel > > createOrUpdate ( @RequestBody DatasetWizardModel profile , Principal principal ) throws Exception {
2020-11-12 15:39:47 +01:00
DatasetWizardModel dataset = new DatasetWizardModel ( ) . fromDataModel ( this . datasetManager . createOrUpdate ( profile , principal ) ) ;
2020-10-29 16:12:59 +01:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DatasetWizardModel > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Created " ) . payload ( dataset ) ) ;
2020-07-15 11:33:10 +02:00
}
2018-01-19 12:11:22 +01:00
@Transactional
2019-01-31 16:53:37 +01:00
@RequestMapping ( method = RequestMethod . GET , value = { " /makepublic/{id} " } , produces = " application/json " )
2018-01-24 15:11:09 +01:00
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity < ResponseItem < Dataset > > makePublic ( @PathVariable UUID id , Principal principal , Locale locale ) throws Exception {
2019-01-31 16:53:37 +01:00
this . datasetManager . makePublic ( this . getApiContext ( ) . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) , id ) ;
2018-08-31 16:12:31 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( this . getApiContext ( ) . getHelpersService ( ) . getMessageSource ( ) . getMessage ( " dataset.public " , new Object [ ] { } , locale ) ) ) ;
2018-01-19 12:11:22 +01:00
}
2021-11-23 13:05:57 +01:00
@Transactional
2020-07-15 11:33:10 +02:00
@RequestMapping ( method = RequestMethod . DELETE , value = { " /delete/{id} " } , produces = " application/json " )
2019-06-12 11:10:46 +02:00
public @ResponseBody
2020-07-15 11:33:10 +02:00
ResponseEntity < ResponseItem < Dataset > > delete ( @PathVariable ( value = " id " ) UUID id , Principal principal ) throws Exception {
new DatasetWizardManager ( ) . delete ( this . getApiContext ( ) , id ) ;
2022-03-16 11:14:08 +01:00
this . fileManager . markAllFilesOfEntityIdAsDeleted ( id ) ;
2020-07-15 11:33:10 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Deleted " ) ) ;
2019-06-12 11:10:46 +02:00
}
2020-03-11 10:06:43 +01:00
2021-11-23 13:05:57 +01:00
@Transactional
2020-07-15 11:33:10 +02:00
@RequestMapping ( method = RequestMethod . GET , value = { " /{id}/unlock " } , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < Dataset > > unlock ( @PathVariable ( value = " id " ) UUID id , Principal principal ) throws Exception {
try {
new DatasetWizardManager ( ) . unlock ( this . getApiContext ( ) , id ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Unlocked " ) ) ;
} catch ( DatasetWizardCannotUnlockException datasetWizardCannotUnlockException ) {
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < Dataset > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( datasetWizardCannotUnlockException . getMessage ( ) ) ) ;
}
}
2021-05-10 12:40:08 +02:00
@RequestMapping ( method = RequestMethod . GET , value = { " /{id}/validate " } , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < Boolean > > validate ( @PathVariable ( value = " id " ) UUID id , Principal principal ) throws Exception {
2022-03-29 14:11:55 +02:00
Dataset dataset = datasetManager . getEntitySingle ( id ) ;
String failedField = datasetManager . checkDatasetValidation ( dataset ) ;
if ( failedField = = null ) {
2021-05-10 12:40:08 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < Boolean > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Valid " ) ) ;
2022-03-29 14:11:55 +02:00
} else {
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < Boolean > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " Field value of " + failedField + " must be filled. " ) ) ;
2021-05-10 12:40:08 +02:00
}
}
2020-07-15 11:33:10 +02:00
/ *
* Data Import
* * /
@RequestMapping ( method = RequestMethod . POST , value = { " /upload " } )
public ResponseEntity < ResponseItem > datasetXmlImport ( @RequestParam ( " file " ) MultipartFile file , @RequestParam ( " dmpId " ) String dmpId , @RequestParam ( " datasetProfileId " ) String datasetProfileId , Principal principal ) {
try {
Dataset dataset = this . datasetManager . createDatasetFromXml ( file , dmpId , datasetProfileId , principal ) ;
if ( dataset ! = null ) {
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) ) ;
}
else {
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem ( ) . status ( ApiMessageCode . NO_MESSAGE ) . message ( " Import was unsuccessful. " ) ) ;
}
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem ( ) . status ( ApiMessageCode . NO_MESSAGE ) . message ( " Import was unsuccessful. " ) ) ;
}
}
/ *
* Data Index
* * /
2021-11-23 13:05:57 +01:00
@Transactional
2020-03-11 10:06:43 +01:00
@RequestMapping ( method = RequestMethod . POST , value = { " /index " } )
public @ResponseBody
ResponseEntity < ResponseItem < Dataset > > generateIndex ( Principal principal ) throws Exception {
this . datasetManager . generateIndex ( principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < eu . eudat . data . entities . Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Generated " ) . payload ( null ) ) ;
}
2021-11-23 13:05:57 +01:00
@Transactional
2020-03-11 10:06:43 +01:00
@RequestMapping ( method = RequestMethod . DELETE , value = { " /index " } )
public @ResponseBody
ResponseEntity < ResponseItem < Dataset > > clearIndex ( Principal principal ) throws Exception {
this . datasetManager . clearIndex ( principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < eu . eudat . data . entities . Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Cleared " ) . payload ( null ) ) ;
}
2020-07-03 15:11:54 +02:00
2020-07-15 11:33:10 +02:00
2017-10-04 11:48:21 +02:00
}