Commit 33f5213d authored by Julien's avatar Julien
Browse files

Merge remote-tracking branch 'origin/Dev' into Scenario3FE

parents 33263b6f eb8422d7
before_script:
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- sudo cp /home/ec2-user/deploy-script-Dev.sh .
- sudo ./deploy-script-Dev.sh --build
push_job:
stage: test
script:
- sudo cp //home/ec2-user/deploy-script-Dev.sh .
- sudo ./deploy-script-Dev.sh --push
deploy_job:
stage: deploy
script:
- cd /home/oai/
- ./deploy-script.sh --push --deploy
when: manual
\ No newline at end of file
......@@ -437,6 +437,15 @@
"integrity": "sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow==",
"dev": true
},
"@types/bootstrap": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/@types/bootstrap/-/bootstrap-4.1.3.tgz",
"integrity": "sha512-4RCCokC8cNHrimMN06HX97lhwhPR7ZTVYXVItj/ZWfr3Sb96q/qgOV9th1irONxZR7KunG2uRyJ+ESQzHI+hAA==",
"requires": {
"@types/jquery": "*",
"popper.js": "^1.14.1"
}
},
"@types/daterangepicker": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/daterangepicker/-/daterangepicker-3.0.0.tgz",
......
# Production ready docker configuration
version: '2'
services:
jhipster-elasticsearch:
image: jhipster/jhipster-elasticsearch:latest
ports:
- 9200:9200
- 9300:9300
# Uncomment this as well as the volume section down below
# to have elasticsearch data persisted to a volume
# you will need to create a named volume with `docker volume create log-data`
#volumes:
# - log-data:/usr/share/elasticsearch/data
jhipster-logstash:
image: jhipster/jhipster-logstash:latest
environment:
- INPUT_TCP_PORT=5000
- INPUT_UDP_PORT=5000
- INPUT_HTTP_PORT=5001
- ELASTICSEARCH_HOST=jhipster-elasticsearch
- ELASTICSEARCH_PORT=9200
- LOGSTASH_DEBUG=false
ports:
- 5000:5000
- 5000:5000/udp
- 5001:5001
# Uncomment this section and add a logstash.conf file in log-conf/
# to have logstash config loaded from a volume
#volumes:
# - ./log-conf/:/usr/share/logstash/pipeline/
jhipster-console:
image: jhipster/jhipster-console:latest
ports:
- 5601:5601
#environment:
# - ELASTICSEARCH_URL=http://jhipster-elasticsearch:9200
jhipster-import-dashboards:
image: jhipster/jhipster-import-dashboards:latest
environment:
- ELASTICSEARCH_URL=http://jhipster-elasticsearch:9200
depends_on:
- jhipster-elasticsearch
jhipster-curator:
image: jhipster/jhipster-curator:latest
environment:
- ES_HOST=jhipster-elasticsearch
- ES_PORT=9200
- UNIT_COUNT=14
- UNIT=days
jhipster-alerter:
image: jhipster/jhipster-alerter:latest
environment:
- ES_HOST=jhipster-elasticsearch
- ES_PORT=9200
volumes:
- ../alerts/rules/:/opt/elastalert/rules/
- ../jhipster-alerter/config.yaml:/opt/elastalert/config.yaml
jhipster-zipkin:
image: jhipster/jhipster-zipkin:latest
environment:
- ES_HOSTS=http://jhipster-elasticsearch:9200
# Change localhost:5601 by the URL by which your client access Kibana
- ZIPKIN_UI_LOGS_URL=http://localhost:5601/app/kibana#/discover/d0682f20-e0e9-11e7-9c68-0b9a0f0c183c?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-30d,mode:quick,to:now))&_a=(columns:!(X-B3-TraceId,app_name,level,message),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'logs-*',key:X-B3-TraceId,negate:!f,params:(query:'trace',type:phrase),type:phrase,value:'trace'),query:(match:(X-B3-TraceId:(query:'{traceId}',type:phrase))))),index:'logs-*',interval:auto,query:(language:lucene,query:''),sort:!('@timestamp',desc))
ports:
- 9411:9411
# Uncomment to use the log-data volume
# volumes:
# log-data:
# driver: local
......@@ -231,4 +231,13 @@ public class User extends AbstractAuditingEntity implements Serializable {
", activationKey='" + activationKey + '\'' +
"}";
}
public String firstAndLastName()
{
return "{\n"
+ "\"firstName\": \"" + firstName + "\",\n"
+ "\"lastName\": \"" + lastName + "\"\n"
+ "}";
}
}
......@@ -10,6 +10,6 @@ import org.springframework.stereotype.Repository;
*/
@SuppressWarnings("unused")
@Repository
public interface TaxiRepository extends JpaRepository<Taxi, Long> {
public interface TaxiRepository extends JpaRepository<Taxi, Long>, TaxiRepositoryCustom {
}
package com.mycompany.myapp.repository;
import java.util.List;
import com.mycompany.myapp.domain.Taxi;
public interface TaxiRepositoryCustom
{
public List<Taxi> getTaxisDisponibleUser(String login);
}
package com.mycompany.myapp.repository;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.mycompany.myapp.domain.ROLE_MANAGER_TAXI;
import com.mycompany.myapp.domain.Taxi;
import com.mycompany.myapp.domain.User;
public class TaxiRepositoryImpl implements TaxiRepositoryCustom
{
@PersistenceContext
EntityManager entityManager;
@Override
public List<Taxi> getTaxisDisponibleUser(String login)
{
List<User> users;
List<ROLE_MANAGER_TAXI> taxiManagers;
ROLE_MANAGER_TAXI taxiM;
//Recup de l'utilisateur par le login
Query query = entityManager.createNativeQuery(
"SELECT * FROM mytransport.jhi_user " + "WHERE mytransport.jhi_user.login = ? ", User.class);
query.setParameter(1, login);
users = query.getResultList();
if (users.isEmpty())
return null;
User user = users.get(0);
//Recup du taxi manager par l'utilisateur
query = entityManager.createNativeQuery(
"Select * FROM mytransport.role_manager_taxi as taxim WHERE taxim.user_id = ? ",
ROLE_MANAGER_TAXI.class);
query.setParameter(1, user.getId());
taxiManagers = query.getResultList();
if(taxiManagers.isEmpty())
{
return null;
}
//Cas où on a trouve un taxi manager
taxiM = taxiManagers.get(0);
//On fait une query pour recup tous les taxis affillies au manager, qui ont le statut en attente
query = entityManager.createNativeQuery(
"Select * FROM mytransport.taxi as taxi WHERE taxi.manager_id = ? AND taxi.statut = 'ATTENTE'",
Taxi.class);
query.setParameter(1, taxiM.getId());
return query.getResultList();
}
}
......@@ -16,7 +16,7 @@ import java.time.Instant;
* Spring Data JPA repository for the User entity.
*/
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
public interface UserRepository extends JpaRepository<User, Long>, UserRepositoryCustom {
String USERS_BY_LOGIN_CACHE = "usersByLogin";
......
package com.mycompany.myapp.repository;
import com.mycompany.myapp.domain.User;
public interface UserRepositoryCustom
{
public User getConducteur(long id);
}
package com.mycompany.myapp.repository;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.mycompany.myapp.domain.ROLE_CONDUCTEUR_TAXI;
import com.mycompany.myapp.domain.User;
import com.mycompany.myapp.domain.Vehicule;
public class UserRepositoryImpl implements UserRepositoryCustom
{
@PersistenceContext
EntityManager entityManager;
@Override
public User getConducteur(long idTaxi)
{
List<ROLE_CONDUCTEUR_TAXI> drivers;
Query query = entityManager.createNativeQuery(
"SELECT * FROM mytransport.role_conducteur_taxi as driver WHERE driver.taxi_id = ?",
ROLE_CONDUCTEUR_TAXI.class);
query.setParameter(1, idTaxi);
drivers = query.getResultList();
if (drivers.isEmpty())
return null;
return drivers.get(0).getUser();
}
}
......@@ -18,27 +18,6 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
@PersistenceContext
EntityManager entityManager;
// Retourne les vehicules disponibles d'une agence entre deux dates
public List<Vehicule> findAllAvailableVehiculesrate(long idAgence, Instant startDate, Instant endDate)
{
Query query = entityManager.createNativeQuery("" + "SELECT * FROM mytransport.vehicule as vehicule "
+ "WHERE vehicule.agence_id = ? " + "AND NOT EXISTS( "
+ "SELECT id FROM mytransport.reservation as reservation WHERE reservation.vehicule_id = vehicule.id) "
+ "UNION " + "SELECT * FROM mytransport.vehicule as vehi " + "WHERE vehi.agence_id = ? "
+ "AND vehi.id NOT IN ( " + "SELECT DISTINCT id FROM mytransport.reservation "
+ "WHERE mytransport.reservation.start_date BETWEEN ? AND ? "
+ "OR mytransport.reservation.end_date BETWEEN ? AND ? " + ") " + "", Vehicule.class);
query.setParameter(1, idAgence);
query.setParameter(2, idAgence);
query.setParameter(3, startDate);
query.setParameter(4, endDate);
query.setParameter(5, startDate);
query.setParameter(6, endDate);
return query.getResultList();
}
public List<Vehicule> findAllAvailableVehicules(long idAgence, Instant startDate, Instant endDate)
{
List<Vehicule> vehicules;
......@@ -60,17 +39,10 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
vehicule = vehicules.get(i);
// On recupere les reservations
/*query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND (reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ?) "
+ "ORDER BY reservation.start_date",
Reservation.class);*/
query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND (? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) ",
+ "AND (reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ?) "
+ "OR (? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) ",
Reservation.class);
......@@ -79,6 +51,10 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
query.setParameter(1, vehicule.getId());
query.setParameter(2, startDate);
query.setParameter(3, endDate);
query.setParameter(4, startDate);
query.setParameter(5, endDate);
query.setParameter(6, startDate);
query.setParameter(7, endDate);
reservations = query.getResultList();
......@@ -97,7 +73,11 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
Reservation reservationNext;
if (reservations.isEmpty())
{
System.out.println("ici0");
return true;
}
for (int i = 0; i < reservations.size(); i++)
{
......@@ -110,6 +90,7 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
Instant dateLimiteDebut = reservation.getStartDate().minus(nbJours, ChronoUnit.DAYS);
if (dateLimiteDebut.compareTo(startDate) > 0)
{
System.out.println("ici1");
return true;
}
}
......@@ -121,6 +102,7 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
Instant dateLimiteFin = reservation.getEndDate().plus(nbJours, ChronoUnit.DAYS);
if (dateLimiteFin.compareTo(endDate) < 0)
{
System.out.println("ici2");
return true;
}
}
......@@ -131,6 +113,7 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
if (reservation.getEndDate().plus(nbJours, ChronoUnit.DAYS)
.compareTo(reservationNext.getStartDate()) < 0)
{
System.out.println("ici3");
return true;
}
}
......@@ -160,22 +143,22 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
vehicule = vehicules.get(i);
// On recupere les reservations
/*query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND (reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ?) "
+ "ORDER BY reservation.start_date",
Reservation.class);*/
query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND ( ? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) "
// + "AND ( ? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) "
+ "AND ( reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ? ) "
+ "OR ( ? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) "
+ "ORDER BY reservation.start_date",
Reservation.class);
query.setParameter(1, vehicule.getId());
query.setParameter(2, startDate);
query.setParameter(3, endDate);
query.setParameter(4, startDate);
query.setParameter(5, endDate);
query.setParameter(6, startDate);
query.setParameter(7, endDate);
reservations = query.getResultList();
......
......@@ -4,17 +4,22 @@ import com.mycompany.myapp.domain.User;
import io.github.jhipster.config.JHipsterProperties;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import javax.mail.internet.MimeMessage;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
......@@ -72,6 +77,31 @@ public class MailService {
}
}
}
@Async
public void sendEmailWithAttachment(String to, String subject, String content, boolean isMultipart, boolean isHtml, String attachment_label, InputStream file) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name());
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
message.addAttachment(attachment_label, new ByteArrayResource(IOUtils.toByteArray(file)));
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Email could not be sent to user '{}'", to, e);
} else {
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
}
}
}
@Async
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
......
package com.mycompany.myapp.web.rest;
import com.codahale.metrics.annotation.Timed;
import com.mycompany.myapp.domain.User;
import com.mycompany.myapp.repository.UserRepository;
import com.mycompany.myapp.security.SecurityUtils;
import com.mycompany.myapp.service.MailService;
import com.mycompany.myapp.service.UserService;
import com.mycompany.myapp.service.dto.PasswordChangeDTO;
import com.mycompany.myapp.service.dto.UserDTO;
import com.mycompany.myapp.web.rest.errors.*;
import com.mycompany.myapp.web.rest.vm.KeyAndPasswordVM;
import com.mycompany.myapp.web.rest.vm.ManagedUserVM;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.*;
/**
* REST controller for managing the current user's account.
*/
@RestController
@RequestMapping("/api")
public class MailResource {
private final Logger log = LoggerFactory.getLogger(AccountResource.class);
private final UserRepository userRepository;
private final UserService userService;
private final MailService mailService;
public MailResource(UserRepository userRepository, UserService userService, MailService mailService) {
this.userRepository = userRepository;
this.userService = userService;
this.mailService = mailService;
}
/**
* POST /mail : Send a new mail
*
* @param voiture the voiture to create
* @return
* @return the ResponseEntity with status 201 (Created) and with body the new voiture, or with status 400 (Bad Request) if the voiture has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
* @throws IOException
*/
@PostMapping("/mail/send")
@Timed
public ResponseEntity<?> sendMail(@RequestParam("file") MultipartFile file) {
log.debug("POST request to send mail");
// get user
final User logged_user = userService.getUserWithAuthorities().get();
log.debug("Logged user is " + logged_user.getFirstName());
log.debug("Its email is " + logged_user.getEmail());
// get document in attachement
log.debug("File size is : " + file.getSize());
InputStream fip;
try {
fip = file.getInputStream();
mailService.sendEmailWithAttachment(logged_user.getEmail(), "Rapport d'agence", "", true, true, "Rapport.pdf", fip);
return ResponseEntity.ok().body("file uploaded : " + file.getSize());
} catch (IOException e) {
log.error("Error sending mail - file error");
e.printStackTrace();
}
return ResponseEntity.badRequest().body("Error processing uploaded file");
}
}
......@@ -4,6 +4,7 @@ import com.codahale.metrics.annotation.Timed;
import com.mycompany.myapp.domain.Taxi;
import com.mycompany.myapp.repository.TaxiRepository;
import com.mycompany.myapp.repository.search.TaxiSearchRepository;
import com.mycompany.myapp.security.SecurityUtils;
import com.mycompany.myapp.web.rest.errors.BadRequestAlertException;
import com.mycompany.myapp.web.rest.util.HeaderUtil;
import io.github.jhipster.web.util.ResponseUtil;
......@@ -120,6 +121,23 @@ public class TaxiResource {
Optional<Taxi> taxi = taxiRepository.findById(id);
return ResponseUtil.wrapOrNotFound(taxi);
}
/**
* GET /taxisDispo : get dispnobile taxis.
*
* @return the ResponseEntity with status 200 (OK) and with body taxis, or with status 404 (Not Found)
*/
@GetMapping("/taxisDispo")
@Timed
public List<Taxi> getTaxiDispo() {
log.debug("REST request to get disponible Taxis : {}");
Optional<String> loginOptional = SecurityUtils.getCurrentUserLogin();
String login = loginOptional.get();
return taxiRepository.getTaxisDisponibleUser(login);
}
/**
* DELETE /taxis/:id : delete the "id" taxi.
......
......@@ -180,6 +180,29 @@ public class UserResource {
userService.getUserWithAuthoritiesByLogin(login)