Skip to content

Commit

Permalink
Fix: Checkstyle Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BLasan committed Sep 14, 2024
1 parent 5be42ca commit 3a6e34f
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public interface APIProvider extends APIManager {
Comment getComment(ApiTypeWrapper apiTypeWrapper, String commentId, Integer replyLimit, Integer replyOffset) throws
APIManagementException;

void deleteCustomBackendByID(String backendUUID, String apiUUID, String type) throws APIManagementException;
void deleteCustomBackendByID(String apiUUID, String type) throws APIManagementException;
void deleteCustomBackendByAPIID(String apiUUID) throws APIManagementException;

/**
Expand Down Expand Up @@ -327,7 +327,9 @@ Map<String, Object> getCustomBackendOfAPIByUUID(String customBackendUUID, String

String getCustomBackendSequenceOfAPIByUUID(String apiUUID, String type) throws APIManagementException;

CustomBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException;
SequenceBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException;

List<SequenceBackendData> getAllSequenceBackendsByAPIUUID(String apiUUID) throws APIManagementException;

/**
* Create a new version of the <code>api</code>, with version <code>newVersion</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ public enum ExceptionCodes implements ErrorHandler {
"Required attributes(s) %s for api policy specification %s are either missing or empty"),
OPERATION_POLICY_NOT_FOUND(902010, "API Policy Not Found", 404,
"Requested api policy with id '%s' not found"),
CUSTOM_BACKEND_NOT_FOUND(903250, "Custom Backend not found",
404, "Requested Custom Backend with id '%s' not found"),
CUSTOM_BACKEND_NOT_FOUND(903250, "Sequence Backend not found",
404, "Requested Sequence Backend of API '%s' not found"),

OPERATION_POLICY_ALREADY_EXISTS(903001, "The API Policy already exists.", 409, "An Operation Policy with name '%s' and version '%s' already exists"),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.wso2.carbon.apimgt.api.model;

public class CustomBackendData {
public class SequenceBackendData {
private String Id;
private String sequence;
private String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
import org.wso2.carbon.apimgt.api.model.BlockConditionsDTO;
import org.wso2.carbon.apimgt.api.model.Comment;
import org.wso2.carbon.apimgt.api.model.CommentList;
import org.wso2.carbon.apimgt.api.model.CustomBackendData;
import org.wso2.carbon.apimgt.api.model.SequenceBackendData;
import org.wso2.carbon.apimgt.api.model.DeployedAPIRevision;
import org.wso2.carbon.apimgt.api.model.Documentation;
import org.wso2.carbon.apimgt.api.model.Documentation.DocumentSourceType;
Expand Down Expand Up @@ -1061,18 +1061,21 @@ public String getCustomBackendSequenceOfAPIByUUID(String apiUUID, String type)
}

@Override
public CustomBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException {
public SequenceBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException {
return apiMgtDAO.getCustomBackendByAPIUUID(apiUUID, type);
}

public List<SequenceBackendData> getAllSequenceBackendsByAPIUUID(String apiUUID) throws APIManagementException {
return apiMgtDAO.getSequenceBackendsByAPIUUID(apiUUID);
}

@Override
public void deleteCustomBackendByAPIID(String apiUUID) throws APIManagementException {
apiMgtDAO.deleteCustomBackendByAPIID(apiUUID);
}
@Override
public void deleteCustomBackendByID(String backendUUID, String apiUUID, String type)
throws APIManagementException {
apiMgtDAO.deleteCustomBackend(apiUUID, backendUUID, type);
public void deleteCustomBackendByID(String apiUUID, String type) throws APIManagementException {
apiMgtDAO.deleteCustomBackend(apiUUID, type);
}

private void validateKeyManagers(API api) throws APIManagementException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import org.wso2.carbon.apimgt.api.model.BlockConditionsDTO;
import org.wso2.carbon.apimgt.api.model.Comment;
import org.wso2.carbon.apimgt.api.model.CommentList;
import org.wso2.carbon.apimgt.api.model.CustomBackendData;
import org.wso2.carbon.apimgt.api.model.SequenceBackendData;
import org.wso2.carbon.apimgt.api.model.DeployedAPIRevision;
import org.wso2.carbon.apimgt.api.model.Environment;
import org.wso2.carbon.apimgt.api.model.GatewayPolicyData;
Expand Down Expand Up @@ -11194,27 +11194,49 @@ public Map<String, Object> retrieveCustomBackendOfAPIRevision(String apiUUID, St
return map;
}

public CustomBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException {
public SequenceBackendData getCustomBackendByAPIUUID(String apiUUID, String type) throws APIManagementException {
String sqlQuery = SQLConstants.CustomBackendConstants.GET_API_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID;
CustomBackendData customBackendData = null;
SequenceBackendData sequenceBackendData = null;
try (Connection con = APIMgtDBUtil.getConnection(); PreparedStatement ps = con.prepareStatement(sqlQuery)) {
ps.setString(1, apiUUID);
ps.setString(2, type);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
customBackendData = new CustomBackendData();
customBackendData.setApiUUID(apiUUID);
customBackendData.setRevisionUUID("0");
customBackendData.setSequence(IOUtils.toString(rs.getBinaryStream("SEQUENCE")));
customBackendData.setId(rs.getString("ID"));
customBackendData.setName(rs.getString("NAME"));
customBackendData.setType(type);
sequenceBackendData = new SequenceBackendData();
sequenceBackendData.setApiUUID(apiUUID);
sequenceBackendData.setRevisionUUID("0");
sequenceBackendData.setSequence(IOUtils.toString(rs.getBinaryStream("SEQUENCE")));
sequenceBackendData.setId(rs.getString("ID"));
sequenceBackendData.setName(rs.getString("NAME"));
sequenceBackendData.setType(type);
}
}
} catch (SQLException | IOException ex) {
handleException("Error when fetching Custom Backend data for API: " + apiUUID, ex);
}
return customBackendData;
return sequenceBackendData;
}

public List<SequenceBackendData> getSequenceBackendsByAPIUUID(String apiUUID) throws APIManagementException {
String sqlQuery = SQLConstants.CustomBackendConstants.GET_ALL_API_SPECIFIC_CUSTOM_BACKENDS;
List<SequenceBackendData> backendDataList = new ArrayList<>();
try (Connection con = APIMgtDBUtil.getConnection(); PreparedStatement ps = con.prepareStatement(sqlQuery)) {
ps.setString(1, apiUUID);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
SequenceBackendData sqBackend = new SequenceBackendData();
sqBackend.setApiUUID(apiUUID);
sqBackend.setId(rs.getString("ID"));
sqBackend.setName(rs.getString("NAME"));
sqBackend.setType(rs.getString("TYPE"));
backendDataList.add(sqBackend);
}
}
return backendDataList;
} catch (SQLException ex) {
handleException("Error when retrieving Sequence Backends of API: " + apiUUID, ex);
}
return null;
}

public String getCustomBackendSequenceOfAPIByUUID(String apiUUID, String type) throws APIManagementException {
Expand Down Expand Up @@ -20919,14 +20941,13 @@ public void updateCustomBackend(String apiUUID, String sequenceName, InputStream
}
}

public void deleteCustomBackend(String apiUUID, String type, String backendUUID) throws APIManagementException {
public void deleteCustomBackend(String apiUUID, String type) throws APIManagementException {
String deleteCustomBackedQuery = SQLConstants.CustomBackendConstants.DELETE_CUSTOM_BACKEND;
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement prepStmt = connection.prepareStatement(deleteCustomBackedQuery)) {
connection.setAutoCommit(false);
prepStmt.setString(1, apiUUID);
prepStmt.setString(2, backendUUID);
prepStmt.setString(3, type);
prepStmt.setString(2, type);
prepStmt.executeUpdate();
connection.commit();
} catch (SQLException e) {
Expand Down Expand Up @@ -21210,7 +21231,7 @@ private void revisionCustomBackend(APIRevision apiRevision, Connection connectio
PreparedStatement addPstmt = connection.prepareStatement(addCBSqlQuery)) {
connection.setAutoCommit(false);
getPstmt.setString(1, apiRevision.getApiUUID());
List<CustomBackendData> customBackendDataList = new ArrayList<>();
List<SequenceBackendData> sequenceBackendDataList = new ArrayList<>();
int count = 0;

try (ResultSet rs = getPstmt.executeQuery()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4406,20 +4406,15 @@ public static class CustomBackendConstants {
"INSERT INTO AM_API_CUSTOM_BACKEND (ID,API_UUID,SEQUENCE,TYPE,REVISION_UUID,NAME) "
+ "VALUES (?,?,?,?,?,?)";
public static final String DELETE_WORKING_COPY_OF_CUSTOM_BACKEND = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND REVISION_UUID = '0'";
public static final String DELETE_CUSTOM_BACKEND = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND TYPE = ? AND ID = ? AND REVISION_UUID = '0'";
public static final String DELETE_CUSTOM_BACKEND = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND TYPE = ? AND REVISION_UUID = '0'";
public static final String DELETE_CUSTOM_BACKEND_BY_API_AND_TYPE = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND TYPE = ? AND REVISION_UUID = '0'";
public static final String DELETE_CUSTOM_BACKEND_BY_REVISION = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND REVISION_UUID = ?";
public static final String DELETE_CUSTOM_BACKEND_BY_API = "DELETE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ?";
public static final String GET_CUSTOM_BACKEND_OF_API_REVISION = "SELECT ID, NAME, SEQUENCE, TYPE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND REVISION_UUID = ?";
public static final String GET_CUSTOM_BACKEND_OF_API_DEFAULT_REVISION = "SELECT ACB.NAME, ACB.TYPE FROM AM_API_CUSTOM_BACKEND WHERE API_UUID = ? AND REVISION_UUID = '0'";
public static final String GET_REVISION_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND ACB.REVISION_UUID = ? AND ACB.TYPE = ?";
public static final String GET_API_SPECIFIC_CUSTOM_BACKEND_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.API_UUID = ? AND ACB.REVISION_UUID = '0' AND ACB.TYPE = ?";
public static final String GET_CUSTOM_BACKEND_FROM_API_AND_REVISION_UUID = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.API_UUID = ? AND ACB.REVISION_UUID = ? AND ACB.TYPE = ?";
public static final String GET_ALL_API_SPECIFIC_CUSTOM_BACKENDS = "SELECT ACB.ID, ACB.NAME, ACB.SEQUENCE, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.API_UUID = ? AND ACB.REVISION_UUID = '0'";
public static final String GET_REVISION_SPECIFIC_CUSTOM_BACKEND_META_DATA_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND ACB.REVISION_UUID = ?";
public static final String GET_API_SPECIFIC_CUSTOM_BACKEND_META_DATA_FROM_SEQUENCE_ID = "SELECT ACB.ID, ACB.NAME, ACB.TYPE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND API_UUID = ?";
public static final String GET_API_SPECIFIC_CUSTOM_BACKEND_SEQUENCE_FROM_SEQUENCE_ID = "SELECT ACB.SEQUENCE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND API_UUID = ?";
public static final String GET_REVISION_SPECIFIC_CUSTOM_BACKEND_SEQUENCE_FROM_SEQUENCE_ID = "SELECT ACB.SEQUENCE FROM AM_API_CUSTOM_BACKEND ACB WHERE ACB.ID = ? AND ACB.REVISION_UUID = ?";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,16 @@ paths:
get:
tags:
- APIs
summary: Get Custom Backends of the API
description: This operation can be used to get Custom Backend data of the API
summary: Get Sequence Backends of the API
description: This operation can be used to get Sequence Backend data of the API
operationId: getSequenceBackendData
parameters:
- $ref: '#/components/parameters/apiId'
responses:
200:
description: |
OK.
Requested API Custom Backend is returned
Requested API Sequence Backend is returned
headers:
Content-Type:
description: |
Expand Down Expand Up @@ -655,7 +655,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/SequenceBackend'
$ref: '#/components/schemas/API'
400:
$ref: '#/components/responses/BadRequest'
403:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.wso2.carbon.apimgt.api.model.OperationPolicy;
import org.wso2.carbon.apimgt.api.model.ResourcePath;
import org.wso2.carbon.apimgt.api.model.Scope;
import org.wso2.carbon.apimgt.api.model.SequenceBackendData;
import org.wso2.carbon.apimgt.api.model.ServiceEntry;
import org.wso2.carbon.apimgt.api.model.Tier;
import org.wso2.carbon.apimgt.api.model.URITemplate;
Expand Down Expand Up @@ -114,6 +115,8 @@
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePolicyInfoDTO;
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePolicyListDTO;
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO;
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SequenceBackendDTO;
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SequenceBackendListDTO;
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLInfoDTO;
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseDTO;
import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WSDLValidationResponseWsdlInfoDTO;
Expand Down Expand Up @@ -503,6 +506,22 @@ public static MockResponsePayloadInfoDTO fromMockPayloadToDTO(APIResourceMediati
return mockResponsePayloadInfoDTO;
}

public static SequenceBackendListDTO fromSequenceDataToDTO(List<SequenceBackendData> list) {
SequenceBackendListDTO res = new SequenceBackendListDTO();
res.setCount(list.size());
List<SequenceBackendDTO> backends = new ArrayList<>();

for (SequenceBackendData backend : list) {
SequenceBackendDTO dto = new SequenceBackendDTO();
dto.sequenceId(backend.getId());
dto.setSequenceName(backend.getName());
dto.setSequenceType(backend.getType());
backends.add(dto);
}
res.setList(backends);
return res;
}

/**
* This method creates the API monetization information DTO.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.wso2.carbon.apimgt.api.model.APIProductIdentifier;
import org.wso2.carbon.apimgt.api.model.APIRevision;
import org.wso2.carbon.apimgt.api.model.APIRevisionDeployment;
import org.wso2.carbon.apimgt.api.model.CustomBackendData;
import org.wso2.carbon.apimgt.api.model.SequenceBackendData;
import org.wso2.carbon.apimgt.api.model.Documentation;
import org.wso2.carbon.apimgt.api.model.DocumentationContent;
import org.wso2.carbon.apimgt.api.model.Identifier;
Expand Down Expand Up @@ -218,11 +218,10 @@ public static File exportApi(APIProvider apiProvider, APIIdentifier apiIdentifie
addOperationPoliciesToArchive(archivePath, tenantDomain, exportFormat, apiProvider,
api, currentApiUuid);

// TODO: Add Custom Backend to the Archive
JsonObject endpointConfig = JsonParser.parseString(api.getEndpointConfig()).getAsJsonObject();
if (APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(
endpointConfig.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString())) {
addCustomBackendToArchive(archivePath, apiProvider, currentApiUuid, endpointConfig);
addCustomBackendToArchive(archivePath, apiProvider, currentApiUuid);
}

addGatewayEnvironmentsToArchive(archivePath, apiDtoToReturn.getId(), exportFormat, apiProvider);
Expand Down Expand Up @@ -637,20 +636,21 @@ public static void addEndpointCertificatesToArchive(String archivePath, APIDTO a
}
}

public static void addCustomBackendToArchive(String archivePath, APIProvider apiProvider, String apiUUID,
JsonObject endpointConfig) throws APIManagementException {
public static void addCustomBackendToArchive(String archivePath, APIProvider apiProvider, String apiUUID)
throws APIManagementException {
try {
CommonUtil.createDirectory(archivePath + File.separator + ImportExportConstants.CUSTOM_BACKEND_DIRECTORY);

// Add production Backend Sequences
CustomBackendData data = apiProvider.getCustomBackendByAPIUUID(apiUUID, APIConstants.API_KEY_TYPE_PRODUCTION);
if(data != null) {
SequenceBackendData data = apiProvider.getCustomBackendByAPIUUID(apiUUID,
APIConstants.API_KEY_TYPE_PRODUCTION);
if (data != null) {
exportCustomBackend(data.getName(), data.getSequence(), archivePath);
}

// Add sandbox Backend Sequences
data = apiProvider.getCustomBackendByAPIUUID(apiUUID, APIConstants.API_KEY_TYPE_SANDBOX);
if(data != null) {
if (data != null) {
exportCustomBackend(data.getName(), data.getSequence(), archivePath);
}

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

package org.wso2.carbon.apimgt.rest.api.publisher.v1.common.mappings;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -696,7 +695,8 @@ public static void updateAPIWithCustomBackend(API api, String extractedFolderPat
String seqName = APIUtil.getCustomBackendName(api.getUuid(), APIConstants.API_KEY_TYPE_PRODUCTION);
String seqId = UUID.randomUUID().toString();
InputStream seq = APIUtil.getCustomBackendSequence(customBackendDir, seqFile, ".xml");
apiProvider.updateCustomBackend(api.getUuid(), APIConstants.API_KEY_TYPE_PRODUCTION, seq, seqName, seqId);
apiProvider.updateCustomBackend(api.getUuid(), APIConstants.API_KEY_TYPE_PRODUCTION, seq, seqName,
seqId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ public static API updateApi(API originalAPI, APIDTO apiDtoToUpdate, APIProvider
* @param endpointType Endpoint Type of the Custom Backend (SANDBOX, PRODUCTION)
* @param customBackend Custom Backend
* @param contentDecomp Header Content of the Request
* @return Custom Backend File Name
* @throws APIManagementException If an error occurs while updating the API and API definition
*/
public static void updateCustomBackend(API api, APIProvider apiProvider, String endpointType,
Expand Down
Loading

0 comments on commit 3a6e34f

Please sign in to comment.