Skip to content

Commit

Permalink
Implement Labels Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dakshina99 committed Jan 26, 2025
1 parent 364ea98 commit 8b7c9dc
Show file tree
Hide file tree
Showing 56 changed files with 3,520 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -266,6 +268,53 @@ 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 labelID label ID to update
* @param updateLabelBody label data to update
* @param tenantDomain tenant domain
* @throws APIManagementException if failed update label
*/
Label updateLabel(String labelID, Label updateLabelBody, String tenantDomain) throws APIManagementException;

/**
* Delete a label
*
* @param labelID label ID to delete
* @param tenantDomain tenant domain
* @throws APIManagementException if failed delete label
*/
void deleteLabel(String labelID, String tenantDomain) throws APIManagementException;

/**
* Returns all labels of the tenant
*
* @param tenantDomain tenant domain
* @return List<Label> list of Label objects
* @throws APIManagementException if failed to get labels
*/
List<Label> getAllLabelsOfTenant(String tenantDomain) throws APIManagementException;

/**
* Get mapped APIs for the given label
*
* @param labelID label UUID
* @param tenantDomain tenant domain
* @return List<ApiResult> list of ApiResult objects
* @throws APIManagementException
*/
List<ApiResult> getMappedApisForLabel(String labelID, String tenantDomain) throws APIManagementException;

/**
* The method converts the date into timestamp
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,46 @@ EnvironmentPropertiesDTO getEnvironmentSpecificAPIProperties(String apiUuid, Str
*/
Environment getEnvironment(String organization, String uuid) throws APIManagementException;

/**
* Returns all labels of the tenant
*
* @param tenantDomain tenant domain
* @return List<Label> list of Label objects
* @throws APIManagementException if failed to get labels
*/
List<Label> getAllLabels(String tenantDomain) throws APIManagementException;

/**
* Returns all attached labels of the API
*
* @param apiID API UUID
* @return List<Label> list of Label objects
* @throws APIManagementException if failed to get labels
*/
List<Label> getAllLabelsOfApi(String apiID) throws APIManagementException;

/**
* Attach labels to an API
*
* @param apiID API UUID
* @param labelList List of Labels
* @param tenantDomain Tenant domain
* @return List<Label> list of Label objects
* @throws APIManagementException if failed to get labels
*/
List<Label> attachApiLabels(String apiID, List<Label> labelList, String tenantDomain) throws APIManagementException;

/**
* Detach labels from an API
*
* @param apiID API UUID
* @param labelList List of Labels
* @param tenantDomain Tenant domain
* @return List<Label> list of Label objects
* @throws APIManagementException if failed to get labels
*/
List<Label> detachApiLabels(String apiID, List<Label> labelList, String tenantDomain) throws APIManagementException;

/**
* Set existing operation policy mapping to the URI Templates
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,13 @@ public enum ExceptionCodes implements ErrorHandler {


// Labels related codes
LABEL_INFORMATION_CANNOT_BE_NULL(900650, "Label information cannot be null", 400, "Label information cannot be " +
"null"),
LABEL_EXCEPTION(900651, "Label Error", 500, "Error occurred while retrieving label information"),
LABEL_NOT_FOUND(900652, "Label Not Found", 404, "Label with specified name cannot be found."),
LABEL_NOT_FOUND_IN_API(900653, "Label Not Found In API", 404, "Label with specified name"
+ " cannot be found in the API."),
LABEL_ADDING_FAILED(900654, "Label Error", 500, "Error occurred while trying to add label"),
LABEL_UPDATE_FAILED(900655, "Label Error", 500, "Error occurred while trying to update label"),
LABEL_DELETION_FAILED(900656, "Label Error", 500, "Error occurred while trying to delete label"),

LABEL_NAME_ALREADY_EXISTS(900650, "Label Name Already Exists", 409, "Label with name '%s' already exists", false),
LABEL_NOT_FOUND(900651, "Label Not Found", 404, "Label not found for the given label ID: %s", false),
LABEL_ADDING_FAILED(900652, "Failed To Create Label", 400, "Error occurred while trying to add label. %s", false),
LABEL_UPDATE_FAILED(900653, "Failed To Update Label", 400, "Error occurred while trying to update label. %s", false),
LABEL_CANNOT_DELETE_ASSOCIATED(900654, "Label Deletion Failed", 409, "The label cannot be deleted as it is associated with API(s).", false),
LABEL_ATTACHMENT_FAILED(900655, "Label Attachment Failed", 400, "Error occurred while attaching label(s) to API. %s", false),
LABEL_DETACHMENT_FAILED(900656, "Label Detachment Failed", 400, "Error occurred while detaching label(s) from API. %s", false),

//WSDL related codes
INVALID_WSDL_URL_EXCEPTION(900675, "Invalid WSDL", 400, "Invalid WSDL URL"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.apimgt.api.model;


import java.util.Objects;

/**
* This class represents the API result object.
*/
public class ApiResult {

private String provider = null;
private String name = null;
private String version = null;
private String id = null;

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}

public String getProvider() {
return provider;
}
public void setProvider(String provider) {
this.provider = provider;
}

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (this == obj) return true;
ApiResult other = (ApiResult) obj;
if (!Objects.equals(this.id, other.id)) return false;
if (!Objects.equals(this.name, other.name)) return false;
if (!Objects.equals(this.version, other.version)) return false;
if (!Objects.equals(this.provider, other.provider)) return false;
return true;
}

public int hashCode() {
return Objects.hash(super.hashCode(), id, name, version, provider);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.wso2.carbon.apimgt.api.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
Expand All @@ -28,9 +26,7 @@
public class Label {
private String labelId;
private String name;
private String tenantId;
private String description;
private List<String> accessUrls = new ArrayList<>();

public Label() {
}
Expand All @@ -51,22 +47,6 @@ public void setName(String name) {
this.name = name;
}

public String getTenantId() {
return tenantId;
}

public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}

public List<String> getAccessUrls() {
return accessUrls;
}

public void setAccessUrls(List<String> accessUrls) {
this.accessUrls = accessUrls;
}

public String getDescription() {
return description;
}
Expand All @@ -83,12 +63,10 @@ public boolean equals(Object obj) {
if (!Objects.equals(this.name, other.name)) return false;
if (!Objects.equals(this.labelId, other.labelId)) return false;
if (!Objects.equals(this.description, other.description)) return false;
if (!Objects.equals(this.tenantId, other.tenantId)) return false;
if (!Objects.equals(this.accessUrls, other.accessUrls)) return false;
return true;
}

public int hashCode() {
return Objects.hash(super.hashCode(), labelId, name, tenantId, description, accessUrls);
return Objects.hash(super.hashCode(), labelId, name, description);
}
}
Loading

0 comments on commit 8b7c9dc

Please sign in to comment.