diff --git a/pom.xml b/pom.xml index 4af28bf..89ca885 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,11 @@ + + org.hibernate + hibernate-search-orm + 5.11.2.Final + javax javaee-web-api diff --git a/resources/PandaX.postman_collection.json b/resources/PandaX.postman_collection.json index 7cf0d4b..6a2eaeb 100644 --- a/resources/PandaX.postman_collection.json +++ b/resources/PandaX.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "ea50b603-efba-42cf-b82c-c3ba2b39a596", + "_postman_id": "ad04b255-f810-42a7-84e6-5729907ad155", "name": "PandaX", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, @@ -1261,9 +1261,11 @@ "});", "pm.collectionVariables.set(\"lastMedia\", pm.response.stream.toString());", "", - "pm.collectionVariables.set(\"lastMediaCity\",JSON.parse(pm.collectionVariables.get(\"lastMedia\")).city);", + "pm.collectionVariables.set(\"lastMediaCity\", JSON.parse(pm.collectionVariables.get(\"lastMedia\")).city);", "", - "pm.collectionVariables.set(\"lastMediaTitle\",JSON.parse(pm.collectionVariables.get(\"lastMedia\")).title);" + "pm.collectionVariables.set(\"lastMediaTitle\", JSON.parse(pm.collectionVariables.get(\"lastMedia\")).title);", + "", + "pm.collectionVariables.set(\"lastMediaDescript\", JSON.parse(pm.collectionVariables.get(\"lastMedia\")).descript);" ], "type": "text/javascript" } @@ -1449,7 +1451,7 @@ } ], "url": { - "raw": "{{url}}/media/?city={{lastMediaCity}}&title={{lastMediaTitle}}", + "raw": "{{url}}/media/?city={{lastMediaCity}}&title={{lastMediaTitle}}&descript={{lastMediaDescript}}", "host": [ "{{url}}" ], @@ -1465,6 +1467,10 @@ { "key": "title", "value": "{{lastMediaTitle}}" + }, + { + "key": "descript", + "value": "{{lastMediaDescript}}" } ] } @@ -1805,135 +1811,21 @@ ], "variable": [ { - "id": "108a3918-1449-4c74-ba9b-07f5cfba1b06", + "id": "386845dd-6f10-4089-8e15-f037d98a6c24", "key": "url", "value": "localhost:8080/PandaX", "type": "string" }, { - "id": "591f7f55-39bb-4dc1-877a-858f7d1a0e56", - "key": "token", - "value": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1IiwiZXhwIjoxNTc1NDA1NTU3LCJpYXQiOjE1NzQ5NzM1NTcsImlzcyI6IlBhbmRhWCBSRVNUIEFQSSIsInJvbCI6IkFETUlOIiwibmFtIjoicGFuZGEifQ.kvdUHGargo48dPSnT9zPyYbgQP_nW5YGqJSwGf8zasb5Sw80L1Ad28tbTtmfxwBkqonSEOzIDqDZ9ULSkpyfug", - "type": "string" - }, - { - "id": "b6e6e6cb-2376-4f9a-9950-320af9bfb71a", - "key": "login", - "value": "panda", - "type": "string" - }, - { - "id": "1c482c62-a467-456e-b14f-3bd1c290da12", + "id": "e3ca4557-b522-44de-ac6f-a37ee7255d79", "key": "password", "value": "panda", "type": "string" }, { - "id": "34a2b9bc-2264-4a1a-81bc-34d237191f6c", - "key": "mediaTypeTest", - "value": "{\"label\":\"Test media type\"}", - "type": "string" - }, - { - "id": "9d1adf43-0690-46ca-b6ea-02538faf5722", - "key": "lastMediaTypeId", - "value": "19", - "type": "string" - }, - { - "id": "fa90d788-5aea-4c52-9ccc-d8ffc0c1b7e4", - "key": "lastMediaType", - "value": "{\"id\":19,\"label\":\"Test media type\"}", - "type": "string" - }, - { - "id": "8367ece3-483c-4918-ac53-6fc3873669a9", - "key": "publisherTest", - "value": "{\"denomination\":\"Test publisher\"}", - "type": "string" - }, - { - "id": "15697872-796b-4ad9-bb13-153c679e6400", - "key": "lastPublisherId", - "value": "13", - "type": "string" - }, - { - "id": "85b69811-cefc-4b24-b472-2355a78fa453", - "key": "lastPublisher", - "value": "{\"denomination\":\"Test publisher\",\"id\":13}", - "type": "string" - }, - { - "id": "f6db81da-ce1f-4d4e-9e44-4bd3b8c29d11", - "key": "userTest", - "value": "{\"pseudo\":\"user test\",\"pwd\":\"test\",\"firstName\":\"test\",\"lastName\":\"test\",\"isAdmin\":\"1\"}", - "type": "string" - }, - { - "id": "f6ef800a-fa7c-42bf-9563-1e8ec2b28de7", - "key": "lastUserId", - "value": "6", - "type": "string" - }, - { - "id": "b213c402-f527-4f66-81c5-8d868acd0bfa", - "key": "lastUser", - "value": "{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}", - "type": "string" - }, - { - "id": "cfe97014-f7a2-458e-a862-c39fd3ac5a2e", - "key": "mediaTest", - "value": "{\"title\" : \"Kung Fu Panda\",\"published\" : \"2019-11-11\",\"city\" : \"KungFuLand\",\"descript\" : \"In the Valley of Peace, a land in ancient China inhabited by anthropomorphic animals, Po Ping the giant panda is a kung fu fanatic who idolizes the Furious Five – Tigress, Monkey, Mantis, Viper, and Crane – a quintet of kung fu masters trained by Master Shifu, the red panda. However, Po is unable to pursue his dream of learning kung fu as he helps his adoptive father, Mr. Ping the goose, in his noodle restaurant.\",\"imageUrl\" : \"http://fr.web.img5.acsta.net/c_215_290/medias/nmedia/18/36/20/29/18944269.jpg\",\"user\" : {\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"},\"publisher\" :{\"denomination\":\"Test publisher\",\"id\":13},\"mediaType\" : {\"id\":19,\"label\":\"Test media type\"}}", - "type": "string" - }, - { - "id": "b16f014f-3120-4643-92f8-7ffb25f130e4", - "key": "lastMediaId", - "value": "1", - "type": "string" - }, - { - "id": "3b3a829d-d542-4888-96f6-b6491b6569a2", - "key": "lastMedia", - "value": "{\"content\":\"comment updated\",\"dateMade\":\"2019-11-28T00:00:00+01:00\",\"id\":1,\"media\":{\"city\":\"KungFuLand\",\"descript\":\"In the Valley of Peace, a land in ancient China inhabited by anthropomorphic animals, Po Ping the giant panda is a kung fu fanatic who idolizes the Furious Five – Tigress, Monkey, Mantis, Viper, and Crane – a quintet of kung fu masters trained by Master Shifu, the red panda. However, Po is unable to pursue his dream of learning kung fu as he helps his adoptive father, Mr. Ping the goose, in his noodle restaurant.\",\"id\":1,\"imageUrl\":\"http://fr.web.img5.acsta.net/c_215_290/medias/nmedia/18/36/20/29/18944269.jpg\",\"mediaType\":{\"id\":19,\"label\":\"Test media type\"},\"published\":\"2019-11-11T00:00:00+01:00\",\"publisher\":{\"denomination\":\"Test publisher\",\"id\":13},\"title\":\"Kung Fu Panda\",\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}},\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}}", - "type": "string" - }, - { - "id": "5fe6a8d0-fea5-464c-8a9e-6ca4087b1a92", - "key": "lastMediaCity", - "value": "KungFuLand", - "type": "string" - }, - { - "id": "e5bb72a1-ad77-44f6-b105-55df75b0c2eb", - "key": "lastMediaTitle", - "value": "Kung Fu Panda", - "type": "string" - }, - { - "id": "b2f62ef2-62e1-412b-86e7-0971ba94b575", - "key": "commentTest", - "value": "{ \"content\": \"test\", \"media\": {\"city\":\"KungFuLand\",\"descript\":\"In the Valley of Peace, a land in ancient China inhabited by anthropomorphic animals, Po Ping the giant panda is a kung fu fanatic who idolizes the Furious Five – Tigress, Monkey, Mantis, Viper, and Crane – a quintet of kung fu masters trained by Master Shifu, the red panda. However, Po is unable to pursue his dream of learning kung fu as he helps his adoptive father, Mr. Ping the goose, in his noodle restaurant.\",\"id\":1,\"imageUrl\":\"http://fr.web.img5.acsta.net/c_215_290/medias/nmedia/18/36/20/29/18944269.jpg\",\"mediaType\":{\"id\":19,\"label\":\"Test media type\"},\"published\":\"2019-11-11T00:00:00+01:00\",\"publisher\":{\"denomination\":\"Test publisher\",\"id\":13},\"title\":\"Kung Fu Panda\",\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}}, \"user\": {\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}}", - "type": "string" - }, - { - "id": "71c9818f-1a5d-417a-b64e-7b78c1a6cf8b", - "key": "lastCommentId", - "value": "1", - "type": "string" - }, - { - "id": "497ced1d-65eb-4977-ae39-006cdbde75a7", - "key": "lastComment", - "value": "{\"content\":\"comment updated\",\"dateMade\":\"2019-11-28T00:00:00+01:00\",\"id\":1,\"media\":{\"city\":\"KungFuLand\",\"descript\":\"In the Valley of Peace, a land in ancient China inhabited by anthropomorphic animals, Po Ping the giant panda is a kung fu fanatic who idolizes the Furious Five – Tigress, Monkey, Mantis, Viper, and Crane – a quintet of kung fu masters trained by Master Shifu, the red panda. However, Po is unable to pursue his dream of learning kung fu as he helps his adoptive father, Mr. Ping the goose, in his noodle restaurant.\",\"id\":1,\"imageUrl\":\"http://fr.web.img5.acsta.net/c_215_290/medias/nmedia/18/36/20/29/18944269.jpg\",\"mediaType\":{\"id\":19,\"label\":\"Test media type\"},\"published\":\"2019-11-11T00:00:00+01:00\",\"publisher\":{\"denomination\":\"Test publisher\",\"id\":13},\"title\":\"Kung Fu Panda\",\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}},\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}}", - "type": "string" - }, - { - "id": "e97e66fa-5dd5-4d71-b9f4-ff1f802c6507", - "key": "possessionTest", - "value": "{\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"},\"media\": {\"content\":\"comment updated\",\"dateMade\":\"2019-11-28T00:00:00+01:00\",\"id\":1,\"media\":{\"city\":\"KungFuLand\",\"descript\":\"In the Valley of Peace, a land in ancient China inhabited by anthropomorphic animals, Po Ping the giant panda is a kung fu fanatic who idolizes the Furious Five – Tigress, Monkey, Mantis, Viper, and Crane – a quintet of kung fu masters trained by Master Shifu, the red panda. However, Po is unable to pursue his dream of learning kung fu as he helps his adoptive father, Mr. Ping the goose, in his noodle restaurant.\",\"id\":1,\"imageUrl\":\"http://fr.web.img5.acsta.net/c_215_290/medias/nmedia/18/36/20/29/18944269.jpg\",\"mediaType\":{\"id\":19,\"label\":\"Test media type\"},\"published\":\"2019-11-11T00:00:00+01:00\",\"publisher\":{\"denomination\":\"Test publisher\",\"id\":13},\"title\":\"Kung Fu Panda\",\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}},\"user\":{\"admin\":false,\"firstName\":\"test\",\"id\":6,\"lastName\":\"test\",\"pseudo\":\"user test\",\"pwd\":\"test\"}},\"dateAcquired\":\"2019-11-05\"}", + "id": "6c718dc5-d300-4e78-be55-41f549f0eb3f", + "key": "login", + "value": "panda", "type": "string" } ], diff --git a/src/main/java/fr/efrei/pandax/model/business/Media.java b/src/main/java/fr/efrei/pandax/model/business/Media.java index df5f552..f28e80c 100644 --- a/src/main/java/fr/efrei/pandax/model/business/Media.java +++ b/src/main/java/fr/efrei/pandax/model/business/Media.java @@ -1,5 +1,8 @@ package fr.efrei.pandax.model.business; +import org.hibernate.search.annotations.Field; +import org.hibernate.search.annotations.Indexed; + import java.io.Serializable; import java.util.Collection; import java.util.Date; @@ -24,11 +27,13 @@ import javax.xml.bind.annotation.XmlTransient; @Entity +@Indexed @Table(name = "media") @NamedQueries({ @NamedQuery(name = "Media.findAll", query = "SELECT m FROM Media m " + - "WHERE m.title LIKE :title " + - "AND m.city LIKE :city"), + "WHERE lower(m.title) LIKE lower(:title) " + + "AND lower(m.city) LIKE lower(:city) " + + "AND lower(m.descript) LIKE lower(:descript)"), @NamedQuery(name = "Media.findById", query = "SELECT m FROM Media m " + "WHERE m.id = :id"), @NamedQuery(name = "Media.findByUser", query = "SELECT m FROM Media m " + @@ -62,6 +67,7 @@ public class Media implements Serializable, IDTO { @Basic(optional = false) @NotNull @Lob + @Field @Size(min = 1, max = 65535) @Column(name = "descript") private String descript; diff --git a/src/main/java/fr/efrei/pandax/model/core/MediaDAO.java b/src/main/java/fr/efrei/pandax/model/core/MediaDAO.java index b803177..6f9e793 100644 --- a/src/main/java/fr/efrei/pandax/model/core/MediaDAO.java +++ b/src/main/java/fr/efrei/pandax/model/core/MediaDAO.java @@ -20,15 +20,18 @@ public MediaDAO(){ * Allows parameter matching for {@link Media#title} and {@link Media#city} * @param title complete or approximate {@link Media#title} * @param city complete or approximate {@link Media#city} + * @param descript complete or approximate {@link Media#descript} * @return {@link List} of all the matching {@link Media} */ - public List getAll(String title, String city) { + public List getAll(String title, String city, String descript) { openEntityManager(); TypedQuery mediaQuery = em.createNamedQuery("Media.findAll", Media.class); - mediaQuery.setParameter("city", - MatchMode.ANYWHERE.toMatchString(city)); mediaQuery.setParameter("title", MatchMode.ANYWHERE.toMatchString(title)); + mediaQuery.setParameter("city", + MatchMode.ANYWHERE.toMatchString(city)); + mediaQuery.setParameter("descript", + MatchMode.ANYWHERE.toMatchString(descript)); List mediaList = mediaQuery.getResultList(); closeEntityManager(); return mediaList; diff --git a/src/main/java/fr/efrei/pandax/resource/MediaResource.java b/src/main/java/fr/efrei/pandax/resource/MediaResource.java index 34aa5e8..ba79597 100644 --- a/src/main/java/fr/efrei/pandax/resource/MediaResource.java +++ b/src/main/java/fr/efrei/pandax/resource/MediaResource.java @@ -31,8 +31,9 @@ public class MediaResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response getAll(@QueryParam("title")@DefaultValue("")String title, - @QueryParam("city")@DefaultValue("")String city) { - medias = new MediaDAO().getAll(title, city); + @QueryParam("city")@DefaultValue("")String city, + @QueryParam("resume")@DefaultValue("")String resume) { + medias = new MediaDAO().getAll(title, city, resume); return Response.ok(new GenericEntity<>(medias) {}).build(); } diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 2db6b7f..c8da165 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -14,6 +14,9 @@ + + +