Corrigiendo errores segun sonarqube
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package xyz.danielcortes.controllers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map.Entry;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
@@ -145,12 +145,12 @@ import xyz.danielcortes.views.usuario.UsuarioViewPanel;
|
||||
public class LaunchController {
|
||||
|
||||
private LaunchFrame frame;
|
||||
private Map<PanelName, BaseController> controllers;
|
||||
private EnumMap<PanelName, BaseController> controllers;
|
||||
private Usuario user;
|
||||
|
||||
public LaunchController(Usuario user) {
|
||||
this.user = user;
|
||||
this.controllers = new HashMap<>();
|
||||
this.controllers = new EnumMap<>(PanelName.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,11 +183,11 @@ public class LaunchController {
|
||||
/**
|
||||
* Crea las cartas que estaran contenidas en la vista
|
||||
* <p>
|
||||
* Estan son agregadas a un <code>HashMap</code> que las almacenara relacionadas a su <code>PanelName</code>
|
||||
* Estan son agregadas a un <code>EnumMap</code> que las almacenara relacionadas a su <code>PanelName</code>
|
||||
* <p>
|
||||
* A cada controlador se le entregara una referencia a esta clase
|
||||
* <p>
|
||||
* Luego de agregar todos los controladores al <code>HashMap</code> estos son agregados al <code>CardLayout</code> del JFrame
|
||||
* Luego de agregar todos los controladores al <code>EnumMap</code> estos son agregados al <code>CardLayout</code> del JFrame
|
||||
*/
|
||||
private void createCards() {
|
||||
this.frame.addCard(new JPanel(), PanelName.EMPTY);
|
||||
@@ -286,9 +286,8 @@ public class LaunchController {
|
||||
this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_CREATE, new DistribuidorDireccionCreateController(new DireccionCreatePanel(), this));
|
||||
this.controllers.put(PanelName.DISTRIBUIDOR_DIRECCION_UPDATE, new DistribuidorDireccionUpdateController(new DireccionUpdatePanel(), this));
|
||||
|
||||
for (PanelName name : this.controllers.keySet()) {
|
||||
BaseController controller = this.controllers.get(name);
|
||||
this.frame.addCard(controller.getView().getContentPane(), name);
|
||||
for (Entry<PanelName, BaseController> entry : this.controllers.entrySet()) {
|
||||
this.frame.addCard(entry.getValue().getView().getContentPane(), entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,20 +31,20 @@ public abstract class AbstractTelefonoUpdateController extends BaseController {
|
||||
}
|
||||
|
||||
protected void update() {
|
||||
String telefono = this.view.getTelefonoField().getText();
|
||||
String sTelefono = this.view.getTelefonoField().getText();
|
||||
|
||||
ValidationResult originalValidation = this.validator.validateOriginal(this.telefono);
|
||||
if (originalValidation.hasError()) {
|
||||
originalValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
ValidationResult telefonoValidation = this.validator.validateTelefono(telefono);
|
||||
ValidationResult telefonoValidation = this.validator.validateTelefono(sTelefono);
|
||||
if (telefonoValidation.hasError()) {
|
||||
telefonoValidation.showErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
this.telefono.setNumero(telefono);
|
||||
this.telefono.setNumero(sTelefono);
|
||||
this.repository.update(this.telefono);
|
||||
|
||||
this.volver();
|
||||
|
||||
@@ -5,6 +5,6 @@ import xyz.danielcortes.views.comprar.ComprarSearchPanel;
|
||||
|
||||
public class ComprarSearchController {
|
||||
|
||||
public ComprarSearchPanel view;
|
||||
private ComprarSearchPanel view;
|
||||
private CompraRepository repository;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private Config() {
|
||||
}
|
||||
|
||||
public static String get(String key) {
|
||||
return defaultProps.getProperty(key);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import java.time.Year;
|
||||
|
||||
public class GeneralValidator {
|
||||
|
||||
private GeneralValidator() {
|
||||
}
|
||||
|
||||
public static boolean isLong(String number) {
|
||||
try {
|
||||
Long.parseLong(number);
|
||||
|
||||
@@ -6,6 +6,9 @@ import javax.swing.ListModel;
|
||||
|
||||
public class JListUtils {
|
||||
|
||||
private JListUtils() {
|
||||
}
|
||||
|
||||
public static void setSelectedValues(JList list, List values) {
|
||||
list.clearSelection();
|
||||
for (Object value : values) {
|
||||
|
||||
@@ -14,6 +14,8 @@ public class PersistenceManager {
|
||||
em = factory.createEntityManager();
|
||||
}
|
||||
|
||||
private PersistenceManager() {
|
||||
}
|
||||
|
||||
public static EntityManager getEntityManager() {
|
||||
return em;
|
||||
|
||||
@@ -4,7 +4,7 @@ import javax.swing.JOptionPane;
|
||||
|
||||
public class ValidationResult {
|
||||
|
||||
public static ValidationResult NON_ERROR = new ValidationResult();
|
||||
public static final ValidationResult NON_ERROR = new ValidationResult();
|
||||
private String message;
|
||||
private String title;
|
||||
private boolean hasError;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Arriendo {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "cliente_id", nullable = false)
|
||||
private Trabajador Cliente;
|
||||
private Cliente cliente;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
@@ -109,12 +109,12 @@ public class Arriendo {
|
||||
this.trabajador = trabajador;
|
||||
}
|
||||
|
||||
public Trabajador getCliente() {
|
||||
return this.Cliente;
|
||||
public Cliente getCliente() {
|
||||
return this.cliente;
|
||||
}
|
||||
|
||||
public void setCliente(Trabajador cliente) {
|
||||
this.Cliente = cliente;
|
||||
public void setCliente(Cliente cliente) {
|
||||
this.cliente = cliente;
|
||||
}
|
||||
|
||||
public List<Ejemplar> getEjemplares() {
|
||||
|
||||
@@ -8,12 +8,12 @@ import xyz.danielcortes.models.Cliente;
|
||||
public class ClienteRespository extends BaseRepository<Cliente> {
|
||||
|
||||
public List<Cliente> getAll() {
|
||||
TypedQuery<Cliente> query = em.createQuery("SELECT c FROM Cliente c", Cliente.class);
|
||||
TypedQuery<Cliente> query = this.em.createQuery("SELECT c FROM Cliente c", Cliente.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Cliente> search(String term) {
|
||||
TypedQuery<Cliente> query = em.createQuery(
|
||||
TypedQuery<Cliente> query = this.em.createQuery(
|
||||
"SELECT c FROM Cliente c WHERE "
|
||||
+ " LOWER(c.rut) LIKE :term OR "
|
||||
+ " LOWER(c.nombre) LIKE :term OR "
|
||||
@@ -23,6 +23,8 @@ public class ClienteRespository extends BaseRepository<Cliente> {
|
||||
Cliente.class
|
||||
);
|
||||
|
||||
query.setParameter("term", term);
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ import xyz.danielcortes.models.Ejemplar;
|
||||
public class EjemplarRepository extends BaseRepository<Ejemplar> {
|
||||
|
||||
public List<Ejemplar> getAll() {
|
||||
TypedQuery<Ejemplar> query = em.createQuery("SELECT e FROM Ejemplar e", Ejemplar.class);
|
||||
TypedQuery<Ejemplar> query = this.em.createQuery("SELECT e FROM Ejemplar e", Ejemplar.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Ejemplar> search(String term) {
|
||||
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
CriteriaBuilder cb = this.em.getCriteriaBuilder();
|
||||
CriteriaQuery<Ejemplar> query = cb.createQuery(Ejemplar.class);
|
||||
Root<Ejemplar> r = query.from(Ejemplar.class);
|
||||
query.where(
|
||||
@@ -26,21 +26,21 @@ public class EjemplarRepository extends BaseRepository<Ejemplar> {
|
||||
)
|
||||
);
|
||||
|
||||
return em.createQuery(query).getResultList();
|
||||
return this.em.createQuery(query).getResultList();
|
||||
}
|
||||
|
||||
public boolean exists(String serie, Integer libro_id) {
|
||||
Query query = em.createQuery("SELECT count(e) FROM Ejemplar e WHERE serie = :serie and libro.id = :libro_id");
|
||||
public boolean exists(String serie, Integer libroId) {
|
||||
Query query = this.em.createQuery("SELECT count(e) FROM Ejemplar e WHERE serie = :serie and libro.id = :libro_id");
|
||||
query.setParameter("serie", serie);
|
||||
query.setParameter("libro_id", libro_id);
|
||||
query.setParameter("libro_id", libroId);
|
||||
return (Long) query.getResultList().get(0) == 1;
|
||||
}
|
||||
|
||||
public boolean exists(String serie, Integer libro_id, Integer id) {
|
||||
Query query = em.createQuery("SELECT count(e) FROM Ejemplar e WHERE id != :id and serie = :serie and libro.id = :libro_id");
|
||||
public boolean exists(String serie, Integer libroId, Integer id) {
|
||||
Query query = this.em.createQuery("SELECT count(e) FROM Ejemplar e WHERE id != :id and serie = :serie and libro.id = :libro_id");
|
||||
query.setParameter("id", id);
|
||||
query.setParameter("serie", serie);
|
||||
query.setParameter("libro_id", libro_id);
|
||||
query.setParameter("libro_id", libroId);
|
||||
return (Long) query.getResultList().get(0) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,18 @@ import xyz.danielcortes.models.Idioma;
|
||||
public class IdiomaRepository extends BaseRepository<Idioma> {
|
||||
|
||||
public List<Idioma> getAll() {
|
||||
TypedQuery<Idioma> query = em.createQuery("SELECT i FROM Idioma i", Idioma.class);
|
||||
TypedQuery<Idioma> query = this.em.createQuery("SELECT i FROM Idioma i", Idioma.class);
|
||||
|
||||
List<Idioma> idiomas = query.getResultList();
|
||||
return idiomas;
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Idioma> search(String term) {
|
||||
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
CriteriaBuilder cb = this.em.getCriteriaBuilder();
|
||||
CriteriaQuery<Idioma> query = cb.createQuery(Idioma.class);
|
||||
Root<Idioma> r = query.from(Idioma.class);
|
||||
query.where(
|
||||
cb.like(cb.lower(r.get("nombre")), "%" + term.toLowerCase() + "%")
|
||||
);
|
||||
return em.createQuery(query).getResultList();
|
||||
return this.em.createQuery(query).getResultList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AutorValidator {
|
||||
}
|
||||
|
||||
public ValidationResult isDeleteable(Autor autor) {
|
||||
if (autor.getLibros().size() > 0) {
|
||||
if (!autor.getLibros().isEmpty()) {
|
||||
return new ValidationResult("No se puede eliminar el autor ya que tiene libros asociados");
|
||||
}
|
||||
return ValidationResult.NON_ERROR;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class CategoriaValidator {
|
||||
}
|
||||
|
||||
public ValidationResult isDeleteable(Categoria categoria) {
|
||||
if (categoria.getLibros().size() > 0) {
|
||||
if (!categoria.getLibros().isEmpty()) {
|
||||
return new ValidationResult("No se puede eliminar la categoria ya que tiene libros asociados");
|
||||
}
|
||||
return ValidationResult.NON_ERROR;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class EditorialValidator {
|
||||
}
|
||||
|
||||
public ValidationResult isDeleteable(Editorial editorial) {
|
||||
if (editorial.getLibros().size() > 0) {
|
||||
if (!editorial.getLibros().isEmpty()) {
|
||||
return new ValidationResult("No se puede eliminar la editorial ya que tiene libros asociados");
|
||||
}
|
||||
return ValidationResult.NON_ERROR;
|
||||
|
||||
@@ -11,14 +11,14 @@ public class EjemplarValidator {
|
||||
this.ejemplarRepository = ejemplarRepository;
|
||||
}
|
||||
|
||||
public ValidationResult validateSerie(String serie, Integer libro_id) {
|
||||
public ValidationResult validateSerie(String serie, Integer libroId) {
|
||||
if (serie == null) {
|
||||
return new ValidationResult("La serie es nula");
|
||||
}
|
||||
if (serie.isEmpty()) {
|
||||
return new ValidationResult("La serie esta vacia");
|
||||
}
|
||||
if (this.ejemplarRepository.exists(serie, libro_id)) {
|
||||
if (this.ejemplarRepository.exists(serie, libroId)) {
|
||||
return new ValidationResult("El numero de serie ya existe");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class IdiomaValidator {
|
||||
}
|
||||
|
||||
public ValidationResult isDeleteable(Idioma idioma) {
|
||||
if (idioma.getLibros().size() > 0) {
|
||||
if (!idioma.getLibros().isEmpty()) {
|
||||
return new ValidationResult("No se puede eliminar el idioma ya que tiene libros asociados");
|
||||
}
|
||||
return ValidationResult.NON_ERROR;
|
||||
|
||||
@@ -144,7 +144,7 @@ public class LibroValidator {
|
||||
}
|
||||
|
||||
public ValidationResult validateIdiomas(List<Idioma> idiomas) {
|
||||
if (idiomas.size() == 0) {
|
||||
if (idiomas.isEmpty()) {
|
||||
return new ValidationResult("No hay idiomas seleccionados");
|
||||
}
|
||||
if (idiomas.stream().anyMatch(Objects::isNull)) {
|
||||
@@ -155,7 +155,7 @@ public class LibroValidator {
|
||||
}
|
||||
|
||||
public ValidationResult validateAutores(List<Autor> autores) {
|
||||
if (autores.size() == 0) {
|
||||
if (autores.isEmpty()) {
|
||||
return new ValidationResult("No hay autores seleccionados");
|
||||
}
|
||||
if (autores.stream().anyMatch(Objects::isNull)) {
|
||||
@@ -166,7 +166,7 @@ public class LibroValidator {
|
||||
}
|
||||
|
||||
public ValidationResult validateCategorias(List<Categoria> categorias) {
|
||||
if (categorias.size() == 0) {
|
||||
if (categorias.isEmpty()) {
|
||||
return new ValidationResult("No hay categorias seleccionadas");
|
||||
}
|
||||
if (categorias.stream().anyMatch(Objects::isNull)) {
|
||||
|
||||
Reference in New Issue
Block a user