Skip to content

Commit 4d30fd1

Browse files
committed
Fix issue with displayName being empty
1 parent 7531948 commit 4d30fd1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ public static API fromDTOtoAPI(APIDTO dto, String provider) throws APIManagement
226226
context = updateContextWithVersion(dto.getVersion(), originalContext, context);
227227
model.setContext(context);
228228
model.setDescription(dto.getDescription());
229-
model.setDisplayName(dto.getDisplayName());
229+
model.setDisplayName((dto.getDisplayName() != null && !dto.getDisplayName().trim().isEmpty())
230+
? dto.getDisplayName() : dto.getName());
230231

231232
Object endpointConfig = dto.getEndpointConfig();
232233
if (endpointConfig != null) {
@@ -819,8 +820,10 @@ public static API fromMCPServerDTOtoAPI(MCPServerDTO dto, String provider) throw
819820
model.getMetadata().put(APIConstants.MCP.PROTOCOL_VERSION_KEY, protocolVersion);
820821
}
821822
String displayName = dto.getDisplayName();
822-
if (displayName != null && !displayName.isEmpty()) {
823+
if (displayName != null && !displayName.trim().isEmpty()) {
823824
model.setDisplayName(displayName);
825+
} else {
826+
model.setDisplayName(dto.getName());
824827
}
825828

826829
try {
@@ -1617,7 +1620,8 @@ public static APIDTO fromAPItoDTO(API model, boolean preserveCredentials,
16171620
}
16181621
APIDTO dto = new APIDTO();
16191622
dto.setName(model.getId().getApiName());
1620-
dto.setDisplayName(model.getDisplayName() != null ? model.getDisplayName() : model.getId().getApiName());
1623+
dto.setDisplayName((model.getDisplayName() != null && !model.getDisplayName().trim().isEmpty())
1624+
? model.getDisplayName() : model.getId().getApiName());
16211625
dto.setVersion(model.getId().getVersion());
16221626
String providerName = model.getId().getProviderName();
16231627
dto.setProvider(APIUtil.replaceEmailDomainBack(providerName));
@@ -3914,6 +3918,8 @@ public static APIProductDTO fromAPIProducttoDTO(APIProduct product, boolean pres
39143918
productDto.setName(product.getId().getName());
39153919
productDto.setDisplayName(
39163920
product.getDisplayName() != null ? product.getDisplayName() : product.getId().getName());
3921+
productDto.setDisplayName((product.getDisplayName() != null && !product.getDisplayName().trim().isEmpty())
3922+
? product.getDisplayName() : product.getId().getName());
39173923
productDto.setProvider(APIUtil.replaceEmailDomainBack(product.getId().getProviderName()));
39183924
productDto.setId(product.getUuid());
39193925
productDto.setVersion(product.getId().getVersion());
@@ -4179,7 +4185,8 @@ public static APIProduct fromDTOtoAPIProduct(APIProductDTO dto, String provider)
41794185
product.setID(id);
41804186
product.setUuid(dto.getId());
41814187
product.setDescription(dto.getDescription());
4182-
product.setDisplayName(dto.getDisplayName() != null ? dto.getDisplayName() : dto.getName());
4188+
product.setDisplayName((dto.getDisplayName() != null && !dto.getDisplayName().trim().isEmpty())
4189+
? dto.getDisplayName() : dto.getName());
41834190

41844191
String context = dto.getContext();
41854192
final String originalContext = context;

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,9 @@ private static API prepareForUpdateApi(API originalAPI, APIDTO apiDtoToUpdate, A
909909
}
910910
apiToUpdate.setWsdlUrl(apiDtoToUpdate.getWsdlUrl());
911911
apiToUpdate.setGatewayType(apiDtoToUpdate.getGatewayType());
912-
apiToUpdate.setDisplayName(apiDtoToUpdate.getDisplayName());
912+
apiToUpdate.setDisplayName((apiDtoToUpdate.getDisplayName() != null
913+
&& !apiDtoToUpdate.getDisplayName().trim().isEmpty()) ? apiDtoToUpdate.getDisplayName()
914+
: apiDtoToUpdate.getName());
913915

914916
//validate API categories
915917
List<APICategory> apiCategories = apiToUpdate.getApiCategories();
@@ -1108,7 +1110,9 @@ public static API prepareForUpdateApi(API originalAPI, MCPServerDTO apiDtoToUpda
11081110
SwaggerData swaggerData = new SwaggerData(apiToUpdate);
11091111
String definitionToAdd = new OAS3Parser().generateAPIDefinition(swaggerData);
11101112
apiToUpdate.setSwaggerDefinition(definitionToAdd);
1111-
apiToUpdate.setDisplayName(apiDtoToUpdate.getDisplayName());
1113+
apiToUpdate.setDisplayName((apiDtoToUpdate.getDisplayName() != null
1114+
&& !apiDtoToUpdate.getDisplayName().trim().isEmpty()) ? apiDtoToUpdate.getDisplayName()
1115+
: apiDtoToUpdate.getName());
11121116

11131117
apiToUpdate.setOrganization(originalAPI.getOrganization());
11141118
apiToUpdate.setSubtype(originalAPI.getSubtype());
@@ -2935,7 +2939,6 @@ public static API prepareToCreateAPIByDTO(APIDTOTypeWrapper apiDtoTypeWrapper, A
29352939
api.setSubtype(apiDtoTypeWrapper.getResolvedApiSubtype());
29362940
api.setAiConfiguration(apiDtoTypeWrapper.getAiConfiguration());
29372941
api.setInitiatedFromGateway(apiDtoTypeWrapper.getInitiatedFromGateway());
2938-
api.setDisplayName(apiDtoTypeWrapper.getDisplayName());
29392942
if (apiDtoTypeWrapper.isMCPServerDTO()) {
29402943
String protocolVersion = apiDtoTypeWrapper.getProtocolVersion();
29412944
api.getMetadata().put(APIConstants.MCP.PROTOCOL_VERSION_KEY,

0 commit comments

Comments
 (0)