Skip to content

Commit

Permalink
Merge branch 'MilestoneV1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ssisaias committed Sep 23, 2016
2 parents a9620ec + 0318daa commit 18124c3
Show file tree
Hide file tree
Showing 46 changed files with 400 additions and 267 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
## SAPE
**Sistema de Acompanhamento Online de Projetos Educacionais**



###Utilização:

Antes de utilizar:

1. **Copiar** o arquivo src/main/java/com/quixada/sme/factory/ConnectionFactory.java.template para ConnectionFactory.java


2. Configurar o banco de dados em ConnectionFactory.java

###Documentação Aberta:

[Documento Visão]

[Documento Visão]: <https://docs.google.com/document/d/1-YlKQVaULGCqkQhcJJyIc8XI6s2bhvmLhb-yCWYkRrU/edit?usp=sharing>


Binary file modified docker/SAPE-RELEASE.jar
Binary file not shown.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.quixada.sme</groupId>
<artifactId>SAPE</artifactId>
<version>1.0.9-BETA</version>
<version>1.1.0-BETA</version>
<packaging>jar</packaging>

<name>SAPE</name>
Expand Down Expand Up @@ -64,12 +64,6 @@
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<!-- fim::security[] -->

<dependency>
<groupId>bsf</groupId>
<artifactId>bsf</artifactId>
<version>2.4.0</version>
</dependency>
<!-- JDBC pro Security - 26/06/2016 -->
<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -98,7 +92,13 @@
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<!-- -->
<!-- Pool de conexao -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.5.1</version>
</dependency>

</dependencies>

<build>
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/com/quixada/sme/dao/AlunoDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@
import java.sql.SQLException;
import java.util.ArrayList;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import com.quixada.sme.factory.ConnectionFactory;
import com.quixada.sme.model.Aluno;



@Component
@ComponentScan(value={"com.quixada.sme.sape.config"})
public class AlunoDAO {

@Autowired
DataSource ds;


public void adiciona(Aluno aluno) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "INSERT INTO aluno "
+ "( idEscola, nome) "
+ "VALUES ( ?, ?)";
Expand All @@ -23,25 +34,27 @@ public void adiciona(Aluno aluno) throws SQLException{
stmt.setString(2, aluno.getNome());
//stmt.setString(3, aluno.getNivel());
stmt.execute();
con.close();
}

/*
* Atualiza o nivel do aluno de acordo com seu ID
*
*/
public void atualizarNivel(Aluno aluno) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "UPDATE aluno "
+ "SET nivelAtual=?"
+ "WHERE idAluno=" + aluno.getIdAluno();

PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, aluno.getNivel());
stmt.execute();
con.close();
}

public Aluno buscar(int id) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "SELECT * FROM aluno WHERE idAluno="+ id;

PreparedStatement stmt = con.prepareStatement(sql);
Expand All @@ -54,11 +67,12 @@ public Aluno buscar(int id) throws SQLException{
aluno.setNome(rs.getString(3));
aluno.setNivel(rs.getString(4));
}
con.close();
return aluno;
}

public void editar(Aluno aluno) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "UPDATE aluno "
+ "SET idEscola=?, nome=?, nivelAtual=?"
+ "WHERE idAluno=" + aluno.getIdAluno();
Expand All @@ -68,18 +82,20 @@ public void editar(Aluno aluno) throws SQLException{
stmt.setString(2, aluno.getNome());
stmt.setString(3, aluno.getNivel());
stmt.execute();
con.close();
}

public void excluir(int id) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "DELETE FROM aluno WHERE idAluno="+ id;

PreparedStatement stmt = con.prepareStatement(sql);
stmt.execute();
con.close();
}

public ArrayList<Aluno> buscarAlunosPorEscola(int idEscola) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "SELECT * FROM aluno WHERE idEscola="+ idEscola;

PreparedStatement stmt = con.prepareStatement(sql);
Expand All @@ -89,7 +105,7 @@ public ArrayList<Aluno> buscarAlunosPorEscola(int idEscola) throws SQLException{
Aluno a = new Aluno(rs.getInt("idAluno"),rs.getInt("idEscola") ,rs.getString("nome"), rs.getString("nivelAtual"));
alunos.add(a);
}

con.close();
return alunos;

}
Expand Down
35 changes: 23 additions & 12 deletions src/main/java/com/quixada/sme/dao/AvaliacaoDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import com.quixada.sme.factory.ConnectionFactory;
import com.quixada.sme.model.Avaliacao;
import com.quixada.sme.model.Nivel;

@ComponentScan(value={"com.quixada.sme"})
@Component
public class AvaliacaoDAO {

@Autowired
DataSource ds;

public void adiciona(Avaliacao aval) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "INSERT INTO avaliacao "
+ "( ano, data, periodo, idAluno, nivel) "
+ "VALUES (?, ?, ?, ?, ?)";
Expand All @@ -25,10 +33,11 @@ public void adiciona(Avaliacao aval) throws SQLException{
stmt.setInt(4, aval.getIdAluno());
stmt.setString(5, aval.getNivel());
stmt.execute();
con.close();
}

public Avaliacao buscar(int id) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "SELECT * FROM avaliacao WHERE idAvaliacao="+ id;

PreparedStatement stmt = con.prepareStatement(sql);
Expand All @@ -42,12 +51,13 @@ public Avaliacao buscar(int id) throws SQLException{
aval.setPeriodo(rs.getInt(4));
aval.setIdAluno(rs.getInt(5));
}
con.close();
return aval;
}
//Atualizar
//
// public void editar(Avaliacao aval) throws SQLException{
// Connection con = ConnectionFactory.getMySqlConnection();
// Connection con = ds.getConnection();
// String sql = "UPDATE avaliacao "
// + "SET ano=?, data=?, periodo=?, idAluno=? "
// + "WHERE idAvaliacao=" + aval.getIdAvaliacao();
Expand All @@ -62,28 +72,29 @@ public Avaliacao buscar(int id) throws SQLException{
// }

public void excluir(int id) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "DELETE FROM avaliacao WHERE idAvaliacao="+ id;

PreparedStatement stmt = con.prepareStatement(sql);
stmt.execute();
con.close();
}

public int resultAvaliacaoPorPeriodo(int idEscola, int periodo, int nivel) throws SQLException{
Connection con = ConnectionFactory.getMySqlConnection();
String sql = "select COUNT(*) from aluno join avaliacao"
+ " ON aluno.idAluno = avaliacao.idAluno where aluno.idEscola = ? and avaliacao.nivel = ? and avaliacao.periodo = ?";

public int resultAvaliacaoPorPeriodo(int idEscola, int periodo, String nivel) throws SQLException{
Connection con = ds.getConnection();
//String sql = "select COUNT(*) from aluno join avaliacao"
// + " ON aluno.idAluno = avaliacao.idAluno where aluno.idEscola = ? and avaliacao.nivel = ? and avaliacao.periodo = ?";
String sql = "select COUNT(*) from aluno join avaliacao ON aluno.idAluno = avaliacao.idAluno where aluno.idEscola = ? and avaliacao.nivel = ? and avaliacao.periodo = ?;";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, idEscola);
stmt.setInt(2, nivel);
stmt.setString(2, nivel);
stmt.setInt(3, periodo);

ResultSet rs = stmt.executeQuery();
int resultado = 0;
if(rs.next())
resultado = rs.getInt(1);

con.close();
return resultado;
}
}
50 changes: 32 additions & 18 deletions src/main/java/com/quixada/sme/dao/EscolaDAO.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
package com.quixada.sme.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import com.quixada.sme.factory.ConnectionFactory;
import com.quixada.sme.model.Escola;
import com.quixada.sme.sape.config.AppConfig;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;

@Component
@ComponentScan(value={"com.quixada.sme.sape.config"})
public class EscolaDAO {
private Connection conexao;

@Autowired
DataSource ds;

public ArrayList<Escola> getEscolas() throws SQLException{
Connection con = ds.getConnection();
String sql = "SELECT * FROM escola";
this.conexao = ConnectionFactory.getMySqlConnection();
PreparedStatement stm = conexao.prepareStatement(sql);
PreparedStatement stm = con.prepareStatement(sql);
ArrayList<Escola> escolas = new ArrayList<>();
ResultSet rs = stm.executeQuery(sql);
while(rs.next()){
Escola e = new Escola(rs.getInt("idEscola"),rs.getInt("idRegional") ,rs.getString("nome"));
escolas.add(e);
}
con.close();
return escolas;
}

public Escola getEscolasPorID(int idEscola) throws SQLException{
Connection con = ds.getConnection();
String sql = "SELECT * FROM escola where idEscola ="+idEscola;
this.conexao = ConnectionFactory.getMySqlConnection();
PreparedStatement stm = conexao.prepareStatement(sql);
PreparedStatement stm = con.prepareStatement(sql);
ResultSet rs = stm.executeQuery(sql);
Escola escola = null;
if (rs.next()) {
Expand All @@ -40,47 +49,52 @@ public Escola getEscolasPorID(int idEscola) throws SQLException{
escola.setIdRegional(rs.getInt(2));
escola.setNome(rs.getString(3));
}
con.close();
return escola;
}

public void addEscola( Escola escola) throws SQLException{
this.conexao = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "INSERT INTO escola"
+ "(idEscola, idRegional, nome) values (?, ?, ?) " ;
PreparedStatement stm = conexao.prepareStatement(sql);
PreparedStatement stm = con.prepareStatement(sql);
stm.setInt(1, escola.getIdEscola());
stm.setInt(2, escola.getIdRegional());
stm.setString(3, escola.getNome());
stm.execute();
con.close();
}
public void editar(Escola escola) throws SQLException{
this.conexao = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "UPDATE escola "
+ "SET idEscola=?, idRegional=?, nome=? "
+ "WHERE idEscola=" + escola.getIdEscola();

PreparedStatement stmt = conexao.prepareStatement(sql);
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, escola.getIdEscola());
stmt.setInt(2, escola.getIdRegional());
stmt.setString(3, escola.getNome());
stmt.execute();
con.close();
}
public void excluir(int idEscola) throws SQLException{
this.conexao = ConnectionFactory.getMySqlConnection();
Connection con = ds.getConnection();
String sql = "DELETE FROM escola WHERE idEscola="+ idEscola;
PreparedStatement stmt = conexao.prepareStatement(sql);
PreparedStatement stmt = con.prepareStatement(sql);
stmt.execute();
}
public ArrayList<Escola> getEscolasRegional(int idRegional) throws SQLException{
String sql = "SELECT * FROM escola WHERE idRegional="+idRegional;
this.conexao = ConnectionFactory.getMySqlConnection();
PreparedStatement stm = conexao.prepareStatement(sql);
Connection con = ds.getConnection();
PreparedStatement stm = con.prepareStatement(sql);
//stm.setInt(1, idRegional);
ArrayList<Escola> escolas = new ArrayList<>();
ResultSet rs = stm.executeQuery(sql);
while(rs.next()){
Escola e = new Escola(rs.getInt("idEscola"),rs.getInt("idRegional") ,rs.getString("nome"));
escolas.add(e);
}
con.close();
return escolas;
}

Expand Down
Loading

0 comments on commit 18124c3

Please sign in to comment.