Skip to content

Commit

Permalink
Fix review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Jan 23, 2025
1 parent c951329 commit a5b20dd
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public enum ErrorMessage {
"Error while retrieving branding preference generation result status for operation."),
ERROR_CODE_ERROR_GETTING_BRANDING_RESULT("65010",
"Error while getting branding preference generation result.",
"Error while retrieving branding preference generation result for operation.");
"Error while retrieving branding preference generation result for operation."),
ERROR_WHILE_CONVERTING_BRANDING_AI_SERVER_RESPONSE("65602",
"Error occurred while converting the AI server response.",
"Could not convert the AI server response to a valid response.");


private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,9 @@ public Response deleteCustomText( @Valid@ApiParam(value = "Type to filter the
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Branding generation process started", response = BrandingGenerationResponseModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 401, message = "Authentication information is missing or invalid.", response = Void.class),
@ApiResponse(code = 403, message = "Access forbidden.", response = Void.class),
@ApiResponse(code = 409, message = "Conflict.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class),
@ApiResponse(code = 501, message = "Not Implemented.", response = Error.class)
@ApiResponse(code = 401, message = "Unauthorized", response = Error.class),
@ApiResponse(code = 403, message = "Forbidden", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response generateBrandingPreference(@ApiParam(value = "This represents the properties of the organization used to generate branding preferences, including the organization's website URL." ,required=true) @Valid BrandingGenerationRequestModel brandingGenerationRequestModel) {

Expand All @@ -182,7 +180,12 @@ public Response generateBrandingPreference(@ApiParam(value = "This represents th
})
}, tags={ "Branding Preference", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = BrandingGenerationResultModel.class)
@ApiResponse(code = 200, message = "OK", response = BrandingGenerationResultModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 401, message = "Unauthorized", response = Error.class),
@ApiResponse(code = 403, message = "Forbidden", response = Error.class),
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
public Response getBrandingGenerationResult(@ApiParam(value = "The unique identifier for the branding generation operation.",required=true) @PathParam("operationId") String operationId) {

Expand All @@ -203,8 +206,8 @@ public Response getBrandingGenerationResult(@ApiParam(value = "The unique identi
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = BrandingGenerationStatusModel.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 401, message = "Authentication information is missing or invalid.", response = Void.class),
@ApiResponse(code = 403, message = "Access forbidden.", response = Void.class),
@ApiResponse(code = 401, message = "Unauthorized", response = Error.class),
@ApiResponse(code = 403, message = "Forbidden", response = Error.class),
@ApiResponse(code = 404, message = "Requested resource is not found.", response = Error.class),
@ApiResponse(code = 500, message = "Internal server error.", response = Error.class)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class BrandingGenerationRequestModel {
private String websiteUrl;

/**
* URL of the company's website.
* URL of the organization's website.
**/
public BrandingGenerationRequestModel websiteUrl(String websiteUrl) {

this.websiteUrl = websiteUrl;
return this;
}

@ApiModelProperty(value = "URL of the company's website.")
@ApiModelProperty(example = "https://wso2.com/", value = "URL of the organization's website.")
@JsonProperty("websiteUrl")
@Valid
public String getWebsiteUrl() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -38,6 +38,7 @@

import static org.wso2.carbon.identity.api.server.branding.preference.management.common.BrandingPreferenceManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_BRANDING_RESULT;
import static org.wso2.carbon.identity.api.server.branding.preference.management.common.BrandingPreferenceManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_BRANDING_RESULT_STATUS;
import static org.wso2.carbon.identity.api.server.branding.preference.management.common.BrandingPreferenceManagementConstants.ErrorMessage.ERROR_WHILE_CONVERTING_BRANDING_AI_SERVER_RESPONSE;

/**
* Service class for AI branding preference management.
Expand Down Expand Up @@ -166,7 +167,7 @@ private APIError handleServerException(AIServerException error) {
return new APIError(Response.Status.INTERNAL_SERVER_ERROR, errorResponseBuilder.build());
}

private static Map<String, Object> convertObjectToMap(Object object) {
private static Map<String, Object> convertObjectToMap(Object object) throws AIServerException {

if (object instanceof Map) {
Map<String, Object> map = new HashMap<>();
Expand All @@ -186,11 +187,11 @@ private static Map<String, Object> convertObjectToMap(Object object) {
}
return map;
}
LOG.warn("Object is not an instance of Map. Returning an empty map.");
return new HashMap<>();
throw new AIServerException(ERROR_WHILE_CONVERTING_BRANDING_AI_SERVER_RESPONSE.getMessage(),
ERROR_WHILE_CONVERTING_BRANDING_AI_SERVER_RESPONSE.getCode());
}

private static Object[] convertListToArray(List<?> list) {
private static Object[] convertListToArray(List<?> list) throws AIServerException {

Object[] array = new Object[list.size()];
for (int i = 0; i < list.size(); i++) {
Expand All @@ -208,6 +209,3 @@ private static Object[] convertListToArray(List<?> list) {
return array;
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
public class BrandingPreferenceManagementService {

private static final Log log = LogFactory.getLog(BrandingPreferenceManagementService.class);

/**
* Create a branding preference resource with a resource file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,18 @@ public Response updateBrandingPreference(BrandingPreferenceModel brandingPrefere
@Override
public Response updateCustomText(CustomTextModel customTextModel) {

// do some magic!
return Response.ok().entity("magic!").build();
if (StringUtils.isBlank(customTextModel.getType().toString())) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (!ORGANIZATION_TYPE.equals(customTextModel.getType().toString())) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (StringUtils.isBlank(customTextModel.getScreen())) {
return Response.status(Response.Status.BAD_REQUEST).build();
}

CustomTextModel updatedCustomTextModel =
brandingPreferenceManagementService.updateCustomTextPreference(customTextModel);
return Response.ok().entity(updatedCustomTextModel).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,19 @@ paths:
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'403':
$ref: '#/components/responses/Forbidden'
'409':
$ref: '#/components/responses/Conflict'
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
$ref: '#/components/responses/ServerError'
'501':
$ref: '#/components/responses/NotImplemented'
'/branding-preference/status/{operationId}':
get:
tags:
Expand All @@ -254,9 +258,17 @@ paths:
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'403':
$ref: '#/components/responses/Forbidden'
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
$ref: '#/components/responses/NotFound'
'500':
Expand All @@ -278,6 +290,24 @@ paths:
'application/json':
schema:
$ref: '#/components/schemas/BrandingGenerationResultModel'
'400':
$ref: '#/components/responses/BadRequest'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/ServerError'

'/branding-preference/text':
get:
Expand Down Expand Up @@ -564,16 +594,13 @@ components:
BrandingGenerationRequestModel:
type: object
properties:
# Define properties related to the organization that are used to generate branding preferences
# Example property:
websiteUrl:
type: string
description: URL of the company's website.
description: URL of the organization's website.
example: "https://wso2.com/"
BrandingGenerationResponseModel:
type: object
properties:
# Define properties related to the organization that are used to generate branding preferences
# Example property:
operationId:
type: string
description: Operation id of the initiated branding generation process.
Expand Down

0 comments on commit a5b20dd

Please sign in to comment.