Skip to content

Commit

Permalink
https://github.com/gbif/registry/issues/352
Browse files Browse the repository at this point in the history
  • Loading branch information
fmendezh committed May 4, 2021
1 parent 1f19447 commit a3e6b82
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/
package org.gbif.registry.domain.ws;

import java.util.UUID;
import javax.annotation.Nullable;

public class OrganizationRequestSearchParams extends RequestSearchParams {

private Boolean isEndorsed;

private UUID networkKey;

@Nullable
public Boolean getIsEndorsed() {
return isEndorsed;
Expand All @@ -29,4 +32,13 @@ public Boolean getIsEndorsed() {
public void setIsEndorsed(@Nullable Boolean isEndorsed) {
this.isEndorsed = isEndorsed;
}

@Nullable
public UUID getNetworkKey() {
return networkKey;
}

public void setNetworkKey(UUID networkKey) {
this.networkKey = networkKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@

import org.gbif.api.model.common.paging.PagingRequest;
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.registry.Dataset;
import org.gbif.api.model.registry.Installation;
import org.gbif.api.model.registry.Network;
import org.gbif.api.model.registry.Node;
import org.gbif.api.model.registry.Organization;
import org.gbif.api.service.registry.DatasetService;
import org.gbif.api.service.registry.NetworkService;
import org.gbif.api.service.registry.NodeService;
import org.gbif.api.service.registry.OrganizationService;
import org.gbif.api.vocabulary.Country;
import org.gbif.registry.domain.ws.OrganizationRequestSearchParams;
import org.gbif.registry.search.test.EsManageServer;
import org.gbif.registry.test.TestDataFactory;
import org.gbif.registry.ws.client.NodeClient;
import org.gbif.registry.ws.client.OrganizationClient;
import org.gbif.registry.ws.resources.OrganizationResource;
import org.gbif.ws.client.filter.SimplePrincipalProvider;
import org.gbif.ws.security.KeyStore;

Expand All @@ -35,6 +41,7 @@
import javax.annotation.Nullable;

import org.apache.commons.beanutils.BeanUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -55,13 +62,18 @@ public class OrganizationIT extends NetworkEntityIT<Organization> {

private final NodeService nodeResource;
private final NodeService nodeClient;
private final NetworkService networkService;
private final OrganizationResource organizationResource;


private final TestDataFactory testDataFactory;

@Autowired
public OrganizationIT(
OrganizationService service,
NodeService nodeResource,
NetworkService networkService,
OrganizationResource organizationResource,
@Nullable SimplePrincipalProvider principalProvider,
TestDataFactory testDataFactory,
EsManageServer esServer,
Expand All @@ -78,6 +90,8 @@ public OrganizationIT(
this.nodeResource = nodeResource;
this.nodeClient = prepareClient(localServerPort, keyStore, NodeClient.class);
this.testDataFactory = testDataFactory;
this.networkService = networkService;
this.organizationResource = organizationResource;
}

@ParameterizedTest
Expand Down Expand Up @@ -128,6 +142,24 @@ public void testByCountry(ServiceType serviceType) {
assertResultsOfSize(service.listByCountry(Country.GERMANY, new PagingRequest()), 0);
}

@Test
public void searchByNetworkTest() {
Installation installation = testDataFactory.newPersistedInstallation();
Dataset dataset = testDataFactory.newPersistedDataset(installation.getOrganizationKey(), installation.getKey());
Network network = testDataFactory.newPersistedNetwork();

OrganizationRequestSearchParams searchParams = new OrganizationRequestSearchParams();
searchParams.setNetworkKey(network.getKey());
PagingResponse<Organization> response = organizationResource.list(null, searchParams, null);

assertResultsOfSize(response, 0);

networkService.addConstituent(network.getKey(), dataset.getKey());
response = organizationResource.list(null, searchParams, null);

assertResultsOfSize(response, 1);
}

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testHostedByInstallationList(ServiceType serviceType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ List<Organization> search(
@Nullable @Param("query") String query,
@Param("country") Country country,
@Param("isEndorsed") Boolean isEndorsed,
@Param("networkKey") UUID networkKey,
@Nullable @Param("page") Pageable page);

/** Overloaded count to allow a search scoped by country. */
int count(
@Nullable @Param("query") String query,
@Param("country") Country country,
@Param("isEndorsed") Boolean isEndorsed);
@Param("isEndorsed") Boolean isEndorsed,
@Param("networkKey") UUID networkKey);

/** Count all the publishing organizations that are part of this network. */
long countPublishingOrganizationsInNetwork(@Param("networkKey") UUID networkKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@
<if test="isEndorsed != null" >
AND o.endorsement_approved = #{isEndorsed,jdbcType=BOOLEAN}
</if>
<if test="networkKey != null" >
AND EXISTS (
SELECT d2.publishing_organization_key
FROM dataset d2
JOIN dataset_network nk ON nk.dataset_key = d2.key
JOIN network n ON n.key = nk.network_key AND n.deleted IS NULL
WHERE d2.publishing_organization_key = o.key AND n.key = #{networkKey,jdbcType=OTHER})
</if>
ORDER BY <if test="query != null" >ts_rank_cd(o.fulltext_search, query) DESC, </if>o.created DESC, key
<if test="page != null" >
LIMIT #{page.limit} OFFSET #{page.offset}
Expand All @@ -211,6 +219,14 @@
<if test="isEndorsed != null" >
AND o.endorsement_approved = #{isEndorsed,jdbcType=BOOLEAN}
</if>
<if test="networkKey != null" >
AND EXISTS (
SELECT d2.publishing_organization_key
FROM dataset d2
JOIN dataset_network nk ON nk.dataset_key = d2.key
JOIN network n ON n.key = nk.network_key AND n.deleted IS NULL
WHERE d2.publishing_organization_key = o.key AND n.key = #{networkKey,jdbcType=OTHER})
</if>
</select>

<!-- TAGS -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public PagingResponse<Organization> list(
// short circuited list all
if (country == null
&& request.getIsEndorsed() == null
&& Strings.isNullOrEmpty(request.getQ())) {
&& Strings.isNullOrEmpty(request.getQ())
&& request.getNetworkKey() == null) {
return list(page);
}

Expand All @@ -221,13 +222,13 @@ public PagingResponse<Organization> list(
request.getQ() != null
? Strings.emptyToNull(CharMatcher.WHITESPACE.trimFrom(request.getQ()))
: request.getQ();
long total = organizationMapper.count(query, country, request.getIsEndorsed());
long total = organizationMapper.count(query, country, request.getIsEndorsed(), request.getNetworkKey());
page = page == null ? new PagingRequest() : page;
return new PagingResponse<>(
page.getOffset(),
page.getLimit(),
total,
organizationMapper.search(query, country, request.getIsEndorsed(), page));
organizationMapper.search(query, country, request.getIsEndorsed(), request.getNetworkKey(), page));
}

@GetMapping("{key}/hostedDataset")
Expand Down

0 comments on commit a3e6b82

Please sign in to comment.