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;
|
|
|
|
import eu.eudat.logic.managers.UserManager;
|
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;
|
|
|
|
import eu.eudat.models.data.helpermodels.Tuple;
|
|
|
|
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;
|
|
|
|
import eu.eudat.models.data.user.composite.DatasetProfile;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
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-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;
|
|
|
|
import static eu.eudat.types.Authorities.ANONYMOUS;
|
|
|
|
|
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
|
|
|
@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) {
|
2018-08-31 16:12:31 +02:00
|
|
|
eu.eudat.data.entities.Dataset dataset = this.getApiContext().getOperationsContext().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().getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(properties);
|
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) {
|
2018-10-16 09:09:54 +02:00
|
|
|
eu.eudat.data.entities.DatasetProfile profile = new DatasetProfileManager().clone(this.getApiContext(), 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()));
|
|
|
|
eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field modelfield = DatasetProfileManager.queryForField(datasetProfile.getDefinition(), lookupItem.getCriteria().getFieldID());
|
2018-08-31 16:12:31 +02:00
|
|
|
AutoCompleteData data = (AutoCompleteData) modelfield.getData();
|
|
|
|
List<Tuple<String, String>> items = DatasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(items);
|
2018-01-25 09:14:43 +01:00
|
|
|
}
|
2017-12-01 15:09:46 +01:00
|
|
|
}
|