fix(manager-api-jpa): JPA syntax error in tags retrieval
Also fix DDL tag+value issues & fix dev portal endpoint
MODIFY
distro/data/src/main/resources/ddls/apiman_h2.ddl
distro/data/src/main/resources/ddls/apiman_h2.ddl
@@ -348,7 +348,7 @@ ALTER TABLE notification_category_preferences ADD CONSTRAINT FKaq4x0n83d83xevui0
ALTER TABLE developer_mappings ADD CONSTRAINT FKhl2dwc4m0kvisedxfb9crceqd FOREIGN KEY (developer_id) REFERENCES developers (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE KeyValueTag (id BIGINT AUTO_INCREMENT NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255) NOT NULL, CONSTRAINT KeyValueTagPK PRIMARY KEY (id));
+CREATE TABLE KeyValueTag (id BIGINT AUTO_INCREMENT NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255), CONSTRAINT KeyValueTagPK PRIMARY KEY (id));
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
CREATE TABLE api_tag (api_id VARCHAR(255) NOT NULL, org_id VARCHAR(255) NOT NULL, tag_id BIGINT NOT NULL, CONSTRAINT PK_API_TAG PRIMARY KEY (api_id, org_id, tag_id));

MODIFY
distro/data/src/main/resources/ddls/apiman_mssql15.ddl
distro/data/src/main/resources/ddls/apiman_mssql15.ddl
@@ -443,7 +443,7 @@ ALTER TABLE developer_mappings ADD CONSTRAINT FKhl2dwc4m0kvisedxfb9crceqd FOREIG
GO
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE KeyValueTag (id bigint IDENTITY (1, 1) NOT NULL, [key] varchar(255) NOT NULL, value varchar(255) NOT NULL, CONSTRAINT KeyValueTagPK PRIMARY KEY (id))
+CREATE TABLE KeyValueTag (id bigint IDENTITY (1, 1) NOT NULL, [key] varchar(255) NOT NULL, value varchar(255), CONSTRAINT KeyValueTagPK PRIMARY KEY (id))
GO
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)

MODIFY
distro/data/src/main/resources/ddls/apiman_oracle19.ddl
distro/data/src/main/resources/ddls/apiman_oracle19.ddl
@@ -332,7 +332,7 @@ ALTER TABLE notification_category_preferences ADD CONSTRAINT FKaq4x0n83d83xevui0
ALTER TABLE developer_mappings ADD CONSTRAINT FKhl2dwc4m0kvisedxfb9crceqd FOREIGN KEY (developer_id) REFERENCES developers (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE KeyValueTag (id NUMBER(38, 0) GENERATED BY DEFAULT AS IDENTITY NOT NULL, key VARCHAR2(255) NOT NULL, value VARCHAR2(255) NOT NULL, CONSTRAINT KeyValueTagPK PRIMARY KEY (id));
+CREATE TABLE KeyValueTag (id NUMBER(38, 0) GENERATED BY DEFAULT AS IDENTITY NOT NULL, key VARCHAR2(255) NOT NULL, value VARCHAR2(255), CONSTRAINT KeyValueTagPK PRIMARY KEY (id));
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
CREATE TABLE api_tag (api_id VARCHAR2(255) NOT NULL, org_id VARCHAR2(255) NOT NULL, tag_id NUMBER(38, 0) NOT NULL, CONSTRAINT PK_API_TAG PRIMARY KEY (api_id, org_id, tag_id));

MODIFY
distro/data/src/main/resources/ddls/apiman_postgresql9.ddl
distro/data/src/main/resources/ddls/apiman_postgresql9.ddl
@@ -335,7 +335,7 @@ ALTER TABLE notification_category_preferences ADD CONSTRAINT "FKaq4x0n83d83xevui
ALTER TABLE developer_mappings ADD CONSTRAINT "FKhl2dwc4m0kvisedxfb9crceqd" FOREIGN KEY (developer_id) REFERENCES developers (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE "KeyValueTag" (id BIGSERIAL NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255) NOT NULL, CONSTRAINT "KeyValueTagPK" PRIMARY KEY (id));
+CREATE TABLE "KeyValueTag" (id BIGSERIAL NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255), CONSTRAINT "KeyValueTagPK" PRIMARY KEY (id));
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
CREATE TABLE api_tag (api_id VARCHAR(255) NOT NULL, org_id VARCHAR(255) NOT NULL, tag_id BIGINT NOT NULL, CONSTRAINT api_tag_pkey PRIMARY KEY (api_id, org_id, tag_id));

MODIFY
distro/ddl/src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml
distro/ddl/src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml
<constraints nullable="false"/>
</column>
<column name="value" type="VARCHAR(255)">
- <constraints nullable="false"/>
+ <constraints nullable="true"/>
</column>
</createTable>
</changeSet>

MODIFY
manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/dto/KeyValueTagDto.java
manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/dto/KeyValueTagDto.java
package io.apiman.manager.api.beans.apis.dto;
import java.util.StringJoiner;
+import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
/**
@@ -10,6 +11,7 @@ import javax.validation.constraints.NotNull;
public class KeyValueTagDto {
@NotNull
private String key;
+ @Nullable
private String value;
public String getKey() {

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
@@ -1166,7 +1166,7 @@ public class JpaStorage extends AbstractJpaStorage implements IStorage, IStorage
public List<ApiBean> getApisByTagNameAndValue(String tagKey, String tagValue) {
TypedQuery<ApiBean> query = getActiveEntityManager()
.createQuery(
- "SELECT ApiBean FROM ApiBean avb "
+ "SELECT avb FROM ApiBean avb "
+ "JOIN avb.tags tag "
+ "WHERE tag.key = :key "
+ "AND tag.value = :value",
@@ -1182,8 +1182,8 @@ public class JpaStorage extends AbstractJpaStorage implements IStorage, IStorage
public List<ApiBean> getApisByTagName(String tagKey) {
TypedQuery<ApiBean> query = getActiveEntityManager()
.createQuery(
- "SELECT ApiBean FROM ApiBean avb "
- + "JOIN avb.tags tag "
+ "SELECT ab FROM ApiBean ab "
+ + "JOIN ab.tags tag "
+ "WHERE tag.key = :key",
ApiBean.class
)

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/DeveloperPortalResourceImpl.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/DeveloperPortalResourceImpl.java
@@ -17,6 +17,7 @@ import io.apiman.manager.api.rest.exceptions.InvalidSearchCriteriaException;
import io.apiman.manager.api.rest.exceptions.NotAuthorizedException;
import io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException;
import io.apiman.manager.api.rest.exceptions.util.ExceptionFactory;
+import io.apiman.manager.api.rest.impl.util.RestHelper;
import io.apiman.manager.api.security.ISecurityContext;
import io.apiman.manager.api.service.ApiService;
import io.apiman.manager.api.service.ApiService.ApiDefinitionStream;
@@ -75,11 +76,8 @@ public class DeveloperPortalResourceImpl implements IDeveloperPortalResource {
@Override
public ApiVersionBean getApiVersion(String orgId, String apiId, String apiVersion) {
- ApiVersionBean retrieved = apiService.getApiVersion(orgId, apiId, apiVersion);
- if (!retrieved.isExposeInPortal()) {
- throw ExceptionFactory.apiVersionNotFoundException(apiId, apiVersion);
- }
- return retrieved;
+ ApiVersionBean retrieved = apiVersionMustBeExposedInPortal(orgId, apiId, apiVersion);
+ return RestHelper.hideSensitiveDataFromApiVersionBean(retrieved);
}
@Override
@@ -113,11 +111,12 @@ public class DeveloperPortalResourceImpl implements IDeveloperPortalResource {
.build();
}
- private void apiVersionMustBeExposedInPortal(String orgId, String apiId, String apiVersion) {
+ private ApiVersionBean apiVersionMustBeExposedInPortal(String orgId, String apiId, String apiVersion) {
ApiVersionBean retrieved = apiService.getApiVersion(orgId, apiId, apiVersion);
if (!retrieved.isExposeInPortal()) {
throw ExceptionFactory.apiVersionNotFoundException(apiId, apiVersion);
}
+ return retrieved;
}
private void mustBeLoggedIn() {

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/DeveloperResourceImpl.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/DeveloperResourceImpl.java
@@ -33,6 +33,7 @@ import io.apiman.manager.api.rest.exceptions.InvalidNameException;
import io.apiman.manager.api.rest.exceptions.NotAuthorizedException;
import io.apiman.manager.api.rest.exceptions.util.ExceptionFactory;
import io.apiman.manager.api.rest.impl.util.DataAccessUtilMixin;
+import io.apiman.manager.api.rest.impl.util.RestHelper;
import io.apiman.manager.api.security.ISecurityContext;
import io.apiman.manager.api.service.ApiService;
import io.apiman.manager.api.service.ApiService.ApiDefinitionStream;
@@ -178,7 +179,7 @@ public class DeveloperResourceImpl implements IDeveloperResource, DataAccessUtil
List<ContractSummaryBean> contracts = getAllClientContracts(id);
for (ContractSummaryBean contract : contracts) {
ApiVersionBean apiVersion = apiService.getApiVersion(contract.getApiOrganizationId(), contract.getApiId(), contract.getApiVersion());
- apiVersionBeans.add(apiVersion);
+ apiVersionBeans.add(RestHelper.hideSensitiveDataFromApiVersionBean(apiVersion));
}
return apiVersionBeans;
}

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java
@@ -583,7 +583,13 @@ public class OrganizationResourceImpl implements IOrganizationResource, DataAcce
public ApiVersionBean getApiVersion(String organizationId, String apiId, String version)
throws ApiVersionNotFoundException {
// No permission check is needed, because this would break All APIs UI
- return apiService.getApiVersion(organizationId, apiId, version);
+ ApiVersionBean apiVersion = apiService.getApiVersion(organizationId, apiId, version);
+ if (securityContext.hasPermission(PermissionType.apiView, organizationId)) {
+ apiService.decryptEndpointProperties(apiVersion);
+ return apiVersion;
+ } else {
+ return RestHelper.hideSensitiveDataFromApiVersionBean(apiVersion);
+ }
}
@Override

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ApiService.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ApiService.java
@@ -483,16 +483,7 @@ public class ApiService implements DataAccessUtilMixin {
public ApiVersionBean getApiVersion(String organizationId, String apiId, String version)
throws ApiVersionNotFoundException {
// No permission check is needed, because this would break All APIs UI
- return tryAction(() -> {
- ApiVersionBean apiVersion = getApiVersionFromStorage(organizationId, apiId, version);
-
- if (securityContext.hasPermission(PermissionType.apiView, organizationId)) {
- decryptEndpointProperties(apiVersion);
- return apiVersion;
- } else {
- return RestHelper.hideSensitiveDataFromApiVersionBean(apiVersion);
- }
- });
+ return tryAction(() -> getApiVersionFromStorage(organizationId, apiId, version));
}
public ApiVersionStatusBean getApiVersionStatus(String organizationId, String apiId,
@@ -1030,7 +1021,7 @@ public class ApiService implements DataAccessUtilMixin {
/**
* Decrypt the endpoint properties
*/
- private void decryptEndpointProperties(ApiVersionBean versionBean) {
+ public void decryptEndpointProperties(ApiVersionBean versionBean) {
Map<String, String> endpointProperties = versionBean.getEndpointProperties();
if (endpointProperties != null) {
for (Entry<String, String> entry : endpointProperties.entrySet()) {

fix(manager-api-jpa): JPA syntax error in tags retrieval

- Also fix DDL tag+value issues & fix dev portal endpoint