Вы находитесь на странице: 1из 6

EXAMEN

Semestre : 1 2 X
Session : Principale
X
Intitulé UE :…………………… Architecture N-tiers ………………………………………
Enseignant(s) :…………… Spring Team/.NET Team/SOA Team …………………..
Classe(s) : 4INFOB

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.....

Intitulé UE Intitulé module ECTS module

Architecture N-tiers Architecture N-tiers .NET 3

Architecture Orientée Service « SOA » 3


Framework SPRING 3

Partie I : Framework Spring [14 questions / 30 points]


[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 - L’association bidirectionnelle Candidat-


gestion d’une auto-école. Examen indique qu’un candidat peut passer
Ci-dessous, le diagramme de classes. 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 ? (/2pts)

A. 3

B. 4

C. 5

- Les identifiants sont auto-générés avec la stratégie D. 6


«IDENTITY».
2 : Compléter QI.2. (/2pts)

1/6
@Entity
public class Candidat implements Serializable { 3 : Compléter QI.3. (/2pts)
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY) @Entity
private int idCd; public class Examen implements Serializable {
@Id
private String login; @GeneratedValue(strategy=GenerationType.IDENT
private String pwd; ITY)
private int budgetFormations; private int idEx;
@Temporal(TemporalType.DATE)
private Date dateExamen;
QI.2. ….
@OneToMany(mappedBy="candidat")
List <Examen> examens; @Enumerated(EnumType.STRING)
} Type type;
@ManyToOne
A. @OneToMany(mappedBy="candidat") QI.3. Candidat
…. candidat; }

B. @ManyToOne(mappedBy="candidat") A. private List <Candidat> candidats;

C. @OneToMany B. private Candidat candidat;

D. @ManyToOne C. a et b sont possibles

D. aucune réponse

4 : Les services sont les suivants. Tous les services sont exposés avec Spring RESTMVC.
Compléter QI.4. (/2pts)
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

QI.4.@PutMapping(value
…. = "/affecterExamenACandidat/{idcdt}/{idex}")
public void affecterExamenACandidat(@PathVariable("idcdt")int cdId,
@PathVariable("idex")int exId) {
icandidatservice.affecterExamenACandidat(cdId, exId);
}}

2/6
A. @PostMapping

B. @PutMapping

B. @GetMapping

D. @DeleteMapping

5 : 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 ulté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.
(/2pts)

@Repository
public interface CandidatRepository extends CrudRepository<Candidat, Integer> {

QI.5 sf from SeanceDeFormation sf where sf.type=:typeex and")


@Query("Select
public SeanceDeFormation getSeanceDeFormation( @Param("typeex") Type

typeex,@Param ("d") Date d);

A. Select SeanceDeFormation sf where sf.type=:typeex and sf.dateSeance<:d and


sf.nbPlaceLibre>0
B. Select sf from SeanceDeFormation sf where sf.type=:typeex or sf.dateSeance<:d or
sf.nbPlaceLibre>0
C. Select sf from SeanceDeFormation sf where sf.type=:typeex and sf.dateSeance<:d
and sf.nbPlaceLibre>0
D. Aucune réponse n’est correcte.

6 : Compléter QI.6. (/2pts)


@Repository

public interface CandidatRepository extends CrudRepository<Candidat, Integer> {

@Query("Select sf from SeanceDeFormation sf where sf.type=:typeex ")


public SeanceDeFormation getSeanceDeFormation( @Param("typeex")
QI.6 Type

typeex,@Param
QI.6 ("d") Date d);
}

A. @PathVariable
B. @Param
C. @QueryParam
D. @ParamQuery
3/6
7 : Authentification (login.xhtml): Le formulaire accepte login.xhtml
un login et un mot de passe, affiche un message d’erreur en <h:form id="form">
cas d’une éventuelle erreur d’identification et oriente <b>Connexion</b>
<h:panelGrid columns="2">
l’utilisateur vers son espace.
<h:outputText value="Login" />
<h:inputText
value="#{candidatController.login}"
QI.6 />
<h:outputText value="Mot de passe" />
<h:inputSecret
value="#{candidatController.pwd}"
QI.6 />
<h:commandButton id="btn" value="Connexion"
action="#{candidatController.dologin}"
QI.6 />
Espace Utilisateur (welcome.xhtml) : Après <h:message for="btn"/>
authentification, l’utilisateur peut visualiser ses formations. Il </h:panelGrid>
peut aussi refuser une formation. L’accès à cette page est </h:form>
sécurisé en utilisant un filtre d’authentification.
A. IControllerCandidatImpl

B. iControllerCandidatImpl

C. candidatController

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

4/6
9 : Nous avons ajouté un filtre d’authentification à notre application. Compléter QI.9
(/2pts).
@WebFilter("/LoginFilter")
QI.9
public class LoginFilter implements Filter {
public LoginFilter() {
}
public void destroy() {
}
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())
// pass the request along the filter chain
{chain.doFilter(request, response);}
else
{ hresponse.sendRedirect(hrequest.getContextPath()+"/");
}
}
public void init(FilterConfig fConfig) throws ServletException {}}

A. @Filter("/LoginFilter")

B. @WebRequestFilter("/LoginFilter")

C. @WebFilter("/LoginFilter")

D. b et c

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 (/2pts).
@Component
@Aspect
public class PerformanceAspect {
private static final Logger logger =
LogManager.getLogger(PerformanceAspect.class);

QI.10
@Around("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;
}}

5/6
A. @Before("execution(* tn.esprit.spring.services.*.*(..))")

B. @After("execution(* tn.esprit.spring.services.*.*(..))")

C. @Around("execution(* tn.esprit.spring.services.*.*(..))")

D. a et b

11 : Erreur1 : C'est quoi la cause de cette erreur ? Le 13 : Erreur 3 : C’est quoi la cause de cette erreur ?
développeur a oublié de mettre (/2pts) : (/2pts)
Description:
Caused by: org.hibernate.AnnotationException: Field icandidatservice in
@OneToOne or @ManyToOne on tn.esprit.spring.controller.RestControlCandidat
required a bean of type
tn.esprit.spring.entities.Examen.candidat references an
'tn.esprit.spring.services.ICandidatService'
unknown entity: tn.esprit.spring.entities.Candidat that could not be found.
The injection point has the following
A. @Id annotations:
@org.springframework.beans.factory.annotation.
B. @Entity Autowired(required=true)

C. @OneToMany A. Le développeur a oublié d’annoter la classe


RestControlCandidat par l’annotation @RestController
D. @ManyToOne
B. Le développeur a oublié d’annoter l’objet
12 : Erreur 2 : C’est quoi la cause de cette erreur ? ICandidatService icandidatservice ; par
(/2pts) l’annotation @Autowired
C. Le développeur a oublié d’annoter la classe
com.mysql.cj.jdbc.exceptions.CommunicationsException: CandidatServiceImpl par l’annotation
Communications link failure @Service
The last packet sent successfully to the server was 0 D. a et b
milliseconds ago.
The driver has not received any packets from the server. 14 : Erreur 4 : C’est quoi la cause de cette erreur ? (/2pts)
At com.mysql.cj.jdbc.exceptions.SQLError. javax.el.PropertyNotFoundException: Target Unreachable,
createCommunicationsException(SQLError.java:174) identifier [candidatControllerTest] resolved to null
~[mysql-connector-java-8.0.18.jar:8.0.18] at org.apache.el.parser.AstValue.getTarget
(AstValue.java:74) ~[tomcat-embed-el-9.0.27.jar:9.0.27]
A. Le développeur a oublié de créer la base de at org.apache.el.parser.AstValue.getType
données. (AstValue.java:58) ~[tomcat-embed-el-9.0.27.jar:9.0.27]
at org.apache.el.ValueExpressionImpl.getType
B. Le développeur a oublié d’annoter les entités par (ValueExpressionImpl.java:174) ~[tomcat-embed-el-
l’annotation @Entity 9.0.27.jar:9.0.27]

C. Le développeur a mis un numéro de port erroné A. Le développeur a oublié de vider le dossier


pour l’accès au serveur de données Target

D. Aucune réponse n’est correcte B. Le développeur a oublié de créer le dossier


Target

C. Le développeur a mis un nom erroné de son


Controller

D. Aucune réponse n’est correcte

6/6

Вам также может понравиться