Skip to content

Commit 3c53605

Browse files
committed
3ed set of required changes
1 parent 877f9d6 commit 3c53605

File tree

4 files changed

+77
-19
lines changed

4 files changed

+77
-19
lines changed

Diff for: components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@
171171
import org.wso2.carbon.apimgt.impl.utils.APIProductNameComparator;
172172
import org.wso2.carbon.apimgt.impl.utils.APIStoreNameComparator;
173173
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
174-
import org.wso2.carbon.apimgt.impl.utils.NewDevPortalHandler;
175174
import org.wso2.carbon.apimgt.impl.utils.APIVersionStringComparator;
176175
import org.wso2.carbon.apimgt.impl.utils.LifeCycleUtils;
177176
import org.wso2.carbon.apimgt.impl.utils.SimpleContentSearchResultNameComparator;
@@ -1059,8 +1058,9 @@ public API updateAPI(API api, API existingAPI) throws APIManagementException {
10591058
}
10601059

10611060
// Update API in new Dev Portal
1062-
if (NewDevPortalHandler.isNewPortalEnabled() && APIConstants.PUBLISHED.equals(api.getStatus())) {
1063-
NewDevPortalHandler.update(organization, new ApiTypeWrapper(api));
1061+
NewDevPortalHandler devPortalHandler = NewDevPortalHandlerImpl.getInstance();
1062+
if (devPortalHandler.isNewPortalEnabled() && APIConstants.PUBLISHED.equals(api.getStatus())) {
1063+
devPortalHandler.update(organization, new ApiTypeWrapper(api));
10641064
}
10651065

10661066
return api;
@@ -2667,8 +2667,9 @@ public void deleteAPI(String apiUuid, String organization) throws APIManagementE
26672667
}
26682668

26692669
// Delete from new Developer Portal
2670-
if (NewDevPortalHandler.isNewPortalEnabled()) {
2671-
NewDevPortalHandler.unpublish(organization, api);
2670+
NewDevPortalHandler devPortalHandler = NewDevPortalHandlerImpl.getInstance();
2671+
if (devPortalHandler.isNewPortalEnabled()) {
2672+
devPortalHandler.unpublish(organization, api);
26722673
}
26732674
} catch (APIManagementException e) {
26742675
log.error("Error while executing API delete operation on external API stores for API "
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.apimgt.impl;
20+
21+
import org.wso2.carbon.apimgt.api.model.ApiTypeWrapper;
22+
import org.wso2.carbon.apimgt.api.model.API;
23+
import org.wso2.carbon.apimgt.api.APIManagementException;
24+
25+
/**
26+
* This interface used to handle newly introduced 2025 version of Developer Portal's configuration with APIM.
27+
*/
28+
public interface NewDevPortalHandler {
29+
30+
boolean isNewPortalEnabled();
31+
32+
void publish(String tenantName, ApiTypeWrapper apiTypeWrapper) throws APIManagementException;
33+
34+
void update(String tenantName, ApiTypeWrapper apiTypeWrapper) throws APIManagementException;
35+
36+
void unpublish(String tenantName, API api) throws APIManagementException;
37+
}

Diff for: components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/NewDevPortalHandler.java renamed to components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/NewDevPortalHandlerImpl.java

+27-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* under the License.
1717
*/
1818

19-
package org.wso2.carbon.apimgt.impl.utils;
19+
package org.wso2.carbon.apimgt.impl;
2020

2121
import com.fasterxml.jackson.core.type.TypeReference;
2222
import org.apache.commons.lang3.StringUtils;
@@ -32,9 +32,6 @@
3232
import org.apache.http.ssl.SSLContexts;
3333
import org.apache.http.util.EntityUtils;
3434
import org.wso2.carbon.apimgt.api.APIConsumer;
35-
import org.wso2.carbon.apimgt.impl.APIConstants;
36-
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
37-
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
3835
import org.wso2.carbon.apimgt.impl.dao.constants.DevPortalProcessingConstants;
3936
import org.wso2.carbon.apimgt.api.APIManagementException;
4037
import org.wso2.carbon.apimgt.api.model.API;
@@ -60,11 +57,27 @@
6057
/**
6158
* This class used to handle newly introduced 2025 version of Developer Portal's configuration with APIM.
6259
*/
63-
public class NewDevPortalHandler {
64-
private static final Log log = LogFactory.getLog(NewDevPortalHandler.class);
60+
public class NewDevPortalHandlerImpl implements NewDevPortalHandler {
61+
62+
private static final Log log = LogFactory.getLog(NewDevPortalHandlerImpl.class);
6563
private static final String baseUrl = getNewPortalURL();
6664
private static final ObjectMapper objectMapper = new ObjectMapper();
6765
private static final Map<String, String> orgIdCache = new ConcurrentHashMap<>();
66+
private static volatile NewDevPortalHandlerImpl instance;
67+
68+
private NewDevPortalHandlerImpl() {}
69+
70+
public static NewDevPortalHandlerImpl getInstance() {
71+
if (instance == null) {
72+
synchronized (NewDevPortalHandlerImpl.class) {
73+
if (instance == null) {
74+
instance = new NewDevPortalHandlerImpl();
75+
}
76+
}
77+
}
78+
return instance;
79+
}
80+
6881

6982
private static class HttpResponseData {
7083
private final int statusCode;
@@ -84,11 +97,13 @@ private String getResponseBody() {
8497
}
8598
}
8699

87-
public static boolean isNewPortalEnabled() {
100+
@Override
101+
public boolean isNewPortalEnabled() {
88102
return Boolean.parseBoolean(getConfigProperty(APIConstants.API_STORE_NEW_PORTAL_ENABLED, "false"));
89103
}
90104

91-
public static void publish(String tenantName, ApiTypeWrapper apiTypeWrapper) {
105+
@Override
106+
public void publish(String tenantName, ApiTypeWrapper apiTypeWrapper) {
92107
try {
93108
SSLConnectionSocketFactory sslsf = generateSSLSF();
94109
publishAPI(apiTypeWrapper, tenantName, sslsf);
@@ -97,7 +112,8 @@ public static void publish(String tenantName, ApiTypeWrapper apiTypeWrapper) {
97112
}
98113
}
99114

100-
public static void update(String tenantName, ApiTypeWrapper apiTypeWrapper) {
115+
@Override
116+
public void update(String tenantName, ApiTypeWrapper apiTypeWrapper) {
101117
try {
102118
SSLConnectionSocketFactory sslsf = generateSSLSF();
103119
updateAPI(apiTypeWrapper, tenantName, sslsf);
@@ -106,7 +122,8 @@ public static void update(String tenantName, ApiTypeWrapper apiTypeWrapper) {
106122
}
107123
}
108124

109-
public static void unpublish(String tenantName, API api) {
125+
@Override
126+
public void unpublish(String tenantName, API api) {
110127
try {
111128
SSLConnectionSocketFactory sslsf = generateSSLSF();
112129
unpublishAPI(api, tenantName, sslsf);

Diff for: components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/LifeCycleUtils.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.wso2.carbon.apimgt.api.ExceptionCodes;
1010
import org.wso2.carbon.apimgt.api.model.*;
1111
import org.wso2.carbon.apimgt.impl.APIConstants;
12+
import org.wso2.carbon.apimgt.impl.NewDevPortalHandler;
13+
import org.wso2.carbon.apimgt.impl.NewDevPortalHandlerImpl;
1214
import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;
1315
import org.wso2.carbon.apimgt.impl.factory.PersistenceFactory;
1416
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
@@ -74,16 +76,17 @@ public static void changeLifecycle(String user, APIProvider apiProvider, String
7476
sendEmailNotification(apiTypeWrapper, orgId);
7577
}
7678

79+
NewDevPortalHandler devPortalHandler = NewDevPortalHandlerImpl.getInstance();
7780
// Next Gen Dev Portal Publication
7881
if (Arrays.asList(APIConstants.PUBLISH, APIConstants.REPUBLISH).contains(action)
79-
&& NewDevPortalHandler.isNewPortalEnabled()) {
80-
NewDevPortalHandler.publish(orgId, apiTypeWrapper);
82+
&& devPortalHandler.isNewPortalEnabled()) {
83+
devPortalHandler.publish(orgId, apiTypeWrapper);
8184
}
8285

8386
// Next Gen Dev Portal Un-Publication
8487
if (Arrays.asList(APIConstants.DEPRECATE, APIConstants.BLOCK, APIConstants.DEMOTE_TO_CREATED).contains(action)
85-
&& NewDevPortalHandler.isNewPortalEnabled()) {
86-
NewDevPortalHandler.unpublish(orgId, apiTypeWrapper.getApi());
88+
&& devPortalHandler.isNewPortalEnabled()) {
89+
devPortalHandler.unpublish(orgId, apiTypeWrapper.getApi());
8790
}
8891

8992
// Change the lifecycle state in the database

0 commit comments

Comments
 (0)