Skip to content

Commit

Permalink
Added filtering by creator and editor for the external resources sear…
Browse files Browse the repository at this point in the history
…ch list.
  • Loading branch information
axl8713 committed Jan 10, 2025
1 parent 29aeb15 commit dc396e6
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Resource> 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<Resource> 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<Resource> 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<Resource> resources = response.getList();
assertEquals(2, resources.size());
}
}

private JSONResult parse(String jsonString) {
JSONResult ret = new JSONResult();

Expand Down

0 comments on commit dc396e6

Please sign in to comment.