Skip to content

Commit

Permalink
Merge pull request #23 from vzwingma/feat/delete_deprecated_functions
Browse files Browse the repository at this point in the history
Feat/delete deprecated functions
  • Loading branch information
vzwingma authored Sep 20, 2023
2 parents 5116f65 + 6814bb7 commit a97c30c
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import io.github.vzwingma.finances.budget.services.communs.data.trace.BusinessTraceContext;
import io.github.vzwingma.finances.budget.services.communs.data.trace.BusinessTraceContextKeyEnum;
import io.github.vzwingma.finances.budget.services.communs.utils.exceptions.BadParametersException;
import io.github.vzwingma.finances.budget.services.communs.utils.exceptions.DataNotFoundException;
import io.github.vzwingma.finances.budget.serverless.services.operations.api.enums.OperationsAPIEnum;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.budget.BudgetMensuel;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.operation.LibellesOperationsAPIObject;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.operation.LigneOperation;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.ports.IBudgetAppProvider;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.ports.IOperationsAppProvider;
Expand Down Expand Up @@ -52,9 +50,6 @@ public class OperationsResource extends AbstractAPIInterceptors {
@Inject
IBudgetAppProvider budgetService;

@Inject
IOperationsAppProvider operationsService;

@Context
SecurityContext securityContext;

Expand Down Expand Up @@ -224,33 +219,6 @@ public Uni<BudgetMensuel> setBudgetActif(
*********************************************************/


/**
* Met à jour le flag de l'opération comme dernière opération réalisée
* @param idBudget id du compte
* @return résultat de l'action
*/
@Operation(description="Met à jour le flag de l'opération comme dernière opération réalisée")
@APIResponses(value = {
@APIResponse(responseCode = "200", description = "Budget mis à jour"),
@APIResponse(responseCode = "401", description = "Utilisateur non authentifié"),
@APIResponse(responseCode = "403", description = "Opération non autorisée"),
@APIResponse(responseCode = "404", description = "Données introuvables")
})
@POST
@RolesAllowed({ OperationsAPIEnum.OPERATIONS_ROLE })
@Path(value= OperationsAPIEnum.BUDGET_OPERATION_DERNIERE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<Boolean> setAsDerniereOperation(
@RestPath("idBudget") String idBudget,
@RestPath("idOperation") String idOperation) {

BusinessTraceContext.getclear().put(BusinessTraceContextKeyEnum.BUDGET, idBudget).put(BusinessTraceContextKeyEnum.OPERATION, idOperation).put(BusinessTraceContextKeyEnum.USER, super.getAuthenticatedUser());
LOG.trace("setAsDerniereOperation");
return operationsService.setLigneAsDerniereOperation(idBudget, idOperation);
}


/**
* Création d'une opération
* @param idBudget id du budget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.github.vzwingma.finances.budget.serverless.services.operations.business.ports.IBudgetAppProvider;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.ports.IOperationsAppProvider;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.ports.IOperationsRepository;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -30,8 +29,6 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Service fournissant les calculs de budget sur les opérations
Expand Down Expand Up @@ -74,7 +71,7 @@ public void calculSoldes(List<LigneOperation> operations, BudgetMensuel.Soldes s

// Calcul par catégorie
calculBudgetTotalCategories(totauxCategorieMap, operation);
// Calcul par sous catégorie
// Calcul par sous catégories
calculBudgetTotalSsCategories(totauxSsCategoriesMap, operation);
// Calcul des totaux
if(operation.getEtat().equals(OperationEtatEnum.REALISEE)){
Expand Down Expand Up @@ -149,42 +146,6 @@ private void calculBudgetTotalSsCategories(Map<String, TotauxCategorie> totauxSs
}



@Override
public Uni<Boolean> setLigneAsDerniereOperation(String idBudget, String ligneId) {
LOGGER.info("Tag de la ligne comme dernière opération {} sur {}", ligneId, idBudget);
final AtomicBoolean operationUpdate = new AtomicBoolean(false);
return this.budgetService.getBudgetMensuel(idBudget)
.onItem()
.invoke(budget -> {
if( budget == null){
LOGGER.warn("Budget NULL");
}
else if(budget.getListeOperations() != null && !budget.getListeOperations().isEmpty()) {
budget.getListeOperations()
.forEach(op -> {
op.setTagDerniereOperation(ligneId.equals(op.getId()));
if(ligneId.equals(op.getId())) {
LOGGER.debug("L'opération a été trouvée dans le budget ");
operationUpdate.set(true);
}
});
// Mise à jour du budget
budget.setDateMiseAJour(LocalDateTime.now());
}})
.call(budget -> {
if(operationUpdate.get()) {
return this.dataOperationsProvider.sauvegardeBudgetMensuel(budget);
}
else{
return Uni.createFrom().failure(new DataNotFoundException("L'opération "+ligneId+" n'a pas été trouvée dans le budget "+idBudget));
}
})
.onItem()
.transform(Objects::nonNull);
}


@Override
public void addOrReplaceOperation(List<LigneOperation> operations, LigneOperation ligneOperation, String auteur) {
BusinessTraceContext.get().put(BusinessTraceContextKeyEnum.OPERATION, ligneOperation.getId());
Expand Down Expand Up @@ -299,7 +260,6 @@ public Uni<LigneOperation> createOperationRemboursement(LigneOperation operation
* @param ligneOperation ligne d'opération à ajouter
* @return ligne de remboursement
*/

private LigneOperation createOperationRemboursement(LigneOperation ligneOperation, CategorieOperations ssCategorieRemboursement, String auteur) {
if(ssCategorieRemboursement != null) {
return completeOperationAttributes(new LigneOperation(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*/
package io.github.vzwingma.finances.budget.serverless.services.operations.business.model.operation;

import lombok.Getter;

/**
* Libellé dans les opérations
* @author vzwingma
*
*/
@Getter
public enum LibellesOperationEnum {

// Libellé en retard
EN_RETARD("retard", "[En Retard]");


private final String id;
private final String libelle;

/**
* Constructeur
* @param id : id de l'enum
* @param libelle : libellé de l'enum
*/
LibellesOperationEnum(String id, String libelle){
this.id = id;
this.libelle = libelle;
}


/* (non-Javadoc)
* @see java.lang.Enum#toString()
*/
@Override
public String toString(){
return getLibelle();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.github.vzwingma.finances.budget.services.communs.data.abstrait.AbstractAPIObjectModel;
import io.github.vzwingma.finances.budget.services.communs.data.model.CategorieOperations;
import io.smallrye.common.constraint.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -64,10 +65,6 @@ public class LigneOperation extends AbstractAPIObjectModel implements Comparable
@Schema(description = "Opération périodique ?")
private Mensualite mensualite;

// tag comme dernière opération
@Schema(description = "Dernier opération ?")
private boolean tagDerniereOperation;

@Schema(description = "Autres infos")
private AddInfos autresInfos;

Expand Down Expand Up @@ -203,7 +200,6 @@ private void buildLigneOperation(Categorie categorie, Categorie ssCategorie, Str

putValeurFromSaisie(absValeur);
this.etat = etat;
this.tagDerniereOperation = false;

setCategorie(categorie);
setSsCategorie(ssCategorie);
Expand Down Expand Up @@ -260,8 +256,8 @@ public LocalDate retrieveDateOperation() {
*/
@Override
public String toString() {
return String.format("LigneOperations [id=%s, categorie=%s, sous-categorie=%s, libelle=%s, typeDepense=%s, etat=%s, valeur=%s, %s, derniereOperation=%s]"
, id, categorie, ssCategorie, libelle, typeOperation, etat, valeur, mensualite != null ? mensualite.toString() : "mensualite=false", tagDerniereOperation);
return String.format("LigneOperations [id=%s, categorie=%s, sous-categorie=%s, libelle=%s, typeDepense=%s, etat=%s, valeur=%s, %s]"
, id, categorie, ssCategorie, libelle, typeOperation, etat, valeur, mensualite != null ? mensualite.toString() : "mensualite=false");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.operation.LigneOperation;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.budget.BudgetMensuel;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.budget.TotauxCategorie;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

import java.util.List;
Expand Down Expand Up @@ -31,15 +30,10 @@ public interface IOperationsAppProvider {
* @param ligneOperationSource ligne de dépense, source, pour créer une nouvelle opération
* @param libelleOperationCible libelle de la nouvelle opération
* @param auteur auteur de l'action
* @return liste des opérations à mettre à jour dans le budget, avec l'intercompte
* liste des opérations à mettre à jour dans le budget, avec l'intercompte
*/
void addOperationIntercompte(List<LigneOperation> operations, LigneOperation ligneOperationSource, String libelleOperationCible, String auteur);
/**
* Mise à jour de la ligne comme dernière opération
*
* @param ligneId identifiant de ligne
*/
Uni<Boolean> setLigneAsDerniereOperation(String idBudget, String ligneId);


/**
* Suppression d'une opération
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.vzwingma.finances.budget.serverless.services.operations.api.enums.ComptesApiUrlEnum;
import io.github.vzwingma.finances.budget.services.communs.data.model.CompteBancaire;
import io.smallrye.mutiny.Uni;
import jakarta.ws.rs.Produces;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

Expand All @@ -12,6 +13,7 @@
/**
* Service Provider Interface de {@link }
*/
@Produces("application/json")
@Path(ComptesApiUrlEnum.COMPTES_BASE)
@RegisterRestClient(configKey = "comptes-service")
@RegisterClientHeaders(RequestJWTHeaderFactory.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
import io.smallrye.mutiny.Uni;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import java.util.List;

/**
* Service Provider Interface de {@link }
*/
@Produces("application/json")
@Path(ParametragesApiUrlEnum.PARAMS_BASE)
@RegisterRestClient(configKey = "parametrages-service")
@RegisterClientHeaders(RequestJWTHeaderFactory.class)
public interface IParametragesServiceProvider {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.vzwingma.finances.budget.serverless.services.operations.utils;

import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.operation.LibellesOperationEnum;
import io.github.vzwingma.finances.budget.services.communs.utils.data.BudgetDateTimeUtils;
import io.github.vzwingma.finances.budget.services.communs.utils.exceptions.BudgetNotFoundException;
import io.github.vzwingma.finances.budget.serverless.services.operations.business.model.budget.BudgetMensuel;
Expand Down Expand Up @@ -153,7 +154,6 @@ public static LigneOperation cloneOperationToMoisSuivant(LigneOperation ligneOpe
ligneOperationClonee.setEtat(OperationEtatEnum.PREVUE);
ligneOperationClonee.setTypeOperation(ligneOperation.getTypeOperation());
ligneOperationClonee.putValeurFromSaisie(Math.abs(ligneOperation.getValeur()));
ligneOperationClonee.setTagDerniereOperation(false);
return ligneOperationClonee;
}

Expand Down Expand Up @@ -182,7 +182,10 @@ public static List<LigneOperation> cloneOperationPeriodiqueToMoisSuivant(final L
LOGGER.warn("L'opération périodique {} est reportée : en retard", ligneOperation.getMensualite().getPeriode().name());
}
LigneOperation ligneOperationEcheanceReportee = cloneOperationToMoisSuivant(ligneOperation);
ligneOperationEcheanceReportee.setLibelle("[En Retard] " + ligneOperation.getLibelle());
if(ligneOperationEcheanceReportee.getLibelle() != null
&& !ligneOperationEcheanceReportee.getLibelle().startsWith(LibellesOperationEnum.EN_RETARD.getLibelle())){
ligneOperationEcheanceReportee.setLibelle(LibellesOperationEnum.EN_RETARD.getLibelle() + ligneOperation.getLibelle());
}
LigneOperation.Mensualite echeanceReportee = new LigneOperation.Mensualite();
echeanceReportee.setPeriode(OperationPeriodiciteEnum.PONCTUELLE);
echeanceReportee.setProchaineEcheance(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,19 @@ class OperationsServiceTest {
private OperationsService operationsAppProvider;

private IParametragesServiceProvider parametragesServiceProvider;
private IBudgetAppProvider budgetAppProvider;
private IOperationsRepository mockOperationDataProvider;

@BeforeEach
public void setup() {
mockOperationDataProvider = Mockito.mock(IOperationsRepository.class);
operationsAppProvider = Mockito.spy(new OperationsService());
budgetAppProvider = Mockito.mock(BudgetService.class);
IBudgetAppProvider budgetAppProvider = Mockito.mock(BudgetService.class);
operationsAppProvider.setDataOperationsProvider(mockOperationDataProvider);
operationsAppProvider.setBudgetService(budgetAppProvider);
parametragesServiceProvider = Mockito.mock(IParametragesServiceProvider.class);
operationsAppProvider.setParametragesService(parametragesServiceProvider);
}

@Test
void testSetDerniereOperationKO(){
// When
Mockito.when(budgetAppProvider.getBudgetMensuel(Mockito.anyString()))
.thenReturn(Uni.createFrom().item(MockDataBudgets.getBudgetActifCompteC1et3operationsRealisees()));
// Test

CompletionException thrown = assertThrows(CompletionException.class, () -> operationsAppProvider.setLigneAsDerniereOperation("Test", "Test")
.await().indefinitely());
assertEquals("io.github.vzwingma.finances.budget.services.communs.utils.exceptions.DataNotFoundException", thrown.getMessage());
Mockito.verify(mockOperationDataProvider, Mockito.never()).sauvegardeBudgetMensuel(Mockito.any());
}


@Test
void testSetDerniereOperation(){
// When
Mockito.when(budgetAppProvider.getBudgetMensuel(Mockito.anyString()))
.thenReturn(Uni.createFrom().item(MockDataBudgets.getBudgetActifCompteC1et3operationsRealisees()));
Mockito.when(mockOperationDataProvider.sauvegardeBudgetMensuel(any(BudgetMensuel.class))).thenReturn(Uni.createFrom().item(new BudgetMensuel()));
// Test
assertTrue(operationsAppProvider.setLigneAsDerniereOperation("Test", "C1B2_L3").await().indefinitely());
Mockito.verify(mockOperationDataProvider, Mockito.times(1)).sauvegardeBudgetMensuel(Mockito.any());
}


@Test
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>3.3.1</quarkus.platform.version>
<quarkus.platform.version>3.4.0</quarkus.platform.version>
<lombok.version>1.18.28</lombok.version>
<surefire-plugin.version>3.1.0</surefire-plugin.version>
<jacoco.version>0.8.10</jacoco.version>
Expand Down

0 comments on commit a97c30c

Please sign in to comment.