2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.controllers;
|
2017-12-01 15:09:46 +01:00
|
|
|
|
2018-05-14 08:44:35 +02:00
|
|
|
import eu.eudat.data.dao.criteria.RequestItem;
|
2018-10-16 13:11:15 +02:00
|
|
|
import eu.eudat.logic.managers.AdminManager;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.managers.DatasetProfileManager;
|
2018-10-16 09:09:54 +02:00
|
|
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
2018-08-31 16:12:31 +02:00
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.components.commons.datafield.AutoCompleteData;
|
2019-07-29 11:26:08 +02:00
|
|
|
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
|
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.data.properties.PropertiesModel;
|
2018-10-16 09:09:54 +02:00
|
|
|
import eu.eudat.models.data.security.Principal;
|
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-08-31 16:12:31 +02:00
|
|
|
import javax.xml.xpath.XPathExpressionException;
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.util.HashMap;
|
2018-05-14 08:44:35 +02:00
|
|
|
import java.util.List;
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
2017-12-01 15:09:46 +01:00
|
|
|
|
2018-10-16 09:09:54 +02:00
|
|
|
import static eu.eudat.types.Authorities.ADMIN;
|
|
|
|
|
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
|
|
|
|
2019-02-01 17:56:55 +01:00
|
|
|
private DatasetProfileManager datasetProfileManager;
|
|
|
|
|
2018-01-25 09:14:43 +01:00
|
|
|
@Autowired
|
2019-02-01 17:56:55 +01:00
|
|
|
public DatasetProfileController(ApiContext apiContext, DatasetProfileManager datasetProfileManager) {
|
2018-01-25 09:14:43 +01:00
|
|
|
super(apiContext);
|
2019-02-01 17:56:55 +01:00
|
|
|
this.datasetProfileManager = datasetProfileManager;
|
2018-01-25 09:14:43 +01:00
|
|
|
}
|
2017-12-05 17:56:21 +01:00
|
|
|
|
2019-10-14 13:14:09 +02:00
|
|
|
/* @Transactional
|
2018-01-25 09:14:43 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/save/{id}"}, consumes = "application/json", produces = "application/json")
|
|
|
|
public ResponseEntity<Object> updateDataset(@PathVariable String id, @RequestBody PropertiesModel properties) {
|
2018-08-31 16:12:31 +02:00
|
|
|
eu.eudat.data.entities.Dataset dataset = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
|
2019-10-14 13:14:09 +02:00
|
|
|
Map<String, Object> values = new HashMap<>();
|
2018-08-31 16:12:31 +02:00
|
|
|
properties.toMap(values);
|
|
|
|
JSONObject jobject = new JSONObject(values);
|
|
|
|
dataset.setProperties(jobject.toString());
|
|
|
|
dataset.setStatus((short) properties.getStatus());
|
|
|
|
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(properties);
|
2019-10-14 13:14:09 +02:00
|
|
|
}*/
|
2018-01-25 09:14:43 +01:00
|
|
|
|
2018-10-16 09:09:54 +02:00
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
2018-10-16 13:11:15 +02:00
|
|
|
public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN})Principal principal) {
|
2019-03-05 16:33:59 +01:00
|
|
|
eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(id);
|
2018-10-16 13:11:15 +02:00
|
|
|
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
|
2018-10-18 11:33:13 +02:00
|
|
|
datasetprofile.setLabel(profile.getLabel() + " new ");
|
2018-10-16 13:11:15 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile));
|
2018-10-16 09:09:54 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 09:14:43 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/search/autocomplete"}, consumes = "application/json", produces = "application/json")
|
2018-08-31 16:12:31 +02:00
|
|
|
public ResponseEntity<Object> getDataForAutocomplete(@RequestBody RequestItem<AutoCompleteLookupItem> lookupItem) throws XPathExpressionException {
|
2019-01-28 13:18:48 +01:00
|
|
|
eu.eudat.data.entities.DatasetProfile datasetProfile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(lookupItem.getCriteria().getProfileID()));
|
2019-02-01 17:56:55 +01:00
|
|
|
eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field modelfield = this.datasetProfileManager.queryForField(datasetProfile.getDefinition(), lookupItem.getCriteria().getFieldID());
|
2018-08-31 16:12:31 +02:00
|
|
|
AutoCompleteData data = (AutoCompleteData) modelfield.getData();
|
2019-07-29 11:26:08 +02:00
|
|
|
List<ExternalAutocompleteFieldModel> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(items);
|
2018-01-25 09:14:43 +01:00
|
|
|
}
|
2019-02-06 12:10:44 +01:00
|
|
|
|
2017-12-01 15:09:46 +01:00
|
|
|
}
|