Resolve some additional maven depedency deprecations and improve performance
This commit is contained in:
parent
93deb96f99
commit
1d1226dc5f
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> {
|
public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ElasticRepository.class);
|
private static final Logger logger = LoggerFactory.getLogger(ElasticRepository.class);
|
||||||
|
private final ObjectMapper mapper = new ObjectMapper();
|
||||||
private RestHighLevelClient client;
|
private RestHighLevelClient client;
|
||||||
|
|
||||||
public RestHighLevelClient getClient() {
|
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) {
|
public <T> T transformFromString(String value, Class<T> tClass) {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
T item = null;
|
T item = null;
|
||||||
try {
|
try {
|
||||||
item = mapper.readValue(value, tClass);
|
item = mapper.readValue(value, tClass);
|
||||||
|
|
|
@ -42,9 +42,12 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
private String hint;
|
private String hint;
|
||||||
private Map<String, Join> joinsMap = new HashMap<>();
|
private Map<String, Join> joinsMap = new HashMap<>();
|
||||||
|
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
public QueryableHibernateList(EntityManager manager, Class<T> tClass) {
|
public QueryableHibernateList(EntityManager manager, Class<T> tClass) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.tClass = tClass;
|
this.tClass = tClass;
|
||||||
|
this.mapper = new ObjectMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryableHibernateList<T> setManager(EntityManager manager) {
|
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 (!this.fields.isEmpty()) this.selectFields();
|
||||||
if (distinct) this.query.distinct(true);
|
if (distinct) this.query.distinct(true);
|
||||||
//if (!this.fields.isEmpty()) this.query.multiselect(this.parseFields(this.fields));
|
//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());
|
if (!this.fields.isEmpty()) return this.toListWithFields().stream().map(m -> mapper.convertValue(m, this.tClass)).collect(Collectors.toList());
|
||||||
return this.toListWithOutFields();
|
return this.toListWithOutFields();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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.externaldataset.ExternalAutocompleteFieldModel;
|
||||||
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
|
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.data.properties.PropertiesModel;
|
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -19,9 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static eu.eudat.types.Authorities.ADMIN;
|
import static eu.eudat.types.Authorities.ADMIN;
|
||||||
|
|
|
@ -47,17 +47,17 @@ import java.util.stream.Stream;
|
||||||
public class DashBoardManager {
|
public class DashBoardManager {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DashBoardManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(DashBoardManager.class);
|
||||||
|
|
||||||
private final Map<String, Comparator<RecentActivityModel>> comparators = Stream.of(new Object[][] {
|
private final Map<String, Comparator<RecentActivityModel>> comparators = Stream.of(new Object[][]{
|
||||||
{ "modified", Comparator.comparing(o -> ((RecentActivityModel)o).getModified()).reversed()},
|
{"modified", Comparator.comparing(o -> ((RecentActivityModel) o).getModified()).reversed()},
|
||||||
{ "created", Comparator.comparing(o -> ((RecentActivityModel)o).getCreated()).reversed()},
|
{"created", Comparator.comparing(o -> ((RecentActivityModel) o).getCreated()).reversed()},
|
||||||
{ "label", Comparator.comparing(o -> ((RecentActivityModel)o).getTitle())},
|
{"label", Comparator.comparing(o -> ((RecentActivityModel) o).getTitle())},
|
||||||
{ "status", Comparator.comparing(o -> ((RecentActivityModel)o).getStatus()).reversed()},
|
{"status", Comparator.comparing(o -> ((RecentActivityModel) o).getStatus()).reversed()},
|
||||||
{ "finalizedAt", Comparator.comparing(o -> ((RecentActivityModel)o).getFinalizedAt(), Comparator.nullsLast(Comparator.naturalOrder())).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()}
|
{"publishedAt", Comparator.comparing(o -> ((RecentActivityModel) o).getPublishedAt(), Comparator.nullsLast(Comparator.naturalOrder())).reversed()}
|
||||||
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Comparator<RecentActivityModel>)data[1]));
|
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Comparator<RecentActivityModel>) data[1]));
|
||||||
|
|
||||||
private ApiContext apiContext;
|
private final ApiContext apiContext;
|
||||||
private DatabaseRepository databaseRepository;
|
private final DatabaseRepository databaseRepository;
|
||||||
private final DataManagementPlanManager dataManagementPlanManager;
|
private final DataManagementPlanManager dataManagementPlanManager;
|
||||||
private final DatasetManager datasetManager;
|
private final DatasetManager datasetManager;
|
||||||
|
|
||||||
|
@ -152,21 +152,14 @@ public class DashBoardManager {
|
||||||
|
|
||||||
List<Integer> roles = new LinkedList<>();
|
List<Integer> roles = new LinkedList<>();
|
||||||
if ((dmps == null || dmps == 0L) && (datasets == null || datasets == 0L)) {
|
if ((dmps == null || dmps == 0L) && (datasets == null || datasets == 0L)) {
|
||||||
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().countAsync()
|
statistics.setTotalDataManagementPlanCount(dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).distinct().count());
|
||||||
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
statistics.setTotalDataSetCount(datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct().count());
|
||||||
CompletableFuture datasetFuture = datasetRepository.getAuthenticated( datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct().countAsync()
|
|
||||||
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
|
||||||
CompletableFuture.allOf(dmpFuture, datasetFuture).join();
|
|
||||||
} else {
|
} else {
|
||||||
statistics.setTotalDataManagementPlanCount(dmps);
|
statistics.setTotalDataManagementPlanCount(dmps);
|
||||||
statistics.setTotalDataSetCount(datasets);
|
statistics.setTotalDataSetCount(datasets);
|
||||||
}
|
}
|
||||||
CompletableFuture grantFuture = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).countAsync()
|
statistics.setTotalGrantCount(grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user).count());
|
||||||
.whenComplete((grantsStats, throwable) -> statistics.setTotalGrantCount(grantsStats));
|
statistics.setTotalOrganisationCount(organisationRepository.getAuthenticated(organisationRepository.getWithCriteria(organisationCriteria).withHint("organisationRecentActivity"), user).count());
|
||||||
CompletableFuture orgnanisationFuture = organisationRepository.getAuthenticated(organisationRepository.getWithCriteria(organisationCriteria).withHint("organisationRecentActivity"), user).countAsync()
|
|
||||||
.whenComplete((organisationStats, throwable) -> statistics.setTotalOrganisationCount(organisationStats));
|
|
||||||
|
|
||||||
CompletableFuture.allOf( grantFuture, orgnanisationFuture).join();
|
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package eu.eudat.models.deposit.zenodo.mapper;
|
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.DMP;
|
||||||
import eu.eudat.data.entities.Organisation;
|
import eu.eudat.data.entities.Organisation;
|
||||||
import eu.eudat.data.entities.UserDMP;
|
import eu.eudat.data.entities.UserDMP;
|
||||||
import eu.eudat.logic.proxy.config.DOIFunder;
|
import eu.eudat.logic.proxy.config.DOIFunder;
|
||||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||||
import eu.eudat.models.deposit.zenodo.*;
|
import eu.eudat.models.deposit.zenodo.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -13,9 +17,16 @@ import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DMPToZenodoMapper {
|
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) {
|
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();
|
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||||
deposit.setMetadata(new ZenodoDepositMetadata());
|
deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
deposit.getMetadata().setTitle(dmp.getLabel());
|
deposit.getMetadata().setTitle(dmp.getLabel());
|
||||||
|
@ -26,11 +37,11 @@ public class DMPToZenodoMapper {
|
||||||
ZenodoComunity community = new ZenodoComunity();
|
ZenodoComunity community = new ZenodoComunity();
|
||||||
community.setIdentifier(environment.getProperty("zenodo.community"));
|
community.setIdentifier(environment.getProperty("zenodo.community"));
|
||||||
deposit.getMetadata().setCommunities(Collections.singletonList(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().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
||||||
deposit.getMetadata().setAccessConditions("");
|
deposit.getMetadata().setAccessConditions("");
|
||||||
} else {
|
} else {
|
||||||
if (((Boolean) extraProperties.get("visible"))) {
|
if (extraProperties != null && ((Boolean) extraProperties.get("visible"))) {
|
||||||
Instant publicationDate = Instant.parse(extraProperties.get("publicDate").toString());
|
Instant publicationDate = Instant.parse(extraProperties.get("publicDate").toString());
|
||||||
if (publicationDate.isBefore(Instant.now())) {
|
if (publicationDate.isBefore(Instant.now())) {
|
||||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.OPEN);
|
deposit.getMetadata().setAccessRight(ZenodoAccessRight.OPEN);
|
||||||
|
|
Loading…
Reference in New Issue