bug fixes
This commit is contained in:
parent
a30bd2e194
commit
d0b97066af
|
@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
|
|||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class AccountingInfoLookup {
|
||||
|
||||
|
@ -39,11 +39,11 @@ public class AccountingInfoLookup {
|
|||
private AccountingMeasureType measure;
|
||||
public static final String _measure = "measure";
|
||||
|
||||
private Set<String> groupingFields;
|
||||
private FieldSet groupingFields;
|
||||
public static final String _groupingFields = "groupingFields";
|
||||
|
||||
public Instant getFrom() {
|
||||
return from;
|
||||
return this.from;
|
||||
}
|
||||
|
||||
public void setFrom(Instant from) {
|
||||
|
@ -51,7 +51,7 @@ public class AccountingInfoLookup {
|
|||
}
|
||||
|
||||
public Instant getTo() {
|
||||
return to;
|
||||
return this.to;
|
||||
}
|
||||
|
||||
public void setTo(Instant to) {
|
||||
|
@ -59,7 +59,7 @@ public class AccountingInfoLookup {
|
|||
}
|
||||
|
||||
public List<AccountingValueType> getTypes() {
|
||||
return types;
|
||||
return this.types;
|
||||
}
|
||||
|
||||
public void setTypes(List<AccountingValueType> types) {
|
||||
|
@ -67,7 +67,7 @@ public class AccountingInfoLookup {
|
|||
}
|
||||
|
||||
public List<AccountingAggregateType> getAggregateTypes() {
|
||||
return aggregateTypes;
|
||||
return this.aggregateTypes;
|
||||
}
|
||||
|
||||
public void setAggregateTypes(List<AccountingAggregateType> aggregateTypes) {
|
||||
|
@ -75,7 +75,7 @@ public class AccountingInfoLookup {
|
|||
}
|
||||
|
||||
public AccountingDataRangeType getDateRangeType() {
|
||||
return dateRangeType;
|
||||
return this.dateRangeType;
|
||||
}
|
||||
|
||||
public void setDateRangeType(AccountingDataRangeType dateRangeType) {
|
||||
|
@ -83,18 +83,18 @@ public class AccountingInfoLookup {
|
|||
}
|
||||
|
||||
public AccountingMeasureType getMeasure() {
|
||||
return measure;
|
||||
return this.measure;
|
||||
}
|
||||
|
||||
public void setMeasure(AccountingMeasureType measure) {
|
||||
this.measure = measure;
|
||||
}
|
||||
|
||||
public Set<String> getGroupingFields() {
|
||||
return groupingFields;
|
||||
public FieldSet getGroupingFields() {
|
||||
return this.groupingFields;
|
||||
}
|
||||
|
||||
public void setGroupingFields(Set<String> groupingFields) {
|
||||
public void setGroupingFields(FieldSet groupingFields) {
|
||||
this.groupingFields = groupingFields;
|
||||
}
|
||||
|
||||
|
@ -121,24 +121,24 @@ public class AccountingInfoLookup {
|
|||
return Arrays.asList(
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getMeasure()))
|
||||
.failOn(AccountingInfoLookup._measure).failWith(messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._measure}, LocaleContextHolder.getLocale())),
|
||||
.failOn(AccountingInfoLookup._measure).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._measure}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getDateRangeType()))
|
||||
.failOn(AccountingInfoLookup._dateRangeType).failWith(messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._dateRangeType}, LocaleContextHolder.getLocale())),
|
||||
.failOn(AccountingInfoLookup._dateRangeType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._dateRangeType}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> !this.isNull(item.getDateRangeType()) && item.getDateRangeType().equals(AccountingDataRangeType.Custom))
|
||||
.must(() -> !this.isNull(item.getFrom()))
|
||||
.failOn(AccountingInfoLookup._from).failWith(messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._from}, LocaleContextHolder.getLocale())),
|
||||
.failOn(AccountingInfoLookup._from).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._from}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> !this.isNull(item.getDateRangeType()) && item.getDateRangeType().equals(AccountingDataRangeType.Custom))
|
||||
.must(() -> !this.isNull(item.getTo()))
|
||||
.failOn(AccountingInfoLookup._to).failWith(messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._to}, LocaleContextHolder.getLocale())),
|
||||
.failOn(AccountingInfoLookup._to).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._to}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isListNullOrEmpty(item.getAggregateTypes()))
|
||||
.failOn(AccountingInfoLookup._aggregateTypes).failWith(messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._aggregateTypes}, LocaleContextHolder.getLocale())),
|
||||
.failOn(AccountingInfoLookup._aggregateTypes).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._aggregateTypes}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getGroupingFields()))
|
||||
.failOn(AccountingInfoLookup._groupingFields).failWith(messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._groupingFields}, LocaleContextHolder.getLocale()))
|
||||
.failOn(AccountingInfoLookup._groupingFields).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{AccountingInfoLookup._groupingFields}, LocaleContextHolder.getLocale()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.opencdmp.query.lookup.accounting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FieldSet{
|
||||
private List<String> fields;
|
||||
|
||||
public FieldSet(List<String> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public List<String> getFields() {
|
||||
return this.fields;
|
||||
}
|
||||
|
||||
public void setFields(List<String> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package org.opencdmp.service.accounting;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeCacheService;
|
||||
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeFilterFunction;
|
||||
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeModel;
|
||||
|
@ -23,10 +26,14 @@ import org.opencdmp.integrationevent.outbox.accountingentrycreated.AccountingEnt
|
|||
import org.opencdmp.model.AccountingAggregateResultItem;
|
||||
import org.opencdmp.query.UserCredentialQuery;
|
||||
import org.opencdmp.query.lookup.accounting.AccountingInfoLookup;
|
||||
import org.opencdmp.query.lookup.accounting.FieldSet;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
@ -42,8 +49,8 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class AccountingServiceImpl implements AccountingService {
|
||||
|
@ -82,7 +89,7 @@ public class AccountingServiceImpl implements AccountingService {
|
|||
if (this.clients.containsKey(repositoryId)) return this.clients.get(repositoryId);
|
||||
|
||||
//GK: It's register time
|
||||
AccountingSourceEntity source = accountingProperties.getSources().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||
AccountingSourceEntity source = this.accountingProperties.getSources().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||
if (source != null) {
|
||||
TokenExchangeModel tokenExchangeModel = new TokenExchangeModel("accounting:" + source, source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
|
||||
TokenExchangeFilterFunction apiKeyExchangeFilterFunction = new TokenExchangeFilterFunction(this.tokenExchangeCacheService, tokenExchangeModel);
|
||||
|
@ -91,9 +98,10 @@ public class AccountingServiceImpl implements AccountingService {
|
|||
exchangeFilterFunctions.add(apiKeyExchangeFilterFunction);
|
||||
exchangeFilterFunctions.add(logRequest());
|
||||
exchangeFilterFunctions.add(logResponse());
|
||||
}).codecs(codecs -> codecs
|
||||
.defaultCodecs()
|
||||
).build();
|
||||
}).codecs(codecs -> {
|
||||
codecs.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(new ObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false).registerModule(new JavaTimeModule()), MediaType.APPLICATION_JSON));
|
||||
codecs.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(new ObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false).registerModule(new JavaTimeModule()), MediaType.APPLICATION_JSON));
|
||||
}).build();
|
||||
AccountingClientImpl accounting = new AccountingClientImpl(webClient);
|
||||
this.clients.put(repositoryId, accounting);
|
||||
return accounting;
|
||||
|
@ -152,14 +160,14 @@ public class AccountingServiceImpl implements AccountingService {
|
|||
lookup.setAggregateTypes(new ArrayList<>());
|
||||
lookup.getAggregateTypes().add(AccountingAggregateType.Sum);
|
||||
|
||||
lookup.setGroupingFields(Set.of(
|
||||
lookup.setGroupingFields(new FieldSet(List.of(
|
||||
AccountingEntryCreatedIntegrationEvent._serviceId,
|
||||
AccountingEntryCreatedIntegrationEvent._action,
|
||||
AccountingEntryCreatedIntegrationEvent._resource,
|
||||
AccountingEntryCreatedIntegrationEvent._userId
|
||||
));
|
||||
)));
|
||||
|
||||
this.validatorFactory.validator(AccountingInfoLookup.AccountingInfoLookupValidator.class).validateForce(lookup);
|
||||
// this.validatorFactory.validator(AccountingInfoLookup.AccountingInfoLookupValidator.class).validateForce(lookup);
|
||||
|
||||
AccountingAggregateResultItem accountingAggregateResultItem = null;
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue