From 715878581a1d5b53a85884aee8a7043178d89a1e Mon Sep 17 00:00:00 2001 From: Robson Date: Mon, 23 Oct 2023 22:52:36 -0300 Subject: [PATCH 01/13] ServiceFileDAO criado --- .../java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java new file mode 100644 index 00000000..50fac9f1 --- /dev/null +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -0,0 +1,5 @@ +package com.casaculturaqxd.sgec.DAO; + +public class ServiceFileDAO { + +} From efddebee972ffb61fb89b68cc7d4f4087354c954 Mon Sep 17 00:00:00 2001 From: Robson Date: Mon, 23 Oct 2023 23:00:51 -0300 Subject: [PATCH 02/13] Atributos e construtor criados --- .../casaculturaqxd/sgec/DAO/ServiceFileDAO.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index 50fac9f1..b8037a36 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -1,5 +1,20 @@ package com.casaculturaqxd.sgec.DAO; +import java.sql.Connection; + +import com.casaculturaqxd.sgec.enums.ServiceType; +import com.casaculturaqxd.sgec.service.Service; + public class ServiceFileDAO { - + String suffix; + ServiceType serviceType; + Connection connection; + Service service; + String bucket; + + ServiceFileDAO(String bucket, Service service){ + this.bucket = bucket; + this.service = service; + serviceType = ServiceType.S3; + } } From 58dcf170f84c246cc6e929bfcc514c04645b5b1f Mon Sep 17 00:00:00 2001 From: Robson Date: Mon, 23 Oct 2023 23:13:45 -0300 Subject: [PATCH 03/13] metodo setConnection implementado --- src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index b8037a36..77269ad4 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -17,4 +17,8 @@ public class ServiceFileDAO { this.service = service; serviceType = ServiceType.S3; } + + public void setConnection(Connection connection){ + this.connection = connection; + } } From 9ac8bd1e60cec0af76945407be266297ada7b40c Mon Sep 17 00:00:00 2001 From: Robson Date: Mon, 23 Oct 2023 23:46:26 -0300 Subject: [PATCH 04/13] metodo inserirArquivo implementado --- .../sgec/DAO/ServiceFileDAO.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index 77269ad4..432a52fd 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -1,8 +1,12 @@ package com.casaculturaqxd.sgec.DAO; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; import com.casaculturaqxd.sgec.enums.ServiceType; +import com.casaculturaqxd.sgec.models.arquivo.ServiceFile; import com.casaculturaqxd.sgec.service.Service; public class ServiceFileDAO { @@ -21,4 +25,29 @@ public class ServiceFileDAO { public void setConnection(Connection connection){ this.connection = connection; } + + public boolean inserirArquivo(ServiceFile arquivo){ + try { + service.enviarArquivo(bucket, arquivo.getFileKey(), arquivo.getContent()); + //1° passo - criar comando sql + String sql = "insert into service_file (file_key,service,bucket,ultima_modificacao)" + + " values(?,?,?,?)"; + //2° passo - conectar o banco de dados e organizar o comando sql + PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + stmt.setString(2, arquivo.getFileKey()); + stmt.setString(3, arquivo.getService()); + stmt.setString(4, arquivo.getBucket()); + stmt.setDate(5, arquivo.getUltimaModificacao()); + //3° passo - executar o comando sql + stmt.executeUpdate(); + ResultSet rs = stmt.getGeneratedKeys(); + if (rs.next()) { + arquivo.setServiceFileId(rs.getInt("id_service_file")); + } + stmt.close(); + return true; + } catch (Exception e) { + return false; + } + } } From 8105c728488952b63a9c84d2469adee2268a7f3b Mon Sep 17 00:00:00 2001 From: Robson Date: Tue, 24 Oct 2023 00:07:56 -0300 Subject: [PATCH 05/13] metodo getArquivo implementado --- .../sgec/DAO/ServiceFileDAO.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index 432a52fd..ba2c3762 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -6,6 +6,7 @@ import java.sql.Statement; import com.casaculturaqxd.sgec.enums.ServiceType; +import com.casaculturaqxd.sgec.models.Evento; import com.casaculturaqxd.sgec.models.arquivo.ServiceFile; import com.casaculturaqxd.sgec.service.Service; @@ -50,4 +51,26 @@ public boolean inserirArquivo(ServiceFile arquivo){ return false; } } + + public ServiceFile getArquivo(ServiceFile arquivo){ + try { + service.getArquivo(arquivo.getBucket(), arquivo.getFileKey()); + String sql = "select * from service_file where id_service_file=?"; + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setInt(1, arquivo.getServiceFileId()); + ResultSet resultSet = stmt.executeQuery(); + ServiceFile arquivoRetorno = null; + if (resultSet.next()) { + arquivoRetorno = arquivo; + arquivoRetorno.setServiceFileId(resultSet.getInt("id_service_file")); + arquivoRetorno.setFileKey(resultSet.getString("file_key")); + arquivoRetorno.setService(resultSet.getString("service")); + arquivoRetorno.setBucket(resultSet.getString("bucket")); + arquivoRetorno.setUltimaModificacao(resultSet.getDate("ultima_modificacao")); + } + return arquivo; + } catch (Exception e) { + return null; + } + } } From e0fb580724240833ded2d404759aa996427d0aba Mon Sep 17 00:00:00 2001 From: Robson Date: Tue, 24 Oct 2023 00:12:27 -0300 Subject: [PATCH 06/13] metodo deleteArquivo implementado --- .../sgec/DAO/ServiceFileDAO.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index ba2c3762..13dba9f2 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -27,7 +27,7 @@ public void setConnection(Connection connection){ this.connection = connection; } - public boolean inserirArquivo(ServiceFile arquivo){ + public boolean inserirArquivo(ServiceFile arquivo){ try { service.enviarArquivo(bucket, arquivo.getFileKey(), arquivo.getContent()); //1° passo - criar comando sql @@ -50,9 +50,9 @@ public boolean inserirArquivo(ServiceFile arquivo){ } catch (Exception e) { return false; } - } + } - public ServiceFile getArquivo(ServiceFile arquivo){ + public ServiceFile getArquivo(ServiceFile arquivo){ try { service.getArquivo(arquivo.getBucket(), arquivo.getFileKey()); String sql = "select * from service_file where id_service_file=?"; @@ -72,5 +72,19 @@ public ServiceFile getArquivo(ServiceFile arquivo){ } catch (Exception e) { return null; } - } + } + + public boolean deleteArquivo(ServiceFile arquivo){ + try { + service.deletarArquivo(arquivo.getBucket(), arquivo.getFileKey()); + String sql = "delete from service_file where id_service_file=?"; + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setInt(1, arquivo.getServiceFileId()); + stmt.execute(); + stmt.close(); + return true; + } catch (Exception e) { + return false; + } + } } From 8e55d37991884a0a4842455af554ba4ab28c1ff0 Mon Sep 17 00:00:00 2001 From: Robson Date: Tue, 24 Oct 2023 00:22:50 -0300 Subject: [PATCH 07/13] metodo vincularArquivos implementado --- .../casaculturaqxd/sgec/DAO/ServiceFileDAO.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index 13dba9f2..f713a156 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -3,6 +3,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import com.casaculturaqxd.sgec.enums.ServiceType; @@ -87,4 +88,18 @@ public boolean deleteArquivo(ServiceFile arquivo){ return false; } } + + private boolean vincularArquivos(ServiceFile arquivo, Evento evento){ + String sql = "INSERT INTO service_file_evento(id_evento, id_service_file) VALUES (?, ?);"; + try { + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setInt(1, evento.getIdEvento()); + stmt.setInt(2, arquivo.getServiceFileId()); + stmt.execute(); + stmt.close(); + return true; + } catch (SQLException e) { + return false; + } + } } From ae7c2e80620890be707ca51587de2c6dc07acb02 Mon Sep 17 00:00:00 2001 From: Robson Date: Thu, 26 Oct 2023 21:31:55 -0300 Subject: [PATCH 08/13] vincularAllArquivos implementado --- .../sgec/DAO/ServiceFileDAO.java | 36 ++++++++++--------- .../sgec/enums/ServiceType.java | 8 +++-- .../sgec/models/arquivo/ServiceFile.java | 28 ++++++++++++--- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index f713a156..dabddc17 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -5,15 +5,13 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.SortedSet; -import com.casaculturaqxd.sgec.enums.ServiceType; import com.casaculturaqxd.sgec.models.Evento; import com.casaculturaqxd.sgec.models.arquivo.ServiceFile; import com.casaculturaqxd.sgec.service.Service; public class ServiceFileDAO { - String suffix; - ServiceType serviceType; Connection connection; Service service; String bucket; @@ -21,7 +19,6 @@ public class ServiceFileDAO { ServiceFileDAO(String bucket, Service service){ this.bucket = bucket; this.service = service; - serviceType = ServiceType.S3; } public void setConnection(Connection connection){ @@ -32,11 +29,12 @@ public boolean inserirArquivo(ServiceFile arquivo){ try { service.enviarArquivo(bucket, arquivo.getFileKey(), arquivo.getContent()); //1° passo - criar comando sql - String sql = "insert into service_file (file_key,service,bucket,ultima_modificacao)" - + " values(?,?,?,?)"; + String sql = "insert into service_file (file_key,suffix,service,bucket,ultima_modificacao)" + + " values(?,?,?,?,?)"; //2° passo - conectar o banco de dados e organizar o comando sql PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); - stmt.setString(2, arquivo.getFileKey()); + stmt.setString(1, arquivo.getFileKey()); + stmt.setString(2, arquivo.getSuffix()); stmt.setString(3, arquivo.getService()); stmt.setString(4, arquivo.getBucket()); stmt.setDate(5, arquivo.getUltimaModificacao()); @@ -65,6 +63,7 @@ public ServiceFile getArquivo(ServiceFile arquivo){ arquivoRetorno = arquivo; arquivoRetorno.setServiceFileId(resultSet.getInt("id_service_file")); arquivoRetorno.setFileKey(resultSet.getString("file_key")); + arquivoRetorno.setSuffix(resultSet.getString("suffix")); arquivoRetorno.setService(resultSet.getString("service")); arquivoRetorno.setBucket(resultSet.getString("bucket")); arquivoRetorno.setUltimaModificacao(resultSet.getDate("ultima_modificacao")); @@ -89,17 +88,20 @@ public boolean deleteArquivo(ServiceFile arquivo){ } } - private boolean vincularArquivos(ServiceFile arquivo, Evento evento){ + public boolean vincularAllArquivos(Evento evento){ + SortedSet listaArquivos = evento.getListaArquivos(); String sql = "INSERT INTO service_file_evento(id_evento, id_service_file) VALUES (?, ?);"; - try { - PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setInt(1, evento.getIdEvento()); - stmt.setInt(2, arquivo.getServiceFileId()); - stmt.execute(); - stmt.close(); - return true; - } catch (SQLException e) { - return false; + for (Integer idArquivo : listaArquivos) { + try { + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setInt(1, evento.getIdEvento()); + stmt.setInt(2, idArquivo); + stmt.execute(); + stmt.close(); + } catch (SQLException e) { + return false; + } } + return true; } } diff --git a/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java b/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java index 419052fd..7df05433 100644 --- a/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java +++ b/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java @@ -3,13 +3,17 @@ public enum ServiceType { S3("s3"); - private final String type; + private String type; ServiceType(String type){ this.type = type; } + + public void setType(String type) { + this.type = type; + } - String getType(){ + public String getType(){ return this.type; } } diff --git a/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java b/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java index c5558384..642882d0 100644 --- a/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java +++ b/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java @@ -3,10 +3,13 @@ import java.io.File; import java.sql.Date; +import com.casaculturaqxd.sgec.enums.ServiceType; + public class ServiceFile { private Integer serviceFileId; private String fileKey; - private String service; + private String suffix; + private ServiceType service; private String bucket; private Date ultimaModificacao; private File preview; @@ -15,9 +18,9 @@ public class ServiceFile { public ServiceFile(File content,String bucket) { this.content = content; this.bucket = bucket; + service = ServiceType.S3; } - public Integer getServiceFileId() { return serviceFileId; } @@ -25,27 +28,43 @@ public Integer getServiceFileId() { public void setServiceFileId(Integer serviceFileId) { this.serviceFileId = serviceFileId; } + public String getFileKey() { return fileKey; } + public void setFileKey(String fileKey) { this.fileKey = fileKey; } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } + public String getService() { - return service; + return service.getType(); } + public void setService(String service) { - this.service = service; + this.service.setType(service);; } + public String getBucket() { return bucket; } + public void setBucket(String bucket) { this.bucket = bucket; } + public File getContent() { return content; } + public void setContent(File content) { this.content = content; } @@ -58,7 +77,6 @@ public void setUltimaModificacao(Date ultimaModificacao) { this.ultimaModificacao = ultimaModificacao; } - @Override public String toString() { return "ServiceFile [serviceFileId=" + serviceFileId + ", fileKey=" + fileKey + ", service=" + service From 8b59c1509802a3f21a8bdf66b03b0b317db95d69 Mon Sep 17 00:00:00 2001 From: Robson Date: Thu, 26 Oct 2023 22:03:37 -0300 Subject: [PATCH 09/13] desvincularArquivos implementado --- .../sgec/DAO/ServiceFileDAO.java | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index dabddc17..b8f2ef1b 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -90,18 +90,50 @@ public boolean deleteArquivo(ServiceFile arquivo){ public boolean vincularAllArquivos(Evento evento){ SortedSet listaArquivos = evento.getListaArquivos(); + for (Integer idServiceFile : listaArquivos) { + boolean temp = vincularArquivo(idServiceFile, evento.getIdEvento()); + if(temp == false) + return false; + } + return true; + } + + public boolean vincularArquivo(int idServiceFile, int idEvento){ String sql = "INSERT INTO service_file_evento(id_evento, id_service_file) VALUES (?, ?);"; - for (Integer idArquivo : listaArquivos) { - try { - PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setInt(1, evento.getIdEvento()); - stmt.setInt(2, idArquivo); - stmt.execute(); - stmt.close(); - } catch (SQLException e) { - return false; - } + try { + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setInt(1, idEvento); + stmt.setInt(2, idServiceFile); + stmt.execute(); + stmt.close(); + return true; + } catch (SQLException e) { + return false; + } + } + + public boolean desvincularArquivo(int idServiceFile, int idEvento) { + String sql = "delete from service_file_evento where id_service_file=? and id_evento=?"; + try { + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setInt(1, idServiceFile); + stmt.setInt(2, idEvento); + stmt.execute(); + stmt.close(); + return true; + } catch (Exception e) { + return false; + } + } + + public boolean desvincularAllArquivos(Evento evento) { + SortedSet listaArquivos = evento.getListaArquivos(); + for (Integer idServiceFile : listaArquivos) { + boolean temp = desvincularArquivo(idServiceFile, evento.getIdEvento()); + if(temp == false) + return false; } + evento.setListaArquivos(null); return true; } } From 41c16fa24921861ed8022cb4549dd232de3451ab Mon Sep 17 00:00:00 2001 From: Robson Date: Sun, 29 Oct 2023 11:09:33 -0300 Subject: [PATCH 10/13] =?UTF-8?q?Mudan=C3=A7as=20solicitadas=20feitas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../casaculturaqxd/sgec/DAO/ServiceFileDAO.java | 12 +++++------- .../casaculturaqxd/sgec/enums/ServiceType.java | 8 ++++---- .../sgec/models/arquivo/ServiceFile.java | 15 +++++++++------ .../casaculturaqxd/sgec/service/S3Service.java | 1 - 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index 3e7c86bd..bfdeedaa 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -7,6 +7,7 @@ import java.sql.Statement; import java.util.SortedSet; +import com.casaculturaqxd.sgec.enums.ServiceType; import com.casaculturaqxd.sgec.models.Evento; import com.casaculturaqxd.sgec.models.arquivo.ServiceFile; import com.casaculturaqxd.sgec.service.Service; @@ -28,24 +29,21 @@ public void setConnection(Connection connection){ public boolean inserirArquivo(ServiceFile arquivo){ try { service.enviarArquivo(arquivo); - //1° passo - criar comando sql String sql = "insert into service_file (file_key,suffix,service,bucket,ultima_modificacao)" + " values(?,?,?,?,?)"; - //2° passo - conectar o banco de dados e organizar o comando sql PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setString(1, arquivo.getFileKey()); stmt.setString(2, arquivo.getSuffix()); stmt.setString(3, arquivo.getService()); stmt.setString(4, arquivo.getBucket()); stmt.setDate(5, arquivo.getUltimaModificacao()); - //3° passo - executar o comando sql - stmt.executeUpdate(); + int numRemocoes = stmt.executeUpdate(); ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { arquivo.setServiceFileId(rs.getInt("id_service_file")); } stmt.close(); - return true; + return numRemocoes > 0; } catch (Exception e) { return false; } @@ -80,9 +78,9 @@ public boolean deleteArquivo(ServiceFile arquivo){ String sql = "delete from service_file where id_service_file=?"; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setInt(1, arquivo.getServiceFileId()); - stmt.execute(); + int numRemocoes = stmt.executeUpdate(); stmt.close(); - return true; + return numRemocoes > 0; } catch (Exception e) { return false; } diff --git a/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java b/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java index 7df05433..0d8047c9 100644 --- a/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java +++ b/src/main/java/com/casaculturaqxd/sgec/enums/ServiceType.java @@ -3,17 +3,17 @@ public enum ServiceType { S3("s3"); - private String type; + private static String type; ServiceType(String type){ - this.type = type; + type = type; } public void setType(String type) { this.type = type; } - public String getType(){ - return this.type; + public static String getType(){ + return type; } } diff --git a/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java b/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java index 0a7c2594..954120cd 100644 --- a/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java +++ b/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java @@ -3,13 +3,16 @@ import java.io.File; import java.sql.Date; + import com.casaculturaqxd.sgec.enums.ServiceType; +import com.casaculturaqxd.sgec.service.Service; +import com.casaculturaqxd.sgec.service.ServiceFactory; public class ServiceFile { private Integer serviceFileId; private String fileKey; private String suffix; - private ServiceType service; + private Service service; private String bucket; private Date ultimaModificacao; private File preview; @@ -19,7 +22,7 @@ public ServiceFile(File content, String bucket) { this.content = content; this.bucket = bucket; this.fileKey = content.getName(); - service = ServiceType.S3; + ServiceFactory.getService(ServiceType.S3, "ACCESS_KEY","SECRET_KEY"); } @@ -28,7 +31,7 @@ public ServiceFile(String fileKey, String bucket, Date ultimaModificacao, File c this.bucket = bucket; this.ultimaModificacao = ultimaModificacao; this.content = content; - service = ServiceType.S3; + ServiceFactory.getService(ServiceType.S3, "ACCESS_KEY","SECRET_KEY"); } @@ -58,11 +61,11 @@ public void setSuffix(String suffix) { } public String getService() { - return service.getType(); + return ServiceType.getType(); } - public void setService(String service) { - this.service.setType(service);; + public void setService(String serviceType) { + this.service = ServiceFactory.getService(ServiceType.valueOf(serviceType), "ACCESS_KEY", "SECRET_KEY"); } public String getBucket() { diff --git a/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java b/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java index 21a53f81..b9c1e866 100644 --- a/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java +++ b/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java @@ -16,7 +16,6 @@ import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import com.amazonaws.services.s3.model.S3Object; import com.casaculturaqxd.sgec.models.arquivo.ServiceFile; import io.github.cdimascio.dotenv.Dotenv; From 8155c0c8f607e16a36538c6ba48cea9ccccd2a4b Mon Sep 17 00:00:00 2001 From: Robson Date: Tue, 31 Oct 2023 10:07:21 -0300 Subject: [PATCH 11/13] =?UTF-8?q?mudan=C3=A7as=20solicitadas=20realizadas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../casaculturaqxd/sgec/DAO/ServiceFileDAO.java | 14 ++++++++++---- .../sgec/models/arquivo/ServiceFile.java | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index bfdeedaa..30b2e5c1 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -11,14 +11,13 @@ import com.casaculturaqxd.sgec.models.Evento; import com.casaculturaqxd.sgec.models.arquivo.ServiceFile; import com.casaculturaqxd.sgec.service.Service; +import com.casaculturaqxd.sgec.service.ServiceFactory; public class ServiceFileDAO { Connection connection; Service service; - String bucket; - ServiceFileDAO(String bucket, Service service){ - this.bucket = bucket; + ServiceFileDAO(Service service){ this.service = service; } @@ -28,13 +27,14 @@ public void setConnection(Connection connection){ public boolean inserirArquivo(ServiceFile arquivo){ try { + setService(arquivo); service.enviarArquivo(arquivo); String sql = "insert into service_file (file_key,suffix,service,bucket,ultima_modificacao)" + " values(?,?,?,?,?)"; PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setString(1, arquivo.getFileKey()); stmt.setString(2, arquivo.getSuffix()); - stmt.setString(3, arquivo.getService()); + stmt.setString(3, arquivo.getService().toString()); stmt.setString(4, arquivo.getBucket()); stmt.setDate(5, arquivo.getUltimaModificacao()); int numRemocoes = stmt.executeUpdate(); @@ -51,6 +51,7 @@ public boolean inserirArquivo(ServiceFile arquivo){ public ServiceFile getArquivo(ServiceFile arquivo){ try { + setService(arquivo); service.getArquivo(arquivo.getBucket(), arquivo.getFileKey()); String sql = "select * from service_file where id_service_file=?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -74,6 +75,7 @@ public ServiceFile getArquivo(ServiceFile arquivo){ public boolean deleteArquivo(ServiceFile arquivo){ try { + setService(arquivo); service.deletarArquivo(arquivo.getBucket(), arquivo.getFileKey()); String sql = "delete from service_file where id_service_file=?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -134,4 +136,8 @@ public boolean desvincularAllArquivos(Evento evento) { evento.setListaArquivos(null); return true; } + + public void setService(ServiceFile arquivo) { + this.service = arquivo.getService(); + } } diff --git a/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java b/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java index 954120cd..d3ecd00a 100644 --- a/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java +++ b/src/main/java/com/casaculturaqxd/sgec/models/arquivo/ServiceFile.java @@ -22,7 +22,7 @@ public ServiceFile(File content, String bucket) { this.content = content; this.bucket = bucket; this.fileKey = content.getName(); - ServiceFactory.getService(ServiceType.S3, "ACCESS_KEY","SECRET_KEY"); + this.service = ServiceFactory.getService(ServiceType.S3, "ACCESS_KEY","SECRET_KEY"); } @@ -31,7 +31,7 @@ public ServiceFile(String fileKey, String bucket, Date ultimaModificacao, File c this.bucket = bucket; this.ultimaModificacao = ultimaModificacao; this.content = content; - ServiceFactory.getService(ServiceType.S3, "ACCESS_KEY","SECRET_KEY"); + this.service = ServiceFactory.getService(ServiceType.S3, "ACCESS_KEY","SECRET_KEY"); } @@ -60,8 +60,8 @@ public void setSuffix(String suffix) { this.suffix = suffix; } - public String getService() { - return ServiceType.getType(); + public Service getService() { + return this.service; } public void setService(String serviceType) { From 7acdc8f0ae0a9a3148d7badff62a76b6a9775777 Mon Sep 17 00:00:00 2001 From: Robson Date: Tue, 31 Oct 2023 10:08:25 -0300 Subject: [PATCH 12/13] imports desnecessarios retirados --- src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java index 30b2e5c1..0a669f13 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/ServiceFileDAO.java @@ -7,11 +7,9 @@ import java.sql.Statement; import java.util.SortedSet; -import com.casaculturaqxd.sgec.enums.ServiceType; import com.casaculturaqxd.sgec.models.Evento; import com.casaculturaqxd.sgec.models.arquivo.ServiceFile; import com.casaculturaqxd.sgec.service.Service; -import com.casaculturaqxd.sgec.service.ServiceFactory; public class ServiceFileDAO { Connection connection; From 264d70377ee661001cad7a5f5c478cadea8131fd Mon Sep 17 00:00:00 2001 From: Joao-Pedro-P-Holanda Date: Tue, 31 Oct 2023 10:33:05 -0300 Subject: [PATCH 13/13] adicionando toString em S3Service --- src/main/java/com/casaculturaqxd/sgec/service/S3Service.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java b/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java index b9c1e866..8e02b769 100644 --- a/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java +++ b/src/main/java/com/casaculturaqxd/sgec/service/S3Service.java @@ -113,4 +113,9 @@ private String findFileSuffix(String fileName) { } return null; } + + @Override + public String toString() { + return "s3"; + } }