2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-11-27 14:40:16 +01:00
|
|
|
|
2017-11-30 11:10:42 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.dao.entities.*;
|
|
|
|
import eu.eudat.managers.DashBoardManager;
|
|
|
|
import eu.eudat.models.dashboard.DashBoardStatistics;
|
2018-01-04 10:32:39 +01:00
|
|
|
import eu.eudat.services.ApiContext;
|
2017-11-30 11:10:42 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-01-03 17:36:31 +01:00
|
|
|
import org.springframework.context.ApplicationContext;
|
2017-11-27 14:40:16 +01:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
2017-11-30 11:10:42 +01:00
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
2017-11-27 14:40:16 +01:00
|
|
|
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.RestController;
|
2017-11-30 11:10:42 +01:00
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.managers.AdminManager;
|
|
|
|
import eu.eudat.models.admin.composite.DatasetProfile;
|
2017-11-27 14:40:16 +01:00
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import javax.transaction.Transactional;
|
2018-01-03 17:36:31 +01:00
|
|
|
import javax.validation.Valid;
|
2017-11-27 14:40:16 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2018-01-03 17:36:31 +01:00
|
|
|
public class Admin extends BaseController{
|
|
|
|
|
|
|
|
@Autowired
|
2018-01-04 10:32:39 +01:00
|
|
|
public Admin(ApiContext apiContext) {
|
|
|
|
super(apiContext);
|
2018-01-03 17:36:31 +01:00
|
|
|
}
|
2017-11-27 14:40:16 +01:00
|
|
|
|
2017-11-30 11:10:42 +01:00
|
|
|
@Transactional
|
2017-11-27 14:40:16 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/admin/addDmp" },consumes = "application/json", produces="application/json")
|
2018-01-03 17:36:31 +01:00
|
|
|
public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile){
|
2017-11-27 14:40:16 +01:00
|
|
|
try{
|
2018-01-03 11:44:54 +01:00
|
|
|
eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile);
|
2018-01-04 10:32:39 +01:00
|
|
|
this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
|
2017-12-22 14:42:47 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
|
2017-11-27 14:40:16 +01:00
|
|
|
}catch(Exception ex){
|
2017-11-30 11:10:42 +01:00
|
|
|
ex.printStackTrace();
|
2017-11-27 14:40:16 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"reason\":\""+ex.getMessage()+"\"}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 17:56:21 +01:00
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/admin/addDmp/{id}" },consumes = "application/json", produces="application/json")
|
|
|
|
public ResponseEntity<Object> updateDmp(@PathVariable String id,@RequestBody DatasetProfile profile){
|
|
|
|
try{
|
2018-01-03 11:44:54 +01:00
|
|
|
eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile);
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2018-01-04 10:32:39 +01:00
|
|
|
eu.eudat.entities.DatasetProfile datasetprofile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
2017-12-05 17:56:21 +01:00
|
|
|
datasetprofile.setDefinition(modelDefinition.getDefinition());
|
2018-01-04 10:32:39 +01:00
|
|
|
this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2017-12-06 13:16:31 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(null);
|
2017-12-05 17:56:21 +01:00
|
|
|
}catch(Exception ex){
|
|
|
|
ex.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"reason\":\""+ex.getMessage()+"\"}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 11:10:42 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/admin/get/{id}" }, produces="application/json")
|
|
|
|
public ResponseEntity<Object> get(@PathVariable String id){
|
|
|
|
try{
|
2018-01-04 10:32:39 +01:00
|
|
|
eu.eudat.entities.DatasetProfile profile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
2017-12-15 00:01:26 +01:00
|
|
|
eu.eudat.models.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
|
2018-01-19 12:11:22 +01:00
|
|
|
datasetprofile.setLabel(profile.getLabel());
|
2017-11-30 11:10:42 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(datasetprofile);
|
|
|
|
}catch(Exception ex){
|
|
|
|
ex.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"reason\":\""+ex.getMessage()+"\"}");
|
|
|
|
}
|
|
|
|
}
|
2017-11-27 14:40:16 +01:00
|
|
|
}
|