2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-12-01 15:09:46 +01:00
|
|
|
|
2017-12-13 17:58:51 +01:00
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
2017-12-05 17:56:21 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2017-12-01 15:09:46 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.models.components.commons.datafield.AutoCompleteData;
|
2018-01-04 10:32:39 +01:00
|
|
|
import eu.eudat.services.ApiContext;
|
2017-12-05 17:56:21 +01:00
|
|
|
import org.json.JSONObject;
|
2017-12-01 15:09:46 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
2017-12-05 17:56:21 +01:00
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
2017-12-01 15:09:46 +01:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2017-12-13 17:58:51 +01:00
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Element;
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.dao.entities.DatasetDao;
|
|
|
|
import eu.eudat.dao.entities.DatasetProfileDao;
|
|
|
|
import eu.eudat.dao.entities.DatasetProfileRulesetDao;
|
|
|
|
import eu.eudat.dao.entities.DatasetProfileViewstyleDao;
|
|
|
|
import eu.eudat.managers.UserManager;
|
|
|
|
import eu.eudat.models.helpers.AutoCompleteLookupItem;
|
|
|
|
import eu.eudat.models.properties.PropertiesModel;
|
|
|
|
import eu.eudat.utilities.builders.XmlBuilder;
|
2017-12-01 15:09:46 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2018-01-04 10:32:39 +01:00
|
|
|
public class DatasetProfileController extends BaseController{
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public DatasetProfileController(ApiContext apiContext) {
|
|
|
|
super(apiContext);
|
|
|
|
}
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2017-12-22 14:42:47 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datasetwizard/get/{id}" }, produces="application/json")
|
2017-12-05 17:56:21 +01:00
|
|
|
public ResponseEntity<Object> getSingle(@PathVariable String id){
|
2017-12-01 15:09:46 +01:00
|
|
|
try {
|
2018-01-04 10:32:39 +01:00
|
|
|
eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
|
2017-12-15 00:01:26 +01:00
|
|
|
eu.eudat.models.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(dataset.getProfile());
|
2017-12-12 13:08:51 +01:00
|
|
|
datasetprofile.setStatus(dataset.getStatus());
|
2017-12-05 17:56:21 +01:00
|
|
|
if(dataset.getProperties()!=null){
|
|
|
|
JSONObject jobject = new JSONObject(dataset.getProperties());
|
|
|
|
Map<String,Object> properties = (Map<String, Object>)jobject.toMap();
|
|
|
|
datasetprofile.fromJsonObject(properties);
|
|
|
|
}
|
2017-12-01 15:09:46 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(datasetprofile);
|
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-12-13 13:01:43 +01:00
|
|
|
ex.printStackTrace();
|
2017-12-01 15:09:46 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 17:56:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/save/{id}" }, consumes="application/json",produces="application/json")
|
2017-12-13 17:58:51 +01:00
|
|
|
public ResponseEntity<Object> updateDataset(@PathVariable String id,@RequestBody PropertiesModel properties){
|
2017-12-05 17:56:21 +01:00
|
|
|
try {
|
2018-01-04 10:32:39 +01:00
|
|
|
eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
|
2017-12-12 09:36:43 +01:00
|
|
|
Map<String,Object> values = new HashMap();
|
2017-12-05 17:56:21 +01:00
|
|
|
properties.toMap(values);
|
|
|
|
JSONObject jobject = new JSONObject(values);
|
|
|
|
dataset.setProperties(jobject.toString());
|
2017-12-12 13:08:51 +01:00
|
|
|
dataset.setStatus((short)properties.getStatus());
|
2018-01-04 10:32:39 +01:00
|
|
|
this.getApiContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
|
2017-12-05 17:56:21 +01:00
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(properties);
|
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2017-12-13 17:58:51 +01:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/search/autocomplete" }, consumes="application/json",produces="application/json")
|
|
|
|
public ResponseEntity<Object> getDataForAutocomplete(@RequestBody AutoCompleteLookupItem lookupItem){
|
|
|
|
try {
|
2018-01-04 10:32:39 +01:00
|
|
|
eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(lookupItem.getProfileID()));
|
2018-01-03 11:44:54 +01:00
|
|
|
eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field modelfield = new eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field();
|
2017-12-13 17:58:51 +01:00
|
|
|
AutoCompleteData data = new AutoCompleteData().fromData(modelfield.getData());
|
|
|
|
|
|
|
|
URL url = new URL(data.getUrl()+lookupItem.getSearchTerm());
|
|
|
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(null);
|
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2017-12-01 15:09:46 +01:00
|
|
|
}
|