2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-12-01 15:09:46 +01:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
import eu.eudat.managers.UserManager;
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.models.components.commons.datafield.AutoCompleteData;
|
2018-02-16 11:34:02 +01:00
|
|
|
import eu.eudat.models.helpers.common.AutoCompleteLookupItem;
|
2018-01-22 08:41:31 +01:00
|
|
|
import eu.eudat.models.helpers.responses.ResponseItem;
|
2018-02-16 11:34:02 +01:00
|
|
|
import eu.eudat.models.properties.PropertiesModel;
|
2018-01-25 09:14:43 +01:00
|
|
|
import eu.eudat.models.user.composite.PagedDatasetProfile;
|
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-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;
|
2018-01-09 12:31:01 +01:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2018-02-16 11:34:02 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
2017-12-01 15:09:46 +01:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2018-02-09 16:54:41 +01:00
|
|
|
@RequestMapping(value = {"/api"})
|
2018-01-25 09:14:43 +01:00
|
|
|
public class DatasetProfileController extends BaseController {
|
2018-01-04 10:32:39 +01:00
|
|
|
|
2018-01-25 09:14:43 +01:00
|
|
|
@Autowired
|
|
|
|
public DatasetProfileController(ApiContext apiContext) {
|
|
|
|
super(apiContext);
|
|
|
|
}
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2018-01-25 09:14:43 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/datasetwizard/get/{id}"}, produces = "application/json")
|
2018-01-26 17:08:17 +01:00
|
|
|
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getSingle(@PathVariable String id) {
|
2018-01-25 09:14:43 +01:00
|
|
|
try {
|
|
|
|
eu.eudat.entities.DatasetProfile profile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
|
|
|
eu.eudat.models.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(profile);
|
|
|
|
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
|
|
|
pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile);
|
2018-01-26 17:08:17 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PagedDatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile));
|
2018-01-25 09:14:43 +01:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2018-01-26 17:08:17 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PagedDatasetProfile>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
2018-01-25 09:14:43 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2018-01-25 09:14:43 +01:00
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/save/{id}"}, consumes = "application/json", produces = "application/json")
|
|
|
|
public ResponseEntity<Object> updateDataset(@PathVariable String id, @RequestBody PropertiesModel properties) {
|
|
|
|
try {
|
|
|
|
eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
|
|
|
|
Map<String, Object> values = new HashMap();
|
|
|
|
properties.toMap(values);
|
|
|
|
JSONObject jobject = new JSONObject(values);
|
|
|
|
dataset.setProperties(jobject.toString());
|
|
|
|
dataset.setStatus((short) properties.getStatus());
|
|
|
|
this.getApiContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(properties);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: " + ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/search/autocomplete"}, consumes = "application/json", produces = "application/json")
|
|
|
|
public ResponseEntity<Object> getDataForAutocomplete(@RequestBody AutoCompleteLookupItem lookupItem) {
|
|
|
|
try {
|
|
|
|
eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(lookupItem.getProfileID()));
|
|
|
|
eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field modelfield = new eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field();
|
|
|
|
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
|
|
|
}
|