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 0000000..f5c1c85 Binary files /dev/null and b/target/classes/ru/molokoin/storage/api/RestConfig.class differ 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 0000000..e08d316 Binary files /dev/null and b/target/classes/ru/molokoin/storage/api/RestStorageService.class differ 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 0000000..9c8b754 Binary files /dev/null and b/target/classes/ru/molokoin/storage/entities/ContentEntity.class differ 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 0000000..68baff5 Binary files /dev/null and b/target/classes/ru/molokoin/storage/services/RepositoryFace.class differ