| | |
| --- | --- |
|  | EXAMEN Semestre : 1 2 X Session : Principale X |
| Unité d’enseignement : Architecture N-tiers ……………………………………… Modules : Famework Spring - Architecture N-tiers .NET - Architecture Orientée Service « SOA » Classe(s) : 4INFOB Nombre de questions : 42 questions Documents autorisés : OUI NON X Nombre de pages : .. Calculatrice autorisée : OUI  NON X Internet autorisée : OUI NON X Date : …02/07/2020……………… Heure ...10h45....... Durée :....1h30..... | |
Partie I : Framework Spring [14 questions]
........
[Spring Boot - Spring Core - Spring Data JPA - Spring MVC REST - Log4J -AOP – JSF] Toutes les questions sont à réponse unique.
1. : On se propose de mettre en place une application de gestion d’une auto-école.

Ci-dessous, le diagramme de classes.
- Les identifiants sont auto-générés avec la stratégie
«IDENTITY».
- L’association bidirectionnelle Candidat-Examen indique qu’un candidat peut passer plusieurs examens et qu’un examen peut être passé par un seul candidat à une date donnée.
- L’association bidirectionnelle Candidat- SeanceDeFormation indique qu’un candidat peut assister à une ou plusieurs séances de formation.
- L’énumération doit être stockée en tant que chaîne de caractères dans la base.
D'après le diagramme de classes, quel est le nombre de tables générées ? (/1pt)
1. 3
4
1. 5
2. 6
3. : Compléter QI.2. (/1pt)
@Entity
public class Candidat implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private int idCd;
private String login; private String pwd;
private int budgetFormations;
QI.2. ….
List <Examen> examens;
}
neToMany(mappedBy="candidat")
@O
@OneToMany(mappedBy="candidat")
1. @ManyToOne(mappedBy="candidat")
2. @OneToMany
3. @ManyToOne
4. : Compléter QI.3. (/1pt)
@Entity

public class Examen implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENT ITY)
private int idEx; @Temporal(TemporalType.DATE) private Date dateExamen;
@Enumerated(EnumType.STRING) Type type;
@ManyToOne
QI.3. ….
}
Candidat candidat;
1. private List <Candidat> candidats;
private Candidat candidat;
1. a et b sont possibles
2. Aucune réponse
@PutMapping
1. : Les services sont les suivants. Tous les services sont exposés avec Spring REST MVC. Compléter QI.4. (/1pt)

Publicité
public interface ICandidatService {
public void ajouterCandidat(Candidat candidat);
public void affecterExamenACandidat(int cdId, int exId);
public void affecterSeanceDeFormationACandidat(int cdId, int idex); public List<SeanceDeFormation> listerFormations(int cdId);
public Candidat getCandidatByLoginAndPassword(String login, String password) ; public void reussirExamen(int idex);
public List<Examen> listerExamens(int cdId);
public void desaffecterSeanceDeFormationACandidat(int idcd, int idsf);}

@RestController
public class RestControlCandidat { @Autowired
ICandidatService icandidatservice; @Autowired
IExamService iexamenservice; @Autowired
ISeanceDeFormation iseanceformation;
// http://localhost:8083/affecterExamenACandidat/1/1
(value = "/affecterExamenACandidat/{idcdt}/{idex}") public void affecterExamenACandidat(@PathVariable("idcdt")int cdId, @PathVariable("idex")int exId) {
icandidatservice.affecterExamenACandidat(cdId, exId);}}
QI.4. ….
1. @PostMapping
@PutMapping
1. @GetMapping
2. @DeleteMapping
3. : Service : Nous allons affecter une séance de formation, pour laquelle on a des places disponibles, au candidat Ali selon le type de son examen et à une date antérieure à sa date d’examen. Après affectation, nous allons mettre jour les places disponibles et le budget du candidat.
En premier lieu, nous avons besoin de chercher la formation correspondante. Compléter QI.5. (/1pt)
Select sf from SeanceDeFormation sf where sf.type=:typeex and
@Param(
@Param

@Repository
public interface CandidatRepository extends CrudRepository<Candidat, Integer> {
@Query("
public SeanceDeFormation getSeanceDeFormation(
")
Type
typeex,
("d") Date d);
}
| | | |
| --- | --- | --- |
| QI.5 | | |
| | | "typeex") |
1. Select SeanceDeFormation sf where sf.type=:typeex and sf.dateSeance<:d and sf.nbPlaceLibre>0
2. Select sf from SeanceDeFormation sf where sf.type=:typeex or sf.dateSeance<:d or sf.nbPlaceLibre>0
Select sf from SeanceDeFormation sf where sf.type=:typeex and sf.dateSeance<:d andsf.nbPlaceLibre>0
1. Aucune réponse n’est correcte.
2. : Compléter QI.6. (/1pt)

@Repository
public interface CandidatRepository extends CrudRepository<Candidat, Integer> {
@Query("
public SeanceDeFormation getSeanceDeFormation(
Publicité
")
("typeex") Type
typeex,
("d") Date d);
}
QI.6
QI.6
Select sf from SeanceDeFormation sf where sf.type=:typeex
@Param
@Param
1. @PathVariable
@Param
1. @QueryParam
2. @ParamQuery
3. : Authentification (login.xhtml): Le formulaire accepte un login et un mot de passe, affiche un message d’erreur en cas d’une éventuelle erreur d’identification et oriente l’utilisateur vers son espace.
login.xhtml
<h:form id="form">
<b>Connexion</b>
<h:panelGrid columns="2">
<h:outputText value="Login" />
<h:inputText
QI.7
value="#{ .login}" />
candidatController
candidatController candidatController
<h:outputText value="Mot de passe" />
<h:inputSecret
value="#{ QI.7 .pwd}" />
<h:commandButton id="btn" value="Connexion"
QI.7
Espace Utilisateur (welcome.xhtml) : Après authentification, l’utilisateur peut visualiser ses formations. Il peut aussi refuser une formation. L’accès à cette page est sécurisé en utilisant un filtre d’authentification.
action="#{
<h:message for="btn"/>
</h:panelGrid>
</h:form>
candidatController
1. iControllerCandidatImpl
2. IControllerCandidatImpl
.dologin}" />

Étant donné ce Controller, compléter QI.7. (/1pt)
@Scope(value = "session") @ELBeanName(value = "candidatController") @Join(path = "/", to = "/login.jsf") @Controller
public class IControllerCandidatImpl { @Autowired
ICandidatService icandidatservice;
private String login; private String pwd; private Candidat candidat; private Boolean loggedIn;
public String dologin() { String navigateTo = "null";
candidat=icandidatservice.getCandidatBy LoginAndPassword(login, pwd);
if (candidat != null ) {
navigateTo = "/welcome.xhtml?faces-redirect=true"; loggedIn = true; } return navigateTo; } }
1. Réponses b et c
Publicité
2. : Voici une partie du code de welcome.xhtml. Compléter QI.8. (/1pt)
<h:panelGroup>
<h:form>
<h:outputText value="Bonjour #{ }"
candidatCo
candidatController
sf.dateSeance
candidatController
/>
<b>Bienvenue à ton espace.</b>
<b>Voici tes formations planifiées. </b>
<br />
<h:dataTable value="#{ . listerFormations(1)}" var="sf">
<h:column>
<f:facet name="header">
<h:outputText value="Date" />
</f:facet>
QI.8
<h:outputText value="#{ }"/>
</h:column>
……….
</h:dataTable>
<h:commandLink value="Déconnexion" action=
"#{ .doLogout()}" />
</h:form>
</h:panelGroup>
1. Formation.dateSeance
sf.dateSeance
1. candidatController.dateSeance
2. Aucune réponse

9 : Nous avons ajouté un filtre d’authentification à notre application. Compléter QI.9. (/1pt)
public class LoginFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest hrequest= (HttpServletRequest)request; HttpServletResponse hresponse= (HttpServletResponse)response; IControllerCandidatImpl candidatcontroller=(IControllerCandidatImpl) hrequest.getSession().getAttribute("candidatController"); if(candidatcontroller!=null && candidatcontroller.getLoggedIn())
{
}
else
{ hresponse.sendRedirect(hrequest.getContextPath()+"/");
}
}
}
QI.9
- 1. Aucune réponse n’est correcte.
chain.doFilter(request, response);
- 1. request.doFilter(request, response);
2. response.doFilter(request, response);
chain.doFilter(request, response);
10 : Nous avons ajouté à notre projet un aspect qui calcule et affiche dans les logs le temps d’exécution de chaque méthode des services. Compléter QI.10 (/1pt).
@Aroun
Publicité

@Component @Aspect
public class PerformanceAspect { private static final Logger logger =
LogManager.getLogger(PerformanceAspect.class);
("execution(\ tn.esprit.spring.services.\.\*(..))") public Object profile(ProceedingJoinPoint pjp) throws Throwable {
long start = System.currentTimeMillis();
Object out=pjp.proceed();
long elapsedTime = System.currentTimeMillis() - start; logger.info("Method execution time: " + elapsedTime + " milliseconds.");
return out;
}}
QI.10
1. @Before("execution(\ tn.esprit.spring.services.\.\*(..))")
2. @After("execution(\ tn.esprit.spring.services.\.\*(..))")
@Around("execution(\ tn.esprit.spring.services.\.\*(..))")
1. A et B
2. : Erreur1 : C'est quoi la cause de cette erreur ? Le développeur a oublié de mettre (/1pt):
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on tn.esprit.spring.entities.Examen.candidat references an unknown entity: tn.esprit.spring.entities.Candidat
1. @Id
@Entity
1. @OneToMany
2. @ManyToOne
3. : Erreur 2 : C’est quoi la cause la plus probable de cette erreur ? (/1pt)
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server. At com.mysql.cj.jdbc.exceptions.SQLError. createCommunicationsException(SQLError.java:174)
~[mysql-connector-java-8.0.18.jar:8.0.18]
1. Le développeur a oublié de créer la base de données.
2. Le développeur a oublié d’annoter les entités par l’annotation @Entity
Le développeur a mis un numéro de port erroné pourl’accès au serveur de données
1. Aucune réponse n’est correcte
2. : Erreur 3 : C’est quoi la cause de cette erreur ? (/1pt)
Description:
Field icandidatservice in tn.esprit.spring.controller.RestControlCandidat required a bean of type 'tn.esprit.spring.services.ICandidatService' that could not be found.
The injection point has the following annotations: @org.springframework.beans.factory.annotation. Autowired(required=true)
1. Le développeur a oublié d’annoter la classe RestControlCandidat par l’annotation @RestController
Le développeur a oublié d’annoter l’objetICandidatService icandidatservice ; par l’annotation @Autowired
1. Le développeur a oublié d’annoter la classe
CandidatServiceImpl par l’annotation @Service
1. a et b
2. : Erreur 4 : C’est quoi la cause de cette erreur ? (/1pt) javax.el.PropertyNotFoundException: Target Unreachable, identifier [candidatControllerTest] resolved to null
at org.apache.el.parser.AstValue.getTarget (AstValue.java:74) ~[tomcat-embed-el-9.0.27.jar:9.0.27] at org.apache.el.parser.AstValue.getType (AstValue.java:58) ~[tomcat-embed-el-9.0.27.jar:9.0.27] at org.apache.el.ValueExpressionImpl.getType (ValueExpressionImpl.java:174) ~[tomcat-embed-el- 9.0.27.jar:9.0.27]
1. Le développeur a oublié de vider le dossier Target
2. Le développeur a oublié de créer le dossier Target
Le développeur a mis un nom erroné de sonController
1. Aucune réponse n’est correcte.