bug fixes regarding tickets: #8739, #8763, #8833

This commit is contained in:
Bernaldo Mihasi 2023-06-21 12:17:22 +03:00
parent dfa2f0cd38
commit 34e4761811
8 changed files with 88 additions and 49 deletions

View File

@ -261,6 +261,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
}
if (criteria.getDatasetTemplates() != null && criteria.getDatasetTemplates().size() > 0) {
criteria.setDatasetTemplates(criteria.getDatasetTemplates().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.template", criteria.getDatasetTemplates().stream().map(UUID::toString).collect(Collectors.toList())));
}
@ -269,14 +270,17 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
}
if (criteria.getDmps() != null && criteria.getDmps().size() > 0) {
criteria.setDmps(criteria.getDmps().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.dmp", criteria.getDmps().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
criteria.setGroupIds(criteria.getGroupIds().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.group", criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
criteria.setGrants(criteria.getGrants().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.grant", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
}
@ -285,6 +289,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
}
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
criteria.setCollaborators(criteria.getCollaborators().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.collaborators.id.keyword", criteria.getCollaborators().stream().map(UUID::toString).collect(Collectors.toList())));
}
@ -295,10 +300,12 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
}
if (criteria.getOrganiztions() != null && criteria.getOrganiztions().size() > 0) {
criteria.setOrganiztions(criteria.getOrganiztions().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.organizations.id", criteria.getOrganiztions()));
}
if (criteria.getTags() != null && criteria.getTags().size() > 0) {
criteria.setTags(criteria.getTags().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.tags.name", criteria.getTags().stream().map(Tag::getName).collect(Collectors.toList())));
}

View File

@ -256,7 +256,8 @@ public class Datasets extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<DatasetWizardModel>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) throws Exception {
DatasetWizardModel dataset = new DatasetWizardModel().fromDataModel(this.datasetManager.createOrUpdate(profile, principal));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dataset));
dataset.setTags(profile.getTags());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dataset));
}
@Transactional

View File

@ -1143,19 +1143,21 @@ public class DatasetManager {
if (!tagNodes.isEmpty()) {
tagNodes.forEach(node -> {
JsonNode value = node.get("value");
if (!value.toString().equals("\"\"") && !value.toString().equals("null") && value.toString().startsWith("[")) {
String stringValue = value.toString().replaceAll("=", ":");
JSONArray values = new JSONArray(stringValue);
values.iterator().forEachRemaining(element -> {
Map<String, Object> data = ((JSONObject) element).toMap();
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
});
} else {
List<String> values = Arrays.asList(value.textValue().split(", "));
List<Tag> tagValues = values.stream().map(stringValue -> new Tag(stringValue, stringValue)).collect(Collectors.toList());
tagValues.iterator().forEachRemaining(tag -> {
this.addTag(tags, wizardModel.getTags(), tag.getId(), tag.getName());
});
if (!value.toString().equals("\"\"") && !value.toString().equals("null")) {
if (value.toString().startsWith("[")) {
String stringValue = value.toString().replaceAll("=", ":");
JSONArray values = new JSONArray(stringValue);
values.iterator().forEachRemaining(element -> {
Map<String, Object> data = ((JSONObject) element).toMap();
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
});
} else {
List<String> values = Arrays.asList(value.textValue().split(", "));
List<Tag> tagValues = values.stream().map(stringValue -> new Tag(stringValue, stringValue)).collect(Collectors.toList());
tagValues.iterator().forEachRemaining(tag -> {
this.addTag(tags, wizardModel.getTags(), tag.getId(), tag.getName());
});
}
}
});
}

View File

@ -271,6 +271,10 @@ public class RemoteFetcher {
*/
completedPath = completedPath.replace("{funderId}", funderId);
}
else if(completedPath.contains("{funderId}")){
logger.warn("FunderId is null.");
completedPath = completedPath.replace("{funderId}", " ");
}
if (externalUrlCriteria.getPage() != null) {
completedPath = completedPath.replace("{page}", externalUrlCriteria.getPage());
} else {
@ -305,33 +309,38 @@ public class RemoteFetcher {
String replacedBody = replaceCriteriaOnUrl(requestBody, externalUrlCriteria, firstPage, queries);
Results results = getResultsFromUrl(replacedPath, jsonDataPath, jsonPaginationPath, contentType, replacedBody, requestType);
if(filterType != null && filterType.equals("local") && (externalUrlCriteria.getLike() != null && !externalUrlCriteria.getLike().isEmpty())){
results.setResults(results.getResults().stream()
.filter(r -> r.get("name").toLowerCase().contains(externalUrlCriteria.getLike().toLowerCase()))
.collect(Collectors.toList()));
if(results != null) {
if (filterType != null && filterType.equals("local") && (externalUrlCriteria.getLike() != null && !externalUrlCriteria.getLike().isEmpty())) {
results.setResults(results.getResults().stream()
.filter(r -> r.get("name").toLowerCase().contains(externalUrlCriteria.getLike().toLowerCase()))
.collect(Collectors.toList()));
}
if (fetchStrategy == FetchStrategy.FIRST)
return results.getResults().stream().peek(x -> x.put("tag", tag)).peek(x -> x.put("key", key)).collect(Collectors.toList());
if (results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set
for (int i = 2; i <= results.getPagination().get("pages"); i++)
pages.add(i);
Long maxResults = configLoader.getExternalUrls().getMaxresults();
if ((maxResults > 0) && (results.getPagination().get("count") > maxResults))
throw new HugeResultSet("The submitted search query " + externalUrlCriteria.getLike() + " is about to return " + results.getPagination().get("count") + " results... Please submit a more detailed search query");
Optional<Results> optionalResults = pages.parallelStream()
.map(page -> getResultsFromUrl(path + "&page=" + page, jsonDataPath, jsonPaginationPath, contentType, replacedBody, requestType))
.filter(Objects::nonNull)
.reduce((result1, result2) -> {
result1.getResults().addAll(result2.getResults());
return result1;
});
Results remainingResults = optionalResults.orElseGet(Results::new);
remainingResults.getResults().addAll(results.getResults());
return remainingResults.getResults().stream().peek(x -> x.put("tag", tag)).collect(Collectors.toList());
}
else {
return new LinkedList<>();
}
if (fetchStrategy == FetchStrategy.FIRST)
return results == null ? new LinkedList<>() : results.getResults().stream().peek(x -> x.put("tag", tag)).peek(x -> x.put("key", key)).collect(Collectors.toList());
if (results != null && results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set
for (int i = 2; i <= results.getPagination().get("pages"); i++)
pages.add(i);
Long maxResults = configLoader.getExternalUrls().getMaxresults();
if ((maxResults > 0 && results != null) && (results.getPagination().get("count") > maxResults))
throw new HugeResultSet("The submitted search query " + externalUrlCriteria.getLike() + " is about to return " + results.getPagination().get("count") + " results... Please submit a more detailed search query");
Optional<Results> optionalResults = pages.parallelStream()
.map(page -> getResultsFromUrl(path + "&page=" + page, jsonDataPath, jsonPaginationPath, contentType, replacedBody, requestType))
.filter(Objects::nonNull)
.reduce((result1, result2) -> {
result1.getResults().addAll(result2.getResults());
return result1;
});
Results remainingResults = optionalResults.orElseGet(Results::new);
remainingResults.getResults().addAll(results.getResults());
return remainingResults.getResults().stream().peek(x -> x.put("tag", tag)).collect(Collectors.toList());
}

View File

@ -256,7 +256,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
@Override
public void toMap(Map<String, Object> fieldValues) {
if (this.value != null) {
if ((this.viewStyle != null && this.viewStyle.getRenderStyle().equals("datasetIdentifier") || this.value instanceof Collection)) {
if ((this.viewStyle != null && this.viewStyle.getRenderStyle().equals("datasetIdentifier") && this.value instanceof Map || this.value instanceof Collection)) {
ObjectMapper mapper = new ObjectMapper();
String valueString = null;
try {

View File

@ -347,7 +347,9 @@ public class DatasetRDAMapper {
List<Tag> tags = this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).collect(Collectors.toList());
if(!rda.getKeyword().isEmpty()){
List<Tag> templateTags = tags.stream().filter(tag -> rda.getKeyword().contains(tag.getName())).collect(Collectors.toList());
properties.put(keywordIds.get(0), mapper.writeValueAsString(templateTags));
if(!templateTags.isEmpty()) {
properties.put(keywordIds.get(0), mapper.writeValueAsString(templateTags));
}
// for (int i = 0; i < keywordIds.size(); i++) {
// //if (takeAll) {
// List<String> tags = new ArrayList<>();

View File

@ -7,9 +7,12 @@ import eu.eudat.models.rda.Cost;
import eu.eudat.models.rda.Dmp;
import eu.eudat.models.rda.DmpId;
import net.minidev.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.persistence.NoResultException;
import javax.transaction.Transactional;
import java.io.IOException;
import java.util.*;
@ -18,6 +21,8 @@ import java.util.stream.Collectors;
@Component
public class DmpRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DmpRDAMapper.class);
private DatasetRDAMapper datasetRDAMapper;
private ApiContext apiContext;
@ -109,10 +114,16 @@ public class DmpRDAMapper {
DMP entity = new DMP();
entity.setLabel(rda.getTitle());
if (rda.getDmpId().getType() == DmpId.Type.DOI) {
EntityDoi doi = apiContext.getOperationsContext().getDatabaseRepository().getEntityDoiDao().findFromDoi(rda.getDmpId().getIdentifier());
Set<EntityDoi> dois = new HashSet<>();
dois.add(doi);
entity.setDois(dois);
try {
EntityDoi doi = apiContext.getOperationsContext().getDatabaseRepository().getEntityDoiDao().findFromDoi(rda.getDmpId().getIdentifier());
Set<EntityDoi> dois = new HashSet<>();
dois.add(doi);
entity.setDois(dois);
}
catch (NoResultException e) {
logger.warn("No entity doi: " + rda.getDmpId().getIdentifier() + " found in database. No dois are added to dmp.");
entity.setDois(new HashSet<>());
}
}
if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty()) {
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).filter(Objects::nonNull).collect(Collectors.toSet()));
@ -127,7 +138,7 @@ public class DmpRDAMapper {
}
}
if (rda.getContributor() != null && !rda.getContributor().isEmpty() && rda.getContributor().get(0).getContributorId() != null) {
entity.setResearchers(rda.getContributor().stream().map(ContributorRDAMapper::toEntity).filter(StreamDistinctBy.distinctByKey(Researcher::getReference)).collect(Collectors.toSet()));
entity.setResearchers(rda.getContributor().stream().filter(r -> r.getContributorId() != null).map(ContributorRDAMapper::toEntity).filter(StreamDistinctBy.distinctByKey(Researcher::getReference)).collect(Collectors.toSet()));
}
entity.setCreated(rda.getCreated());
entity.setModified(rda.getModified());

View File

@ -9,8 +9,15 @@ export class DatasetIdModel {
try{
const parsed = JSON.parse(data);
if (!isNullOrUndefined(parsed)) {
this.identifier = parsed.identifier;
this.type = parsed.type;
if(typeof parsed !== 'string'){
this.identifier = parsed.identifier;
this.type = parsed.type;
}
else{
const parsedObjectFromString = JSON.parse(parsed);
this.identifier = parsedObjectFromString.identifier;
this.type = parsedObjectFromString.type;
}
}
}
catch(error){