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 package fr.paris.lutece.plugins.gipse.v1.rs;
36
37 import java.util.ArrayList;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Optional;
41
42 import com.google.gson.reflect.TypeToken;
43 import fr.paris.lutece.plugins.gipse.v1.model.dto.TypeEnseignementRestDto;
44 import fr.paris.lutece.plugins.gipse.v1.model.exception.ReferentielException;
45 import fr.paris.lutece.plugins.gipse.v1.model.utils.Constants;
46 import fr.paris.lutece.portal.service.util.AppLogService;
47 import fr.paris.lutece.util.httpaccess.HttpAccess;
48 import fr.paris.lutece.util.httpaccess.HttpAccessException;
49
50 public class TypeEnseignementService extends AbstractWSReferentiel implements ITypeEnseignementService
51 {
52
53 public TypeEnseignementService( String referentielBaseUrl, String xGraviteeApiKey )
54 {
55 super( referentielBaseUrl, xGraviteeApiKey );
56 }
57
58 @Override
59 public Optional<List<TypeEnseignementRestDto>> getListTypesEnseignement( String strCode, Boolean bIsVisible, String strLibelle ) throws ReferentielException
60 {
61 HttpAccess httpAccess = new HttpAccess( );
62 try
63 {
64 String apiUrl = getReferentielBaseUrl() + Constants.API_PATH_TYPE_ENSEIGNEMENT;
65 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
66 if( ( strCode != null ) || ( bIsVisible != null ) || ( strLibelle != null ) )
67 {
68 apiUrl += "?";
69 if(bIsVisible != null)
70 {
71 apiUrl += Constants.PARAM_VISIBLE+"="+bIsVisible+"&";
72 }
73 if(strCode != null)
74 {
75 apiUrl += Constants.PARAM_CODE+"="+strCode+"&";
76 }
77 if(strLibelle != null)
78 {
79 apiUrl += Constants.PARAM_LIBELLE+"="+strLibelle+"&";
80 }
81 }
82 String response = appelDoGet( httpAccess, Constants.API_PATH_TYPE_ENSEIGNEMENT, apiUrl, mapHeadersRequest );
83
84 gererErreur( response );
85
86 List<TypeEnseignementRestDto> listTypesEnseignementDto = getGson( ).fromJson( response, new TypeToken<ArrayList<TypeEnseignementRestDto>>( ) {}.getType( ) );
87 return Optional.ofNullable( listTypesEnseignementDto );
88 }
89 catch( HttpAccessException e )
90 {
91 AppLogService.error(e);
92 throw new ReferentielException( e );
93 }
94 }
95
96 @Override
97 public Optional<TypeEnseignementRestDto> getTypeEnseignementById( int nId ) throws ReferentielException
98 {
99 HttpAccess httpAccess = new HttpAccess( );
100 try
101 {
102 String apiUrl = getReferentielBaseUrl() + Constants.API_PATH_TYPE_ENSEIGNEMENT + "/" + nId;
103 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
104 String response = appelDoGet( httpAccess, Constants.API_PATH_TYPE_ENSEIGNEMENT, apiUrl, mapHeadersRequest );
105
106 gererErreur( response );
107
108 TypeEnseignementRestDto typeEnseignementDto = getGson( ).fromJson( response, TypeEnseignementRestDto.class );
109 return Optional.ofNullable( typeEnseignementDto );
110 }
111 catch( HttpAccessException e )
112 {
113 AppLogService.error(e);
114 throw new ReferentielException( e );
115 }
116 }
117
118 }