prefiling service refactor

This commit is contained in:
Efstratios Giannopoulos 2024-01-08 12:58:00 +02:00
parent 658310d8ce
commit 614fa9314a
9 changed files with 237 additions and 171 deletions

View File

@ -129,5 +129,9 @@ public class AuditableAction {
public static final EventId ContactSupport_Sent = new EventId(210000, "ContactSupport_Sent");
public static final EventId ContactSupport_PublicSent = new EventId(210001, "ContactSupport_PublicSent");
public static final EventId Prefilling_Query = new EventId(220000, "Prefilling_Query");
public static final EventId Prefilling_Generate = new EventId(210001, "Prefilling_Generate");
public static final EventId Prefilling_GenerateWithData = new EventId(210002, "Prefilling_GenerateWithData");
}

View File

@ -28,8 +28,14 @@ import eu.eudat.model.persist.DescriptionProfilingWithDataRequest;
import eu.eudat.query.ReferenceQuery;
import eu.eudat.service.remotefetcher.ExternalUrlConfigProvider;
import eu.eudat.service.remotefetcher.RemoteFetcherService;
import eu.eudat.service.remotefetcher.config.AuthenticationConfiguration;
import eu.eudat.service.remotefetcher.config.DataFieldsUrlConfiguration;
import eu.eudat.service.remotefetcher.config.DataUrlConfiguration;
import eu.eudat.service.remotefetcher.config.UrlConfiguration;
import eu.eudat.service.remotefetcher.config.entities.*;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.service.remotefetcher.criteria.FetchStrategy;
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
@ -54,6 +60,8 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -361,27 +369,27 @@ public class PrefillingServiceImpl implements PrefillingService {
if(fieldEntity.getData().getFieldType().equals(FieldType.AUTO_COMPLETE)) {
AutoCompleteDataEntity autoCompleteData = (AutoCompleteDataEntity)fieldEntity.getData();
isMultiSelect = autoCompleteData.getMultiAutoComplete();
// for (String format : parsedValues) {
// List<ExternalAutocompleteFieldModel> result = new ArrayList<>();
// try {
// result = datasetProfileManager.getAutocomplete(autoCompleteData, format);
// }
// catch (Exception e) {
// logger.error(e.getMessage(), e);
// }
// result = result.stream().filter(StreamDistinctBy.distinctByKey(ExternalAutocompleteFieldModel::getId)).collect(Collectors.toList());
// if(!result.isEmpty()){
// List<String> tempValues = new LinkedList<>();
// for (ExternalAutocompleteFieldModel f : result) {
// if (format.equals(f.getId()) || f.getLabel().toUpperCase(Locale.ROOT).contains(format.toUpperCase(Locale.ROOT)))
// tempValues.add(mapper.valueToTree(f).toString());
// }
// if (isMultiSelect)
// normalizedValues.addAll(tempValues);
// else if (!tempValues.isEmpty())
// normalizedValues.add(tempValues.get(0));
// }
// }
for (String format : parsedValues) {
List<ExternalAutocompleteFieldResult> result = new ArrayList<>();
try {
result = this.getAutocomplete(autoCompleteData, format);
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
result = result.stream().filter(StreamDistinctBy.distinctByKey(ExternalAutocompleteFieldResult::getId)).collect(Collectors.toList());
if(!result.isEmpty()){
List<String> tempValues = new LinkedList<>();
for (ExternalAutocompleteFieldResult f : result) {
if (format.equals(f.getId()) || f.getLabel().toUpperCase(Locale.ROOT).contains(format.toUpperCase(Locale.ROOT)))
tempValues.add(this.jsonHandlingService.toJsonSafe(f));
}
if (isMultiSelect)
normalizedValues.addAll(tempValues);
else if (!tempValues.isEmpty())
normalizedValues.add(tempValues.get(0));
}
}
return !normalizedValues.isEmpty() ? (isMultiSelect ? normalizedValues : normalizedValues.getFirst()) : null;
} else {
WordListDataEntity wordListDataEntity = (WordListDataEntity)fieldEntity.getData();
@ -411,6 +419,90 @@ public class PrefillingServiceImpl implements PrefillingService {
}
return parsedTags;
}
//endregion aa
public List<ExternalAutocompleteFieldResult> getAutocomplete(AutoCompleteDataEntity data, String like) throws URISyntaxException {
List<ExternalAutocompleteFieldResult> result = new LinkedList<>();
ExternalReferenceCriteria urlCriteria = new ExternalReferenceCriteria();
GeneralUrls genericUrls = new GeneralUrls();
int ordinal = 1;
List<Map<String, String>> rawResults = new ArrayList<>();
genericUrls.setFetchMode(FetchStrategy.FIRST);
urlCriteria.setLike(like);
for (AutoCompleteDataEntity.AutoCompleteSingleData singleData : data.getAutoCompleteSingleDataList()) {
UrlConfiguration urlConfiguration = new UrlConfiguration();
try {
URI uri;
if (singleData.getUrl().contains("?")) {
uri = new URI(singleData.getUrl().substring(0, singleData.getUrl().lastIndexOf("?")));
} else {
uri = new URI(singleData.getUrl());
}
String source = singleData.getAutoCompleteOptions().getSource();
source = source != null && !source.isEmpty() ? source : uri.getHost();
String uriString = singleData.getAutoCompleteOptions().getUri();
uriString = uriString != null && !uriString.isEmpty() ? uriString : "uri";
String parsedUrl = singleData.getUrl();
parsedUrl = parsedUrl.replace("%20", " ");
parsedUrl = parsedUrl.replace("%22", "\"");
while (parsedUrl.contains("&amp;")) {
parsedUrl = parsedUrl.replace("&amp;", "&");
}
urlConfiguration.setUrl(parsedUrl);
urlConfiguration.setOrdinal(ordinal);
urlConfiguration.setType("External");
urlConfiguration.setContentType(MediaType.APPLICATION_JSON_VALUE);
urlConfiguration.setFirstpage("1");
urlConfiguration.setRequestType(singleData.getMethod() != null ? singleData.getMethod() : "GET");
DataUrlConfiguration dataUrlConfiguration = new DataUrlConfiguration();
dataUrlConfiguration.setPath(singleData.getOptionsRoot());
DataFieldsUrlConfiguration fieldsUrlConfiguration = new DataFieldsUrlConfiguration();
fieldsUrlConfiguration.setId(singleData.getAutoCompleteOptions().getValue());
fieldsUrlConfiguration.setName(singleData.getAutoCompleteOptions().getLabel());
fieldsUrlConfiguration.setSource(singleData.getAutoCompleteOptions().getSource().isEmpty()? null : singleData.getAutoCompleteOptions().getSource());
fieldsUrlConfiguration.setUri(uriString);
dataUrlConfiguration.setFieldsUrlConfiguration(fieldsUrlConfiguration);
urlConfiguration.setKey(source);
urlConfiguration.setLabel(source);
urlConfiguration.setData(dataUrlConfiguration);
if (singleData.getHasAuth()) {
AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
authenticationConfiguration.setAuthUrl(singleData.getAuth().getUrl());
authenticationConfiguration.setAuthMethod(singleData.getAuth().getMethod());
authenticationConfiguration.setAuthTokenPath(singleData.getAuth().getPath());
authenticationConfiguration.setAuthRequestBody(singleData.getAuth().getBody());
authenticationConfiguration.setType(singleData.getAuth().getType());
urlConfiguration.setAuth(authenticationConfiguration);
}
genericUrls.getUrls().add(urlConfiguration);
List<Map<String, String>> singleResults = this.remoteFetcherService.getExternalGeneric(urlCriteria, genericUrls);
if (!singleResults.isEmpty() && !singleResults.get(0).containsKey("source") && !singleData.getAutoCompleteOptions().getSource().isEmpty()) {
singleResults.forEach(singleResult -> singleResult.put("source", singleData.getAutoCompleteOptions().getSource()));
}
rawResults.addAll(singleResults);
genericUrls.getUrls().clear();
} catch (URISyntaxException e) {
logger.error(e.getMessage(), e);
}
}
rawResults.forEach(item -> result.add(new ExternalAutocompleteFieldResult(parseItem(item.get("pid")), parseItem(item.get("name")), parseItem(item.get("source")), parseItem(item.get("uri")))));
return result;
}
private static String parseItem(Object item) {
if (item instanceof String) {
return (String) item;
}
if (item instanceof List) {
List listedItems = (List) item;
return parseItem(listedItems.get(0));
}
if (item instanceof Map) {
return String.valueOf(((Map)item).get("$"));
}
return item != null ? item.toString() : null;
}
//endregion Description Mapping
}

View File

@ -1,12 +1,12 @@
package eu.eudat.models.data.externaldataset;
package eu.eudat.service.remotefetcher.models;
public class ExternalAutocompleteFieldModel {
public class ExternalAutocompleteFieldResult {
private String id;
private String label;
private String source;
private String uri;
public ExternalAutocompleteFieldModel(String id, String label, String source, String uri) {
public ExternalAutocompleteFieldResult(String id, String label, String source, String uri) {
this.id = id;
this.label = label;
this.source = source;

View File

@ -6,7 +6,7 @@ import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
import eu.eudat.models.data.helpers.common.AutoCompleteOptionsLookupItem;
import gr.cite.commons.web.authz.service.AuthorizationService;
@ -64,7 +64,7 @@ public class DatasetProfileController extends BaseController {
DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(lookupItem.getCriteria().getProfileID()));
FieldEntity modelfield = this.datasetProfileManager.queryForField(descriptionTemplateEntity.getDefinition(), lookupItem.getCriteria().getFieldID());
AutoCompleteDataEntity data = (AutoCompleteDataEntity) modelfield.getData();
List<ExternalAutocompleteFieldModel> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
List<ExternalAutocompleteFieldResult> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
return ResponseEntity.status(HttpStatus.OK).body(items);
}
@ -72,7 +72,7 @@ public class DatasetProfileController extends BaseController {
public ResponseEntity<Object> getDataForAutocompleteOptions(@RequestBody RequestItem<AutoCompleteOptionsLookupItem> lookupItem) {
AutoCompleteDataEntity data = new AutoCompleteDataEntity();
data.setAutoCompleteSingleDataList(lookupItem.getCriteria().getAutoCompleteSingleDataList());
List<ExternalAutocompleteFieldModel> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
List<ExternalAutocompleteFieldResult> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
return ResponseEntity.status(HttpStatus.OK).body(items);
}

View File

@ -1,46 +0,0 @@
package eu.eudat.controllers;
import eu.eudat.logic.managers.PrefillingManager;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.commons.types.prefilling.PrefillingEntity;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api"})
public class Prefillings {
private final PrefillingManager prefillingManager;
@Autowired
public Prefillings(PrefillingManager prefillingManager) {
this.prefillingManager = prefillingManager;
}
@RequestMapping(method = RequestMethod.GET, value = {"/prefilling/list"}, produces = "application/json")
public ResponseEntity<ResponseItem<List<PrefillingEntity>>> getPrefillingList(@RequestParam String like) {
List<PrefillingEntity> prefillingList = prefillingManager.getPrefillings(like);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<PrefillingEntity>>().payload(prefillingList).status(ApiMessageCode.NO_MESSAGE));
}
@RequestMapping(method = RequestMethod.GET, value = {"/prefilling/generate/{id}"}, produces = "application/json")
public ResponseEntity<ResponseItem<DatasetWizardModel>> getPrefillingDataset(@PathVariable String id, @RequestParam String configId, @RequestParam UUID profileId) throws Exception {
DatasetWizardModel datasetWizardModel = prefillingManager.getPrefilledDataset(id, configId, profileId);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().payload(datasetWizardModel).status(ApiMessageCode.NO_MESSAGE));
}
@RequestMapping(method = RequestMethod.POST, value = {"/prefilling/generateUsingData"}, produces = "application/json")
public ResponseEntity<ResponseItem<DatasetWizardModel>> getPrefillingDataset(@RequestBody Map<String, Object> data, @RequestParam String configId, @RequestParam UUID profileId) throws Exception {
DatasetWizardModel datasetWizardModel = prefillingManager.getPrefilledDatasetUsingData(data, configId, profileId);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().payload(datasetWizardModel).status(ApiMessageCode.NO_MESSAGE));
}
}

View File

@ -0,0 +1,105 @@
package eu.eudat.controllers.v2;
import eu.eudat.audit.AuditableAction;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.model.Description;
import eu.eudat.model.Prefilling;
import eu.eudat.model.PrefillingLookup;
import eu.eudat.model.censorship.DescriptionCensor;
import eu.eudat.model.censorship.PrefillingCensor;
import eu.eudat.model.persist.DescriptionProfilingRequest;
import eu.eudat.model.persist.DescriptionProfilingWithDataRequest;
import eu.eudat.service.prefilling.PrefillingService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(path = "api/prefilling")
public class PrefillingController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PrefillingController.class));
@Autowired
private final AuditService auditService;
private final PrefillingService prefillingService;
private final CensorFactory censorFactory;
public PrefillingController(
AuditService auditService,
PrefillingService prefillingService,
CensorFactory censorFactory) {
this.auditService = auditService;
this.prefillingService = prefillingService;
this.censorFactory = censorFactory;
}
@PostMapping("query")
public List<Prefilling> query(@RequestBody PrefillingLookup model) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
this.censorFactory.censor(PrefillingCensor.class).censor(model.getProject(), null);
logger.debug(new MapLogEntry("persisting" + Prefilling.class.getSimpleName()).And("model", model));
List<Prefilling> items = this.prefillingService.getPrefillings(model);
this.auditService.track(AuditableAction.Prefilling_Query, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model)
));
return items;
}
@PostMapping("generate")
@ValidationFilterAnnotation(validator = DescriptionProfilingRequest.DescriptionProfilingRequestValidator.ValidatorName, argumentName = "model")
public Description generate(@RequestBody DescriptionProfilingRequest model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("persisting" + Prefilling.class.getSimpleName()).And("model", model));
this.censorFactory.censor(DescriptionCensor.class).censor(model.getProject(), null);
Description item = this.prefillingService.getPrefilledDescription(model);
this.auditService.track(AuditableAction.Prefilling_Generate, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model)
));
return item;
}
@PostMapping("generate-with-data")
@ValidationFilterAnnotation(validator = DescriptionProfilingWithDataRequest.DescriptionProfilingWithDataRequestValidator.ValidatorName, argumentName = "model")
public Description generateWithData(@RequestBody DescriptionProfilingWithDataRequest model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException {
logger.debug(new MapLogEntry("persisting" + Prefilling.class.getSimpleName()).And("model", model));
this.censorFactory.censor(DescriptionCensor.class).censor(model.getProject(), null);
Description item = this.prefillingService.getPrefilledDescriptionUsingData(model);
this.auditService.track(AuditableAction.Prefilling_GenerateWithData, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model)
));
return item;
}
}

View File

@ -9,7 +9,7 @@ import eu.eudat.service.remotefetcher.config.entities.GeneralUrls;
import eu.eudat.service.remotefetcher.RemoteFetcherService;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
import eu.eudat.service.remotefetcher.config.AuthenticationConfiguration;
import eu.eudat.service.remotefetcher.config.DataFieldsUrlConfiguration;
import eu.eudat.service.remotefetcher.config.DataUrlConfiguration;
@ -71,7 +71,7 @@ public class DatasetProfileManager {
return fieldEntity;
}
public List<ExternalAutocompleteFieldModel> getAutocomplete(AutoCompleteDataEntity data, String like) {
public List<ExternalAutocompleteFieldResult> getAutocomplete(AutoCompleteDataEntity data, String like) {
/*List<ExternalAutocompleteFieldModel> result = new LinkedList<>();
SimpleClientHttpRequestFactory simpleFactory = new SimpleClientHttpRequestFactory();
@ -136,7 +136,7 @@ public class DatasetProfileManager {
return result.stream().sorted(Comparator.comparing(ExternalAutocompleteFieldModel::getLabel)).collect(Collectors.toList());
*/
List<ExternalAutocompleteFieldModel> result = new LinkedList<>();
List<ExternalAutocompleteFieldResult> result = new LinkedList<>();
ExternalReferenceCriteria urlCriteria = new ExternalReferenceCriteria();
GeneralUrls genericUrls = new GeneralUrls();
int ordinal = 1;
@ -199,7 +199,7 @@ public class DatasetProfileManager {
logger.error(e.getMessage(), e);
}
}
rawResults.forEach(item -> result.add(new ExternalAutocompleteFieldModel(parseItem(item.get("pid")), parseItem(item.get("name")), parseItem(item.get("source")), parseItem(item.get("uri")))));
rawResults.forEach(item -> result.add(new ExternalAutocompleteFieldResult(parseItem(item.get("pid")), parseItem(item.get("name")), parseItem(item.get("source")), parseItem(item.get("uri")))));
return result;
}

View File

@ -1,89 +0,0 @@
package eu.eudat.logic.managers;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.logic.mapper.prefilling.PrefillingMapper;
import eu.eudat.service.remotefetcher.ExternalUrlConfigProvider;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.service.remotefetcher.config.entities.PrefillingConfig;
import eu.eudat.service.remotefetcher.config.entities.PrefillingGet;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.commons.types.prefilling.PrefillingEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class PrefillingManager {
private static final Logger logger = LoggerFactory.getLogger(PrefillingManager.class);
private final ApiContext apiContext;
private final ObjectMapper objectMapper;
private final DatasetManager datasetManager;
// private final LicenseManager licenseManager;
private final PrefillingMapper prefillingMapper;
private final ExternalUrlConfigProvider externalUrlConfigProvider;
@Autowired
public PrefillingManager(ApiContext apiContext, DatasetManager datasetManager /*, LicenseManager licenseManager*/, PrefillingMapper prefillingMapper, ExternalUrlConfigProvider externalUrlConfigProvider) {
this.apiContext = apiContext;
this.prefillingMapper = prefillingMapper;
this.externalUrlConfigProvider = externalUrlConfigProvider;
this.objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.datasetManager = datasetManager;
// this.licenseManager = licenseManager;
}
public List<PrefillingEntity> getPrefillings(String like) {
ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria();
externalReferenceCriteria.setLike(like);
List<PrefillingEntity> prefillings = new ArrayList<>();
List<Map<String, String>> map;
Map<String, PrefillingConfig> prefillingConfigs = this.externalUrlConfigProvider.getExternalUrls().getPrefillings();
for (PrefillingConfig prefillingConfig: prefillingConfigs.values()) {
map = apiContext.getOperationsContext().getRemoteFetcher().getExternalGeneric(externalReferenceCriteria, prefillingConfig.getPrefillingSearch());
prefillings.addAll(map.stream().map(submap -> objectMapper.convertValue(submap, PrefillingEntity.class)).collect(Collectors.toList()));
if (prefillingConfig.getPrefillingSearch().getUrlConfig().isDataInListing()) {
List<Map<String, Object>> mapData = apiContext.getOperationsContext().getRemoteFetcher().getExternalGenericWithData(externalReferenceCriteria, prefillingConfig.getPrefillingSearch());
for (int i = 0; i < mapData.size(); i++) {
prefillings.get(i).setData(mapData.get(i));
}
prefillings = prefillings.stream().filter(prefilling -> prefilling.getData() != null).collect(Collectors.toList());
}
}
return prefillings;
}
public DatasetWizardModel getPrefilledDataset(String prefillId, String configId, UUID profileId) throws Exception {
PrefillingConfig prefillingConfig = this.externalUrlConfigProvider.getExternalUrls().getPrefillings().get(configId);
PrefillingGet prefillingGet = prefillingConfig.getPrefillingGet();
Map<String, Object> prefillingEntity = getSingle(prefillingGet.getUrl(), prefillId);
DescriptionTemplateEntity descriptionTemplateEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(profileId);
return prefillingMapper.mapPrefilledEntityToDatasetWizard(prefillingEntity, prefillingGet, prefillingConfig.getType(), descriptionTemplateEntity, datasetManager/*, licenseManager*/);
}
public DatasetWizardModel getPrefilledDatasetUsingData(Map<String, Object> data, String configId, UUID profileId) throws Exception {
PrefillingConfig prefillingConfig = this.externalUrlConfigProvider.getExternalUrls().getPrefillings().get(configId);
PrefillingGet prefillingGet = prefillingConfig.getPrefillingGet();
DescriptionTemplateEntity descriptionTemplateEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(profileId);
return prefillingMapper.mapPrefilledEntityToDatasetWizard(data, prefillingGet, prefillingConfig.getType(), descriptionTemplateEntity, datasetManager/*, licenseManager*/);
}
private Map<String, Object> getSingle(String url, String id) {
RestTemplate restTemplate = new RestTemplate();
String parsedUrl = url.replace("{id}", id);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity("", headers);
return restTemplate.exchange(parsedUrl, HttpMethod.GET, entity, LinkedHashMap.class).getBody();
}
}

View File

@ -18,7 +18,7 @@ import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -230,17 +230,17 @@ public class PrefillingMapper {
AutoCompleteDataEntity autoCompleteDataEntity = mapper.treeToValue(dataNode, AutoCompleteDataEntity.class);
isMultiSelect = autoCompleteDataEntity.getMultiAutoComplete();
for (String format : parsedValues) {
List<ExternalAutocompleteFieldModel> result = new ArrayList<>();
List<ExternalAutocompleteFieldResult> result = new ArrayList<>();
try {
result = datasetProfileManager.getAutocomplete(autoCompleteDataEntity, format);
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
result = result.stream().filter(StreamDistinctBy.distinctByKey(ExternalAutocompleteFieldModel::getId)).collect(Collectors.toList());
result = result.stream().filter(StreamDistinctBy.distinctByKey(ExternalAutocompleteFieldResult::getId)).collect(Collectors.toList());
if(!result.isEmpty()){
List<String> tempValues = new LinkedList<>();
for (ExternalAutocompleteFieldModel f : result) {
for (ExternalAutocompleteFieldResult f : result) {
if (format.equals(f.getId()) || f.getLabel().toUpperCase(Locale.ROOT).contains(format.toUpperCase(Locale.ROOT)))
tempValues.add(mapper.valueToTree(f).toString());
}