2017-12-15 00:01:26 +01:00
package eu.eudat.controllers ;
2017-10-04 11:48:21 +02:00
2017-11-03 18:55:04 +01:00
import java.util.Date ;
2017-10-04 11:48:21 +02:00
import java.util.List ;
import java.util.UUID ;
2017-12-15 00:01:26 +01:00
import eu.eudat.entities.DMP ;
import eu.eudat.entities.Dataset ;
import eu.eudat.entities.DatasetProfile ;
import eu.eudat.entities.UserInfo ;
2017-12-15 13:25:21 +01:00
import eu.eudat.managers.DatasetManager ;
import eu.eudat.models.dataset.DatasetTableRequest ;
import eu.eudat.models.helpers.DataTableData ;
2017-12-17 22:34:24 +01:00
import eu.eudat.models.helpers.responses.* ;
2017-12-19 17:22:30 +01:00
import eu.eudat.models.listingmodels.DatasetListingModel ;
2018-01-08 12:44:48 +01:00
import eu.eudat.models.security.Principal ;
2018-01-04 10:32:39 +01:00
import eu.eudat.services.ApiContext ;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode ;
2017-10-04 11:48:21 +02:00
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.http.HttpStatus ;
import org.springframework.http.ResponseEntity ;
2018-01-19 12:11:22 +01:00
import org.springframework.transaction.annotation.Transactional ;
2017-10-04 11:48:21 +02:00
import org.springframework.web.bind.annotation.CrossOrigin ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.springframework.web.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.ResponseBody ;
import org.springframework.web.bind.annotation.RestController ;
@RestController
@CrossOrigin
2018-01-12 09:05:44 +01:00
public class Datasets extends BaseController {
2017-12-15 13:25:21 +01:00
2018-01-12 09:05:44 +01:00
@Autowired
public Datasets ( ApiContext apiContext ) {
super ( apiContext ) ;
}
2017-12-15 13:25:21 +01:00
2018-01-12 09:05:44 +01:00
@RequestMapping ( method = RequestMethod . POST , value = { " /datasets/getPaged " } , consumes = " application/json " , produces = " application/json " )
2018-01-22 08:41:31 +01:00
public @ResponseBody ResponseEntity < ResponseItem < DataTableData < DatasetListingModel > > > getPaged ( @RequestBody DatasetTableRequest datasetTableRequest , Principal principal ) {
2018-01-12 09:05:44 +01:00
try {
DataTableData < DatasetListingModel > dataTable = new DatasetManager ( ) . getPaged ( this . getApiContext ( ) , datasetTableRequest , principal ) ;
2018-01-23 16:21:38 +01: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
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
2018-01-23 16:21:38 +01:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < DataTableData < DatasetListingModel > > ( ) . status ( ApiMessageCode . DEFAULT_ERROR_MESSAGE ) . message ( ex . getMessage ( ) ) ) ;
2018-01-12 09:05:44 +01:00
}
}
2017-12-15 13:25:21 +01:00
2018-01-19 12:11:22 +01:00
@Transactional
@RequestMapping ( method = RequestMethod . GET , value = { " /datasets/makepublic/{id} " } , produces = " application/json " )
2018-01-22 08:41:31 +01:00
public @ResponseBody ResponseEntity < ResponseItem < Dataset > > makePublic ( @PathVariable UUID id , Principal principal ) {
2018-01-19 12:11:22 +01:00
try {
DatasetManager . makePublic ( this . getApiContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) , id ) ;
2018-01-23 16:21:38 +01:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Dataset Has Been Made Public " ) ) ;
2018-01-19 12:11:22 +01:00
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
2018-01-23 16:21:38 +01:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < Dataset > ( ) . status ( ApiMessageCode . DEFAULT_ERROR_MESSAGE ) . message ( ex . getMessage ( ) ) ) ;
2018-01-19 12:11:22 +01:00
}
}
2017-10-04 11:48:21 +02:00
}