Source:
<code>public Response addCommentToAPI(String apiId, CommentDTO body, MessageContext messageContext) { String username = RestApiUtil.getLoggedInUsername(); String requestedTenantDomain = RestApiUtil.getLoggedInUserTenantDomain(); try { APIConsumer apiConsumer = RestApiUtil.getLoggedInUserConsumer(); ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, requestedTenantDomain); Comment comment = CommentMappingUtil.fromDTOToComment(body, username, apiId); <START> String createdCommentId = apiConsumer.addComment(apiTypeWrapper, comment, username); <END> Comment createdComment = apiConsumer.getComment(apiTypeWrapper, createdCommentId); CommentDTO commentDTO = CommentMappingUtil.fromCommentToDTO(createdComment); String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS + "/" + createdCommentId; URI uri = new URI(uriString); return Response.created(uri).entity(commentDTO).build(); } catch (APIManagementException e) { if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) { RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log); } else { RestApiUtil.handleInternalServerError("Failed to add comment to the API " + apiId, e, log); } } catch (URISyntaxException e) { String errorMessage = "Error while retrieving comment content location for API " + apiId; RestApiUtil.handleInternalServerError(errorMessage, e, log); } return null; }</code><technical_language>pass Identifier object instead of apiTypeWrapper itself? this PR cleaner. Example: ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, requestedTenantDomain); Identifier identifier; if (apiTypeWrapper.isAPIProduct()) { identifier = apiTypeWrapper.getApiProduct().getId(); } else { identifier = apiTypeWrapper.getApi().getId(); }</technical_language>

Target:
public Response addCommentToAPI(String apiId, CommentDTO body, MessageContext messageContext) { String username = RestApiUtil.getLoggedInUsername(); String requestedTenantDomain = RestApiUtil.getLoggedInUserTenantDomain(); try { APIConsumer apiConsumer = RestApiUtil.getLoggedInUserConsumer(); ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, requestedTenantDomain); Identifier identifier; if (apiTypeWrapper.isAPIProduct()) { identifier = apiTypeWrapper.getApiProduct().getId(); } else { identifier = apiTypeWrapper.getApi().getId(); } Comment comment = CommentMappingUtil.fromDTOToComment(body, username, apiId); String createdCommentId = apiConsumer.addComment(identifier, comment, username); Comment createdComment = apiConsumer.getComment(identifier, createdCommentId); CommentDTO commentDTO = CommentMappingUtil.fromCommentToDTO(createdComment); String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS + "/" + createdCommentId; URI uri = new URI(uriString); return Response.created(uri).entity(commentDTO).build(); } catch (APIManagementException e) { if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) { RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log); } else { RestApiUtil.handleInternalServerError("Failed to add comment to the API " + apiId, e, log); } } catch (URISyntaxException e) { String errorMessage = "Error while retrieving comment content location for API " + apiId; RestApiUtil.handleInternalServerError(errorMessage, e, log); } return null; }