push init
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
public abstract class AbstractJpaDao<K, T extends Serializable> implements IGenericDao<K, T> {
|
||||
protected EntityManager em;
|
||||
private Class<T> entityClass;
|
||||
|
||||
public AbstractJpaDao() {
|
||||
this.em = EntityManagerHelper.getEntityManager();
|
||||
}
|
||||
|
||||
//Pour connaitre qu'on travaille avec quelle classe
|
||||
public void setClass(Class<T> class2){
|
||||
this.entityClass= class2;
|
||||
}
|
||||
|
||||
public T findOne(K id) {
|
||||
return em.find(entityClass, id);
|
||||
}
|
||||
|
||||
public List<T> findAll() {
|
||||
return em.createQuery("select e from " + entityClass.getName() + " as e", entityClass).getResultList();
|
||||
}
|
||||
|
||||
//CRUD
|
||||
public void create(T entity){
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
em.persist(entity);
|
||||
t.commit();
|
||||
}
|
||||
|
||||
public T findById(K id) {
|
||||
return em.find(entityClass, id);
|
||||
}
|
||||
|
||||
public T update(T entity){
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
T T_sync = em.merge(entity);
|
||||
t.commit();
|
||||
return T_sync;
|
||||
}
|
||||
|
||||
public void delete(T entity){
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
em.remove(entity);
|
||||
t.commit();
|
||||
}
|
||||
|
||||
public void deleteById(K id) {
|
||||
T T_to_be_deleted = em.find(entityClass, id);
|
||||
em.remove(T_to_be_deleted);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
|
||||
public class EntityManagerHelper {
|
||||
|
||||
private static final EntityManagerFactory emf;
|
||||
private static final ThreadLocal<EntityManager> threadLocal;
|
||||
|
||||
static {
|
||||
emf = Persistence.createEntityManagerFactory("dev");
|
||||
threadLocal = new ThreadLocal<EntityManager>();
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
EntityManager em = threadLocal.get();
|
||||
|
||||
if (em == null) {
|
||||
em = emf.createEntityManager();
|
||||
threadLocal.set(em);
|
||||
}
|
||||
return em;
|
||||
}
|
||||
|
||||
public static void closeEntityManager() {
|
||||
EntityManager em = threadLocal.get();
|
||||
if (em != null) {
|
||||
em.close();
|
||||
threadLocal.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeEntityManagerFactory() {
|
||||
emf.close();
|
||||
}
|
||||
|
||||
public static void beginTransaction() {
|
||||
getEntityManager().getTransaction().begin();
|
||||
}
|
||||
|
||||
public static void rollback() {
|
||||
getEntityManager().getTransaction().rollback();
|
||||
}
|
||||
|
||||
public static void commit() {
|
||||
getEntityManager().getTransaction().commit();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public interface IGenericDao<K, T extends Serializable> {
|
||||
void create(final T entity);
|
||||
T findById(final K id);
|
||||
T update(final T entity);
|
||||
void delete(final T entity);
|
||||
void deleteById(final K id);
|
||||
List<T> findAll();
|
||||
T findOne(final K id);
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Choix;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
import fr.istic.taa.jaxrs.metier.ReponseCourte;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
|
||||
public class QuestionDAO extends AbstractJpaDao<Integer, Question> {
|
||||
public QuestionDAO(){
|
||||
super();
|
||||
this.setClass(Question.class);
|
||||
}
|
||||
|
||||
|
||||
public void addReponse(String reponse, int questionId){
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Question q = em.find(Question.class,questionId);
|
||||
|
||||
q.getReponse().getReponses().add(reponse);
|
||||
em.merge(q);
|
||||
t.commit();
|
||||
}
|
||||
|
||||
|
||||
public void deleteReponse( int questionId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Question q = em.find(Question.class,questionId);
|
||||
|
||||
q.getReponse().setReponses(new ArrayList<>());
|
||||
em.merge(q);
|
||||
t.commit();
|
||||
}
|
||||
|
||||
|
||||
public void setReponse(Reponse rep, Integer id) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Question q = em.find(Question.class,id);
|
||||
q.setReponse(rep);
|
||||
em.merge(q);
|
||||
t.commit();
|
||||
}
|
||||
|
||||
|
||||
public void setChoix(Integer id) {
|
||||
setReponse(new Choix(),id);
|
||||
}
|
||||
|
||||
public void setReponseCourte(Integer id) {
|
||||
setReponse(new ReponseCourte(),id);
|
||||
}
|
||||
|
||||
|
||||
public void addChoix(Integer id, String choix) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Question q = em.find(Question.class,id);
|
||||
|
||||
((Choix)q.getReponse()).getChoix().add(choix);
|
||||
em.merge(q);
|
||||
t.commit();
|
||||
}
|
||||
|
||||
|
||||
public void changeQuestion(String newQuestion, Integer id) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Question q = em.find(Question.class,id);
|
||||
q.setQuestion(newQuestion);
|
||||
em.merge(q);
|
||||
t.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
|
||||
public class QuizzDAO extends AbstractJpaDao<Integer, Quizz> {
|
||||
public QuizzDAO(){
|
||||
super();
|
||||
this.setClass(Quizz.class);
|
||||
}
|
||||
|
||||
public void deleteAllQustion(int quizz_id){
|
||||
EntityTransaction et= em.getTransaction();
|
||||
et.begin();
|
||||
Quizz quizz = em.find(Quizz.class, quizz_id);
|
||||
quizz.getQuestions().clear();
|
||||
em.merge(quizz);
|
||||
et.commit();
|
||||
}
|
||||
|
||||
public void addQuestion(int quizz_id, int question_id){
|
||||
EntityTransaction et= em.getTransaction();
|
||||
et.begin();
|
||||
Quizz quizz = em.find(Quizz.class, quizz_id);
|
||||
Question question =em.find(Question.class, question_id);
|
||||
|
||||
quizz.getQuestions().add(question);
|
||||
em.merge(quizz);
|
||||
et.commit();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
|
||||
public class ReponseDAO extends AbstractJpaDao<Integer, Reponse> {
|
||||
public ReponseDAO(){
|
||||
super();
|
||||
this.setClass(Reponse.class);
|
||||
}
|
||||
|
||||
/*public List<String> getGoodResponses(){
|
||||
EntityTransaction t=em.getTransaction();
|
||||
t.begin();
|
||||
Query query=em.createQuery("select r from Reponse r where r.reponses");
|
||||
List<String> lString=query.getResultList();
|
||||
t.commit();
|
||||
return lString;
|
||||
}*/
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.Query;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SessionDAO extends AbstractJpaDao<Integer, Session> {
|
||||
public SessionDAO() {
|
||||
super();
|
||||
this.setClass(Session.class);
|
||||
}
|
||||
|
||||
public List<Session> findByTheme(String theme){
|
||||
EntityTransaction t=em.getTransaction();
|
||||
Query query=em.createQuery("select s from Session s where s.theme=:theme");
|
||||
query.setParameter("theme",theme);
|
||||
List<Session> sessions=query.getResultList();
|
||||
if(sessions.size()>0){
|
||||
return sessions;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UtilisateurDAO extends AbstractJpaDao<Integer, Utilisateur> {
|
||||
public UtilisateurDAO() {
|
||||
super();
|
||||
this.setClass(Utilisateur.class);
|
||||
}
|
||||
|
||||
public Utilisateur findByEmail(String email) {
|
||||
List<Utilisateur> results =
|
||||
em.createQuery("SELECT u FROM Utilisateur u WHERE u.email = :email", Utilisateur.class)
|
||||
.setParameter("email", email).getResultList();
|
||||
|
||||
if (results.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return results.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToSession(int sessionId, int userId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Session s = em.find(Session.class, sessionId);
|
||||
Utilisateur u = em.find(Utilisateur.class, userId);
|
||||
|
||||
//FAUT AJOUTER OWNING SIDE ( Ici u --> s)
|
||||
u.getSession().add(s);
|
||||
//Jsp il faut birectionnelle ou pas?
|
||||
//s.getUtilisateurs().add(u);
|
||||
em.merge(u);
|
||||
t.commit();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class QuestionDTO {
|
||||
private int id;
|
||||
private String question;
|
||||
private List<String> reponses_string;
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class QuizzDTO {
|
||||
private int id;
|
||||
private Integer sessionId;
|
||||
private Integer utilisateurId;
|
||||
private List<Integer> questionsId;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class SessionDTO {
|
||||
private String theme;
|
||||
private int codePIN;
|
||||
private int id;
|
||||
|
||||
private List<Integer> quizzsId;
|
||||
private List<Integer> utilisateursId;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.DTO;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@XmlRootElement
|
||||
public class UtilisateurDTO {
|
||||
private int id;
|
||||
private String name;
|
||||
private String email;
|
||||
private String password;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.QuestionDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface QuestionMapper {
|
||||
QuestionMapper INSTANCE = Mappers.getMapper( QuestionMapper.class );
|
||||
|
||||
|
||||
@Mapping(target = "reponses_string", expression = "java(question_ReponseString(question.getReponse()))")
|
||||
QuestionDTO toDTO(Question question);
|
||||
|
||||
Question toEntity(QuestionDTO questionDTO);
|
||||
|
||||
List<QuestionDTO> toDTOs(List<Question> questionList);
|
||||
|
||||
default List<String> question_ReponseString(Reponse reponse){
|
||||
return reponse.getReponses();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.QuizzDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface QuizzMapper {
|
||||
QuizzMapper INSTANCE = Mappers.getMapper( QuizzMapper.class );
|
||||
|
||||
//https://www.baeldung.com/mapstruct-map-source-object-target-list
|
||||
//https://mapstruct.org/
|
||||
@Mapping(target="sessionId", source="session.id")
|
||||
@Mapping(target="utilisateurId", source = "utilisateur.id")
|
||||
@Mapping(target="questionsId",expression="java(function_mapQ(quizz.getQuestions()))")
|
||||
QuizzDTO toDTO(Quizz quizz);
|
||||
Quizz toEntity(QuizzDTO quizzDTO);
|
||||
|
||||
List<QuizzDTO> toDTOs(List<Quizz> quizzes);
|
||||
|
||||
default List<Integer> function_mapQ(List<Question> questionList){
|
||||
List<Integer> list=new ArrayList<Integer>();
|
||||
for(Question question : questionList){
|
||||
list.add(question.getId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.SessionDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SessionMapper {
|
||||
SessionMapper INSTANCE = Mappers.getMapper( SessionMapper.class );
|
||||
|
||||
@Mapping(target="utilisateursId",expression="java(function_mapU(session.getUtilisateurs()))")
|
||||
@Mapping(target="quizzsId",expression="java(function_mapQ(session.getQuizzs()))")
|
||||
SessionDTO toDTO(Session session);
|
||||
Session toEntity(SessionDTO sessionDTO);
|
||||
|
||||
List<SessionDTO> toDTOs(List<Session> sessions);
|
||||
|
||||
//https://www.baeldung.com/mapstruct-map-source-object-target-list
|
||||
default List<Integer> function_mapU(List<Utilisateur> utilisateurList) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (Utilisateur utilisateur : utilisateurList) {
|
||||
result.add(utilisateur.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
default List<Integer> function_mapQ(List<Quizz> quizzList) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (Quizz quizz : quizzList) {
|
||||
result.add(quizz.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.Mapper;
|
||||
|
||||
import fr.istic.taa.jaxrs.DTO.UtilisateurDTO;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UtilisateurMapper {
|
||||
UtilisateurMapper INSTANCE = Mappers.getMapper(UtilisateurMapper.class);
|
||||
|
||||
UtilisateurDTO toDTO(Utilisateur utilisateur);
|
||||
Utilisateur toEntity(UtilisateurDTO dto);
|
||||
|
||||
List<UtilisateurDTO> toDTOs(List<Utilisateur> utilisateurList);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package fr.istic.taa.jaxrs;
|
||||
|
||||
import io.undertow.Undertow;
|
||||
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* RESTfull microservice, based on JAX-RS and JBoss Undertow
|
||||
*
|
||||
*/
|
||||
public class RestServer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(RestServer.class.getName());
|
||||
|
||||
public static void main(String[] args) {
|
||||
UndertowJaxrsServer ut = new UndertowJaxrsServer();
|
||||
TestApplication ta = new TestApplication();
|
||||
ut.deploy(ta);
|
||||
ut.start(
|
||||
Undertow.builder()
|
||||
.addHttpListener(8080, "localhost")
|
||||
|
||||
);
|
||||
|
||||
logger.info("JAX-RS based micro-service running!");
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright Red Hat, Inc., and individual contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package fr.istic.taa.jaxrs;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import fr.istic.taa.jaxrs.rest.*;
|
||||
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
|
||||
import jakarta.ws.rs.ApplicationPath;
|
||||
import jakarta.ws.rs.core.Application;
|
||||
|
||||
@ApplicationPath("/")
|
||||
public class TestApplication extends Application {
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
|
||||
final Set<Class<?>> clazzes = new HashSet<Class<?>>();
|
||||
|
||||
clazzes.add(OpenApiResource.class);
|
||||
clazzes.add(PetResource.class);
|
||||
clazzes.add(QuestionResource.class);
|
||||
clazzes.add(QuizzResource.class);
|
||||
clazzes.add(UtilisateurResource.class);
|
||||
clazzes.add(SessionResource.class);
|
||||
clazzes.add(SwaggerResource.class);
|
||||
return clazzes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.v3.oas.models.tags.Tag;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlElementWrapper;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "Pet")
|
||||
public class Pet {
|
||||
private long id;
|
||||
private String name;
|
||||
private List<Tag> tags = new ArrayList<Tag>();
|
||||
|
||||
@XmlElement(name = "id")
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "tags")
|
||||
@XmlElement(name = "tag")
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import fr.istic.taa.jaxrs.domain.Pet;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("pet")
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class PetResource {
|
||||
|
||||
@GET
|
||||
@Path("/{petId}")
|
||||
public Pet getPetById(@PathParam("petId") Long petId) {
|
||||
// return pet
|
||||
return new Pet();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
public Pet getPet(Long petId) {
|
||||
return new Pet();
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Consumes("application/json")
|
||||
public Response addPet(
|
||||
@Parameter(description = "Pet object that needs to be added to the store", required = true) Pet pet) {
|
||||
// add pet
|
||||
return Response.ok().entity("SUCCESS").build();
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.QuestionDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuestionDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuestionMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Choix;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.PATCH;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
|
||||
@Path("question")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class QuestionResource {
|
||||
private final QuestionDAO questionDAO = new QuestionDAO();
|
||||
private final QuestionMapper mapper = QuestionMapper.INSTANCE;
|
||||
|
||||
@GET
|
||||
public List<Question> listQuestion(){
|
||||
List<Question> questions = questionDAO.findAll();
|
||||
return questions;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/addQuestion")
|
||||
public Response addQuestion(QuestionDTO dto){
|
||||
Question question = mapper.toEntity(dto);
|
||||
questionDAO.create(question);
|
||||
return Response.status(Response.Status.CREATED).entity("Question ajouté avec Succès : \"" + dto.getQuestion() + "\"").build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/changeQuestion/")
|
||||
public Response changeQuestion(@PathParam("question_id") Integer id, String newQuestion){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.changeQuestion(newQuestion,id);
|
||||
return Response.status(Response.Status.CREATED).entity("Question mis à jour : " + newQuestion).build();
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{question_id}/getReponse/")
|
||||
public Response getReponse(@PathParam("question_id") Integer id){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
Reponse result = question.getReponse();
|
||||
return Response.ok(result).build();
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/addReponse/")
|
||||
public Response addReponse(@PathParam("question_id") Integer id, String reponse){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.addReponse(reponse,id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponse correct \""+reponse+"\" ajouté à la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{question_id}/deletReponses/")
|
||||
public Response addReponse(@PathParam("question_id") Integer id){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.deleteReponse(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses supprimé de la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/setReponse/choix")
|
||||
public Response setChoix(@PathParam("question_id") Integer id){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.setChoix(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses à choix multiple mise sur la question " + id).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/setReponse/reponseCourte")
|
||||
public Response setReponseCourte(@PathParam("question_id") Integer id){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.setReponseCourte(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses courte mise sur la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/AddChoix")
|
||||
public Response addChoix(@PathParam("question_id") Integer id, String choix){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
if(question.getReponse() instanceof Choix){
|
||||
return Response.status(Response.Status.EXPECTATION_FAILED).build();
|
||||
}
|
||||
questionDAO.addChoix(id, choix);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses courte mise sur la question " + id).build();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.QuestionDAO;
|
||||
import fr.istic.taa.jaxrs.DAO.QuizzDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuestionDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuizzDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuestionMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuizzMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Quizz;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Path("quizz")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class QuizzResource {
|
||||
public final QuizzMapper mapper = QuizzMapper.INSTANCE;
|
||||
public final QuizzDAO quizzDAO= new QuizzDAO();
|
||||
public final QuestionDAO questionDAO = new QuestionDAO();
|
||||
|
||||
@GET
|
||||
@Path("/{quizz_id}")
|
||||
public Response getQuizzById(@PathParam("quizz_id") Integer quizzId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
if (quizz == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
QuizzDTO dto = mapper.toDTO(quizz);
|
||||
return Response.status(Response.Status.OK).entity(dto).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{quizz_id}/questions")
|
||||
public Response getQuestions(@PathParam("quizz_id") Integer quizzId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
if (quizz == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<Question> questionList= quizz.getQuestions();
|
||||
List<QuestionDTO> dtos = QuestionMapper.INSTANCE.toDTOs(questionList);
|
||||
|
||||
return Response.status(Response.Status.OK).entity(dtos).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{quizz_id}/add_question/{question_id}")
|
||||
public Response addQuestion(@PathParam("quizz_id") Integer quizzId, @PathParam("question_id") Integer questionId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
Question question = questionDAO.findById(questionId);
|
||||
if (quizz == null || question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
quizzDAO.addQuestion(quizzId,questionId);
|
||||
quizzDAO.update(quizz);
|
||||
QuizzDTO quizzDTO = mapper.toDTO(quizz);
|
||||
return Response.status(Response.Status.OK).entity(quizzDTO).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{quizz_id}/deleteQ")
|
||||
public Response deleteQuestion(@PathParam("quizz_id") Integer quizzId) {
|
||||
Quizz quizz = quizzDAO.findById(quizzId);
|
||||
if (quizz == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
quizzDAO.deleteAllQustion(quizzId);
|
||||
quizzDAO.update(quizz);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.SessionDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.QuizzDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.SessionDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.UtilisateurDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.QuizzMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.SessionMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.UtilisateurMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Path("session")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class SessionResource {
|
||||
private final SessionDAO sessionDAO = new SessionDAO();
|
||||
private final SessionMapper mapper = SessionMapper.INSTANCE;
|
||||
|
||||
@GET
|
||||
public List<Session> listSession() {
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
return sessions;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
public Response getSession(@PathParam("id") Integer id) {
|
||||
Session session = sessionDAO.findById(id);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
SessionDTO result = mapper.toDTO(session);
|
||||
return Response.status(Response.Status.OK).entity(result).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{session_id}/quizzs")
|
||||
public Response getQuizzs(@PathParam("session_id") Integer sessionId) {
|
||||
Session session = sessionDAO.findById(sessionId);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<QuizzDTO> results= QuizzMapper.INSTANCE.toDTOs(session.getQuizzs());
|
||||
return Response.status(Response.Status.OK).entity(results).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{session_id}/utilisateurs")
|
||||
public Response getUtilisateurs(@PathParam("session_id") Integer sessionId) {
|
||||
Session session = sessionDAO.findById(sessionId);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<Utilisateur> utilisateurList= session.getUtilisateurs();
|
||||
List<UtilisateurDTO> dtos= UtilisateurMapper.INSTANCE.toDTOs(utilisateurList);
|
||||
return Response.status(Response.Status.OK).entity(dtos).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{session_id}/delete")
|
||||
public Response deleteSession(@PathParam("session_id") Integer sessionId) {
|
||||
Session session = sessionDAO.findById(sessionId);
|
||||
if (session == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
sessionDAO.delete(session);
|
||||
return Response.status(Response.Status.OK).entity("Réussi de supprimer").build();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
|
||||
@Path("/api")
|
||||
public class SwaggerResource {
|
||||
private static final Logger logger = Logger.getLogger(SwaggerResource.class.getName());
|
||||
|
||||
@GET
|
||||
public byte[] Get1() {
|
||||
try {
|
||||
return Files.readAllBytes(FileSystems.getDefault().getPath("src/main/webapp/swagger/index.html"));
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{path:.*}")
|
||||
public byte[] Get(@PathParam("path") String path) {
|
||||
try {
|
||||
return Files.readAllBytes(FileSystems.getDefault().getPath("src/main/webapp/swagger/"+path));
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package fr.istic.taa.jaxrs.rest;
|
||||
|
||||
import fr.istic.taa.jaxrs.DAO.SessionDAO;
|
||||
import fr.istic.taa.jaxrs.DAO.UtilisateurDAO;
|
||||
import fr.istic.taa.jaxrs.DTO.SessionDTO;
|
||||
import fr.istic.taa.jaxrs.DTO.UtilisateurDTO;
|
||||
import fr.istic.taa.jaxrs.Mapper.SessionMapper;
|
||||
import fr.istic.taa.jaxrs.Mapper.UtilisateurMapper;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Session;
|
||||
import fr.istic.taa.jaxrs.metier.Utilisateur;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Path("utilisateur")
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
@Produces({"application/json", "application/xml"})
|
||||
public class UtilisateurResource {
|
||||
private final UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||
private final UtilisateurMapper mapper = UtilisateurMapper.INSTANCE;
|
||||
|
||||
@GET
|
||||
public List<Utilisateur> listUtilisateur() {
|
||||
List<Utilisateur> utilisateurs = utilisateurDAO.findAll();
|
||||
return utilisateurs;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/register")
|
||||
public Response registerUtilisateur(UtilisateurDTO dto) {
|
||||
String email_verification = dto.getEmail();
|
||||
Utilisateur existing = utilisateurDAO.findByEmail(email_verification);
|
||||
|
||||
//VERIFACTION S'IL EXISTE DANS BDD
|
||||
if (existing != null) {
|
||||
return Response.status(Response.Status.CONFLICT).entity("Email est déjà registré").build();
|
||||
}
|
||||
|
||||
Utilisateur utilisateur = mapper.toEntity(dto);
|
||||
utilisateurDAO.create(utilisateur);
|
||||
|
||||
return Response.status(Response.Status.CREATED).entity("Registration succès").build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/login")
|
||||
public Response loginUtilisateur(UtilisateurDTO dto) {
|
||||
Utilisateur utilisateur = utilisateurDAO.findByEmail(dto.getEmail());
|
||||
|
||||
if (utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Email n'existe pas").build();
|
||||
} else if (!utilisateur.getPassword().equals(dto.getPassword())) {
|
||||
return Response.status(Response.Status.UNAUTHORIZED).entity("Mauvais mdp").build();
|
||||
}
|
||||
UtilisateurDTO result = mapper.toDTO(utilisateur);
|
||||
|
||||
return Response.status(Response.Status.OK).entity(result).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@Operation(summary = "Get user by ID",
|
||||
tags = {"utilisateur"},
|
||||
description = "Get User by ID",
|
||||
responses = {
|
||||
@ApiResponse(description = "Utilisateur", content = @Content(
|
||||
schema = @Schema(implementation = Utilisateur.class)
|
||||
)),
|
||||
@ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
|
||||
@ApiResponse(responseCode = "404", description = "User not found")
|
||||
})
|
||||
public Response getUtilisateur(@Parameter(
|
||||
description = "ID of user that needs to be fetched",
|
||||
schema = @Schema(
|
||||
type = "integer",
|
||||
format = "int32",
|
||||
description = "param ID of user that needs to be fetched"
|
||||
),
|
||||
required = true)
|
||||
@PathParam("id") Integer id) {
|
||||
Utilisateur utilisateur = utilisateurDAO.findById(id);
|
||||
if (utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
UtilisateurDTO result = mapper.toDTO(utilisateur);
|
||||
return Response.ok(result).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{user_id}/add_session/{session_id}")
|
||||
public Response addSession(@PathParam("user_id") Integer user_id, @PathParam("session_id") Integer session_id) {
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
|
||||
Session existingSession = sessionDAO.findById(session_id);
|
||||
Utilisateur utilisateur = utilisateurDAO.findById(user_id);
|
||||
|
||||
if (existingSession == null || utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
//If user already joined
|
||||
if (utilisateur.getSession().contains(existingSession)) {
|
||||
return Response.status(Response.Status.CONFLICT).build();
|
||||
}
|
||||
utilisateurDAO.addToSession(user_id, session_id);
|
||||
utilisateurDAO.update(utilisateur);
|
||||
|
||||
// We update it so have to return new DTO
|
||||
UtilisateurDTO dto = mapper.toDTO(utilisateur);
|
||||
|
||||
return Response.status(Response.Status.OK).entity(dto).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{user_id}/session")
|
||||
public Response listSession(@PathParam("user_id") Integer user_id) {
|
||||
Utilisateur utilisateur = utilisateurDAO.findById(user_id);
|
||||
if (utilisateur == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
List<Session> sess = utilisateur.getSession();
|
||||
List<SessionDTO> dtos = SessionMapper.INSTANCE.toDTOs(sess);
|
||||
return Response.status(Response.Status.OK).entity(dtos).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{user_id}/delete")
|
||||
public Response deleteUtilisateur(@PathParam("user_id") Integer user_id) {
|
||||
Utilisateur existing = utilisateurDAO.findById(user_id);
|
||||
if (existing == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
utilisateurDAO.delete(existing);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
}
|
||||
29
src/main/java/sample/data/jpa/SampleDataJpaApplication.java
Normal file
29
src/main/java/sample/data/jpa/SampleDataJpaApplication.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.data.jpa;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SampleDataJpaApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleDataJpaApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
66
src/main/java/sample/data/jpa/domain/User.java
Normal file
66
src/main/java/sample/data/jpa/domain/User.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package sample.data.jpa.domain;
|
||||
// Imports ...
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User {
|
||||
|
||||
// An autogenerated id (unique for each user in the db)
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long id;
|
||||
|
||||
@NotNull
|
||||
private String email;
|
||||
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
// Public methods
|
||||
|
||||
public User() { }
|
||||
|
||||
public User(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public User(String email, String name) {
|
||||
this.email = email;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// Getter and setter methods
|
||||
// ...
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package sample.data.jpa.metier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package sample.data.jpa.metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package sample.data.jpa.metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package sample.data.jpa.metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package sample.data.jpa.metier;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package sample.data.jpa.metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.istic.taa.jaxrs.metier;
|
||||
package sample.data.jpa.metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
4
src/main/java/sample/data/jpa/service/QuestionDao.java
Normal file
4
src/main/java/sample/data/jpa/service/QuestionDao.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface QuestionDao {
|
||||
}
|
||||
4
src/main/java/sample/data/jpa/service/QuizzDao.java
Normal file
4
src/main/java/sample/data/jpa/service/QuizzDao.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface QuizzDao {
|
||||
}
|
||||
4
src/main/java/sample/data/jpa/service/ReponseDao.java
Normal file
4
src/main/java/sample/data/jpa/service/ReponseDao.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface ReponseDao {
|
||||
}
|
||||
4
src/main/java/sample/data/jpa/service/SessionDao.java
Normal file
4
src/main/java/sample/data/jpa/service/SessionDao.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface SessionDao {
|
||||
}
|
||||
20
src/main/java/sample/data/jpa/service/UserDao.java
Normal file
20
src/main/java/sample/data/jpa/service/UserDao.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import sample.data.jpa.domain.User;
|
||||
|
||||
// Imports ...
|
||||
|
||||
@Transactional
|
||||
public interface UserDao extends JpaRepository<User, Long> {
|
||||
|
||||
/**
|
||||
* This method will find an User instance in the database by its email.
|
||||
* Note that this method is not implemented and its working code will be
|
||||
* automagically generated from its signature by Spring Data JPA.
|
||||
*/
|
||||
public User findByEmail(String email);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package sample.data.jpa.service;
|
||||
|
||||
public interface UtilisateurDao {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
@Controller
|
||||
public class QuestionController {
|
||||
|
||||
}
|
||||
6
src/main/java/sample/data/jpa/web/QuizzController.java
Normal file
6
src/main/java/sample/data/jpa/web/QuizzController.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
@Controller
|
||||
public class QuizzController {
|
||||
|
||||
}
|
||||
6
src/main/java/sample/data/jpa/web/ReponseController.java
Normal file
6
src/main/java/sample/data/jpa/web/ReponseController.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
@Controller
|
||||
public class ReponseController {
|
||||
|
||||
}
|
||||
6
src/main/java/sample/data/jpa/web/SessionController.java
Normal file
6
src/main/java/sample/data/jpa/web/SessionController.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
@Controller
|
||||
public class SessionController {
|
||||
|
||||
}
|
||||
91
src/main/java/sample/data/jpa/web/UserController.java
Normal file
91
src/main/java/sample/data/jpa/web/UserController.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import sample.data.jpa.domain.User;
|
||||
import sample.data.jpa.service.UserDao;
|
||||
|
||||
@Controller
|
||||
public class UserController {
|
||||
|
||||
/**
|
||||
* GET /create --> Create a new user and save it in the database.
|
||||
*/
|
||||
@RequestMapping("/create")
|
||||
@ResponseBody
|
||||
public String create(String email, String name) {
|
||||
String userId = "";
|
||||
try {
|
||||
User user = new User(email, name);
|
||||
userDao.save(user);
|
||||
userId = String.valueOf(user.getId());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error creating the user: " + ex.toString();
|
||||
}
|
||||
return "User succesfully created with id = " + userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /delete --> Delete the user having the passed id.
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
@ResponseBody
|
||||
public String delete(long id) {
|
||||
try {
|
||||
User user = new User(id);
|
||||
userDao.delete(user);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error deleting the user:" + ex.toString();
|
||||
}
|
||||
return "User succesfully deleted!";
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /get-by-email --> Return the id for the user having the passed
|
||||
* email.
|
||||
*/
|
||||
@RequestMapping("/get-by-email/{email}")
|
||||
@ResponseBody
|
||||
public String getByEmail(@PathVariable("email") String email) {
|
||||
String userId = "";
|
||||
try {
|
||||
User user = userDao.findByEmail(email);
|
||||
userId = String.valueOf(user.getId());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "User not found";
|
||||
}
|
||||
return "The user id is: " + userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /update --> Update the email and the name for the user in the
|
||||
* database having the passed id.
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
@ResponseBody
|
||||
public String updateUser(long id, String email, String name) {
|
||||
try {
|
||||
User user = userDao.findById(id).get();
|
||||
user.setEmail(email);
|
||||
user.setName(name);
|
||||
userDao.save(user);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "Error updating the user: " + ex.toString();
|
||||
}
|
||||
return "User succesfully updated!";
|
||||
}
|
||||
|
||||
// Private fields
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package sample.data.jpa.web;
|
||||
|
||||
@Controller
|
||||
public class UtilisateurController {
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
||||
version="3.0">
|
||||
|
||||
<persistence-unit name="dev" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<properties>
|
||||
<property name="jakarta.persistence.jdbc.driver"
|
||||
value="org.hsqldb.jdbcDriver" />
|
||||
<property name="jakarta.persistence.jdbc.url"
|
||||
value="jdbc:hsqldb:hsql://localhost/" />
|
||||
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||
<property
|
||||
name="jakarta.persistence.schema-generation.database.action"
|
||||
value="create" />
|
||||
<property name="jakarta.persistence.dialect"
|
||||
value="org.hibernate.dialect.HSQLDialect" />
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
<persistence-unit name="prod" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<properties>
|
||||
<property name="jakarta.persistence.jdbc.driver"
|
||||
value="org.hsqldb.jdbcDriver" />
|
||||
<property name="jakarta.persistence.jdbc.url"
|
||||
value="jdbc:hsqldb:hsql://localhost/" />
|
||||
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||
<property
|
||||
name="jakarta.persistence.schema-generation.database.action"
|
||||
value="update" />
|
||||
<property name="jakarta.persistence.dialect"
|
||||
value="org.hibernate.dialect.HSQLDialect" />
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<persistence-unit name="mysql">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<properties>
|
||||
<property name="jakarta.persistence.jdbc.driver"
|
||||
value="com.mysql.cj.jdbc.Driver" />
|
||||
<property name="jakarta.persistence.jdbc.url"
|
||||
value="jdbc:mysql://localhost/mydatabase" />
|
||||
<property name="jakarta.persistence.jdbc.user" value="tlc" />
|
||||
<property name="jakarta.persistence.jdbc.password" value="tlc" />
|
||||
<property
|
||||
name="jakarta.persistence.schema-generation.database.action"
|
||||
value="update" />
|
||||
<property name="jakarta.persistence.dialect"
|
||||
value="org.hibernate.dialect.MySQL8Dialect" />
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
<property name="hibernate.c3p0.min_size" value="5" />
|
||||
<property name="hibernate.c3p0.max_size" value="20" />
|
||||
<property name="hibernate.c3p0.timeout" value="300" />
|
||||
<property name="hibernate.c3p0.max_statements" value="50" />
|
||||
<property name="hibernate.c3p0.idle_test_period" value="3000" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
24
src/main/resources/application.properties
Normal file
24
src/main/resources/application.properties
Normal file
@@ -0,0 +1,24 @@
|
||||
spring.h2.console.enabled=true
|
||||
|
||||
logging.level.org.hibernate.SQL=debug
|
||||
|
||||
# DataSource settings: set here your own configurations for the database
|
||||
# connection. In this example we have "netgloo_blog" as database name and
|
||||
# "root" as username and password.
|
||||
spring.datasource.url = jdbc:mysql://localhost:3306/testspringdata?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
|
||||
spring.datasource.username = tlc
|
||||
spring.datasource.password = tlc
|
||||
|
||||
|
||||
# Show or not log for each sql query
|
||||
spring.jpa.show-sql = true
|
||||
|
||||
# Hibernate ddl auto (create, create-drop, update)
|
||||
spring.jpa.hibernate.ddl-auto = update
|
||||
|
||||
|
||||
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
|
||||
# stripped before adding them to the entity manager)
|
||||
|
||||
# The SQL dialect makes Hibernate generate better SQL for the chosen database
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
|
||||
186
src/main/resources/import.sql
Normal file
186
src/main/resources/import.sql
Normal file
@@ -0,0 +1,186 @@
|
||||
--
|
||||
-- Sample dataset containing a number of Hotels in various Cities across the world. The reviews are entirely fictional :)
|
||||
--
|
||||
|
||||
-- =================================================================================================
|
||||
-- AUSTRALIA
|
||||
|
||||
-- Brisbane
|
||||
insert into city(country, name, state, map) values ('Australia', 'Brisbane', 'Queensland', '-27.470933, 153.023502')
|
||||
insert into hotel(city_id, name, address, zip) values (1, 'Conrad Treasury Place', 'William & George Streets', '4001')
|
||||
|
||||
-- Melbourne
|
||||
insert into city(country, name, state, map) values ('Australia', 'Melbourne', 'Victoria', '-37.813187, 144.96298')
|
||||
insert into hotel(city_id, name, address, zip) values (2, 'The Langham', '1 Southgate Ave, Southbank', '3006')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (2, 0, '2005-05-10', 2, 4, 'Pretty average', 'I stayed in 2005, the hotel was nice enough but nothing special.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (2, 1, '2006-01-12', 4, 2, 'Bright hotel with big rooms', 'This hotel has a fantastic lovely big windows. The room we stayed in had lots of space. Recommended.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (2, 2, '2006-05-25', 3, 1, 'Pretty good', 'I liked this hotel and would stay again.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (2, 3, '2009-01-20', 3, 2, 'Nice clean rooms', 'The rooms are maintained to a high standard and very clean, the bathroom was spotless!!')
|
||||
|
||||
-- Sydney
|
||||
insert into city(country, name, state, map) values ('Australia', 'Sydney', 'New South Wales', '-33.868901, 151.207091')
|
||||
insert into hotel(city_id, name, address, zip) values (3, 'Swissotel', '68 Market Street', '2000')
|
||||
|
||||
|
||||
-- =================================================================================================
|
||||
-- CANADA
|
||||
|
||||
-- Montreal
|
||||
insert into city(country, name, state, map) values ('Canada', 'Montreal', 'Quebec', '45.508889, -73.554167')
|
||||
insert into hotel(city_id, name, address, zip) values (4, 'Ritz Carlton', '1228 Sherbrooke St', 'H3G1H6')
|
||||
|
||||
|
||||
-- =================================================================================================
|
||||
-- ISRAEL
|
||||
|
||||
-- Tel Aviv
|
||||
insert into city(country, name, state, map) values ('Israel', 'Tel Aviv', '', '32.066157, 34.777821')
|
||||
insert into hotel(city_id, name, address, zip) values (5, 'Hilton Tel Aviv', 'Independence Park', '63405')
|
||||
|
||||
|
||||
-- =================================================================================================
|
||||
-- JAPAN
|
||||
|
||||
-- Tokyo
|
||||
insert into city(country, name, state, map) values ('Japan', 'Tokyo', '', '35.689488, 139.691706')
|
||||
insert into hotel(city_id, name, address, zip) values (6, 'InterContinental Tokyo Bay', 'Takeshiba Pier', '105')
|
||||
|
||||
|
||||
-- =================================================================================================
|
||||
-- SPAIN
|
||||
|
||||
-- Barcelona
|
||||
insert into city(country, name, state, map) values ('Spain', 'Barcelona', 'Catalunya', '41.387917, 2.169919')
|
||||
insert into hotel(city_id, name, address, zip) values (7, 'Hilton Diagonal Mar', 'Passeig del Taulat 262-264', '08019')
|
||||
|
||||
-- =================================================================================================
|
||||
-- SWITZERLAND
|
||||
|
||||
-- Neuchatel
|
||||
insert into city(country, name, state, map) values ('Switzerland', 'Neuchatel', '', '46.992979, 6.931933')
|
||||
insert into hotel(city_id, name, address, zip) values (8, 'Hotel Beaulac', ' Esplanade Leopold-Robert 2', '2000')
|
||||
|
||||
|
||||
-- =================================================================================================
|
||||
-- UNITED KINGDOM
|
||||
|
||||
-- Bath
|
||||
insert into city(country, name, state, map) values ('UK', 'Bath', 'Somerset', '51.381428, -2.357454')
|
||||
insert into hotel(city_id, name, address, zip) values (9, 'The Bath Priory Hotel', 'Weston Road', 'BA1 2XT')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 0, '2000-01-23', 4, 1, 'A lovely hotel', 'We stayed here after a wedding and it was fantastic. Recommend to all.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 1, '2000-08-04', 3, 1, 'Very special', 'A very special hotel with lovely staff.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 2, '2001-01-01', 2, 4, 'Nice but too hot', 'Stayed during the summer heat wave (exceptional for England!) and the room was very hot. Still recommended.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 3, '2002-01-20', 3, 1, 'Big rooms and a great view', 'Considering how central this hotel is the rooms are a very good size.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 4, '2002-11-03', 2, 1, 'Good but pricey', 'A nice hotel but be prepared to pay over the odds for your stay.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 5, '2003-09-18', 4, 1, 'Fantastic place', 'Just lovely.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 6, '2004-03-21', 4, 3, 'A very special place', 'I stayed here in 2004 and found it to be very relaxing, a nice pool and good gym is cherry on the cake.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 7, '2004-04-10', 0, 0, 'Terrible', 'I complained after I was told I could not check out after 11pm. Ridiculous!!!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 8, '2004-12-20', 4, 4, 'A perfect location', 'Central location makes this a perfect hotel. Be warned though, it''s not cheap.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 9, '2005-04-19', 3, 2, 'Expensive but worth it', 'Dig deep into your pockets and enjoy this lovely City and fantastic hotel.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 10, '2005-05-21', 4, 1, 'The best hotel in the area', 'Top hotel in the area, would not stay anywhere else.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 11, '2005-11-17', 4, 2, 'Lovely hotel, fantastic grounds', 'The garden upkeep run into thousands (perhaps explaining why the rooms are so much) but so lovely and relaxing.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 12, '2006-01-04', 3, 4, 'Gorgeous Top Quality Hotel', 'Top draw stuff.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 13, '2006-01-21', 4, 1, 'Fabulous Hotel and Restaurant', 'The food at this hotel is second to none, try the peppered steak!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 14, '2006-01-29', 4, 4, 'Feels like home', 'A lovely home away from home.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 15, '2006-03-21', 1, 1, 'Far too expensive', 'Overpriced, Overpriced, Overpriced!!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 16, '2006-05-10', 4, 1, 'Excellent Hotel, Wonderful Staff', 'The staff went out of their way to help us after we missed our last train home, organising a Taxi back to Newport even after we had checked out.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 17, '2007-09-11', 3, 2, 'The perfect retreat', 'If you want a relaxing stay, this is the place.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 18, '2008-06-01', 3, 3, 'Lovely stay, fantastic staff', 'As other reviews have noted, the staff in this hotel really are the best in Bath.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 19, '2009-05-14', 4, 2, 'Can''t Wait to go back', 'We will stay again for sure.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 20, '2010-04-26', 4, 1, 'Amazing Hotel', 'We won a trip here after entering a competition. Not sure we would pay the full price but such a wonderful place.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (9, 21, '2010-10-26', 2, 2, 'Dissapointed', 'The pool was closed, the chief was ill, the staff were rude my wallet is bruised!')
|
||||
insert into hotel(city_id, name, address, zip) values (9, 'Bath Travelodge', 'Rossiter Road, Widcombe Basin', 'BA2 4JP')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 0, '2002-08-21', 0, 2, 'Terrible hotel', 'One of the worst hotels that I have ever stayed in.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 1, '2003-01-28', 0, 0, 'Rude and unpleasant staff', 'The staff refused to help me with any aspect of my stay, I will not stay here again.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 2, '2004-06-17', 1, 0, 'Below par', 'Don''t stay here!!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 3, '2005-07-12', 0, 1, 'Small and Unpleasant', 'The room was far too small and felt unclean. Not recommended.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 4, '2006-01-07', 1, 4, 'Cheap if you are not fussy', 'This hotel has some rough edges but I challenge you to find somewhere cheaper.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 5, '2006-01-13', 0, 2, 'Terrible', 'Just terrible!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 6, '2006-03-25', 0, 0, 'Smelly and dirty room', 'My room smelt of damp and I found the socks of the previous occupant under my bed.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 7, '2006-04-09', 0, 4, 'Grim', 'Grim. I would try elsewhere before staying here.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 8, '2006-08-01', 1, 3, 'Very Noisy', 'Building work during the day and a disco at night. Good grief!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 9, '2009-01-03', 1, 4, 'Tired and falling down', 'This hotel is in serious need of refurbishment, the windows are rotting, the paintwork is tired and the carpets are from the 1970s.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 10, '2009-07-20', 0, 0, 'Not suitable for human habitation', 'I would not put my dog up in this hotel.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 11, '2010-05-20', 1, 0, 'Conveient for the railway', 'Average place but useful if you need to commute')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 12, '2010-01-22', 2, 2, 'Not as bad as the reviews', 'Some of the reviews seem a bit harsh, it''s not too bad for the price.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (10, 13, '2011-01-10', 3, 1, 'Reburished and nice', 'Looks like this hotel has had a major facelift. If you have stayed before 2011 perhaps it''s time to give this hotel another try. Very good value for money and pretty nice.')
|
||||
|
||||
-- London
|
||||
insert into city(country, name, state, map) values ('UK', 'London', '', '51.500152, -0.126236')
|
||||
insert into hotel(city_id, name, address, zip) values (10, 'Melia White House', 'Albany Street', 'NW1 3UP')
|
||||
|
||||
-- Southampton
|
||||
insert into city(country, name, state, map) values ('UK', 'Southampton', 'Hampshire', '50.902571, -1.397238')
|
||||
insert into hotel(city_id, name, address, zip) values (11, 'Chilworth Manor', 'The Cottage, Southampton Business Park', 'SO16 7JF')
|
||||
|
||||
|
||||
-- =================================================================================================
|
||||
-- USA
|
||||
|
||||
-- Atlanta
|
||||
insert into city(country, name, state, map) values ('USA', 'Atlanta', 'GA', '33.748995, -84.387982')
|
||||
insert into hotel(city_id, name, address, zip) values (12, 'Marriott Courtyard', 'Tower Place, Buckhead', '30305')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (13, 0, '2009-01-20', 3, 0, 'Better than most', 'Most other hotels is this area are a bit ropey, this one is actually pretty good.')
|
||||
insert into hotel(city_id, name, address, zip) values (12, 'Ritz Carlton', 'Peachtree Rd, Buckhead', '30326')
|
||||
insert into hotel(city_id, name, address, zip) values (12, 'Doubletree', 'Tower Place, Buckhead', '30305')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (15, 0, '2006-01-12', 2, 3, 'No fuss hotel', 'Cheap, no fuss hotel. Good if you are travelling on business and just need a place to stay.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (15, 1, '2009-01-20', 2, 2, 'Nice area but small rooms', 'The area felt nice and safe but the rooms are a little on the small side')
|
||||
|
||||
-- Chicago
|
||||
insert into city(country, name, state, map) values ('USA', 'Chicago', 'IL', '41.878114, -87.629798')
|
||||
insert into hotel(city_id, name, address, zip) values (13, 'Hotel Allegro', '171 West Randolph Street', '60601')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (16, 0, '2009-12-15', 3, 2, 'Cheap and Recommended', 'Good value for money, can''t really fault it.')
|
||||
|
||||
-- Eau Claire
|
||||
insert into city(country, name, state, map) values ('USA', 'Eau Claire', 'WI', '44.811349, -91.498494')
|
||||
insert into hotel(city_id, name, address, zip) values (14, 'Sea Horse Inn', '2106 N Clairemont Ave', '54703')
|
||||
insert into hotel(city_id, name, address, zip) values (14, 'Super 8 Eau Claire Campus Area', '1151 W Macarthur Ave', '54701')
|
||||
|
||||
-- Hollywood
|
||||
insert into city(country, name, state, map) values ('USA', 'Hollywood', 'FL', '26.011201, -80.14949')
|
||||
insert into hotel(city_id, name, address, zip) values (15, 'Westin Diplomat', '3555 S. Ocean Drive', '33019')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (19, 0, '2006-01-11', 0, 0, 'Avoid', 'The hotel has a very bad reputation. I would avoid it if I were you.')
|
||||
|
||||
-- Miami
|
||||
insert into city(country, name, state, map) values ('USA', 'Miami', 'FL', '25.788969, -80.226439')
|
||||
insert into hotel(city_id, name, address, zip) values (16, 'Conrad Miami', '1395 Brickell Ave', '33131')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (20, 0, '2010-01-09', 3, 2, 'Close to the local attractions', 'Fantastic access to all the local attractions mean you won''t mind the small rooms.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (20, 1, '2010-09-10', 2, 2, 'Good value and friendly', 'Not expensive and very welcoming staff. I would stay again.')
|
||||
|
||||
-- Melbourne
|
||||
insert into city(country, name, state, map) values ('USA', 'Melbourne', 'FL', '28.083627, -80.608109')
|
||||
insert into hotel(city_id, name, address, zip) values (17, 'Radisson Suite Hotel Oceanfront', '3101 North Hwy', '32903')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (21, 0, '2005-06-15', 3, 3, 'A very nice hotel', 'I can''t fault this hotel and I have stayed here many times. Always friendly staff and lovely atmosphere.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (21, 1, '2006-01-20', 2, 4, 'Comfortable and good value', 'To complaints at all.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (21, 2, '2007-08-21', 3, 1, 'Above average', 'Better than a lot of hotels in the area and not too pricey.')
|
||||
|
||||
-- New York
|
||||
insert into city(country, name, state, map) values ('USA', 'New York', 'NY', '40.714353, -74.005973')
|
||||
insert into hotel(city_id, name, address, zip) values (18, 'W Union Hotel', 'Union Square, Manhattan', '10011')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (22, 0, '2002-01-19', 0, 1, 'Too noisy, too small', 'The city never sleeps and neither will you if you say here. The rooms are small and the sound insulation is poor!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (22, 1, '2004-03-10', 1, 4, 'Overpriced', 'Far too much money for such a tiny room!')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (22, 2, '2007-04-11', 2, 0, 'So so, nothing special', 'Not brilliant but not too bad either.')
|
||||
insert into hotel(city_id, name, address, zip) values (18, 'W Lexington Hotel', 'Lexington Ave, Manhattan', '10011')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (23, 0, '2004-07-21', 3, 2, 'Excellent location', 'So close to the heart of the city. Recommended.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (23, 1, '2006-05-20', 3, 1, 'Very nice', 'I can''t fault this hotel, clean, good location and nice staff.')
|
||||
insert into hotel(city_id, name, address, zip) values (18, '70 Park Avenue Hotel', '70 Park Avenue', '10011')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (24, 0, '2003-11-10', 4, 1, 'Great!!', 'I own this hotel and I think it is pretty darn good.')
|
||||
|
||||
-- Palm Bay
|
||||
insert into city(country, name, state, map) values ('USA', 'Palm Bay', 'FL', '28.034462, -80.588665')
|
||||
insert into hotel(city_id, name, address, zip) values (19, 'Jameson Inn', '890 Palm Bay Rd NE', '32905')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (25, 0, '2005-10-20', 3, 2, 'Fantastical', 'This is the BEST hotel in Palm Bay, not complaints at all.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (25, 1, '2006-01-12', 4, 1, 'Top marks', 'I rate this hotel 5 stars, the best in the area by miles.')
|
||||
|
||||
-- San Francisco
|
||||
insert into city(country, name, state, map) values ('USA', 'San Francisco', 'CA', '37.77493, -122.419415')
|
||||
insert into hotel(city_id, name, address, zip) values (20, 'Marriot Downtown', '55 Fourth Street', '94103')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (26, 0, '2006-07-02', 2, 3, 'Could be better', 'I stayed in late 2006 with work, the room was very small and the restaurant does not stay open very late.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (26, 1, '2008-07-01', 1, 4, 'Brrrr cold!', 'My room was freezing cold, I would not recommend this place.')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (26, 2, '2009-01-05', 3, 2, 'Nice for money', 'You can''t really go wrong here for the money. There may be better places to stay but not for this price.')
|
||||
|
||||
-- Washington
|
||||
insert into city(country, name, state, map) values ('USA', 'Washington', 'DC', '38.895112, -77.036366')
|
||||
insert into hotel(city_id, name, address, zip) values (21, 'Hotel Rouge', '1315 16th Street NW', '20036')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (27, 0, '2000-01-29', 0, 2, 'Never again', 'I will never ever stay here again!! They wanted extra cash to get fresh batteries for the TV remote')
|
||||
insert into review(hotel_id, idx, check_in_date, rating, trip_type, title, details) values (27, 1, '2006-02-20', 0, 0, 'Avoid', 'This place is the pits, they charged us twice for a single night stay. I only got refunded after contacting my credit card company.')
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sample.data.jpa;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Integration test to run the application.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
// Enable JMX so we can test the MBeans (you can't do this in a properties file)
|
||||
@TestPropertySource(properties = { "spring.jmx.enabled:true",
|
||||
"spring.datasource.jmx-enabled:true" })
|
||||
@ActiveProfiles("scratch")
|
||||
// Separate profile for web tests to avoid clashing databases
|
||||
public class SampleDataJpaApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
private MockMvc mvc;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
|
||||
this.mvc.perform(get("/")).andExpect(status().isOk())
|
||||
.andExpect(content().string("Bath"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJmx() throws Exception {
|
||||
assertThat(ManagementFactory.getPlatformMBeanServer()
|
||||
.queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null))
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
2
src/test/resources/application-scratch.properties
Normal file
2
src/test/resources/application-scratch.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
spring.datasource.name=scratchdb
|
||||
spring.jmx.default-domain=jpa.sample
|
||||
Reference in New Issue
Block a user