From f41db319a1fe93c7c113bf3af22b88e306e1cae1 Mon Sep 17 00:00:00 2001 From: esoe Date: Mon, 10 Jul 2023 22:58:34 +0300 Subject: [PATCH] qq --- README.md | 2 +- pom.xml | 95 +++++++++++++++ .../ru/molokoin/storage/api/RestConfig.java | 17 +++ .../storage/api/RestStorageService.java | 36 ++++++ .../storage/entities/ContentEntity.java | 112 ++++++++++++++++++ .../storage/services/RepositoryFace.java | 32 +++++ src/main/webapp/WEB-INF/web.xml | 7 ++ src/main/webapp/index.jsp | 5 + .../ru/molokoin/storage/api/RestConfig.class | Bin 0 -> 846 bytes .../storage/api/RestStorageService.class | Bin 0 -> 1274 bytes .../storage/entities/ContentEntity.class | Bin 0 -> 2962 bytes .../storage/services/RepositoryFace.class | Bin 0 -> 438 bytes 12 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 pom.xml create mode 100644 src/main/java/ru/molokoin/storage/api/RestConfig.java create mode 100644 src/main/java/ru/molokoin/storage/api/RestStorageService.java create mode 100644 src/main/java/ru/molokoin/storage/entities/ContentEntity.java create mode 100644 src/main/java/ru/molokoin/storage/services/RepositoryFace.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.jsp create mode 100644 target/classes/ru/molokoin/storage/api/RestConfig.class create mode 100644 target/classes/ru/molokoin/storage/api/RestStorageService.class create mode 100644 target/classes/ru/molokoin/storage/entities/ContentEntity.class create mode 100644 target/classes/ru/molokoin/storage/services/RepositoryFace.class diff --git a/README.md b/README.md index 1641937..8607f7d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Storage-service Сервис обмена файлами большого размера -API +## API - getFile - postFile - deleteFile \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ae4372a --- /dev/null +++ b/pom.xml @@ -0,0 +1,95 @@ + + + + 4.0.0 + + ru.molokoin + storage + 1.0 + war + + storage Maven Webapp + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + jakarta.ejb + jakarta.ejb-api + 4.0.0 + provided + + + jakarta.persistence + jakarta.persistence-api + 3.0.0 + provided + + + jakarta.servlet + jakarta.servlet-api + 5.0.0 + provided + + + jakarta.ws.rs + jakarta.ws.rs-api + 3.1.0 + + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.0 + + + junit + junit + 4.11 + test + + + + + storage + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-war-plugin + 3.2.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/src/main/java/ru/molokoin/storage/api/RestConfig.java b/src/main/java/ru/molokoin/storage/api/RestConfig.java new file mode 100644 index 0000000..6b827d9 --- /dev/null +++ b/src/main/java/ru/molokoin/storage/api/RestConfig.java @@ -0,0 +1,17 @@ +package ru.molokoin.storage.api; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +import java.util.HashSet; +import java.util.Set; + +@ApplicationPath("api") +public class RestConfig extends Application { + @Override + public Set> getClasses() { + Set> resources = new HashSet<>(); + resources.add(RestStorageService.class); + return resources; + } +} \ 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 new file mode 100644 index 0000000..94a65a5 --- /dev/null +++ b/src/main/java/ru/molokoin/storage/api/RestStorageService.java @@ -0,0 +1,36 @@ +package ru.molokoin.storage.api; + +import java.util.Collection; + +import jakarta.ejb.EJB; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import ru.molokoin.storage.entities.ContentEntity; +import ru.molokoin.storage.services.RepositoryFace; + +@Path("content") +public class RestStorageService { + @EJB + private RepositoryFace repository; + + /** + * Получение сведений о всех файлах в хранилище. + * Данные предоставляются в формате *.xml + * - имя файла + * - размер в мегабайтах + * - расширение (*.pdf, *.docx, *.mp3) + * - путь к файлу в хранилище (дерево директорий: path) + * + * @return + */ + @GET + @Produces(MediaType.APPLICATION_XML) + public Collection getFiles(){ + System.out.println("Передача данных обо всех файлах ..."); + Collection cce = repository.getInfo(); + return cce; + } + +} diff --git a/src/main/java/ru/molokoin/storage/entities/ContentEntity.java b/src/main/java/ru/molokoin/storage/entities/ContentEntity.java new file mode 100644 index 0000000..a78f4ec --- /dev/null +++ b/src/main/java/ru/molokoin/storage/entities/ContentEntity.java @@ -0,0 +1,112 @@ +package ru.molokoin.storage.entities; + +import java.io.Serializable; + +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.xml.bind.annotation.XmlRootElement; + +/** + * Сущность (модель) + * содержащая сведения об отдельном файле + */ +@Entity +@XmlRootElement(name = "storage") +@Table(name = "Storage", schema = "j200", catalog = "")//поправить схему +public class ContentEntity implements Serializable{ + @Id //уникальный идентификатор строки + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Basic(optional = false) //не может быть null + @Column(name = "id") + Long id; //Идентификатор файла + + @Basic(optional = false) //не может быть null + @Column(name = "filename", length = 300) + String filename; //Наименование файла + + @Basic(optional = false) //не может быть null + @Column(name = "location", length = 1000) + String location; //Путь к файлу на локальной машине + + byte[] content; //массив байткода - содержимое файла + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public byte[] getContent() { + return content; + } + + public void setContent(byte[] content) { + this.content = content; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((filename == null) ? 0 : filename.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ContentEntity other = (ContentEntity) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (filename == null) { + if (other.filename != null) + return false; + } else if (!filename.equals(other.filename)) + return false; + if (location == null) { + if (other.location != null) + return false; + } else if (!location.equals(other.location)) + return false; + return true; + } + + @Override + public String toString() { + return "ContentEntity [id=" + id + ", filename=" + filename + ", location=" + location + "]"; + } + +} diff --git a/src/main/java/ru/molokoin/storage/services/RepositoryFace.java b/src/main/java/ru/molokoin/storage/services/RepositoryFace.java new file mode 100644 index 0000000..a445502 --- /dev/null +++ b/src/main/java/ru/molokoin/storage/services/RepositoryFace.java @@ -0,0 +1,32 @@ +package ru.molokoin.storage.services; + +import java.util.List; + +import jakarta.ejb.Local; +import ru.molokoin.storage.entities.ContentEntity; +/** + * Интерфейс работы с хранилищем файлов на жестком диске + */ +@Local +public interface RepositoryFace { + /** + * Коллекция сведений о файлах, доступных в хранилице + */ + List getInfo(); + + /** + * Получение байткода из файловой системы по идентификатору файла + */ + byte[] getContentById(); + + /** + * Сохранение байткода в файловой системе + */ + void save(String filename, byte[] content); + + /** + * Удаление файла из файловой системы по id + */ + void delete(Long id); +} + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + Archetype Created Web Application + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..c38169b --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Hello World!

+ + diff --git a/target/classes/ru/molokoin/storage/api/RestConfig.class b/target/classes/ru/molokoin/storage/api/RestConfig.class new file mode 100644 index 0000000000000000000000000000000000000000..f5c1c850afa27c2b06f02eb330fc28361053d986 GIT binary patch literal 846 zcmah{+ins;82)B~E=Lh+(RygLwiamOTzCl~X-JG0L`^Xmy&IMhhAul~W)|aH=~bg9 zK7bEp{1{Q76 z(vd^1uf~yZv7vm&zuVg@_fSM*zC>v^JFQO3$2Nhjk)8=VA+$WI$oZ%-H2+mwe>KCt zGz%5T0&d~9k6nh+8j!$>xP!YiD=``|?9?|3c`=;Iz_l80sdyu;j!lp>SN@~5+ST!W znEx8#(N)*KbV<*uokeM+%;4jY&7 zQn(2XKC=*EOt>k!B|HEzbaa469GwIGK1rM?BbsSmAp2=)&eNZmfjkQI7gr8MOC&K| zLzzIX6Yrt21QEn}ByWF3_00ut^iHZfpK;T}>ywY9P7x3&EXiL&mbeN*B+#{0*d=t9 iboa1FDfY>hq+Mz56X#I}Nx}m>Bw8TNA-yAuM?V42UCR0Z literal 0 HcmV?d00001 diff --git a/target/classes/ru/molokoin/storage/api/RestStorageService.class b/target/classes/ru/molokoin/storage/api/RestStorageService.class new file mode 100644 index 0000000000000000000000000000000000000000..e08d3165f06eb438610b9c3396638297557841e3 GIT binary patch literal 1274 zcmb7D%T5$Q6g@Qq3=E?@1$;92GA>wj-MY7KoqPJ+TR(q&-vcm(yBVYe#{JN$dXBg1Y1ayj z=gW$+WKCO(DlnzQFDZXb+bV+=f$kN#CM`$073*1fMcGCm>#Ld^jUoVKWQ^f3oA-tv$REp{ezz>U7{V&Sr4t zKr2h@fl<{Q&S99!dLg@dBKbY-Sqr{)ISRg#)#-MO2+T&GqV4+IXgk`9HtQdv&3wFx zcB9?;$NEM-+KWC%d->=~{TL~BPTF;_(c|C{RH}1EqN!&Y%ECg zisUnPGDR4nR%yO@fmAFQZH8WK+i6p@d^%h^=~=Xbwsrg)a-SQ=$GOJIz;SeO%_Rxw zMh`tIhd#phbDzSA26QiX1M~-ZI`kYOz{v)9nei0k{af4#3tiu zR*0*_WQR#EPwbIK&4J|Je$5#F8m<%l1~X$mNo0z<6mBw>!mS3APDXC?8wzmeH=AEz A+W-In literal 0 HcmV?d00001 diff --git a/target/classes/ru/molokoin/storage/entities/ContentEntity.class b/target/classes/ru/molokoin/storage/entities/ContentEntity.class new file mode 100644 index 0000000000000000000000000000000000000000..9c8b754584c6b15231bfd43087287c5d63e233ea GIT binary patch literal 2962 zcma)7ZF3V<6n<{r2?1(od9Ai0N}Dun2`Fk>kd%UfLa`}@w!CeUCE0ef8?qZmoN*lf zhTp|6e9##zGdkn=NoM>Ve(*;);&XR5&5NnnPLq4?ea^YhdCs|~zyJNyF91%X6-7WG z)odws%dj>r-BfJHYN}OD(M(5obj?=gEYqPeFYU)sgan2*)X!DLP|d2cSlZCaP81P= zVRu)zl%m$uRYU($Eg70XK(Ekaq2sb(nbn-Y;iVQM*0mMg)(N~|nwFzFx@Fn|hX~(P zn~th9w5F}wyuYj|g$mt{4?Mc8nOakIw91NVv^2tEwj=H8Am2GD(NFenqFLyK+Q$ zT6JoSDW-@vtg7xA0}`FM|sMdwok(o>vOHmGtxY0{8X1Onv=a=j5$o^1NouS$fYc_@|%Wzk+)Du_+UtPRtwVGv3Hd=pf zC#4KKy>)Li@@Y&l6K`&PQ8$#5ZdMd^d#)+B>&B90IrD~A=R74m>d)GpCXU+<5?AzQ zGIg}eHLXq}p^fbHw44j7qZ$@70p4a82l*F9h!)=<*SolShjyIbyJ;sh?7?2_<8o*X zZy?FVew$#(cjh}BMxYxJkceR%DBvJrd{F-ZJ0xL;3FBMhXM#`;B!0d{OX0U98cw~y z*biI;$Qg*Zn`& zA0G@*+X*}W5}S} zsz=xn;4}@QKw?+e*;lCp2QhzT`;L3p`~4H-$wkbQoWx$@DuByG%_8!O4=Nai5KKV4 zVpQJ<2yx>zHp6k8dl`$2pYfAa`YFPpXX%#+2cM<3a3#&ZZ>5p`72=wwLt=^={Du)C zxRAycu7BftJO}lV=b83-MjBhV(LSdx@;uu<&q||x9_nax&m9v>%(=+dv&^w`lQU<9 zgX0#b!flLUm5+K28LV?6+@TtGaUS=m&wZ-+0EnWArO>ba*-sVOKPq_zS}ndY}9uf^*)JjIlUSQShkoDyK zEvQ^Gc{N$_)=X4QKIF$1YW*Ev@9OYVKBWLQ7&?GWcLE>dRR--kFXSvWnNLtI8hB)* I3EPJA4-M8xI{*Lx literal 0 HcmV?d00001 diff --git a/target/classes/ru/molokoin/storage/services/RepositoryFace.class b/target/classes/ru/molokoin/storage/services/RepositoryFace.class new file mode 100644 index 0000000000000000000000000000000000000000..68baff598ee0fe643025c929de1123bf2ced0b67 GIT binary patch literal 438 zcmZut!A=4(5Pd~t1r-qv#y^0V*n`J41~HP5Y+?cl7fxjvH-*xgZI^^!^WX>gQO4QT zgGMiXdGp?M-pu>Q>l=U@^di&*uJS@|opBqdt@Od=DkJGB-|3XRoYIT)nydSh0j1vFzvqpW_a8y8r+H literal 0 HcmV?d00001