From 7cf5bccf152333138090c820f82047e64562e8dd Mon Sep 17 00:00:00 2001 From: esoe Date: Wed, 9 Aug 2023 21:07:32 +0300 Subject: [PATCH] qq --- README.md | 3 +- .../storage/api/RestStorageService.java | 32 +++++++++-- .../storage/entities/ContentEntity.java | 2 +- .../ru/molokoin/storage/services/Storage.java | 50 ++++++++++++++++++ .../{RepositoryFace.java => StorageFace.java} | 12 +++-- src/main/resources/META-INF/persistance.xml | 9 ++++ src/main/scripts/prepare.sql | 5 ++ target/classes/META-INF/persistance.xml | 9 ++++ .../storage/api/RestStorageService.class | Bin 1274 -> 1254 bytes .../storage/entities/ContentEntity.class | Bin 2962 -> 2962 bytes .../storage/services/RepositoryFace.class | Bin 438 -> 0 bytes .../molokoin/storage/services/Storage.class | Bin 0 -> 1851 bytes .../storage/services/StorageFace.class | Bin 0 -> 479 bytes 13 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 src/main/java/ru/molokoin/storage/services/Storage.java rename src/main/java/ru/molokoin/storage/services/{RepositoryFace.java => StorageFace.java} (63%) create mode 100644 src/main/resources/META-INF/persistance.xml create mode 100644 src/main/scripts/prepare.sql create mode 100644 target/classes/META-INF/persistance.xml delete mode 100644 target/classes/ru/molokoin/storage/services/RepositoryFace.class create mode 100644 target/classes/ru/molokoin/storage/services/Storage.class create mode 100644 target/classes/ru/molokoin/storage/services/StorageFace.class diff --git a/README.md b/README.md index 8607f7d..cf5f364 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,5 @@ ## API - getFile - postFile -- deleteFile \ No newline at end of file +- deleteFile +- listFiles \ No newline at end of file diff --git a/src/main/java/ru/molokoin/storage/api/RestStorageService.java b/src/main/java/ru/molokoin/storage/api/RestStorageService.java index 94a65a5..27ceb40 100644 --- a/src/main/java/ru/molokoin/storage/api/RestStorageService.java +++ b/src/main/java/ru/molokoin/storage/api/RestStorageService.java @@ -1,19 +1,24 @@ package ru.molokoin.storage.api; +import java.io.File; import java.util.Collection; import jakarta.ejb.EJB; +import jakarta.servlet.http.HttpServletResponse; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import ru.molokoin.storage.entities.ContentEntity; -import ru.molokoin.storage.services.RepositoryFace; +import ru.molokoin.storage.services.StorageFace; @Path("content") public class RestStorageService { @EJB - private RepositoryFace repository; + private StorageFace storage; /** * Получение сведений о всех файлах в хранилище. @@ -27,10 +32,29 @@ public class RestStorageService { */ @GET @Produces(MediaType.APPLICATION_XML) - public Collection getFiles(){ + public Collection getInfo(){ System.out.println("Передача данных обо всех файлах ..."); - Collection cce = repository.getInfo(); + Collection cce = storage.getInfo(); return cce; } + // @GET + // @Path("{id}") + // @Produces(MediaType.APPLICATION_OCTET_STREAM) + // //@Produces(MediaType.MULTIPART_FORM_DATA) + // public Response getContent(@PathParam("id") Integer id, @Context HttpServletResponse response){ + // System.out.println("Передача байткода по id файла ..."); + + // return storage.findContentById(id); + // } + + // @GET + // @Produces(MediaType.APPLICATION_OCTET_STREAM) + // public Response getFile() { + // File file = ... // Initialize this to the File path you want to serve. + // return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM) + // .header("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"" ) //optional + // .build(); + // } + } diff --git a/src/main/java/ru/molokoin/storage/entities/ContentEntity.java b/src/main/java/ru/molokoin/storage/entities/ContentEntity.java index a78f4ec..e5a318d 100644 --- a/src/main/java/ru/molokoin/storage/entities/ContentEntity.java +++ b/src/main/java/ru/molokoin/storage/entities/ContentEntity.java @@ -17,7 +17,7 @@ import jakarta.xml.bind.annotation.XmlRootElement; */ @Entity @XmlRootElement(name = "storage") -@Table(name = "Storage", schema = "j200", catalog = "")//поправить схему +@Table(name = "Storage", schema = "home", catalog = "")//поправить схему public class ContentEntity implements Serializable{ @Id //уникальный идентификатор строки @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/ru/molokoin/storage/services/Storage.java b/src/main/java/ru/molokoin/storage/services/Storage.java new file mode 100644 index 0000000..2b63bf8 --- /dev/null +++ b/src/main/java/ru/molokoin/storage/services/Storage.java @@ -0,0 +1,50 @@ +package ru.molokoin.storage.services; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.ejb.Singleton; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import jakarta.ws.rs.core.Response; +import ru.molokoin.storage.entities.ContentEntity; + +@Singleton +public class Storage implements StorageFace{ + @PersistenceContext (unitName="Storage") + private EntityManager em; + + @Override + public List getInfo() { + List list = new ArrayList<>(); + System.out.println("getInfo()"); + //Обращаемся к базе и запрашиваем сведения + + + return list; + } + + @Override + public void save(String filename, byte[] content) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'save'"); + } + + @Override + public void delete(Long id) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'delete'"); + } + + public static void main(String[] args) { + new Storage().getInfo(); + } + + @Override + public Response findContentById(Integer id) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'findContentById'"); + } + + +} \ No newline at end of file diff --git a/src/main/java/ru/molokoin/storage/services/RepositoryFace.java b/src/main/java/ru/molokoin/storage/services/StorageFace.java similarity index 63% rename from src/main/java/ru/molokoin/storage/services/RepositoryFace.java rename to src/main/java/ru/molokoin/storage/services/StorageFace.java index a445502..4f471e4 100644 --- a/src/main/java/ru/molokoin/storage/services/RepositoryFace.java +++ b/src/main/java/ru/molokoin/storage/services/StorageFace.java @@ -3,21 +3,25 @@ package ru.molokoin.storage.services; import java.util.List; import jakarta.ejb.Local; +import jakarta.ws.rs.core.Response; import ru.molokoin.storage.entities.ContentEntity; /** - * Интерфейс работы с хранилищем файлов на жестком диске + * Интерфейс работы с хранилищем + * - файлов на жестком диске + * - сведениями о файлах в базе данных */ @Local -public interface RepositoryFace { +public interface StorageFace { /** * Коллекция сведений о файлах, доступных в хранилице + * полученная из базы данных */ List getInfo(); /** * Получение байткода из файловой системы по идентификатору файла */ - byte[] getContentById(); + //byte[] getContentById(); /** * Сохранение байткода в файловой системе @@ -28,5 +32,7 @@ public interface RepositoryFace { * Удаление файла из файловой системы по id */ void delete(Long id); + + Response findContentById(Integer id); } diff --git a/src/main/resources/META-INF/persistance.xml b/src/main/resources/META-INF/persistance.xml new file mode 100644 index 0000000..28f7f16 --- /dev/null +++ b/src/main/resources/META-INF/persistance.xml @@ -0,0 +1,9 @@ + + + + Подключение к базе molokoin.ru:3306/home + java:/home + ru.molokoin.storage.entities.ContentEntity + true + + \ No newline at end of file diff --git a/src/main/scripts/prepare.sql b/src/main/scripts/prepare.sql new file mode 100644 index 0000000..75dadc6 --- /dev/null +++ b/src/main/scripts/prepare.sql @@ -0,0 +1,5 @@ +create table home.Storage ( + id INT PRIMARY KEY AUTO_INCREMENT, + filename varchar(50) not null, + location varchar(1000) not null +); \ No newline at end of file diff --git a/target/classes/META-INF/persistance.xml b/target/classes/META-INF/persistance.xml new file mode 100644 index 0000000..28f7f16 --- /dev/null +++ b/target/classes/META-INF/persistance.xml @@ -0,0 +1,9 @@ + + + + Подключение к базе molokoin.ru:3306/home + java:/home + ru.molokoin.storage.entities.ContentEntity + true + + \ No newline at end of file diff --git a/target/classes/ru/molokoin/storage/api/RestStorageService.class b/target/classes/ru/molokoin/storage/api/RestStorageService.class index e08d3165f06eb438610b9c3396638297557841e3..9c5de4595a0493ba40533b00828be0b9643ace05 100644 GIT binary patch delta 172 zcmeyx`HWNG)W2Q(7#J9g8O+%km>3zfCMJqZRMF#RFD}V1N=#1$i6qFe2Sa!hJGOAM zr>B;9=B4E`GDu9$XB6KY&sf9As4+27RsgEVEipNjhe3!zZ?hP)8Y83dWLuVOP89|Y z234S-+T@Ka;zs%m1`Lc0hCq9HfV2<;6N5g35s<|MbO!^FG+|%|(%e81Qy`WoW-tQ) DIi({X delta 210 zcmaFH`HNHF)W2Q(7#J9g87$Ztm>3zfCO0yQOqOL7n`kA$$5oVCkYAixl3!HG$e=s9 zfl*YrIJKxOGdZ0v1tn@M|x_BTV_sb@n$>5X^f28AXC(^sC7$BPUT_HW6)=0 zUx|o`HiwfkB8taq?UiaU%l;Lk30$BcSVefV2<;6N3TJ bos2-*1SrPDV9LM_q`842WgQO4QT zgGMiXdGp?M-pu>Q>l=U@^di&*uJS@|opBqdt@Od=DkJGB-|3XRoYIT)nydSh0j1vFzvqpW_a8y8r+H diff --git a/target/classes/ru/molokoin/storage/services/Storage.class b/target/classes/ru/molokoin/storage/services/Storage.class new file mode 100644 index 0000000000000000000000000000000000000000..a4d275af0bcb639fab31cd879d8b46f87429533d GIT binary patch literal 1851 zcmb7E?^7E^7=AWTE~K%AV8OPwqQ#Q5%GuW6K`bCBngY|q+wd?dFtINWq#sDr_P2KTRnvMH6DYsV`E}V;0yz~5+^Fr#r!uzE z@2EJ@iB+bl{54~>?LCl&+2g9f<%eDFgsPzvy&I@yVHQx%{HYK8=I+EU8;JxDlm1DV>ymx&m}703MR*K9kU+ZJJr&9kF5xccpo27nW$?8 zE@dor-EC+6?Ee3j_;KPlqgeS5 zRnppU5r^W)s{1VA$f3m11%Y8x9E({1 z-o_=qQE1FC>K(3gxSWFg%2kf0@QstlGHqql6qZmm@HZfrnE}qIVYzn0{?JS1B=D{D}k220K z#*pZxlh^m=z3KGx>-_@&ZlD)IO+eola_x*;Ic;Si=T(j}px@{WgG_f9Bb8wUbpf5F z+9+w1&E@lKi5Urqa-^|cI04=MAgTC*w2_Gp6bopkI=6}nj{@%h2yT=A;?a^O&GC=U z5`(7_Z{s_*s|U4Vr;GkBshT7uuWcT`3b%7 literal 0 HcmV?d00001