diff --git a/dmp-backend/dmp-backend.iml b/dmp-backend/dmp-backend.iml new file mode 100644 index 000000000..c5ac1805e --- /dev/null +++ b/dmp-backend/dmp-backend.iml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dmp-backend/src/main/java/models/components/commons/datafield/WordListData.java b/dmp-backend/src/main/java/models/components/commons/datafield/WordListData.java index a53dae0f2..993eb4dca 100644 --- a/dmp-backend/src/main/java/models/components/commons/datafield/WordListData.java +++ b/dmp-backend/src/main/java/models/components/commons/datafield/WordListData.java @@ -53,6 +53,7 @@ public class WordListData extends ComboBoxData{ } @Override public WordListData fromData(Object data) { + super.fromData(data); this.options = new LinkedList(); if(data!=null){ diff --git a/dmp-backend/src/main/java/models/helpers/AutoCompleteLookupItem.java b/dmp-backend/src/main/java/models/helpers/AutoCompleteLookupItem.java new file mode 100644 index 000000000..1ebae4d5d --- /dev/null +++ b/dmp-backend/src/main/java/models/helpers/AutoCompleteLookupItem.java @@ -0,0 +1,29 @@ +package models.helpers; + +import java.util.UUID; + +public class AutoCompleteLookupItem { + private String profileID; + private String fieldID; + private String searchTerm; + public String getProfileID() { + return profileID; + } + public void setProfileID(String profileID) { + this.profileID = profileID; + } + public String getFieldID() { + return fieldID; + } + public void setFieldID(String fieldID) { + this.fieldID = fieldID; + } + + public String getSearchTerm() { + return searchTerm; + } + + public void setSearchTerm(String searchTerm) { + this.searchTerm = searchTerm; + } +} diff --git a/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java b/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java index 9f6e34ef3..34c0bfc62 100644 --- a/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java +++ b/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java @@ -1,10 +1,14 @@ package rest.entities; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import models.components.commons.datafield.AutoCompleteData; +import models.user.components.datasetprofile.Field; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -15,7 +19,8 @@ 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; - +import org.w3c.dom.Document; +import org.w3c.dom.Element; import dao.entities.DatasetDao; import dao.entities.DatasetProfileDao; @@ -24,7 +29,9 @@ import dao.entities.DatasetProfileViewstyleDao; import helpers.SerializerProvider; import managers.AdminManager; import managers.UserManager; +import models.helpers.AutoCompleteLookupItem; import models.properties.PropertiesModel; +import utilities.builders.XmlBuilder; @RestController @CrossOrigin @@ -56,7 +63,7 @@ public class DatasetProfileController { @RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/save/{id}" }, consumes="application/json",produces="application/json") - public ResponseEntity postDataset(@PathVariable String id,@RequestBody PropertiesModel properties){ + public ResponseEntity updateDataset(@PathVariable String id,@RequestBody PropertiesModel properties){ try { entities.Dataset dataset = datasetDao.read(UUID.fromString(id)); Map values = new HashMap(); @@ -72,4 +79,23 @@ public class DatasetProfileController { 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 getDataForAutocomplete(@RequestBody AutoCompleteLookupItem lookupItem){ + try { + entities.Dataset dataset = datasetDao.read(UUID.fromString(lookupItem.getProfileID())); + Document viewStyleDoc = XmlBuilder.fromXml(dataset.getProfile().getViewstyle().getDefinition()); + Element field = viewStyleDoc.getElementById(lookupItem.getFieldID()); + entities.xmlmodels.viewstyledefinition.Field modelfield = new entities.xmlmodels.viewstyledefinition.Field(); + modelfield.fromXml(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()); + } + } } diff --git a/dmp-backend/src/main/java/utilities/builders/ModelBuilder.java b/dmp-backend/src/main/java/utilities/builders/ModelBuilder.java index d4362918e..bcc17d35b 100644 --- a/dmp-backend/src/main/java/utilities/builders/ModelBuilder.java +++ b/dmp-backend/src/main/java/utilities/builders/ModelBuilder.java @@ -75,11 +75,6 @@ public class ModelBuilder { return (U) new AutoCompleteData().fromData(data); }else if(dataElement.getAttribute("type").equals("wordlist")) return (U) new WordListData().fromData(data); - }else{ - if(((ComboBoxData)data).getType().equals("autocomplete")){ - return (U) new AutoCompleteData().fromData(data); - }else if(((ComboBoxData)data).getType().equals("wordlist")) - return (U) new WordListData().fromData(data); } } if(type.equals("booleanDecision"))return null;