Improve json parsing

This commit is contained in:
George Kalampokis 2022-01-18 17:58:47 +02:00
parent fea9adcebc
commit 6c4f98e5c8
19 changed files with 63 additions and 77 deletions

View File

@ -156,6 +156,11 @@
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.13.1</version> <version>2.13.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.13.1</version>
</dependency>
<!-- g/a spring --> <!-- g/a spring -->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackeu.eudat.corecore/jackson-databind --> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackeu.eudat.corecore/jackson-databind -->

View File

@ -50,7 +50,6 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId> <artifactId>jackson-annotations</artifactId>
<version>2.12.3</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
@ -71,7 +70,7 @@
<dependency> <dependency>
<groupId>com.github.ben-manes.caffeine</groupId> <groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId> <artifactId>caffeine</artifactId>
<version>2.9.0</version> <version>3.0.5</version>
</dependency> </dependency>
@ -80,14 +79,14 @@
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version> <version>5.8.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>42.2.22</version> <version>42.3.1</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -7,7 +7,6 @@ import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.*; import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
@ -67,7 +66,7 @@ public class DevelDatabaseConfiguration {
private Properties additionalProperties() { private Properties additionalProperties() {
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect"); properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
properties.setProperty("hibernate.show_sql", "true"); properties.setProperty("hibernate.show_sql", "false");
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false"); properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
return properties; return properties;
} }

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

@ -1026,9 +1026,8 @@ public class DatasetManager {
public void getTagsFromProfile(DatasetWizardModel wizardModel, Dataset dataset) throws IOException { public void getTagsFromProfile(DatasetWizardModel wizardModel, Dataset dataset) throws IOException {
dataset.setProfile(apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId())); dataset.setProfile(apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId()));
wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, dataset)); wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, dataset));
ObjectMapper mapper = new ObjectMapper(); String json = apiContext.getObjectMapper().writeValueAsString(wizardModel.getDatasetProfileDefinition());
String json = mapper.writeValueAsString(wizardModel.getDatasetProfileDefinition()); JsonNode propertiesJson = apiContext.getObjectMapper().readTree(json);
JsonNode propertiesJson = mapper.readTree(json);
DatasetCriteria criteria = new DatasetCriteria(); DatasetCriteria criteria = new DatasetCriteria();
criteria.setHasTags(true); criteria.setHasTags(true);
List<Tag> tags = 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()); List<Tag> tags = 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());

View File

@ -60,9 +60,8 @@ public class ExternalDatasetManager {
List<Map<String, String>> remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type); List<Map<String, String>> remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type);
// Parse items from external sources to listing models. // Parse items from external sources to listing models.
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<ExternalDatasetListingModel> externalDatasetModels = remoteRepos.stream() List<ExternalDatasetListingModel> externalDatasetModels = remoteRepos.stream()
.map(item -> mapper.convertValue(item, ExternalDatasetListingModel.class)) .map(item -> apiContext.getObjectMapper().convertValue(item, ExternalDatasetListingModel.class))
.collect(Collectors.toCollection(LinkedList::new)); .collect(Collectors.toCollection(LinkedList::new));
// Merge fetched and local. // Merge fetched and local.

View File

@ -40,8 +40,7 @@ public class LicenseManager {
List<LicenseModel> licenseModels = new LinkedList<>(); List<LicenseModel> licenseModels = new LinkedList<>();
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); licenseModels.addAll(remoteRepos.stream().map(item -> apiContext.getObjectMapper().convertValue(item, LicenseModel.class)).collect(Collectors.toList()));
licenseModels.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, LicenseModel.class)).collect(Collectors.toList()));
licenseModels = licenseModels.stream().filter(licenseModel -> licenseModel.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList()); licenseModels = licenseModels.stream().filter(licenseModel -> licenseModel.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
return licenseModels; return licenseModels;
} }

View File

@ -51,7 +51,7 @@ public class NotificationManager {
notification.setNotifiedAt(new Date()); notification.setNotifiedAt(new Date());
notification.setUpdatedAt(new Date()); notification.setUpdatedAt(new Date());
try { try {
Map<String, String> data = new ObjectMapper().readValue(notification.getData(), HashMap.class); Map<String, String> data = apiContext.getObjectMapper().readValue(notification.getData(), HashMap.class);
UserInfo userInfo = this.apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString(data.get("userId"))); UserInfo userInfo = this.apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString(data.get("userId")));
String subjectTemplate = ""; String subjectTemplate = "";
String contentTemplate = ""; String contentTemplate = "";

View File

@ -46,8 +46,7 @@ public class ServiceManager {
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList(); List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
serviceModels = serviceList.stream().map(item -> new ServiceModel().fromDataModel(item)).collect(Collectors.toList()); serviceModels = serviceList.stream().map(item -> new ServiceModel().fromDataModel(item)).collect(Collectors.toList());
} }
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); serviceModels.addAll(remoteRepos.stream().map(item -> apiContext.getObjectMapper().convertValue(item, ServiceModel.class)).collect(Collectors.toList()));
serviceModels.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ServiceModel.class)).collect(Collectors.toList()));
return serviceModels; return serviceModels;
} }

View File

@ -2,6 +2,8 @@ package eu.eudat.logic.proxy.config.configloaders;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import eu.eudat.logic.proxy.config.ExternalUrls; import eu.eudat.logic.proxy.config.ExternalUrls;
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders; import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -106,7 +108,7 @@ public class DefaultConfigLoader implements ConfigLoader {
InputStream is = null; InputStream is = null;
try { try {
is = getStreamFromPath(filePath); is = getStreamFromPath(filePath);
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); ObjectMapper mapper = new ObjectMapper();
this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class); this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class);
} catch (IOException | NullPointerException e) { } catch (IOException | NullPointerException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);

View File

@ -23,7 +23,7 @@ public class PrefillingGet{
} }
@XmlElement(name = "mapping") @XmlElement(name = "mapping")
@XmlElementWrapper @XmlElementWrapper(name = "mappings")
public void setMappings(List<DefaultPrefillingMapping> mappings) { public void setMappings(List<DefaultPrefillingMapping> mappings) {
this.mappings = mappings; this.mappings = mappings;
} }
@ -33,7 +33,7 @@ public class PrefillingGet{
} }
@XmlElement(name = "fixedMapping") @XmlElement(name = "fixedMapping")
@XmlElementWrapper @XmlElementWrapper (name = "fixedMappings")
public void setFixedMappings(List<PrefillingFixedMapping> fixedMappings) { public void setFixedMappings(List<PrefillingFixedMapping> fixedMappings) {
this.fixedMappings = fixedMappings; this.fixedMappings = fixedMappings;
} }

View File

@ -3,6 +3,8 @@ package eu.eudat.logic.proxy.fetching;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.proxy.fetching.entities.Config; import eu.eudat.logic.proxy.fetching.entities.Config;
import eu.eudat.logic.proxy.fetching.entities.ConfigSingle; import eu.eudat.logic.proxy.fetching.entities.ConfigSingle;
import eu.eudat.logic.services.ApiContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -14,6 +16,12 @@ import java.util.*;
@Component @Component
public class LocalFetcher { public class LocalFetcher {
private final ApiContext apiContext;
@Autowired
public LocalFetcher(ApiContext apiContext) {
this.apiContext = apiContext;
}
@Cacheable("currencies") @Cacheable("currencies")
public List<Map<String, String>> retrieveCurrency() throws Exception { public List<Map<String, String>> retrieveCurrency() throws Exception {
@ -45,7 +53,6 @@ public class LocalFetcher {
String camelCaseGetter =configSingle.getParseField() != null && !configSingle.getParseField().isEmpty() ? "get" + configSingle.getParseField().substring(0, 1).toUpperCase() + configSingle.getParseField().substring(1) : ""; String camelCaseGetter =configSingle.getParseField() != null && !configSingle.getParseField().isEmpty() ? "get" + configSingle.getParseField().substring(0, 1).toUpperCase() + configSingle.getParseField().substring(1) : "";
reader = aClass.getMethod(camelCaseGetter); reader = aClass.getMethod(camelCaseGetter);
} }
ObjectMapper objectMapper = new ObjectMapper();
List<Map<String, String>> values = new ArrayList<>(); List<Map<String, String>> values = new ArrayList<>();
int max = 1; int max = 1;
if (reader != null) { if (reader != null) {
@ -66,7 +73,7 @@ public class LocalFetcher {
} else { } else {
value = object; value = object;
} }
Map<String, String> map = objectMapper.convertValue(value, Map.class); Map<String, String> map = apiContext.getObjectMapper().convertValue(value, Map.class);
result.add(new HashMap<>()); result.add(new HashMap<>());
result.get(result.size() - 1).put("name", map.get(configSingle.getName())); result.get(result.size() - 1).put("name", map.get(configSingle.getName()));
result.get(result.size() - 1).put("value", map.get(configSingle.getValue())); result.get(result.size() - 1).put("value", map.get(configSingle.getValue()));

View File

@ -14,6 +14,7 @@ import eu.eudat.logic.proxy.config.entities.GenericUrls;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.entities.Results; import eu.eudat.logic.proxy.fetching.entities.Results;
import eu.eudat.logic.services.ApiContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -34,8 +35,9 @@ import java.util.stream.Collectors;
@Service @Service
public class RemoteFetcher { public class RemoteFetcher {
private static final Logger logger = LoggerFactory.getLogger(RemoteFetcher.class); private static final Logger logger = LoggerFactory.getLogger(RemoteFetcher.class);
private final static ObjectMapper mapper = new ObjectMapper();
private ConfigLoader configLoader; private final ConfigLoader configLoader;
@Autowired @Autowired
public RemoteFetcher(ConfigLoader configLoader) { public RemoteFetcher(ConfigLoader configLoader) {
@ -294,7 +296,7 @@ public class RemoteFetcher {
headers.setAccept(Collections.singletonList(MediaType.valueOf(contentType))); headers.setAccept(Collections.singletonList(MediaType.valueOf(contentType)));
headers.setContentType(MediaType.valueOf(contentType)); headers.setContentType(MediaType.valueOf(contentType));
} }
JsonNode jsonBody = new ObjectMapper().readTree(requestBody); JsonNode jsonBody = mapper.readTree(requestBody);
entity = new HttpEntity<>(jsonBody, headers); entity = new HttpEntity<>(jsonBody, headers);
response = restTemplate.exchange(urlString, HttpMethod.resolve(requestType), entity, String.class); response = restTemplate.exchange(urlString, HttpMethod.resolve(requestType), entity, String.class);
@ -325,7 +327,6 @@ public class RemoteFetcher {
String camelCaseGetter = jsonDataPath.getParseField() != null && !jsonDataPath.getParseField().isEmpty() ? "get" + jsonDataPath.getParseField().substring(0, 1).toUpperCase() + jsonDataPath.getParseField().substring(1) : ""; String camelCaseGetter = jsonDataPath.getParseField() != null && !jsonDataPath.getParseField().isEmpty() ? "get" + jsonDataPath.getParseField().substring(0, 1).toUpperCase() + jsonDataPath.getParseField().substring(1) : "";
reader = aClass.getMethod(camelCaseGetter); reader = aClass.getMethod(camelCaseGetter);
} }
ObjectMapper objectMapper = new ObjectMapper();
List<Map<String, String>> values = new ArrayList<>(); List<Map<String, String>> values = new ArrayList<>();
int max = 1; int max = 1;
if (reader != null) { if (reader != null) {
@ -346,7 +347,7 @@ public class RemoteFetcher {
} else { } else {
value = data; value = data;
} }
Map<String, String> map = objectMapper.convertValue(value, Map.class); Map<String, String> map = mapper.convertValue(value, Map.class);
if (jsonDataPath.getMergedFields() != null && !jsonDataPath.getMergedFields().isEmpty() && jsonDataPath.getMergedFieldName() != null && !jsonDataPath.getMergedFieldName().isEmpty()) { if (jsonDataPath.getMergedFields() != null && !jsonDataPath.getMergedFields().isEmpty() && jsonDataPath.getMergedFieldName() != null && !jsonDataPath.getMergedFieldName().isEmpty()) {
Map<String, String> finalMap = new HashMap<>(); Map<String, String> finalMap = new HashMap<>();
for (Map.Entry<String, String> entry : map.entrySet()) { for (Map.Entry<String, String> entry : map.entrySet()) {
@ -385,7 +386,6 @@ public class RemoteFetcher {
List<Map<String, String>> internalResults; List<Map<String, String>> internalResults;
try { try {
String filePath = Paths.get(path).toUri().toURL().toString(); String filePath = Paths.get(path).toUri().toURL().toString();
ObjectMapper mapper = new ObjectMapper();
internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, String>>>(){}); internalResults = mapper.readValue(new File(filePath), new TypeReference<List<Map<String, String>>>(){});
return searchListMap(internalResults, query); return searchListMap(internalResults, query);
} catch (Exception e) { } catch (Exception e) {

View File

@ -1,8 +1,11 @@
package eu.eudat.logic.security.customproviders.ConfigurableProvider.entities; package eu.eudat.logic.security.customproviders.ConfigurableProvider.entities;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConfigurableProviders { public class ConfigurableProviders {
private List<ConfigurableProvider> providers = new ArrayList<>(); private List<ConfigurableProvider> providers = new ArrayList<>();

View File

@ -30,49 +30,49 @@ public class NonVerifiedUserEmailAuthenticationService extends AbstractAuthentic
if (user == null) return null; if (user == null) return null;
String avatarUrl; String avatarUrl;
try { try {
avatarUrl = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("avatarUrl").asText() : ""; avatarUrl = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("avatarUrl").asText() : "";
} catch (Exception e) { } catch (Exception e) {
avatarUrl = ""; avatarUrl = "";
} }
String zenodoToken; String zenodoToken;
try { try {
zenodoToken = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoToken").asText() : ""; zenodoToken = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoToken").asText() : "";
} catch (Exception e) { } catch (Exception e) {
zenodoToken = ""; zenodoToken = "";
} }
Instant zenodoDuration; Instant zenodoDuration;
try { try {
zenodoDuration = user.getAdditionalinfo() != null ? Instant.ofEpochMilli(new ObjectMapper().readTree(user.getAdditionalinfo()).get("expirationDate").asLong()) : Instant.now(); zenodoDuration = user.getAdditionalinfo() != null ? Instant.ofEpochMilli(apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("expirationDate").asLong()) : Instant.now();
} catch (Exception e) { } catch (Exception e) {
zenodoDuration = Instant.now(); zenodoDuration = Instant.now();
} }
String zenodoEmail; String zenodoEmail;
try { try {
zenodoEmail = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoEmail").asText() : ""; zenodoEmail = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoEmail").asText() : "";
} catch (Exception e) { } catch (Exception e) {
zenodoEmail = ""; zenodoEmail = "";
} }
String zenodoRefresh; String zenodoRefresh;
try { try {
zenodoRefresh = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoRefresh").asText() : ""; zenodoRefresh = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoRefresh").asText() : "";
} catch (Exception e) { } catch (Exception e) {
zenodoRefresh = ""; zenodoRefresh = "";
} }
String culture; String culture;
try { try {
culture = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("culture").get("name").asText() : ""; culture = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("culture").get("name").asText() : "";
} catch (Exception e) { } catch (Exception e) {
culture = ""; culture = "";
} }
String language; String language;
try { try {
language = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("language").get("value").asText() : ""; language = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("language").get("value").asText() : "";
} catch (Exception e) { } catch (Exception e) {
language = ""; language = "";
} }
String timezone; String timezone;
try { try {
timezone = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("timezone").asText() : ""; timezone = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("timezone").asText() : "";
} catch (Exception e) { } catch (Exception e) {
timezone = ""; timezone = "";
} }

View File

@ -33,49 +33,49 @@ public class VerifiedUserAuthenticationService extends AbstractAuthenticationSer
if (user.getEmail() == null) throw new NullEmailException(); if (user.getEmail() == null) throw new NullEmailException();
String avatarUrl; String avatarUrl;
try { try {
avatarUrl = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("avatarUrl").asText() : ""; avatarUrl = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("avatarUrl").asText() : "";
} catch (Exception e) { } catch (Exception e) {
avatarUrl = ""; avatarUrl = "";
} }
String zenodoToken; String zenodoToken;
try { try {
zenodoToken = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoToken").asText() : ""; zenodoToken = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoToken").asText() : "";
} catch (Exception e) { } catch (Exception e) {
zenodoToken = ""; zenodoToken = "";
} }
Instant zenodoDuration; Instant zenodoDuration;
try { try {
zenodoDuration = user.getAdditionalinfo() != null ? Instant.ofEpochMilli(new ObjectMapper().readTree(user.getAdditionalinfo()).get("expirationDate").asLong()) : Instant.now(); zenodoDuration = user.getAdditionalinfo() != null ? Instant.ofEpochMilli(apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("expirationDate").asLong()) : Instant.now();
} catch (Exception e) { } catch (Exception e) {
zenodoDuration = Instant.now(); zenodoDuration = Instant.now();
} }
String zenodoEmail; String zenodoEmail;
try { try {
zenodoEmail = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoEmail").asText() : ""; zenodoEmail = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoEmail").asText() : "";
} catch (Exception e) { } catch (Exception e) {
zenodoEmail = ""; zenodoEmail = "";
} }
String zenodoRefresh; String zenodoRefresh;
try { try {
zenodoRefresh = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoRefresh").asText() : ""; zenodoRefresh = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("zenodoRefresh").asText() : "";
} catch (Exception e) { } catch (Exception e) {
zenodoRefresh = ""; zenodoRefresh = "";
} }
String culture; String culture;
try { try {
culture = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("culture").get("name").asText() : ""; culture = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("culture").get("name").asText() : "";
} catch (Exception e) { } catch (Exception e) {
culture = ""; culture = "";
} }
String language; String language;
try { try {
language = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("language").get("value").asText() : ""; language = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("language").get("value").asText() : "";
} catch (Exception e) { } catch (Exception e) {
language = ""; language = "";
} }
String timezone; String timezone;
try { try {
timezone = user.getAdditionalinfo() != null ? new ObjectMapper().readTree(user.getAdditionalinfo()).get("timezone").asText() : ""; timezone = user.getAdditionalinfo() != null ? apiContext.getObjectMapper().readTree(user.getAdditionalinfo()).get("timezone").asText() : "";
} catch (Exception e) { } catch (Exception e) {
timezone = ""; timezone = "";
} }

View File

@ -8,6 +8,7 @@ import eu.eudat.models.data.mail.SimpleMail;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -20,11 +21,11 @@ import java.util.concurrent.CompletableFuture;
@Service("ConfirmationEmailService") @Service("ConfirmationEmailService")
public class ConfirmationEmailServiceImpl implements ConfirmationEmailService { public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
private static final Logger logger = LoggerFactory.getLogger(ConfirmationEmailServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(ConfirmationEmailServiceImpl.class);
//private Logger logger; private static final ObjectMapper mapper = new ObjectMapper();
private Environment environment; private final Environment environment;
public ConfirmationEmailServiceImpl(/*Logger logger,*/ Environment environment) { @Autowired
// this.logger = logger; public ConfirmationEmailServiceImpl(Environment environment) {
this.environment = environment; this.environment = environment;
} }
@ -118,7 +119,7 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("userId", principal.getId()); map.put("userId", principal.getId());
map.put("provider", provider.toString()); map.put("provider", provider.toString());
confirmationEmail.setData(new ObjectMapper().writeValueAsString(map)); confirmationEmail.setData(mapper.writeValueAsString(map));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.models.data.license; package eu.eudat.models.data.license;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import eu.eudat.data.entities.DataRepository; import eu.eudat.data.entities.DataRepository;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
@ -7,6 +8,7 @@ import eu.eudat.models.DataModel;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
@JsonIgnoreProperties(ignoreUnknown = true)
public class LicenseModel implements DataModel<DataRepository, LicenseModel> { public class LicenseModel implements DataModel<DataRepository, LicenseModel> {
private UUID id; private UUID id;
private String name; private String name;

View File

@ -1,5 +1,6 @@
package eu.eudat.models.data.services; package eu.eudat.models.data.services;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import eu.eudat.data.entities.Service; import eu.eudat.data.entities.Service;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
@ -7,6 +8,7 @@ import eu.eudat.models.DataModel;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
@JsonIgnoreProperties(ignoreUnknown = true)
public class ServiceModel implements DataModel<Service, ServiceModel> { public class ServiceModel implements DataModel<Service, ServiceModel> {
private UUID id; private UUID id;
private String label; private String label;