Skip to content

Commit

Permalink
Refactor : ajout DTO web + mapper + TU
Browse files Browse the repository at this point in the history
Ajout TU controller rest
  • Loading branch information
pierre-maraval committed Apr 29, 2024
1 parent 9d91497 commit 27cb3ec
Show file tree
Hide file tree
Showing 18 changed files with 611 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public TypeExemp(Integer numTypeExemp) {
this.numTypeExemp = numTypeExemp;
}

public TypeExemp(int numTypeExemp, String libelle) {
this.numTypeExemp = numTypeExemp;
this.libelle = libelle;
}

@Override
public Integer getId(){
return this.numTypeExemp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fr.abes.item.core.configuration.ItemConfiguration;
import fr.abes.item.core.entities.item.DemandeExemp;
import fr.abes.item.core.entities.item.TypeExemp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -22,8 +23,8 @@ public interface IDemandeExempDao extends JpaRepository<DemandeExemp, Integer> {
@Query("select d from DemandeExemp d where d.etatDemande.numEtat = 5 and d.indexRecherche.code != 'DAT' order by d.dateModification asc")
List<DemandeExemp> getNextDemandeToProceedWithoutDAT();

@Query("select e.libelle from TypeExemp e where e.numTypeExemp in (select d.typeExemp.numTypeExemp from DemandeExemp d where d.numDemande = :numDemande)")
String getTypeExemp(@Param("numDemande") Integer numDemande);
@Query("select e from TypeExemp e where e.numTypeExemp in (select d.typeExemp.numTypeExemp from DemandeExemp d where d.numDemande = :numDemande)")
TypeExemp getTypeExemp(@Param("numDemande") Integer numDemande);

@Query("select d from DemandeExemp d where d.iln = :iln and d.etatDemande.numEtat not in (9, 2, 10)")
List<DemandeExemp> getActiveDemandesExempForUserExceptedPreparedStatus(@Param("iln") String iln);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public interface IDemandeExempService extends IDemandeService {

DemandeExemp majTypeExemp(Integer idDemande, Integer typeExemp);

Demande changeState(Demande demande, int etatDemande) throws DemandeCheckingException;
Object changeState(Demande demande, int etatDemande) throws DemandeCheckingException;

Demande changeStateCanceled(Demande demande, int etatDemande);

String stockerFichier(MultipartFile file, Demande demande) throws IOException, FileTypeException, FileCheckingException, DemandeCheckingException;

String getTypeExempDemande(Integer idDemande);
String getLibelleTypeExempDemande(Integer idDemande);

int getNbReponses();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface IDemandeService {

String getInfoHeaderFichierResultat(Demande demande, LocalDateTime dateDebut);

Demande changeState(Demande demande, int etatDemande) throws DemandeCheckingException;
Object changeState(Demande demande, int etatDemande) throws DemandeCheckingException;

List<Demande> getAllArchivedDemandes(String iln);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public List<Demande> getAllActiveDemandesForAdminExtended() {
}

@Override
public String getTypeExempDemande(Integer idDemande) {
return demandeExempDao.getTypeExemp(idDemande);
public String getLibelleTypeExempDemande(Integer idDemande) {
return demandeExempDao.getTypeExemp(idDemande).getLibelle();
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
Expand Down
20 changes: 0 additions & 20 deletions web/src/main/java/fr/abes/item/dto/DemandeExempDto.java

This file was deleted.

27 changes: 27 additions & 0 deletions web/src/main/java/fr/abes/item/dto/DemandeExempWebDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fr.abes.item.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@JsonTypeName("EXEMP")
@NoArgsConstructor
@AllArgsConstructor
public class DemandeExempWebDto extends DemandeWebDto {
@JsonProperty("typeExemp")
private String typeExemp;
@JsonProperty("indexRecherche")
private String indexRecherche;

public DemandeExempWebDto(Integer id, String rcr, String iln, String etatDemande, String commentaire, Integer pourcentageProgressionTraitement, String dateCreation, String dateModification, String typeExemp, String indexRecherche) {
super(id, rcr, iln, etatDemande, commentaire, pourcentageProgressionTraitement, dateCreation, dateModification);
this.typeExemp = typeExemp;
this.indexRecherche = indexRecherche;
}

}
21 changes: 0 additions & 21 deletions web/src/main/java/fr/abes/item/dto/DemandeModifDto.java

This file was deleted.

25 changes: 25 additions & 0 deletions web/src/main/java/fr/abes/item/dto/DemandeModifWebDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fr.abes.item.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@JsonTypeName("MODIF")
@NoArgsConstructor
public class DemandeModifWebDto extends DemandeWebDto {
@JsonProperty("zone")
private String zoneEtSousZone;
@JsonProperty("traitement")
private String traitement;

public DemandeModifWebDto(Integer id, String rcr, String iln, String etatDemande, String commentaire, Integer pourcentageProgressionTraitement, String dateCreation, String dateModification, String zoneEtSousZone, String traitement) {
super(id, rcr, iln, etatDemande, commentaire, pourcentageProgressionTraitement, dateCreation, dateModification);
this.zoneEtSousZone = zoneEtSousZone;
this.traitement = traitement;
}

}
16 changes: 0 additions & 16 deletions web/src/main/java/fr/abes/item/dto/DemandeRecouvDto.java

This file was deleted.

22 changes: 22 additions & 0 deletions web/src/main/java/fr/abes/item/dto/DemandeRecouvWebDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.abes.item.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@JsonTypeName("RECOUV")
@NoArgsConstructor
public class DemandeRecouvWebDto extends DemandeWebDto {
@JsonProperty("indexRecherche")
private String indexRecherche;

public DemandeRecouvWebDto(Integer id, String rcr, String iln, String etatDemande, String commentaire, Integer pourcentageProgressionTraitement, String dateCreation, String dateModification, String indexRecherche) {
super(id, rcr, iln, etatDemande, commentaire, pourcentageProgressionTraitement, dateCreation, dateModification);
this.indexRecherche = indexRecherche;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = DemandeModifDto.class, name = "MODIF"),
@JsonSubTypes.Type(value = DemandeExempDto.class, name = "EXEMP"),
@JsonSubTypes.Type(value = DemandeRecouvDto.class, name = "RECOUV"),
@JsonSubTypes.Type(value = DemandeModifWebDto.class, name = "MODIF"),
@JsonSubTypes.Type(value = DemandeExempWebDto.class, name = "EXEMP"),
@JsonSubTypes.Type(value = DemandeRecouvWebDto.class, name = "RECOUV"),
})
public abstract class DemandeDto {
@AllArgsConstructor
@NoArgsConstructor
public class DemandeWebDto {
@JsonProperty("id")
protected Integer id;
@JsonProperty("rcr")
protected String rcr;
@JsonProperty("utilisateur")
protected Integer userNum;
@JsonProperty("iln")
protected Integer iln;
protected String iln;
@JsonProperty("etatDemande")
protected Integer etatDemande;
protected String etatDemande;
@JsonProperty("commentaire")
protected String commentaire;
@JsonProperty("pourcentageProgressionTraitement")
protected Integer pourcentageProgressionTraitement;
@JsonProperty("dateCreation")
protected String dateCreation;
@JsonProperty("dateModification")
protected String dateModification;


}
54 changes: 47 additions & 7 deletions web/src/main/java/fr/abes/item/utils/WebDtoMapper.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package fr.abes.item.utils;

import fr.abes.item.core.entities.item.DemandeExemp;
import fr.abes.item.core.entities.item.DemandeModif;
import fr.abes.item.core.entities.item.DemandeRecouv;
import fr.abes.item.core.utilitaire.UtilsMapper;
import fr.abes.item.dto.DemandeExempDto;
import fr.abes.item.dto.DemandeExempWebDto;
import fr.abes.item.dto.DemandeModifWebDto;
import fr.abes.item.dto.DemandeRecouvWebDto;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

@Component
public class WebDtoMapper {
private final UtilsMapper mapper;
Expand All @@ -17,15 +24,48 @@ public WebDtoMapper(UtilsMapper mapper) {
}

@Bean
public void converterDemandeExempDtoToDemandeExemp() {
Converter<DemandeExempDto, DemandeExemp> myConverter = new Converter<DemandeExempDto, DemandeExemp>() {
public void converterDemandeExempToDemandeExempDto() {
Converter<DemandeExemp, DemandeExempWebDto> myConverter = new Converter<DemandeExemp, DemandeExempWebDto>() {
@Override
public DemandeExempWebDto convert(MappingContext<DemandeExemp, DemandeExempWebDto> mappingContext) {
DemandeExemp source = mappingContext.getSource();
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String dateCreation = format.format(source.getDateCreation());
String dateModification = format.format(source.getDateModification());
return new DemandeExempWebDto(source.getId(), source.getRcr(), source.getIln(), source.getEtatDemande().getLibelle(), source.getCommentaire(), source.getPourcentageProgressionTraitement(), dateCreation, dateModification, source.getTypeExemp().getLibelle(), source.getIndexRecherche().getLibelle());
}
};
mapper.addConverter(myConverter);
}

@Bean
public void converterDemandeRecouvToDemandeRecouvDto() {
Converter<DemandeRecouv, DemandeRecouvWebDto> myConverter = new Converter<DemandeRecouv, DemandeRecouvWebDto>() {
@Override
public DemandeExemp convert(MappingContext<DemandeExempDto, DemandeExemp> mappingContext) {
DemandeExempDto source = mappingContext.getSource();
DemandeExemp target = new DemandeExemp(source.getId());
return target;
public DemandeRecouvWebDto convert(MappingContext<DemandeRecouv, DemandeRecouvWebDto> mappingContext) {
DemandeRecouv source = mappingContext.getSource();
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String dateCreation = format.format(source.getDateCreation());
String dateModification = format.format(source.getDateModification());
return new DemandeRecouvWebDto(source.getId(), source.getRcr(), source.getIln(), source.getEtatDemande().getLibelle(), source.getCommentaire(), source.getPourcentageProgressionTraitement(), dateCreation, dateModification, ((DemandeRecouv) source).getIndexRecherche().getLibelle());
}
};
mapper.addConverter(myConverter);
}

@Bean
public void converterDemandeModifToDemandeModifDto() {
Converter<DemandeModif, DemandeModifWebDto> myConverter = new Converter<DemandeModif, DemandeModifWebDto>() {
@Override
public DemandeModifWebDto convert(MappingContext<DemandeModif, DemandeModifWebDto> mappingContext) {
DemandeModif source = mappingContext.getSource();
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String dateCreation = format.format(source.getDateCreation());
String dateModification = format.format(source.getDateModification());
return new DemandeModifWebDto(source.getId(), source.getRcr(), source.getIln(), source.getEtatDemande().getLibelle(), source.getCommentaire(), source.getPourcentageProgressionTraitement(), dateCreation, dateModification, source.getZone() + " " + source.getSousZone(), source.getTraitement().getLibelle());
}
};
mapper.addConverter(myConverter);
}
}

Loading

0 comments on commit 27cb3ec

Please sign in to comment.