Bonjour,
Alors voilà j'ai un petit souci.
Je dois développer une évolution sur une application d'entreprise.
En fonction d'une date récupérer en base, on doit pour empecher de télécharger un fichier.
Je ne suis pas très à l'aise avec Spring et c'est un projet très costaud.
Du coup j'ai essayer de développer des classes en essayant de m'adapter comme je peux à l'environnement.
Voici la classe Autorisation
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 package com.biocodex.elisa.domain; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @Entity @Table(name = "ZELISA_BLOC_PERI") @JsonIgnoreProperties(ignoreUnknown = true) public class Autorisation extends AbstractPersistable<Long>{ /** * */ private static final long serialVersionUID = 1L; /** * */ @Id @Column(name = "PERIODE") private Integer periode; // correspond au mois en cours sur lequel on veut // controler @Column(name = "ZDATE") @Temporal(TemporalType.DATE) @JsonProperty("") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") private Date date; // correspond à la date maximale au dela de laquelle on // peut charger un fichier @Column(name = "DEBLOQ") private char debloque; // correspond à l'élément qui retire la condition de // la limite de chargement public Autorisation(@JsonProperty("periode") Integer periode, @JsonProperty("date") Date date, @JsonProperty("debloque") char debloque) { this.date = date; this.periode = periode; this.debloque = debloque; } public Autorisation() { periode = 0; date = new Date(); debloque = 'x'; } @JsonProperty("periode") public Integer getPeriode() { return periode; } public void setPeriode(Integer periode) { this.periode = periode; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public char getDebloque() { return debloque; } public void setDebloque(char debloque) { this.debloque = debloque; } // @Override // public int compareTo(Autorisation o) { // // TODO Auto-generated method stub // return 0; // } public boolean isAutorise() { return debloque == 'X' ?true:false ; } private Date now() { return new Date(); } }
Le controller
Le service
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 package com.biocodex.elisa.resources; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.List; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.biocodex.elisa.domain.Autorisation; import com.biocodex.elisa.services.AutorisationService; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @Controller @RequestMapping public class AutorisationController { @Autowired AutorisationService service; public AutorisationController() { init(); } public List<Autorisation> findAll() { return service.findAll(); } public List<Autorisation> init() { System.out.println("-------------*----------init: " + service); if (service == null) service = new AutorisationService(); System.out.println("service : " + service); System.out.println("service 2 : " + service.findAll()); return service.findAll(); } public static void main(String[] args) { ObjectMapper mapper = new ObjectMapper(); AutorisationController controller = new AutorisationController(); List<Autorisation> autorisations; autorisations = controller.findAll(); Autorisation autorisation = new Autorisation(); String pathname = "C:\\projets\\Biocodex\\elisa\\fileTest.json"; try { /* * écriture dans le fichier json */ mapper.writeValue(new File(pathname), autorisations); System.out.println(pathname); } catch (JsonGenerationException e) { System.out .println("---------------------ERREUR : JsonGenerationException" + e.getMessage()); } catch (JsonMappingException e) { System.out .println("---------------------ERREUR : JsonMappingException" + e.getMessage()); } catch (IOException e) { System.out .println("---------------------ERREUR : impossible de créer le fichier" + e.getMessage()); } JSONParser parser = new JSONParser(); System.out.println("parser : " + parser); try { Object obj = parser.parse(new FileReader(pathname)); System.out.println("obj :" + obj); JSONObject jsonObject = new JSONObject(); JSONArray array = (JSONArray) obj; System.out.println("array : " + array); Integer periode; for (Object object : array) { jsonObject = (JSONObject) object; periode = (Integer) jsonObject.get("periode"); System.out.println("periode" + periode); } } catch (FileNotFoundException e) { System.out .println("---------------------ERREUR : Fichier introuvable " + e.getMessage()); } catch (IOException e) { System.out .println("---------------------ERREUR : Impossible de lire le fichier" + e.getMessage()); } catch (ParseException e) { System.out.println("---------------------ERREUR : ParseException" + e.getMessage()); } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 package com.biocodex.elisa.services; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.biocodex.elisa.dao.AutorisationDAO; import com.biocodex.elisa.domain.Autorisation; @Service public class AutorisationService implements IAutorisationService{ private static final Logger LOGGER = LoggerFactory .getLogger(AutorisationService.class); @Resource AutorisationDAO dao; @Transactional (readOnly = true) public List<Autorisation> findAll() { List<Autorisation> autorisations = new ArrayList<Autorisation>(); System.out.println("autorisations : "+ dao.findAll()); for (Autorisation autorisation : dao.findAll()) { autorisations.add(autorisation); } return autorisations; } // private Autorisation getByPeriode() { // return dao.getByPeriode(); // } }
La dao
La dto que je n'utilise pas vraiment pour l'instant parce que je ne sais pas trop à quoi elle peut servir.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.biocodex.elisa.dao; import java.util.List; import java.util.Set; import javax.annotation.Resource; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import com.biocodex.elisa.domain.Autorisation; @Resource public interface AutorisationDAO extends JpaRepository<Autorisation, Long> { @Query (value = "Select a from Autorisation a") @Override public List<Autorisation> findAll(); }
J'ai essayer de me baser sur l'architecture déjà existante du projet.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 package com.biocodex.elisa.dto; import java.io.Serializable; import com.biocodex.elisa.domain.Autorisation; import com.biocodex.elisa.resources.LCMResource.Status; public class AutorisationDTO implements Serializable { /** * */ private static final long serialVersionUID = 1L; private Autorisation autorisation; private Status status; private String workflowInst; public AutorisationDTO() { } // public Autorisation getAutorisation() { return autorisation; } // public void setAutorisation(Autorisation autorisation) { this.autorisation = autorisation; } // public Status getStatus() { return status; } // public void setStatus(Status status) { this.status = status; } // // public String getWorkflowInst() { // return workflowInst; // } // // public void setWorkflowInst(String workflowInst) { // this.workflowInst = workflowInst; // } public String getWorkflowInst() { return workflowInst; } public void setWorkflowInst(String workflowInst) { this.workflowInst = workflowInst; } }
Pour l'instant j'ai développé mon module en dehors du projet et mon module va récupérer mes infos en base et me créer un fichier JSON.
Par contre ici, je n'arrive pas à récupérer les informations en base et j'ai même droit à un NullPointer sur le service alors que je l'instancie.
Je ne sais pas si j'ai été très claire, j'ai la tête dans le guidon depuis des jours.
Quelqu'un aurait une idée pour me venir en aide svp ?
Ce code est la propriété de Biocodex et il ne doit être ni diffuser ni réutiliser.
Partager