Resolve some additional maven depedency deprecations and improve performance

This commit is contained in:
George Kalampokis 2022-04-18 18:30:15 +03:00
parent 93deb96f99
commit 1d1226dc5f
6 changed files with 32 additions and 60 deletions

View File

@ -17,6 +17,7 @@ import java.io.IOException;
*/
public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> {
private static final Logger logger = LoggerFactory.getLogger(ElasticRepository.class);
private final ObjectMapper mapper = new ObjectMapper();
private RestHighLevelClient client;
public RestHighLevelClient getClient() {
@ -35,7 +36,6 @@ public abstract class ElasticRepository<T extends ElasticEntity,C extends Criter
}
public <T> T transformFromString(String value, Class<T> tClass) {
ObjectMapper mapper = new ObjectMapper();
T item = null;
try {
item = mapper.readValue(value, tClass);

View File

@ -42,9 +42,12 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
private String hint;
private Map<String, Join> joinsMap = new HashMap<>();
private final ObjectMapper mapper;
public QueryableHibernateList(EntityManager manager, Class<T> tClass) {
this.manager = manager;
this.tClass = tClass;
this.mapper = new ObjectMapper();
}
public QueryableHibernateList<T> setManager(EntityManager manager) {
@ -246,7 +249,6 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
if (!this.fields.isEmpty()) this.selectFields();
if (distinct) this.query.distinct(true);
//if (!this.fields.isEmpty()) this.query.multiselect(this.parseFields(this.fields));
ObjectMapper mapper = new ObjectMapper();
if (!this.fields.isEmpty()) return this.toListWithFields().stream().map(m -> mapper.convertValue(m, this.tClass)).collect(Collectors.toList());
return this.toListWithOutFields();
}

View File

@ -1,30 +0,0 @@
package eu.eudat.configurations;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import eu.eudat.criteria.entities.Criteria;
import eu.eudat.criteria.serialzier.CriteriaSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
@Configuration
public class JacksonConfiguration {
@Bean
public ObjectMapper buildObjectMapper() {
ArrayList<Module> modules = new ArrayList<>();
SimpleModule criteriaSerializerModule = new SimpleModule();
criteriaSerializerModule.addDeserializer(Criteria.class, new CriteriaSerializer());
modules.add(criteriaSerializerModule);
return new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModules(modules);
}
}

View File

@ -9,9 +9,7 @@ import eu.eudat.models.data.components.commons.datafield.AutoCompleteData;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.properties.PropertiesModel;
import eu.eudat.models.data.security.Principal;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -19,9 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.xml.xpath.XPathExpressionException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static eu.eudat.types.Authorities.ADMIN;

View File

@ -47,17 +47,17 @@ import java.util.stream.Stream;
public class DashBoardManager {
private static final Logger logger = LoggerFactory.getLogger(DashBoardManager.class);
private final Map<String, Comparator<RecentActivityModel>> comparators = Stream.of(new Object[][] {
{ "modified", Comparator.comparing(o -> ((RecentActivityModel)o).getModified()).reversed()},
{ "created", Comparator.comparing(o -> ((RecentActivityModel)o).getCreated()).reversed()},
{ "label", Comparator.comparing(o -> ((RecentActivityModel)o).getTitle())},
{ "status", Comparator.comparing(o -> ((RecentActivityModel)o).getStatus()).reversed()},
{ "finalizedAt", Comparator.comparing(o -> ((RecentActivityModel)o).getFinalizedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()},
{ "publishedAt", Comparator.comparing(o -> ((RecentActivityModel)o).getPublishedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Comparator<RecentActivityModel>)data[1]));
private final Map<String, Comparator<RecentActivityModel>> comparators = Stream.of(new Object[][]{
{"modified", Comparator.comparing(o -> ((RecentActivityModel) o).getModified()).reversed()},
{"created", Comparator.comparing(o -> ((RecentActivityModel) o).getCreated()).reversed()},
{"label", Comparator.comparing(o -> ((RecentActivityModel) o).getTitle())},
{"status", Comparator.comparing(o -> ((RecentActivityModel) o).getStatus()).reversed()},
{"finalizedAt", Comparator.comparing(o -> ((RecentActivityModel) o).getFinalizedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()},
{"publishedAt", Comparator.comparing(o -> ((RecentActivityModel) o).getPublishedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Comparator<RecentActivityModel>) data[1]));
private ApiContext apiContext;
private DatabaseRepository databaseRepository;
private final ApiContext apiContext;
private final DatabaseRepository databaseRepository;
private final DataManagementPlanManager dataManagementPlanManager;
private final DatasetManager datasetManager;
@ -152,21 +152,14 @@ public class DashBoardManager {
List<Integer> roles = new LinkedList<>();
if ((dmps == null || dmps == 0L) && (datasets == null || datasets == 0L)) {
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().countAsync()
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
CompletableFuture datasetFuture = datasetRepository.getAuthenticated( datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct().countAsync()
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
CompletableFuture.allOf(dmpFuture, datasetFuture).join();
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().count());
statistics.setTotalDataSetCount(datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct().count());
} else {
statistics.setTotalDataManagementPlanCount(dmps);
statistics.setTotalDataSetCount(datasets);
}
CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync()
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
CompletableFuture orgnanisationFuture = organisationRepository.getAuthenticated(organisationRepository.getWithCriteria(organisationCriteria).withHint("organisationRecentActivity"), user).countAsync()
.whenComplete((organisationStats, throwable) -> statistics.setTotalOrganisationCount(organisationStats));
CompletableFuture.allOf( grantFuture, orgnanisationFuture).join();
statistics.setTotalGrantCount(grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).count());
statistics.setTotalOrganisationCount(organisationRepository.getAuthenticated(organisationRepository.getWithCriteria(organisationCriteria).withHint("organisationRecentActivity"), user).count());
return statistics;
}

View File

@ -1,11 +1,15 @@
package eu.eudat.models.deposit.zenodo.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Organisation;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.logic.proxy.config.DOIFunder;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.models.deposit.zenodo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import java.time.Instant;
@ -13,9 +17,16 @@ import java.util.*;
import java.util.stream.Collectors;
public class DMPToZenodoMapper {
private static final ObjectMapper objectmapper = new ObjectMapper();
private static final Logger logger = LoggerFactory.getLogger(DMPToZenodoMapper.class);
public static ZenodoDeposit fromDMP(DMP dmp, Environment environment, ConfigLoader configLoader) {
Map<String, Object> extraProperties = dmp.getExtraProperties() != null ? new org.json.JSONObject(dmp.getExtraProperties()).toMap() : new HashMap<>();
Map<String, Object> extraProperties = null;
try {
extraProperties = dmp.getExtraProperties() != null ? objectmapper.readValue(dmp.getExtraProperties(), LinkedHashMap.class) : new HashMap<>();
} catch (JsonProcessingException e) {
logger.error(e.getLocalizedMessage(), e);
}
ZenodoDeposit deposit = new ZenodoDeposit();
deposit.setMetadata(new ZenodoDepositMetadata());
deposit.getMetadata().setTitle(dmp.getLabel());
@ -26,11 +37,11 @@ public class DMPToZenodoMapper {
ZenodoComunity community = new ZenodoComunity();
community.setIdentifier(environment.getProperty("zenodo.community"));
deposit.getMetadata().setCommunities(Collections.singletonList(community));
if (extraProperties.get("visible") == null) {
if (extraProperties != null && extraProperties.get("visible") == null) {
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
deposit.getMetadata().setAccessConditions("");
} else {
if (((Boolean) extraProperties.get("visible"))) {
if (extraProperties != null && ((Boolean) extraProperties.get("visible"))) {
Instant publicationDate = Instant.parse(extraProperties.get("publicDate").toString());
if (publicationDate.isBefore(Instant.now())) {
deposit.getMetadata().setAccessRight(ZenodoAccessRight.OPEN);