fix(manager-api): check whether featured API has any exposed versions.
Fixes:
MODIFY
manager/api/core/src/main/java/io/apiman/manager/api/core/IStorageQuery.java
manager/api/core/src/main/java/io/apiman/manager/api/core/IStorageQuery.java
@@ -91,8 +91,16 @@ public interface IStorageQuery {
*/
public SearchResultsBean<ApiSummaryBean> findApis(SearchCriteriaBean criteria) throws StorageException;
+ /**
+ * Find APIs that are exposed in the developer portal using criteria.
+ */
public SearchResultsBean<ApiSummaryBean> findExposedApis(SearchCriteriaBean criteria) throws StorageException;
+ /**
+ * Determine whether a given API has any API Versions exposed in the developer portal.
+ */
+ boolean isAnyApiVersionExposed(String apiId);
+
/**
* Finds plans (within an organization) with the given criteria.
* @param organizationId the organization id

MODIFY
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java
@@ -823,6 +823,21 @@ public class JpaStorage extends AbstractJpaStorage implements IStorage, IStorage
return apiMapper.toSummary(apisWithExposedVersions);
}
+ @Override
+ public boolean isAnyApiVersionExposed(String apiId) {
+ Long result = getJdbi()
+ .withHandle(handle -> handle
+ .createQuery("SELECT COUNT(*) "
+ + "FROM API_VERSIONS av "
+ + "WHERE av.api_id = :apiId "
+ + "AND av.expose_in_portal = true")
+ .bind("apiId", apiId)
+ .mapTo(long.class)
+ .one()
+ );
+ return result > 0;
+ }
+
/**
* {@inheritDoc}
*/

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/DevPortalService.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/DevPortalService.java
@@ -8,7 +8,6 @@ import io.apiman.manager.api.beans.search.SearchCriteriaBean;
import io.apiman.manager.api.beans.search.SearchResultsBean;
import io.apiman.manager.api.beans.summary.ApiPlanSummaryBean;
import io.apiman.manager.api.beans.summary.ApiSummaryBean;
-import io.apiman.manager.api.beans.summary.PolicySummaryBean;
import io.apiman.manager.api.beans.summary.mappers.ApiMapper;
import io.apiman.manager.api.core.IStorage;
import io.apiman.manager.api.core.IStorageQuery;
@@ -23,8 +22,6 @@ import javax.transaction.Transactional;
import com.google.common.collect.Lists;
-import static io.apiman.manager.api.service.SearchService.emptySearchResults;
-
/**
* @author Marc Savy {@literal <marc@blackparrotlabs.io>}
*/
@@ -63,8 +60,8 @@ public class DevPortalService implements DataAccessUtilMixin {
* @return list of featured ApiSummaries
*/
public List<ApiSummaryBean> getFeaturedApis() {
- return query.getApisByTagName("featured")
- .stream()
+ return query.getApisByTagName("featured").stream()
+ .filter(api -> query.isAnyApiVersionExposed(api.getId()))
.map(apiMapper::toSummary)
.collect(Collectors.toList());
}

fix(manager-api): check whether featured API has any exposed versions.

Fixes: #1681