2017-12-15 00:01:26 +01:00
package eu.eudat.controllers ;
2017-09-14 12:37:36 +02:00
2017-10-27 12:52:12 +02:00
2019-07-31 16:57:34 +02:00
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration ;
2019-05-21 17:17:41 +02:00
import eu.eudat.criteria.DMPCriteria ;
2018-03-28 15:24:47 +02:00
import eu.eudat.data.dao.criteria.DynamicFieldsCriteria ;
import eu.eudat.data.dao.criteria.RequestItem ;
2018-03-21 11:57:56 +01:00
import eu.eudat.data.entities.DMP ;
2020-04-01 17:16:06 +02:00
import eu.eudat.data.entities.Dataset ;
2019-06-12 11:13:50 +02:00
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem ;
2018-03-28 15:24:47 +02:00
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest ;
2019-04-26 16:05:15 +02:00
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest ;
2019-03-26 15:52:19 +01:00
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException ;
2018-11-30 15:57:20 +01:00
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException ;
2020-02-26 12:36:42 +01:00
import eu.eudat.exceptions.security.UnauthorisedException ;
2018-06-27 12:29:21 +02:00
import eu.eudat.logic.managers.DataManagementPlanManager ;
2018-10-18 11:33:13 +02:00
import eu.eudat.logic.managers.DatasetManager ;
2019-11-11 09:40:12 +01:00
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader ;
2019-04-26 16:05:15 +02:00
import eu.eudat.logic.security.claims.ClaimedAuthorities ;
2018-08-31 16:12:31 +02:00
import eu.eudat.logic.services.ApiContext ;
2019-05-21 17:17:41 +02:00
import eu.eudat.logic.services.operations.DatabaseRepository ;
2020-04-02 16:22:41 +02:00
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope ;
2019-06-12 11:13:50 +02:00
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel ;
2019-06-28 14:58:25 +02:00
import eu.eudat.models.data.datasetwizard.DatasetsToBeFinalized ;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.dmp.DataManagementPlan ;
import eu.eudat.models.data.helpermodels.Tuple ;
import eu.eudat.models.data.helpers.common.DataTableData ;
import eu.eudat.models.data.helpers.responses.ResponseItem ;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel ;
2019-05-17 17:21:56 +02:00
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel ;
2020-07-07 11:22:45 +02:00
import eu.eudat.models.data.listingmodels.UserInfoListingModel ;
2020-07-09 12:11:43 +02:00
import eu.eudat.models.data.listingmodels.VersionListingModel ;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.security.Principal ;
2019-05-21 17:17:41 +02:00
import eu.eudat.query.DMPQuery ;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode ;
2019-04-26 16:05:15 +02:00
import eu.eudat.types.Authorities ;
2020-01-16 16:46:24 +01:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2017-09-14 12:37:36 +02:00
import org.springframework.beans.factory.annotation.Autowired ;
2018-10-18 11:33:13 +02:00
import org.springframework.core.env.Environment ;
2018-10-08 17:14:27 +02:00
import org.springframework.http.HttpHeaders ;
2017-09-14 12:37:36 +02:00
import org.springframework.http.HttpStatus ;
2018-10-08 17:14:27 +02:00
import org.springframework.http.MediaType ;
2018-01-22 08:41:31 +01:00
import org.springframework.http.ResponseEntity ;
2018-02-07 10:56:30 +01:00
import org.springframework.transaction.annotation.Transactional ;
2017-12-23 16:56:05 +01:00
import org.springframework.web.bind.annotation.* ;
2019-03-05 12:59:34 +01:00
import org.springframework.web.multipart.MultipartFile ;
2017-09-14 12:37:36 +02:00
2018-10-08 17:14:27 +02:00
import javax.activation.MimetypesFileTypeMap ;
2018-02-16 11:34:02 +01:00
import javax.validation.Valid ;
2018-10-18 11:33:13 +02:00
import java.io.File ;
2018-10-08 17:14:27 +02:00
import java.io.FileInputStream ;
import java.io.IOException ;
import java.io.InputStream ;
2019-06-05 15:40:47 +02:00
import java.nio.file.Files ;
2018-02-16 11:34:02 +01:00
import java.util.List ;
2019-05-23 17:03:44 +02:00
import java.util.Map ;
2018-02-16 11:34:02 +01:00
import java.util.UUID ;
2017-09-14 12:37:36 +02:00
2020-09-15 12:21:22 +02:00
import static org.springframework.http.MediaType.* ;
2020-03-26 17:39:25 +01:00
2017-09-14 12:37:36 +02:00
@RestController
@CrossOrigin
2018-10-18 11:33:13 +02:00
@RequestMapping ( value = { " /api/dmps/ " } )
2018-01-03 11:44:54 +01:00
public class DMPs extends BaseController {
2020-01-16 16:46:24 +01:00
private static final Logger logger = LoggerFactory . getLogger ( DMPs . class ) ;
2018-01-04 10:32:39 +01:00
2019-07-31 16:57:34 +02:00
private DynamicGrantConfiguration dynamicGrantConfiguration ;
2019-06-28 14:58:25 +02:00
private Environment environment ;
private DataManagementPlanManager dataManagementPlanManager ;
private DatasetManager datasetManager ;
2019-11-11 09:40:12 +01:00
private ConfigLoader configLoader ;
2019-06-28 14:58:25 +02:00
@Autowired
2019-07-31 16:57:34 +02:00
public DMPs ( ApiContext apiContext , DynamicGrantConfiguration dynamicGrantConfiguration , Environment environment ,
2019-11-11 09:40:12 +01:00
DataManagementPlanManager dataManagementPlanManager , DatasetManager datasetManager , ConfigLoader configLoader ) {
2019-06-28 14:58:25 +02:00
super ( apiContext ) ;
2019-07-31 16:57:34 +02:00
this . dynamicGrantConfiguration = dynamicGrantConfiguration ;
2019-06-28 14:58:25 +02:00
this . environment = environment ;
this . dataManagementPlanManager = dataManagementPlanManager ;
this . datasetManager = datasetManager ;
2019-11-11 09:40:12 +01:00
this . configLoader = configLoader ;
2019-06-28 14:58:25 +02:00
}
2020-04-22 17:40:43 +02:00
/ *
* Data Retrieval
* * /
2019-06-28 14:58:25 +02:00
@RequestMapping ( method = RequestMethod . POST , value = { " /paged " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
2020-04-01 17:16:06 +02:00
ResponseEntity < ResponseItem < DataTableData < DataManagementPlanListingModel > > > getPaged ( @Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest ,
@RequestParam String fieldsGroup ,
@ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
2019-06-28 14:58:25 +02:00
DataTableData < DataManagementPlanListingModel > dataTable = this . dataManagementPlanManager . getPaged ( dataManagementPlanTableRequest , principal , fieldsGroup ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataTableData < DataManagementPlanListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataTable ) ) ;
}
@RequestMapping ( method = RequestMethod . GET , value = { " {id} " } )
public @ResponseBody
2019-10-29 12:30:44 +01:00
ResponseEntity getSingle ( @PathVariable String id , @RequestHeader ( " Content-Type " ) String contentType ,
2020-04-22 17:40:43 +02:00
@ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
2019-10-14 13:14:09 +02:00
if ( contentType . equals ( " application/xml " ) | | contentType . equals ( " application/msword " ) ) {
2019-11-11 09:40:12 +01:00
return this . dataManagementPlanManager . getDocument ( id , contentType , principal , this . configLoader ) ;
2019-06-28 14:58:25 +02:00
} else {
2020-04-22 17:40:43 +02:00
eu . eudat . models . data . dmp . DataManagementPlan dataManagementPlan = this . dataManagementPlanManager . getSingle ( id , principal , false ) ;
2019-06-28 14:58:25 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataManagementPlan > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataManagementPlan ) ) ;
}
}
@RequestMapping ( method = RequestMethod . POST , value = { " /datasetProfilesUsedByDmps/paged " } , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < DataTableData < DatasetProfileListingModel > > > getUsingDatasetProfilesPaged ( @RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem , Principal principal ) {
DataTableData < DatasetProfileListingModel > datasetProfileTableData = this . dataManagementPlanManager . getDatasetProfilesUsedByDMP ( datasetProfileTableRequestItem , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataTableData < DatasetProfileListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( datasetProfileTableData ) ) ;
}
@RequestMapping ( method = RequestMethod . GET , value = { " /overview/{id} " } )
public @ResponseBody
2020-04-01 17:16:06 +02:00
ResponseEntity getOverviewSingle ( @PathVariable String id , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) {
2020-01-16 16:14:50 +01:00
try {
2020-04-22 17:40:43 +02:00
DataManagementPlanOverviewModel dataManagementPlan = this . dataManagementPlanManager . getOverviewSingle ( id , principal , false ) ;
2020-01-16 16:14:50 +01:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataManagementPlanOverviewModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataManagementPlan ) ) ;
} catch ( Exception e ) {
2020-02-26 12:36:42 +01:00
if ( e instanceof UnauthorisedException ) {
return ResponseEntity . status ( HttpStatus . FORBIDDEN ) . body ( new ResponseItem < DataManagementPlanOverviewModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
} else {
return ResponseEntity . status ( HttpStatus . NOT_FOUND ) . body ( new ResponseItem < DataManagementPlanOverviewModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
}
2020-01-16 16:14:50 +01:00
}
2019-06-28 14:58:25 +02:00
}
@RequestMapping ( method = RequestMethod . GET , value = { " /public/{id} " } )
public @ResponseBody
2020-04-22 17:40:43 +02:00
ResponseEntity getSinglePublic ( @PathVariable String id , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
// try {
eu . eudat . models . data . dmp . DataManagementPlan dataManagementPlan = this . dataManagementPlanManager . getSingle ( id , principal , true ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataManagementPlan > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataManagementPlan ) ) ;
// } catch (Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
// }
2019-06-28 14:58:25 +02:00
}
@RequestMapping ( method = RequestMethod . GET , value = { " /publicOverview/{id} " } )
public @ResponseBody
2020-04-22 17:40:43 +02:00
ResponseEntity getOverviewSinglePublic ( @PathVariable String id , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
// try {
DataManagementPlanOverviewModel dataManagementPlan = this . dataManagementPlanManager . getOverviewSingle ( id , principal , true ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataManagementPlanOverviewModel > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataManagementPlan ) ) ;
// } catch (Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
// }
}
@RequestMapping ( method = RequestMethod . POST , value = { " /dynamic " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < List < Tuple < String , String > > > > getWithCriteria ( @RequestBody RequestItem < DynamicFieldsCriteria > criteriaRequestItem , Principal principal ) throws InstantiationException , IllegalAccessException {
List < Tuple < String , String > > dataTable = this . dataManagementPlanManager . getDynamicFields ( criteriaRequestItem . getCriteria ( ) . getId ( ) , this . dynamicGrantConfiguration , criteriaRequestItem . getCriteria ( ) ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < List < Tuple < String , String > > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dataTable ) ) ;
}
2020-07-09 12:11:43 +02:00
@RequestMapping ( method = RequestMethod . GET , value = { " /versions/{id} " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
2020-10-12 11:45:32 +02:00
ResponseEntity < ResponseItem < List < VersionListingModel > > > getVersions ( @PathVariable ( value = " id " ) String groupId , @RequestParam ( value = " public " ) Boolean isPublic ,
2020-07-09 12:11:43 +02:00
@ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
2020-10-12 11:45:32 +02:00
List < VersionListingModel > versions = this . dataManagementPlanManager . getAllVersions ( groupId , principal , isPublic ) ;
2020-07-09 12:11:43 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < List < VersionListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( versions ) ) ;
}
2020-04-22 17:40:43 +02:00
/ *
* Data Export
* * /
@RequestMapping ( method = RequestMethod . GET , value = { " rda/{id} " } )
public @ResponseBody
2020-09-24 11:37:03 +02:00
ResponseEntity getRDAJsonDocument ( @PathVariable String id , @ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) {
try {
2020-04-22 17:40:43 +02:00
return this . dataManagementPlanManager . getRDAJsonDocument ( id , datasetManager , principal ) ;
2020-09-24 11:37:03 +02:00
} catch ( Exception e ) {
return ResponseEntity . status ( HttpStatus . EXPECTATION_FAILED ) . body ( new ResponseItem < > ( ) . message ( e . getMessage ( ) ) . status ( ApiMessageCode . ERROR_MESSAGE ) ) ;
}
2020-04-22 17:40:43 +02:00
}
@RequestMapping ( method = RequestMethod . GET , value = { " /getPDF/{id} " } )
public @ResponseBody
ResponseEntity < byte [ ] > getPDFDocument ( @PathVariable String id , @RequestHeader ( " Content-Type " ) String contentType ,
@ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ) throws IllegalAccessException , IOException , InstantiationException , InterruptedException {
FileEnvelope file = this . dataManagementPlanManager . getWordDocument ( id , principal , configLoader ) ;
String name = file . getFilename ( ) . substring ( 0 , file . getFilename ( ) . length ( ) - 5 ) ;
File pdffile = datasetManager . convertToPDF ( file , environment ) ;
InputStream resource = new FileInputStream ( pdffile ) ;
logger . info ( " Mime Type of " + name + " is " +
new MimetypesFileTypeMap ( ) . getContentType ( file . getFile ( ) ) ) ;
HttpHeaders responseHeaders = new HttpHeaders ( ) ;
responseHeaders . setContentLength ( pdffile . length ( ) ) ;
responseHeaders . setContentType ( MediaType . APPLICATION_OCTET_STREAM ) ;
responseHeaders . set ( " Content-Disposition " , " attachment;filename= " + name + " .pdf " ) ;
responseHeaders . set ( " Access-Control-Expose-Headers " , " Content-Disposition " ) ;
responseHeaders . get ( " Access-Control-Expose-Headers " ) . add ( " Content-Type " ) ;
byte [ ] content = org . apache . poi . util . IOUtils . toByteArray ( resource ) ;
resource . close ( ) ;
Files . deleteIfExists ( file . getFile ( ) . toPath ( ) ) ;
Files . deleteIfExists ( pdffile . toPath ( ) ) ;
return new ResponseEntity < > ( content , responseHeaders , HttpStatus . OK ) ;
2019-06-28 14:58:25 +02:00
}
2020-04-22 17:40:43 +02:00
/ *
* Data Management
* * /
2019-06-28 14:58:25 +02:00
@Transactional
@RequestMapping ( method = RequestMethod . POST , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
2020-10-01 17:54:01 +02:00
ResponseEntity < ResponseItem < eu . eudat . models . data . dmp . DataManagementPlan > > createOrUpdate ( @RequestBody eu . eudat . models . data . dmp . DataManagementPlanEditorModel dataManagementPlanEditorModel , Principal principal ) throws Exception {
2020-07-27 12:09:30 +02:00
DMP dmp = this . dataManagementPlanManager . createOrUpdate ( dataManagementPlanEditorModel , principal ) ;
2020-10-01 17:54:01 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < eu . eudat . models . data . dmp . DataManagementPlan > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Created " ) . payload ( new eu . eudat . models . data . dmp . DataManagementPlan ( ) . fromDataModel ( dmp ) ) ) ;
2020-07-27 12:09:30 +02:00
}
@Transactional
@RequestMapping ( method = RequestMethod . POST , path = " full " , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < UUID > > createOrUpdateWithDatasets ( @RequestBody eu . eudat . models . data . dmp . DataManagementPlanEditorModel dataManagementPlanEditorModel , Principal principal ) throws Exception {
DMP dmp = this . dataManagementPlanManager . createOrUpdateWithDatasets ( dataManagementPlanEditorModel , principal ) ;
2019-07-02 11:36:25 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < UUID > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Created " ) . payload ( dmp . getId ( ) ) ) ;
2019-06-28 14:58:25 +02:00
}
@RequestMapping ( method = RequestMethod . POST , value = { " /new/{id} " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
2020-09-03 16:57:14 +02:00
ResponseEntity < ResponseItem < UUID > > newVersion ( @PathVariable UUID id , @Valid @RequestBody eu . eudat . models . data . dmp . DataManagementPlanNewVersionModel dataManagementPlan , Principal principal ) throws Exception {
2019-06-28 14:58:25 +02:00
try {
2020-09-03 16:57:14 +02:00
UUID result = this . dataManagementPlanManager . newVersion ( id , dataManagementPlan , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < UUID > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( result ) ) ;
2019-06-28 14:58:25 +02:00
} catch ( DMPNewVersionException exception ) {
2020-09-03 16:57:14 +02:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < UUID > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( exception . getMessage ( ) ) ) ;
2019-06-28 14:58:25 +02:00
}
}
@RequestMapping ( method = RequestMethod . POST , value = { " /clone/{id} " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
2020-09-02 17:32:12 +02:00
ResponseEntity < ResponseItem < UUID > > clone ( @PathVariable UUID id , @RequestBody eu . eudat . models . data . dmp . DataManagementPlanNewVersionModel dataManagementPlan , Principal principal ) throws Exception {
UUID cloneId = this . dataManagementPlanManager . clone ( dataManagementPlan , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < UUID > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . payload ( cloneId ) ) ;
2019-06-28 14:58:25 +02:00
}
@Transactional
@RequestMapping ( method = RequestMethod . DELETE , value = { " {id} " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < DMP > > delete ( @PathVariable UUID id , Principal principal ) {
try {
this . dataManagementPlanManager . delete ( id ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Successfully Deleted Datamanagement Plan " ) ) ;
2020-04-01 17:16:06 +02:00
} catch ( DMPWithDatasetsDeleteException | IOException exception ) {
2019-06-28 14:58:25 +02:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( exception . getMessage ( ) ) ) ;
}
}
@RequestMapping ( method = RequestMethod . POST , value = { " /upload " } )
2020-06-03 11:43:31 +02:00
public ResponseEntity < ResponseItem > dmpUpload ( @RequestParam ( " file " ) MultipartFile [ ] files , @RequestParam ( name = " profiles " , required = false ) String [ ] profiles , Principal principal ) throws Exception {
2020-03-26 17:39:25 +01:00
if ( files [ 0 ] . getContentType ( ) . equals ( APPLICATION_JSON . toString ( ) ) ) {
2020-05-29 12:39:18 +02:00
this . dataManagementPlanManager . createFromRDA ( files , principal , profiles ) ;
2020-09-15 12:21:22 +02:00
} else if ( files [ 0 ] . getContentType ( ) . equals ( APPLICATION_ATOM_XML . toString ( ) ) | | files [ 0 ] . getContentType ( ) . equals ( TEXT_XML . toString ( ) ) ) {
2020-03-26 17:39:25 +01:00
this . dataManagementPlanManager . createDmpFromXml ( this . getApiContext ( ) , files , principal ) ;
2020-09-15 12:21:22 +02:00
} else {
return ResponseEntity . badRequest ( ) . body ( new ResponseItem ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " File format is not supported " ) ) ;
2020-03-26 17:39:25 +01:00
}
2019-06-28 14:58:25 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < List > ( )
. status ( ApiMessageCode . SUCCESS_MESSAGE ) ) ;
}
@RequestMapping ( method = RequestMethod . GET , value = { " /makepublic/{id} " } )
public ResponseEntity < ResponseItem < DMP > > makePublic ( @PathVariable String id , Principal principal ) {
try {
this . dataManagementPlanManager . makePublic ( UUID . fromString ( id ) , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Successfully Data Datamanagement Plan made public. " ) ) ;
} catch ( Exception e ) {
2020-07-27 12:09:30 +02:00
logger . error ( e . getMessage ( ) , e ) ;
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " Failed to make Data Management Plan public. " ) ) ;
2019-06-28 14:58:25 +02:00
}
}
@Transactional
@RequestMapping ( method = RequestMethod . POST , value = { " /finalize/{id} " } )
public ResponseEntity < ResponseItem < DMP > > makeFinalize ( @PathVariable String id , Principal principal , @RequestBody DatasetsToBeFinalized datasetsToBeFinalized ) {
try {
this . dataManagementPlanManager . makeFinalize ( UUID . fromString ( id ) , principal , datasetsToBeFinalized ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Successfully Data Datamanagement Plan made finalized. " ) ) ;
} catch ( Exception e ) {
2020-07-27 12:09:30 +02:00
logger . error ( e . getMessage ( ) , e ) ;
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " Failed to finalize Data Management Plan. " ) ) ;
2019-06-28 14:58:25 +02:00
}
}
2019-07-04 16:30:15 +02:00
2020-05-26 13:31:47 +02:00
@Transactional
@RequestMapping ( method = RequestMethod . POST , value = { " /unfinalize/{id} " } )
public ResponseEntity < ResponseItem < DMP > > undoFinalize ( @PathVariable String id , Principal principal ) {
try {
this . dataManagementPlanManager . undoFinalize ( UUID . fromString ( id ) , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Successfully Data Datamanagement Plan made active. " ) ) ;
} catch ( Exception e ) {
2020-07-27 12:09:30 +02:00
logger . error ( e . getMessage ( ) , e ) ;
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " Failed to unfinalize the Data Management Plan. " ) ) ;
2020-05-26 13:31:47 +02:00
}
}
2020-07-07 11:22:45 +02:00
@Transactional
@RequestMapping ( method = RequestMethod . POST , value = { " /updateusers/{id} " } )
public ResponseEntity < ResponseItem < DMP > > updateUsers ( @PathVariable String id , @RequestBody List < UserInfoListingModel > users , Principal principal ) {
try {
this . dataManagementPlanManager . updateUsers ( UUID . fromString ( id ) , users , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Successfully Updated Colaborators for Data Datamanagement Plan. " ) ) ;
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " Failed to update the users of Data Management Plan. " ) ) ;
}
}
2020-04-22 17:40:43 +02:00
/ *
* DOI Generation
* * /
2019-08-21 16:31:33 +02:00
@Transactional
2019-07-04 16:30:15 +02:00
@RequestMapping ( method = RequestMethod . POST , value = { " /createZenodoDoi/{id} " } )
public ResponseEntity < ResponseItem < String > > createZenodoDoi ( @PathVariable String id , Principal principal ) {
try {
2019-11-11 09:40:12 +01:00
String zenodoDOI = this . dataManagementPlanManager . createZenodoDoi ( UUID . fromString ( id ) , principal , configLoader ) ;
2019-07-04 16:30:15 +02:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < String > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Successfully created DOI for Data Datamanagement Plan in question. " ) . payload ( zenodoDOI ) ) ;
} catch ( Exception e ) {
2020-01-16 16:46:24 +01:00
logger . error ( e . getMessage ( ) , e ) ;
2020-07-27 12:09:30 +02:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < String > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " Failed to create DOI for the Data Management Plan. " ) ) ;
2019-07-04 16:30:15 +02:00
}
}
2020-04-01 17:16:06 +02:00
2020-04-22 17:40:43 +02:00
/ *
* Data Index
* * /
@Transactional
2020-04-01 17:16:06 +02:00
@RequestMapping ( method = RequestMethod . POST , value = { " /index " } )
public @ResponseBody
ResponseEntity < ResponseItem < Dataset > > generateIndex ( Principal principal ) throws Exception {
this . dataManagementPlanManager . generateIndex ( principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < eu . eudat . data . entities . Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Generated " ) . payload ( null ) ) ;
}
2020-04-22 17:40:43 +02:00
@Transactional
2020-04-01 17:16:06 +02:00
@RequestMapping ( method = RequestMethod . DELETE , value = { " /index " } )
public @ResponseBody
ResponseEntity < ResponseItem < Dataset > > clearIndex ( Principal principal ) throws Exception {
this . dataManagementPlanManager . clearIndex ( principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < eu . eudat . data . entities . Dataset > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Cleared " ) . payload ( null ) ) ;
}
2020-04-22 17:40:43 +02:00
/ *
* Misc
* * /
@RequestMapping ( method = RequestMethod . POST , value = { " /test " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < DataTableData < Map > > > test ( @RequestBody DMPCriteria criteria , @ClaimedAuthorities ( claims = { Authorities . ANONYMOUS } ) Principal principal ) throws Exception {
DatabaseRepository dbRepo = this . getApiContext ( ) . getOperationsContext ( ) . getDatabaseRepository ( ) ;
DMPQuery query = criteria . buildQuery ( dbRepo ) ;
List < Map > models = query . getQuery ( ) . toListWithFields ( ) ;
DataTableData < Map > dmp = new DataTableData < > ( ) ;
dmp . setData ( models ) ;
dmp . setTotalCount ( query . getQuery ( ) . count ( ) ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataTableData < Map > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dmp ) ) ;
}
/ * @RequestMapping ( method = RequestMethod . POST , value = { " /public/paged " } , consumes = " application/json " , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < DataTableData < DataManagementPlanListingModel > > > getPublicPaged ( @RequestBody DataManagmentPlanPublicTableRequest dmpTableRequest ,
@ClaimedAuthorities ( claims = { Authorities . ADMIN , Authorities . MANAGER , Authorities . USER , Authorities . ANONYMOUS } ) Principal principal ,
@RequestParam String fieldsGroup ) throws Exception {
DataTableData < DataManagementPlanListingModel > dmp = this . dataManagementPlanManager . getPublicPaged ( dmpTableRequest , fieldsGroup , principal ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DataTableData < DataManagementPlanListingModel > > ( ) . status ( ApiMessageCode . NO_MESSAGE ) . payload ( dmp ) ) ;
} * /
/ * @Transactional
@RequestMapping ( method = RequestMethod . GET , value = { " {id}/unlock " } , produces = " application/json " )
public @ResponseBody
ResponseEntity < ResponseItem < DMP > > unlock ( @PathVariable ( value = " id " ) UUID id , Principal principal ) throws Exception {
this . dataManagementPlanManager . unlock ( id ) ;
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < DMP > ( ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) . message ( " Unlocked " ) ) ;
} * /
2019-06-20 15:25:49 +02:00
}