Commit ac445e53 authored by paloma.piot's avatar paloma.piot

Merge branch 'develop'

parents 91b421df a0568f20
......@@ -22,7 +22,7 @@
"content/scss/vendor.scss",
"content/scss/global.scss"
],
"scripts": []
"scripts": ["../node_modules/chart.js/dist/Chart.bundle.min.js"]
}],
"e2e": {
"protractor": {
......
......@@ -301,6 +301,32 @@
"supports-color": "2.0.0"
}
},
"chart.js": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.7.2.tgz",
"integrity": "sha512-90wl3V9xRZ8tnMvMlpcW+0Yg13BelsGS9P9t0ClaDxv/hdypHDr/YAGf+728m11P5ljwyB0ZHfPKCapZFqSqYA==",
"requires": {
"chartjs-color": "2.2.0",
"moment": "2.18.1"
}
},
"chartjs-color": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.2.0.tgz",
"integrity": "sha1-hKL7dVeH7YXDndbdjHsdiEKbrq4=",
"requires": {
"chartjs-color-string": "0.5.0",
"color-convert": "0.5.3"
}
},
"chartjs-color-string": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/chartjs-color-string/-/chartjs-color-string-0.5.0.tgz",
"integrity": "sha512-amWNvCOXlOUYxZVDSa0YOab5K/lmEhbFNKI55PWc4mlv28BDzA7zaoQTGxSBgJMHIW+hGX8YUrvw/FH4LyhwSQ==",
"requires": {
"color-name": "1.1.3"
}
},
"chokidar": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.6.1.tgz",
......@@ -324,6 +350,16 @@
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=",
"dev": true
},
"color-convert": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-0.5.3.tgz",
"integrity": "sha1-vbbGnOZg+t/+CwAHzER+G59ygr0="
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"colors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
......@@ -2038,8 +2074,7 @@
"moment": {
"version": "2.18.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.18.1.tgz",
"integrity": "sha1-w2GT3Tzhwu7SrbfIAtu8d6gbHA8=",
"dev": true
"integrity": "sha1-w2GT3Tzhwu7SrbfIAtu8d6gbHA8="
},
"ms": {
"version": "0.7.2",
......
......@@ -18,6 +18,7 @@
"@angular/router": "5.1.0",
"@ng-bootstrap/ng-bootstrap": "^1.0.0",
"bootstrap": "4.0.0-beta.2",
"chart.js": "^2.7.2",
"core-js": "2.4.1",
"font-awesome": "4.7.0",
"jquery": "3.2.1",
......@@ -116,6 +117,7 @@
"webpack-dev-server": "node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"webpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js",
"e2e": "protractor src/test/javascript/protractor.conf.js",
"postinstall": "webdriver-manager update && node node_modules/phantomjs-prebuilt/install.js"
"postinstall": "webdriver-manager update && node node_modules/phantomjs-prebuilt/install.js",
"chart.js": "../node_modules/chart.js/dist/Chart.min.js"
}
}
......@@ -4,7 +4,7 @@
<groupId>es.festis.backstage</groupId>
<artifactId>backstage</artifactId>
<version>4.4.5</version>
<version>5.0.3</version>
<packaging>war</packaging>
<name>Backstage</name>
......
package es.festis.backstage.repository;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
......@@ -11,6 +12,7 @@ import org.springframework.stereotype.Repository;
import es.festis.backstage.domain.Contenido;
import es.festis.backstage.domain.ContenidoEdicion;
import es.festis.backstage.service.dto.ChartDataDTO;
import es.festis.backstage.service.dto.ContenidoEdicionDTO;
/**
......@@ -42,4 +44,21 @@ public interface ContenidoEdicionRepository extends JpaRepository<ContenidoEdici
@Query("select c.contenido from ContenidoEdicion c where c.edicion.id = :id")
Page<Contenido> findContenidoByEdicionId(@Param("id") Long id, Pageable page);
@Query("select new es.festis.backstage.service.dto.ChartDataDTO (c.tipo, count(*)) from ContenidoEdicion ce join Contenido c "
+ " on ce.contenido.id = c.id where ce.edicion.id = :id and c.tipo not like 'MUSICAL' group by c.tipo order by c.tipo")
List<ChartDataDTO> findForInformeTiposByEdicion(@Param("id") Long id);
@Query("select new es.festis.backstage.service.dto.ChartDataDTO (c.nombre, count(*) as num) from ContenidoEdicion ce join Contenido c "
+ " on ce.contenido.id = c.id where YEAR(ce.edicion.fechaIinicio) = :year and c.tipo like 'MUSICAL' group by ce.contenido.id, c.nombre order by num desc")
List<ChartDataDTO> informeTopXArtistasEdicion(@Param("year") int year, Pageable page);
@Query("select new es.festis.backstage.service.dto.ChartDataDTO (s.nombre, sum(se.contribucion)) from SponsorEdicion se join Sponsor s "
+ " on se.sponsor.id = s.id where se.edicion.id = :id group by s.nombre order by s.nombre")
List<ChartDataDTO> findForInformeSponsorsByEdicion(@Param("id") Long id);
@Query("select new es.festis.backstage.service.dto.ChartDataDTO (c.pais, count(c.pais)) from ContenidoEdicion ce join Contenido c "
+ " on ce.contenido.id = c.id where ce.edicion.id = :id group by c.pais order by c.pais")
List<ChartDataDTO> findForInformeProcedenciaArtistasByEdicion(@Param("id") Long id);
}
......@@ -23,7 +23,7 @@ public interface EdicionRepository extends JpaRepository<Edicion, Long> {
@Query("select edicion from Edicion edicion left join fetch edicion.users where edicion.id =:id")
Edicion findOneWithEagerRelationships(@Param("id") Long id);
@Query("select edicion from Edicion edicion where edicion.festival.id = :id")
@Query("select edicion from Edicion edicion where edicion.festival.id = :id order by edicion.fechaIinicio")
List<Edicion> findAllEdicionesFestival(@Param("id") Long id);
@Query("select edicion from Edicion edicion where edicion.fechaIinicio = :fechaIinicio and edicion.festival.id = :festivalId")
......
......@@ -3,12 +3,14 @@ package es.festis.backstage.repository;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import es.festis.backstage.domain.Festival;
import es.festis.backstage.service.dto.ChartDataDTO;
import es.festis.backstage.service.dto.EdicionFestivalDTO;
/**
......@@ -30,4 +32,9 @@ public interface FestivalRepository extends JpaRepository<Festival, Long> {
Optional<Festival> findOneByNombreIgnoreCase(@Param("nombre") String nombre);
@Query("select new es.festis.backstage.service.dto.ChartDataDTO (c.nombre, count(*) as num) from Festival f left join Edicion e on f.id = e.festival.id "
+ "left join ContenidoEdicion ce on e.id = ce.edicion.id left join Contenido c on ce.contenido.id = c.id where f.id = :id and c.tipo like 'MUSICAL' "
+ " group by c.nombre order by num desc")
List<ChartDataDTO> findTopXArtistasFestival(@Param("id") Long id, Pageable page);
}
package es.festis.backstage.service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import es.festis.backstage.domain.ContenidoEdicion;
import es.festis.backstage.domain.Edicion;
import es.festis.backstage.domain.SponsorEdicion;
import es.festis.backstage.domain.enumeration.TipoContenido;
import es.festis.backstage.domain.enumeration.TipoSponsor;
import es.festis.backstage.repository.ContenidoEdicionRepository;
import es.festis.backstage.repository.EdicionRepository;
import es.festis.backstage.repository.UserRepository;
import es.festis.backstage.security.SecurityUtils;
import es.festis.backstage.service.dto.ChartData3DDTO;
import es.festis.backstage.service.dto.ChartDataDTO;
import es.festis.backstage.service.dto.ContenidoDTO;
import es.festis.backstage.service.dto.ContenidoEdicionDTO;
import es.festis.backstage.service.dto.DatasetDTO;
import es.festis.backstage.service.mapper.ContenidoEdicionMapper;
import es.festis.backstage.service.mapper.ContenidoMapper;
......@@ -27,13 +45,20 @@ public class ContenidoEdicionService {
private final ContenidoEdicionMapper contenidoEdicionMapper;
private final EdicionRepository edicionRepository;
private final UserRepository userRepository;
private final ContenidoMapper contenidoMapper;
public ContenidoEdicionService(ContenidoEdicionRepository contenidoEdicionRepository,
ContenidoEdicionMapper contenidoEdicionMapper, ContenidoMapper contenidoMapper) {
ContenidoEdicionMapper contenidoEdicionMapper, ContenidoMapper contenidoMapper,
EdicionRepository edicionRepository, UserRepository userRepository) {
this.contenidoEdicionRepository = contenidoEdicionRepository;
this.contenidoEdicionMapper = contenidoEdicionMapper;
this.contenidoMapper = contenidoMapper;
this.edicionRepository = edicionRepository;
this.userRepository = userRepository;
}
/**
......@@ -130,4 +155,145 @@ public class ContenidoEdicionService {
log.debug("Request to get all Contenidos by edicion");
return contenidoEdicionRepository.findContenidoByEdicionId(id, pageable).map(contenidoMapper::toDto);
}
/**
* Get all the types of contenido extramusical for edicion.
*
* @param idedicion
* @return the list of entities
*/
@Transactional(readOnly = true)
public List<ChartDataDTO> findForInformeTiposByEdicion(Long idedicion) {
log.debug("Request to get all types of contenido extramusical by edicion");
return contenidoEdicionRepository.findForInformeTiposByEdicion(idedicion);
}
/**
* Get all the types of contenido extramusical for festival.
*
* @param idfestival
* @return the list of entities
*/
@Transactional(readOnly = true)
public ChartData3DDTO findForInformeTiposByFestival(Long idfestival) {
log.debug("Request to get all types of contenido extramusical by festival");
ChartData3DDTO chartData = new ChartData3DDTO();
List<Edicion> ediciones = edicionRepository.findAllEdicionesFestival(idfestival);
chartData.setLabels(
ediciones.stream().map(Edicion::getFechaIinicio).map(LocalDate::toString).collect(Collectors.toList()));
chartData.setDatasets(new ArrayList<DatasetDTO>());
String[] colores = new String[] { "rgba(255, 99, 132, 0.4)", "rgba(54, 162, 235, 0.4)",
"rgba(255, 206, 86, 0.4)", "rgba(75, 192, 192, 0.4)", "rgba(153, 102, 255, 0.4)" };
String[] bordes = new String[] { "rgba(255, 99, 132, 1)", "rgba(54, 162, 235, 1)", "rgba(255, 206, 86, 1)",
"rgba(75, 192, 192, 1)", "rgba(153, 102, 255, 1)" };
int i = 0;
for (TipoContenido t : TipoContenido.values()) {
if (!t.equals(TipoContenido.MUSICAL)) {
DatasetDTO dataset = new DatasetDTO();
dataset.setLabel(t.toString());
dataset.setData(new ArrayList<BigDecimal>());
dataset.setBackgroundColor(colores[i]);
dataset.setBorderColor(bordes[i]);
i++;
for (Edicion e : ediciones) {
dataset.data.add(new BigDecimal(e.getContenidoEdicions().stream()
.filter(ce -> ce.getContenido().getTipo().equals(t)).count()));
}
chartData.datasets.add(dataset);
}
}
return chartData;
}
/**
* Get all the types of contenido extramusical for edicion.
*
* @param idedicion
* @return the list of entities
*/
@Transactional(readOnly = true)
public List<ChartDataDTO> informeTopXArtistasEdicion(Long idedicion) {
log.debug("Request to get top x artistas for edicion");
return contenidoEdicionRepository.informeTopXArtistasEdicion(
edicionRepository.findOne(idedicion).getFechaIinicio().getYear(), new PageRequest(0, 10));
}
/**
* Get all the contribuciones publicas vs privadas for festival.
*
* @param idfestival
* @return the list of entities
*/
@Transactional(readOnly = true)
public ChartData3DDTO informeContribucionesPublicasvsPrivadas(Long idfestival) {
log.debug("Request to get all types of contenido extramusical by festival");
ChartData3DDTO chartData = new ChartData3DDTO();
List<Edicion> ediciones = edicionRepository.findAllEdicionesFestival(idfestival);
chartData.setLabels(
ediciones.stream().map(Edicion::getFechaIinicio).map(LocalDate::toString).collect(Collectors.toList()));
chartData.setDatasets(new ArrayList<DatasetDTO>());
String[] colores = new String[] { "rgba(75, 192, 192, 0.4)", "rgba(153, 102, 255, 0.4)" };
String[] bordes = new String[] { "rgba(75, 192, 192, 1)", "rgba(153, 102, 255, 1)" };
int i = 0;
for (TipoSponsor t : TipoSponsor.values()) {
DatasetDTO dataset = new DatasetDTO();
dataset.setLabel(t.toString());
dataset.setData(new ArrayList<BigDecimal>());
dataset.setBackgroundColor(colores[i]);
dataset.setBorderColor(bordes[i]);
i++;
for (Edicion e : ediciones) {
dataset.data.add(e.getSponsorEdicions().stream().filter(se -> se.getSponsor().getTipo().equals(t))
.map(SponsorEdicion::getContribucion).reduce(BigDecimal.ZERO, BigDecimal::add));
}
chartData.datasets.add(dataset);
}
return chartData;
}
/**
* Get all the sponsors for edicion.
*
* @param idedicion
* @return the list of entities
*/
@Transactional(readOnly = true)
public List<ChartDataDTO> findForInformeSponsorsByEdicion(Long idedicion) {
log.debug("Request to get all types of sponsots by edicion");
return contenidoEdicionRepository.findForInformeSponsorsByEdicion(idedicion);
}
/**
* Get all paises
*
* @return the list of strings
*/
@Transactional(readOnly = true)
public List<String> findAllPaises() {
log.debug("Request to get all paises");
Locale local = new Locale(
userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin().get()).get().getLangKey());
List<String> paises = new ArrayList<>();
for (String country : Locale.getISOCountries()) {
paises.add((new Locale("", country).getDisplayCountry(local)));
}
return paises;
}
/**
* Get all the procedencia artistas for edicion.
*
* @param idedicion
* @return the list of entities
*/
@Transactional(readOnly = true)
public List<ChartDataDTO> findForInformeProcedenciaArtistasByEdicion(Long idedicion) {
log.debug("Request to get all types of Procedencia artistas by edicion");
return contenidoEdicionRepository.findForInformeProcedenciaArtistasByEdicion(idedicion);
}
}
......@@ -7,6 +7,7 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -18,6 +19,7 @@ import es.festis.backstage.repository.FestivalRepository;
import es.festis.backstage.repository.PersonaRepository;
import es.festis.backstage.repository.UserRepository;
import es.festis.backstage.security.SecurityUtils;
import es.festis.backstage.service.dto.ChartDataDTO;
import es.festis.backstage.service.dto.EdicionFestivalDTO;
import es.festis.backstage.service.dto.FestivalDTO;
import es.festis.backstage.service.mapper.FestivalMapper;
......@@ -148,4 +150,17 @@ public class FestivalService {
return edicionesActuales;
}
/**
* Get top X artistas for Festival.
*
* @param id
* the festival id
* @return the list of entities
*/
@Transactional(readOnly = true)
public List<ChartDataDTO> findTopXArtistasFestival(Long id) {
log.debug("Request to get top X artistas for Festival");
return festivalRepository.findTopXArtistasFestival(id, new PageRequest(0, 10));
}
}
package es.festis.backstage.service.dto;
import java.util.List;
public class ChartData3DDTO {
public List<String> labels;
public List<DatasetDTO> datasets;
public ChartData3DDTO() {
}
public ChartData3DDTO(List<String> labels, List<DatasetDTO> datasets) {
super();
this.labels = labels;
this.datasets = datasets;
}
public List<String> getLabels() {
return labels;
}
public void setLabels(List<String> labels) {
this.labels = labels;
}
public List<DatasetDTO> getDatasets() {
return datasets;
}
public void setDatasets(List<DatasetDTO> datasets) {
this.datasets = datasets;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((datasets == null) ? 0 : datasets.hashCode());
result = prime * result + ((labels == null) ? 0 : labels.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ChartData3DDTO other = (ChartData3DDTO) obj;
if (datasets == null) {
if (other.datasets != null)
return false;
} else if (!datasets.equals(other.datasets))
return false;
if (labels == null) {
if (other.labels != null)
return false;
} else if (!labels.equals(other.labels))
return false;
return true;
}
@Override
public String toString() {
return "ChartData3DDTO [labels=" + labels + ", datasets=" + datasets + "]";
}
}
package es.festis.backstage.service.dto;
import java.math.BigDecimal;
import es.festis.backstage.domain.enumeration.TipoContenido;
public class ChartDataDTO {
public String label;
public BigDecimal data;
public ChartDataDTO(String label, BigDecimal data) {
super();
this.label = label;
this.data = data;
}
public ChartDataDTO(TipoContenido label, BigDecimal data) {
super();
this.label = label.toString();
this.data = data;
}
public ChartDataDTO(String label, long data) {
super();
this.label = label;
this.data = new BigDecimal(data);
}
public ChartDataDTO(TipoContenido label, long data) {
super();
this.label = label.toString();
this.data = new BigDecimal(data);
}
public ChartDataDTO() {
}
public String getLabel() {
return label;
}
public void setLabel(String labels) {
this.label = label;
}
public BigDecimal getData() {
return data;
}
public void setData(BigDecimal data) {
this.data = data;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((data == null) ? 0 : data.hashCode());
result = prime * result + ((label == null) ? 0 : label.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ChartDataDTO other = (ChartDataDTO) obj;
if (data == null) {
if (other.data != null)
return false;
} else if (!data.equals(other.data))
return false;
if (label == null) {
if (other.label != null)
return false;
} else if (!label.equals(other.label))
return false;
return true;
}
@Override
public String toString() {
return "ChartDataDTO [label=" + label + ", data=" + data + "]";
}
}
package es.festis.backstage.service.dto;
import java.math.BigDecimal;
import java.util.List;
public class DatasetDTO {
public String label;
public List<BigDecimal> data;
public String backgroundColor;
public String borderColor;
public DatasetDTO(String label, List<BigDecimal> data, String backgroundColor, String borderColor) {
super();
this.label = label;
this.data = data;
this.backgroundColor = backgroundColor;
this.borderColor = borderColor;
}
public DatasetDTO() {
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<BigDecimal> getData() {
return data;
}
public void setData(List<BigDecimal> data) {
this.data = data;
}
public String getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}
public String getBorderColor() {
return borderColor;
}
public void setBorderColor(String borderColor) {
this.borderColor = borderColor;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((backgroundColor == null) ? 0 : backgroundColor.hashCode());
result = prime * result + ((borderColor == null) ? 0 : borderColor.hashCode());
result = prime * result + ((data == null) ? 0 : data.hashCode());
result = prime * result + ((label == null) ? 0 : label.hashCode());
return result;
}