From 442a3c865c07d2061589f44d1c3b94b33f48ff79 Mon Sep 17 00:00:00 2001 From: dakshina Date: Sun, 12 Jan 2025 11:47:34 +0530 Subject: [PATCH] Implement Labels Feature --- .../org/wso2/carbon/apimgt/api/APIAdmin.java | 71 ++++ .../carbon/apimgt/api/ExceptionCodes.java | 2 + .../org/wso2/carbon/apimgt/api/model/API.java | 10 + .../carbon/apimgt/api/model/APIProduct.java | 9 + .../carbon/apimgt/api/model/ApiResult.java | 78 ++++ .../wso2/carbon/apimgt/api/model/Label.java | 36 +- .../wso2/carbon/apimgt/impl/APIAdminImpl.java | 40 ++ .../wso2/carbon/apimgt/impl/APIConstants.java | 1 + .../carbon/apimgt/impl/APIConsumerImpl.java | 75 ++-- .../carbon/apimgt/impl/APIProviderImpl.java | 7 + .../carbon/apimgt/impl/dao/ApiMgtDAO.java | 369 ++++++++++++++++++ .../impl/dao/constants/SQLConstants.java | 44 +++ .../carbon/apimgt/impl/utils/APIUtil.java | 35 ++ .../src/test/resources/dbscripts/h2.sql | 18 + .../apimgt/persistence/dto/PublisherAPI.java | 13 +- .../persistence/dto/PublisherAPIProduct.java | 9 + .../RegistryPersistenceUtilTestCase.java | 5 - .../apimgt/rest/api/admin/v1/LabelsApi.java | 122 ++++++ .../rest/api/admin/v1/LabelsApiService.java | 31 ++ .../rest/api/admin/v1/dto/LabelDTO.java | 122 ++++++ .../rest/api/admin/v1/dto/LabelListDTO.java | 129 ++++++ .../api/admin/v1/dto/LabelUsageApisDTO.java | 110 ++++++ .../rest/api/admin/v1/dto/LabelUsageDTO.java | 83 ++++ .../admin/v1/impl/LabelsApiServiceImpl.java | 200 ++++++++++ .../v1/utils/mappings/LabelMappingUtil.java | 96 +++++ .../mappings/LabelsUsageMappingUtil.java | 77 ++++ .../src/main/resources/admin-api.yaml | 221 +++++++++++ .../src/main/webapp/WEB-INF/beans.xml | 1 + .../src/main/webapp/WEB-INF/web.xml | 3 +- .../rest/api/common/RestApiConstants.java | 2 + .../src/main/resources/admin-api.yaml | 221 +++++++++++ .../src/main/resources/publisher-api.yaml | 77 ++++ .../rest/api/publisher/v1/dto/APIDTO.java | 26 +- .../api/publisher/v1/dto/APIProductDTO.java | 26 +- .../rest/api/publisher/v1/dto/LabelDTO.java | 122 ++++++ .../api/publisher/v1/dto/LabelListDTO.java | 107 +++++ .../v1/common/mappings/APIMappingUtil.java | 12 + .../v1/common/mappings/LabelMappingUtil.java | 87 +++++ .../common/mappings/PublisherCommonUtils.java | 19 + .../rest/api/publisher/v1/LabelsApi.java | 53 +++ .../api/publisher/v1/LabelsApiService.java | 24 ++ .../v1/impl/LabelsApiServiceImpl.java | 54 +++ .../src/main/resources/publisher-api.yaml | 77 ++++ .../src/main/webapp/WEB-INF/beans.xml | 1 + .../src/main/webapp/WEB-INF/web.xml | 3 +- .../multi-dc/OGG/oracle/apimgt/tables.sql | 18 + .../multi-dc/OGG/oracle/apimgt/tables_23c.sql | 18 + .../multi-dc/Postgresql/apimgt/tables.sql | 22 +- .../SQLServer/mssql/apimgt/tables.sql | 18 + .../src/main/resources/sql/db2.sql | 18 + .../src/main/resources/sql/h2.sql | 18 + .../src/main/resources/sql/mssql.sql | 19 + .../src/main/resources/sql/mysql.sql | 18 + .../src/main/resources/sql/mysql_cluster.sql | 18 + .../src/main/resources/sql/oracle.sql | 20 + .../src/main/resources/sql/oracle_23c.sql | 20 + .../src/main/resources/sql/oracle_rac.sql | 20 + .../src/main/resources/sql/postgresql.sql | 20 + .../src/main/resources/sql/h2.sql | 18 + 59 files changed, 3125 insertions(+), 68 deletions(-) create mode 100644 components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/ApiResult.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/LabelsApi.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/LabelsApiService.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/LabelDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/LabelListDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/LabelUsageApisDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/LabelUsageDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/LabelsApiServiceImpl.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/LabelMappingUtil.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/LabelsUsageMappingUtil.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/LabelDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/LabelListDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/LabelMappingUtil.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/LabelsApi.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/LabelsApiService.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/LabelsApiServiceImpl.java diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java index 8d06ba4e1ed2..687cbcbbafc8 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIAdmin.java @@ -20,10 +20,12 @@ import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO; import org.wso2.carbon.apimgt.api.dto.KeyManagerPermissionConfigurationDTO; import org.wso2.carbon.apimgt.api.model.APICategory; +import org.wso2.carbon.apimgt.api.model.ApiResult; import org.wso2.carbon.apimgt.api.model.Application; import org.wso2.carbon.apimgt.api.model.ApplicationInfo; import org.wso2.carbon.apimgt.api.model.Environment; import org.wso2.carbon.apimgt.api.model.LLMProvider; +import org.wso2.carbon.apimgt.api.model.Label; import org.wso2.carbon.apimgt.api.model.Monetization; import org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo; import org.wso2.carbon.apimgt.api.model.Workflow; @@ -266,6 +268,75 @@ void updateMonetizationUsagePublishInfo(MonetizationUsagePublishInfo monetizatio */ APICategory getAPICategoryByID(String apiCategoryId) throws APIManagementException; + /** + * Adds a new label for the tenant + * + * @param label label to add + * @param tenantDomain tenant domain + * @throws APIManagementException if failed add label + */ + Label addLabel(Label label, String tenantDomain) throws APIManagementException; + + /** + * Updates a label + * + * @param label label to update + * @throws APIManagementException if failed update label + */ + void updateLabel(Label label) throws APIManagementException; + + /** + * Delete a label + * + * @param labelID label ID to delete + * @throws APIManagementException if failed delete label + */ + void deleteLabel(String labelID) throws APIManagementException; + + /** + * Checks whether a label exists by the given name + * + * 1. in case uuid is null : checks whether the labelName is already taken in the tenantDomain for the given type + * (this flow is used when adding a new label) + * 2. in case uuid is not null: checks whether the labelName is already taken by any label other than the one + * defined by the passed uuid in the given tenant and type + * + * @param labelName label name to check + * @param type label type + * @param uuid label UUID + * @param tenantDomain tenant domain + * @return true if a label exists by the given label name + * @throws APIManagementException if failed + */ + boolean isLabelNameExists(String labelName, String type, String uuid, String tenantDomain) throws APIManagementException; + + /** + * Returns all labels of the tenant + * + * @param tenantDomain tenant domain + * @return List