Commit 91b421df authored by paloma.piot's avatar paloma.piot

Merge branch 'develop'

parents e3ec8b1b aa31a2b9
......@@ -7,6 +7,14 @@
"otherEntityName": "user",
"otherEntityField": "id"
},
{
"relationshipType": "many-to-many",
"otherEntityRelationshipName": "",
"relationshipName": "roles",
"otherEntityName": "rolValue",
"otherEntityField": "id",
"ownerSide": true
},
{
"relationshipType": "many-to-one",
"relationshipName": "edicion",
......
{
"fluentMethods": true,
"relationships": [
{
"relationshipType": "many-to-one",
"relationshipName": "user",
"otherEntityName": "user",
"otherEntityField": "id"
},
{
"relationshipType": "many-to-one",
"relationshipName": "persona",
"otherEntityName": "persona",
"otherEntityField": "id"
},
{
"relationshipType": "many-to-many",
"otherEntityRelationshipName": "",
"relationshipName": "rolesantiguos",
"otherEntityName": "rolValue",
"otherEntityField": "id",
"ownerSide": true
},
{
"relationshipType": "many-to-many",
"otherEntityRelationshipName": "",
"relationshipName": "rolesnuevos",
"otherEntityName": "rolValue",
"otherEntityField": "id",
"ownerSide": true
}
],
"fields": [
{
"fieldName": "fechaModificacion",
"fieldType": "ZonedDateTime"
}
],
"changelogDate": "20180406184004",
"entityTableName": "persona_rol_log",
"dto": "mapstruct",
"pagination": "no",
"service": "serviceClass",
"jpaMetamodelFiltering": false
}
\ No newline at end of file
{
"fluentMethods": true,
"relationships": [],
"fields": [
{
"fieldName": "rol",
"fieldType": "Rol",
"fieldValues": "EXTRAMUSICAL,MUSICAL,LOGISTICA,RRHH,MARKETING,IT,COMERCIO,FINANZAS,DISENO",
"fieldValidateRules": [
"required"
]
}
],
"changelogDate": "20180403145052",
"entityTableName": "rol_value",
"dto": "mapstruct",
"pagination": "no",
"service": "serviceClass",
"jpaMetamodelFiltering": false
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
<groupId>es.festis.backstage</groupId>
<artifactId>backstage</artifactId>
<version>3.1.6</version>
<version>4.4.5</version>
<packaging>war</packaging>
<name>Backstage</name>
......
......@@ -66,6 +66,11 @@ public class CacheConfiguration {
cm.createCache(es.festis.backstage.domain.Escenario.class.getName() + ".slots", jcacheConfiguration);
cm.createCache(es.festis.backstage.domain.Persona.class.getName(), jcacheConfiguration);
cm.createCache(es.festis.backstage.domain.Edicion.class.getName() + ".personas", jcacheConfiguration);
cm.createCache(es.festis.backstage.domain.Persona.class.getName() + ".roles", jcacheConfiguration);
cm.createCache(es.festis.backstage.domain.RolValue.class.getName(), jcacheConfiguration);
cm.createCache(es.festis.backstage.domain.PersonaRolLog.class.getName(), jcacheConfiguration);
cm.createCache(es.festis.backstage.domain.PersonaRolLog.class.getName() + ".rolesantiguos", jcacheConfiguration);
cm.createCache(es.festis.backstage.domain.PersonaRolLog.class.getName() + ".rolesnuevos", jcacheConfiguration);
// jhipster-needle-ehcache-add-entry
};
}
......
package es.festis.backstage.domain;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;
/**
* A PersonaRolLog.
*/
@Entity
@Table(name = "persona_rol_log")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class PersonaRolLog implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "fecha_modificacion")
private ZonedDateTime fechaModificacion;
@ManyToOne
private User user;
@ManyToOne
private Persona persona;
@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "persona_rol_log_rolesantiguos",
joinColumns = @JoinColumn(name="persona_rol_logs_id", referencedColumnName="id"),
inverseJoinColumns = @JoinColumn(name="rolesantiguos_id", referencedColumnName="id"))
private Set<RolValue> rolesantiguos = new HashSet<>();
@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "persona_rol_log_rolesnuevos",
joinColumns = @JoinColumn(name="persona_rol_logs_id", referencedColumnName="id"),
inverseJoinColumns = @JoinColumn(name="rolesnuevos_id", referencedColumnName="id"))
private Set<RolValue> rolesnuevos = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ZonedDateTime getFechaModificacion() {
return fechaModificacion;
}
public PersonaRolLog fechaModificacion(ZonedDateTime fechaModificacion) {
this.fechaModificacion = fechaModificacion;
return this;
}
public void setFechaModificacion(ZonedDateTime fechaModificacion) {
this.fechaModificacion = fechaModificacion;
}
public User getUser() {
return user;
}
public PersonaRolLog user(User user) {
this.user = user;
return this;
}
public void setUser(User user) {
this.user = user;
}
public Persona getPersona() {
return persona;
}
public PersonaRolLog persona(Persona persona) {
this.persona = persona;
return this;
}
public void setPersona(Persona persona) {
this.persona = persona;
}
public Set<RolValue> getRolesantiguos() {
return rolesantiguos;
}
public PersonaRolLog rolesantiguos(Set<RolValue> rolValues) {
this.rolesantiguos = rolValues;
return this;
}
public PersonaRolLog addRolesantiguos(RolValue rolValue) {
this.rolesantiguos.add(rolValue);
return this;
}
public PersonaRolLog removeRolesantiguos(RolValue rolValue) {
this.rolesantiguos.remove(rolValue);
return this;
}
public void setRolesantiguos(Set<RolValue> rolValues) {
this.rolesantiguos = rolValues;
}
public Set<RolValue> getRolesnuevos() {
return rolesnuevos;
}
public PersonaRolLog rolesnuevos(Set<RolValue> rolValues) {
this.rolesnuevos = rolValues;
return this;
}
public PersonaRolLog addRolesnuevos(RolValue rolValue) {
this.rolesnuevos.add(rolValue);
return this;
}
public PersonaRolLog removeRolesnuevos(RolValue rolValue) {
this.rolesnuevos.remove(rolValue);
return this;
}
public void setRolesnuevos(Set<RolValue> rolValues) {
this.rolesnuevos = rolValues;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PersonaRolLog personaRolLog = (PersonaRolLog) o;
if (personaRolLog.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), personaRolLog.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(getId());
}
@Override
public String toString() {
return "PersonaRolLog{" +
"id=" + getId() +
", fechaModificacion='" + getFechaModificacion() + "'" +
"}";
}
}
package es.festis.backstage.domain;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;
import es.festis.backstage.domain.enumeration.Rol;
/**
* A RolValue.
*/
@Entity
@Table(name = "rol_value")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class RolValue implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "rol", nullable = false)
private Rol rol;
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Rol getRol() {
return rol;
}
public RolValue rol(Rol rol) {
this.rol = rol;
return this;
}
public void setRol(Rol rol) {
this.rol = rol;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RolValue rolValue = (RolValue) o;
if (rolValue.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), rolValue.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(getId());
}
@Override
public String toString() {
return "RolValue{" +
"id=" + getId() +
", rol='" + getRol() + "'" +
"}";
}
}
package es.festis.backstage.domain.enumeration;
/**
* The Rol enumeration.
*/
public enum Rol {
EXTRAMUSICAL, MUSICAL, LOGISTICA, RRHH, MARKETING, IT, COMERCIO, FINANZAS, DISENO
}
......@@ -21,12 +21,12 @@ public interface FestivalRepository extends JpaRepository<Festival, Long> {
@Query("select festival from Festival festival where festival.user.login = ?#{principal.username} order by festival.nombre")
List<Festival> findByUserIsCurrentUser();
@Query("select new es.festis.backstage.service.dto.EdicionFestivalDTO "
@Query("select distinct new es.festis.backstage.service.dto.EdicionFestivalDTO "
+ " (f.id, f.nombre, f.ubicacion, e.id, e.fechaIinicio, e.fechaFin, e.logo, e.logoContentType) "
+ " from Festival f left join Edicion e on f.id = e.festival.id "
+ " where (f.user.login = ?#{principal.username}) and (e.fechaIinicio is null or e.fechaIinicio in (select max(e2.fechaIinicio) from Edicion e2"
+ " group by e2.festival.id)) order by e.fechaIinicio")
List<EdicionFestivalDTO> findAllEdicionesActuales();
+ " where ((f.user.login = ?#{principal.username}) and (e.fechaIinicio is null or e.fechaIinicio in (select max(e2.fechaIinicio) from Edicion e2 "
+ " where e2.festival.id = f.id))) order by e.fechaIinicio")
List<EdicionFestivalDTO> findOwnEdicionesActuales();
Optional<Festival> findOneByNombreIgnoreCase(@Param("nombre") String nombre);
......
......@@ -19,6 +19,12 @@ import es.festis.backstage.domain.Persona;
@Repository
public interface PersonaRepository extends JpaRepository<Persona, Long> {
@Query("select distinct persona from Persona persona left join fetch persona.roles")
List<Persona> findAllWithEagerRelationships();
@Query("select persona from Persona persona left join fetch persona.roles where persona.id =:id")
Persona findOneWithEagerRelationships(@Param("id") Long id);
@Query("select p from Persona p where p.edicion.id = :id")
Page<Persona> findByEdicionId(@Param("id") Long id, Pageable page);
......@@ -27,4 +33,11 @@ public interface PersonaRepository extends JpaRepository<Persona, Long> {
Optional<Persona> findByToken(@Param("token") String token);
List<Persona> findByUserId(@Param("userId") Long userId);
@Query("select persona from Persona persona where persona.edicion.festival.id = :festivalId")
List<Persona> findByFestivalId(@Param("festivalId") Long festivalId);
Optional<Persona> findByUserIdAndEdicionId(@Param("userId") Long userId, @Param("edicionId") Long edicionId);
}
package es.festis.backstage.repository;
import java.util.List;
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.PersonaRolLog;
/**
* Spring Data JPA repository for the PersonaRolLog entity.
*/
@SuppressWarnings("unused")
@Repository
public interface PersonaRolLogRepository extends JpaRepository<PersonaRolLog, Long> {
@Query("select persona_rol_log from PersonaRolLog persona_rol_log where persona_rol_log.user.login = ?#{principal.username}")
List<PersonaRolLog> findByUserIsCurrentUser();
@Query("select distinct persona_rol_log from PersonaRolLog persona_rol_log left join fetch persona_rol_log.rolesantiguos left join fetch persona_rol_log.rolesnuevos")
List<PersonaRolLog> findAllWithEagerRelationships();
@Query("select persona_rol_log from PersonaRolLog persona_rol_log left join fetch persona_rol_log.rolesantiguos left join fetch persona_rol_log.rolesnuevos where persona_rol_log.id =:id")
PersonaRolLog findOneWithEagerRelationships(@Param("id") Long id);
List<PersonaRolLog> findByPersonaId(@Param("personaId") Long personaId);
}
package es.festis.backstage.repository;
import es.festis.backstage.domain.RolValue;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.*;
/**
* Spring Data JPA repository for the RolValue entity.
*/
@SuppressWarnings("unused")
@Repository
public interface RolValueRepository extends JpaRepository<RolValue, Long> {
}
package es.festis.backstage.service;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -9,11 +11,17 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import es.festis.backstage.domain.Edicion;
import es.festis.backstage.domain.Festival;
import es.festis.backstage.domain.Persona;
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.EdicionFestivalDTO;
import es.festis.backstage.service.dto.FestivalDTO;
import es.festis.backstage.service.mapper.FestivalMapper;
import es.festis.backstage.service.mapper.PersonaMapper;
/**
* Service Implementation for managing Festival.
......@@ -28,9 +36,19 @@ public class FestivalService {
private final FestivalMapper festivalMapper;
public FestivalService(FestivalRepository festivalRepository, FestivalMapper festivalMapper) {
private final UserRepository userRepository;
private final PersonaRepository personaRepository;
private final PersonaMapper personaMapper;
public FestivalService(FestivalRepository festivalRepository, FestivalMapper festivalMapper,
UserRepository userRepository, PersonaRepository personaRepository, PersonaMapper personaMapper) {
this.festivalRepository = festivalRepository;
this.festivalMapper = festivalMapper;
this.userRepository = userRepository;
this.personaRepository = personaRepository;
this.personaMapper = personaMapper;
}
/**
......@@ -93,7 +111,41 @@ public class FestivalService {
@Transactional(readOnly = true)
public List<EdicionFestivalDTO> findAllEdicionesActuales() {
log.debug("Request to get all Festivals with current or latest edition");
return festivalRepository.findAllEdicionesActuales();
List<EdicionFestivalDTO> edicionesActuales = festivalRepository.findOwnEdicionesActuales();
// obtener las ediciones del usuario en las que está como recurso
List<Edicion> ediciones = personaRepository
.findByUserId(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin().get()).get().getId())
.stream().map(Persona::getEdicion)
.sorted((e1, e2) -> e1.getFechaIinicio().compareTo(e2.getFechaIinicio())).collect(Collectors.toList());
for (Edicion e : ediciones) {
if (!edicionesActuales.stream().anyMatch(ed -> ed.getFestivalId().equals(e.getFestival().getId()))) {
edicionesActuales.add(new EdicionFestivalDTO(e.getFestival().getId(), e.getFestival().getNombre(),
e.getFestival().getUbicacion(), e.getId(), e.getFechaIinicio(), e.getFechaFin(), e.getLogo(),
e.getLogoContentType()));
}
}
Comparator<EdicionFestivalDTO> byFechaInicio = new Comparator<EdicionFestivalDTO>() {
@Override
public int compare(EdicionFestivalDTO o1, EdicionFestivalDTO o2) {
if (o1.getFechaInicio() != null && o2.getFechaInicio() != null) {
return o1.getFechaInicio().compareTo(o2.getFechaInicio());
} else if (o1.getFechaInicio() == null && o2.getFechaInicio() == null) {
return o1.getNombre().compareTo(o2.getNombre());
} else if (o1.getFechaInicio() == null) {
return -1;
} else {
return 1;
}
}
};
edicionesActuales.sort(byFechaInicio);
return edicionesActuales;
}
}
package es.festis.backstage.service;
import es.festis.backstage.domain.PersonaRolLog;
import es.festis.backstage.repository.PersonaRolLogRepository;
import es.festis.backstage.service.dto.PersonaRolLogDTO;
import es.festis.backstage.service.mapper.PersonaRolLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Service Implementation for managing PersonaRolLog.
*/
@Service
@Transactional
public class PersonaRolLogService {
private final Logger log = LoggerFactory