diff --git a/src/core/services-api/src/main/java/it/geosolutions/geostore/services/dto/search/BaseField.java b/src/core/services-api/src/main/java/it/geosolutions/geostore/services/dto/search/BaseField.java index 5b8717f8..f2fc9f76 100644 --- a/src/core/services-api/src/main/java/it/geosolutions/geostore/services/dto/search/BaseField.java +++ b/src/core/services-api/src/main/java/it/geosolutions/geostore/services/dto/search/BaseField.java @@ -19,8 +19,8 @@ */ package it.geosolutions.geostore.services.dto.search; -import java.util.Date; import javax.xml.bind.annotation.XmlType; +import java.util.Date; /** * Enum BaseField. @@ -35,8 +35,9 @@ public enum BaseField { LASTUPDATE("lastUpdate", Date.class), NAME("name", String.class), DESCRIPTION("description", String.class), - METADATA("metadata", String.class); - ; + METADATA("metadata", String.class), + CREATOR("creator", String.class), + EDITOR("editor", String.class); private String fieldName; diff --git a/src/modules/rest/extjs/src/main/java/it/geosolutions/geostore/services/rest/RESTExtJsService.java b/src/modules/rest/extjs/src/main/java/it/geosolutions/geostore/services/rest/RESTExtJsService.java index c2a8a826..caa0c4da 100644 --- a/src/modules/rest/extjs/src/main/java/it/geosolutions/geostore/services/rest/RESTExtJsService.java +++ b/src/modules/rest/extjs/src/main/java/it/geosolutions/geostore/services/rest/RESTExtJsService.java @@ -52,7 +52,7 @@ public interface RESTExtJsService { @GET - @Path("/search//{nameLike: [^/]+}\")") + @Path("/search/{nameLike: [^/]+}\")") @Produces({MediaType.APPLICATION_JSON}) @Secured({"ROLE_ADMIN", "ROLE_USER", "ROLE_ANONYMOUS"}) String getAllResources( diff --git a/src/modules/rest/extjs/src/test/java/it/geosolutions/geostore/services/rest/impl/RESTExtJsServiceImplTest.java b/src/modules/rest/extjs/src/test/java/it/geosolutions/geostore/services/rest/impl/RESTExtJsServiceImplTest.java index 260aa727..5a83ce0e 100644 --- a/src/modules/rest/extjs/src/test/java/it/geosolutions/geostore/services/rest/impl/RESTExtJsServiceImplTest.java +++ b/src/modules/rest/extjs/src/test/java/it/geosolutions/geostore/services/rest/impl/RESTExtJsServiceImplTest.java @@ -27,6 +27,9 @@ import it.geosolutions.geostore.core.model.enums.Role; import it.geosolutions.geostore.services.dto.ShortResource; import it.geosolutions.geostore.services.dto.search.AndFilter; +import it.geosolutions.geostore.services.dto.search.BaseField; +import it.geosolutions.geostore.services.dto.search.FieldFilter; +import it.geosolutions.geostore.services.dto.search.SearchOperator; import it.geosolutions.geostore.services.model.ExtResourceList; import it.geosolutions.geostore.services.rest.model.SecurityRuleList; import java.util.Arrays; @@ -406,6 +409,94 @@ public void testExtResourcesList_sorted() throws Exception { } } + @Test + public void testExtResourcesList_creatorFiltered() throws Exception { + final String CAT0_NAME = "CAT000"; + final String CREATOR_A = "creatorA"; + final String CREATOR_B = "creatorB"; + + long u0 = restCreateUser("u0", Role.USER, null, "p0"); + SecurityContext sc = new SimpleSecurityContext(u0); + + createCategory(CAT0_NAME); + + long resourceAId = restCreateResource("name_A", "description_A", CAT0_NAME, u0, true); + long resourceBId = restCreateResource("name_B", "description_B", CAT0_NAME, u0, true); + + Resource resourceA = resourceService.get(resourceAId); + resourceA.setCreator(CREATOR_A); + resourceService.update(resourceA); + + Resource resourceB = resourceService.get(resourceBId); + resourceB.setCreator(CREATOR_B); + resourceService.update(resourceB); + + { + FieldFilter editorFieldFilter = new FieldFilter(BaseField.CREATOR, "creatorB", SearchOperator.EQUAL_TO); + + ExtResourceList response = restExtJsService.getExtResourcesList(sc, 0, 1000, "", "", false, false, editorFieldFilter); + + List resources = response.getList(); + assertEquals(1, resources.size()); + Resource resource = resources.get(0); + assertEquals(CREATOR_B, resource.getCreator()); + + } + + { + FieldFilter editorFieldFilter = new FieldFilter(BaseField.CREATOR, "CREATOR_", SearchOperator.ILIKE); + + ExtResourceList response = restExtJsService.getExtResourcesList(sc, 0, 1000, "", "", false, false, editorFieldFilter); + + List resources = response.getList(); + assertEquals(2, resources.size()); + } + } + + @Test + public void testExtResourcesList_editorFiltered() throws Exception { + final String CAT0_NAME = "CAT000"; + final String EDITOR_A = "editorA"; + final String EDITOR_B = "editorB"; + + long u0 = restCreateUser("u0", Role.USER, null, "p0"); + SecurityContext sc = new SimpleSecurityContext(u0); + + createCategory(CAT0_NAME); + + long resourceAId = restCreateResource("name_A", "description_A", CAT0_NAME, u0, true); + long resourceBId = restCreateResource("name_B", "description_B", CAT0_NAME, u0, true); + + Resource resourceA = resourceService.get(resourceAId); + resourceA.setEditor(EDITOR_A); + resourceService.update(resourceA); + + Resource resourceB = resourceService.get(resourceBId); + resourceB.setEditor(EDITOR_B); + resourceService.update(resourceB); + + { + FieldFilter editorFieldFilter = new FieldFilter(BaseField.EDITOR, "editorA", SearchOperator.EQUAL_TO); + + ExtResourceList response = restExtJsService.getExtResourcesList(sc, 0, 1000, "", "", false, false, editorFieldFilter); + + List resources = response.getList(); + assertEquals(1, resources.size()); + Resource resource = resources.get(0); + assertEquals(EDITOR_A, resource.getEditor()); + + } + + { + FieldFilter editorFieldFilter = new FieldFilter(BaseField.EDITOR, "EDITOR_", SearchOperator.ILIKE); + + ExtResourceList response = restExtJsService.getExtResourcesList(sc, 0, 1000, "", "", false, false, editorFieldFilter); + + List resources = response.getList(); + assertEquals(2, resources.size()); + } + } + private JSONResult parse(String jsonString) { JSONResult ret = new JSONResult();