Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ingsw-sarmiento/libro-matriz-digi…
Browse files Browse the repository at this point in the history
…tal into 112-criterios-persistencia

# Conflicts:
#	src/main/java/ar/edu/unq/sarmiento/hibernate/DataGenerator.java
  • Loading branch information
faloi committed Nov 26, 2018
2 parents 2ccafa6 + 9c179e1 commit 1276740
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/main/java/ar/edu/unq/sarmiento/hibernate/CarreraHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.stereotype.Component;

import ar.edu.unq.sarmiento.modelo.Carrera;
import ar.edu.unq.sarmiento.modelo.Materia;

@Component
public class CarreraHome extends Home<Carrera> {
Expand All @@ -15,4 +16,5 @@ public List<Carrera> listadoDeCarrerasVigentes() {
return this.getSession().createQuery("FROM Carrera WHERE archivada = :archiv", Carrera.class)
.setParameter("archiv", false).getResultList();
}

}
17 changes: 14 additions & 3 deletions src/main/java/ar/edu/unq/sarmiento/hibernate/DataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,20 @@ protected void generate() {

Materia materia = new Materia();
materia.setNombre("Hibernate");

materia.setAnioEnCarrera(2);
materia.setDocente("Jorgelina Ceriani");
materia.setEsPromocionable(true);
carrera.agregarMateria(materia);
materia.setDocente(docente);
materia.setAnioEnCarrera(5);

Materia materia2 = new Materia();
materia2.setNombre("Ingenieria de Software");
materia2.setAnioEnCarrera(3);
materia2.setDocente("Federico Aloi");
materia2.setEsPromocionable(false);
carrera.agregarMateria(materia2);


materia.setAnioEnCarrera(2);
materia.setEsPromocionable(true);

Cursada cursada = new Cursada();
Expand All @@ -115,6 +125,7 @@ protected void generate() {
docenteHome.saveOrUpdate(docente);
examenHome.saveOrUpdate(examen);
materiaHome.saveOrUpdate(materia);
materiaHome.saveOrUpdate(materia2);
direccionHome.saveOrUpdate(direccion);
cursadaHome.saveOrUpdate(cursada);
estudioCursadoHome.saveOrUpdate(titulo);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/ar/edu/unq/sarmiento/modelo/Carrera.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public List<Materia> getListadoMaterias() {
return listadoMaterias;
}

public void setListadoMaterias(List<Materia> listadoMaterias) {
this.listadoMaterias = listadoMaterias;
}

public Boolean getArchivada() {
return archivada;
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/ar/edu/unq/sarmiento/modelo/Materia.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
Expand All @@ -19,12 +20,10 @@ public class Materia extends Persistible {
private String nombre;
@ManyToMany
private List<Materia> correlativas = new ArrayList<>();
@Type(type="yes_no")
@Column
private boolean esPromocionable;
private int anioEnCarrera;
@ManyToOne
@JoinColumn(name="docente")
private Docente docente;
private String docente;

public String getNombre() {
return nombre;
Expand All @@ -42,7 +41,7 @@ public void setCorrelativas(List<Materia> correlativas) {
this.correlativas = correlativas;
}

public boolean isEsPromocionable() {
public boolean getEsPromocionable() {
return esPromocionable;
}

Expand All @@ -58,11 +57,11 @@ public void setAnioEnCarrera(int anioEnCarrera) {
this.anioEnCarrera = anioEnCarrera;
}

public Docente getDocente() {
public String getDocente() {
return docente;
}

public void setDocente(Docente docente) {
public void setDocente(String docente) {
this.docente = docente;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public void setResolucion(String resolucion) {
public List<Carrera> getListadoDeCarrerasVigentes() {
return carreraHome.listadoDeCarrerasVigentes();
}

public Carrera attach(Carrera carrera) {
carreraHome.attach(carrera);
return carrera;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ <h4>Listado de Carreras</h4>
<td>
<button wicket:id="editarCarrera" class="btn btn-info">Editar carrera</button>
</td>
<td>
<button wicket:id="materia" class="btn btn-warning">Materias</button>
</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.springframework.stereotype.Controller;

import ar.edu.unq.sarmiento.modelo.Carrera;
import ar.edu.unq.sarmiento.wicket.crearCarrera.CrearCarreraPage;
import ar.edu.unq.sarmiento.wicket.home.HomePage;
import ar.edu.unq.sarmiento.wicket.layout.LayoutPage;
import ar.edu.unq.sarmiento.wicket.materia.ListadoDeMateriasPage;

public class ListadoDeCarrerasPage extends LayoutPage {

Expand Down Expand Up @@ -49,6 +51,14 @@ public void onClick() {
setResponsePage(new EditarCarreraPage(item.getModelObject()));
}
});
item.add(new Link<String>("materia"){
private static final long serialVersionUID = 1L;

@Override
public void onClick() {
this.setResponsePage(new ListadoDeMateriasPage(carreraController.attach(item.getModelObject())));
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ar.edu.unq.sarmiento.wicket.materia;

import java.io.Serializable;
import java.util.List;

import org.apache.wicket.model.IModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ar.edu.unq.sarmiento.hibernate.CarreraHome;
import ar.edu.unq.sarmiento.modelo.Carrera;
import ar.edu.unq.sarmiento.modelo.Materia;

@Service
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Transactional
public class ListadoDeMateriasController implements Serializable{

private Carrera carrera;

public Carrera getCarrera() {
return carrera;
}

public void setCarrera(Carrera carrera) {
this.carrera = carrera;
}

public String getNombreCarrera(){
return this.getCarrera().getNombre();
}

public List<Materia> getMaterias(){
return this.getCarrera().getListadoMaterias();
}

public String convertirString(Boolean promocion) {
return promocion ? "Sí" : "No";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<wicket:extend>
<div class="panel panel-primary">
<div class="panel-heading titulo">
<h4>Materias de <span wicket:id="nombreCarrera"></span></h4>
</div>
<div class="panel-body">
<table class="table">
<thead>
<th>Año</th>
<th>Nombre</th>
<th>Promocionable</th>
<th>Docente</th>
</thead>
<tbody>
<tr wicket:id="materias" class="fila">
<td wicket:id="año"></td>
<td wicket:id="nombre"></td>
<td wicket:id="promocionable"></td>
<td wicket:id="docente"></td>
</tr>
</tbody>
</table>
</div>
</div>
</wicket:extend>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ar.edu.unq.sarmiento.wicket.materia;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import ar.edu.unq.sarmiento.modelo.Carrera;
import ar.edu.unq.sarmiento.modelo.Materia;
import ar.edu.unq.sarmiento.wicket.layout.LayoutPage;

public class ListadoDeMateriasPage extends LayoutPage{

@SpringBean(name="listadoDeMateriasController")
private ListadoDeMateriasController controller;

public ListadoDeMateriasPage(Carrera carrera) {
controller.setCarrera(carrera);
this.add(new Label("nombreCarrera", new PropertyModel<>(controller, "nombreCarrera")));
this.add(new ListView<Materia>("materias", new PropertyModel<>(controller, "materias")){

@Override
protected void populateItem(ListItem<Materia> item) {
CompoundPropertyModel<Materia> materia = new CompoundPropertyModel<>(item.getModelObject());
item.add(new Label("nombre", new PropertyModel<>(materia, "nombre")));
item.add(new Label("año", new PropertyModel<>(materia, "anioEnCarrera")));
item.add(new Label("promocionable", controller.convertirString(item.getModelObject().getEsPromocionable())));
item.add(new Label("docente", new PropertyModel<>(materia, "docente")));
}

});

}

}

0 comments on commit 1276740

Please sign in to comment.