diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/pom.xml b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/pom.xml index 9a10523d04..d7b9160d65 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/pom.xml @@ -45,6 +45,11 @@ + + org.wso2.carbon + org.wso2.carbon.utils + provided + org.wso2.carbon.identity.branding.preference.management org.wso2.carbon.identity.branding.preference.management.core diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceManagementConstants.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceManagementConstants.java index 79b696e16c..332aa679ea 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceManagementConstants.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceManagementConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2021-2024, 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 @@ -91,7 +91,16 @@ public enum ErrorMessage { "Server encountered an error while deleting custom text configurations for organization: %s"), ERROR_CODE_ERROR_UPDATING_CUSTOM_TEXT_PREFERENCE("65008", "Unable to update custom text preference configurations.", - "Error while updating custom text preference configurations for organization: %s."); + "Error while updating custom text preference configurations for organization: %s."), + ERROR_CODE_ERROR_GETTING_BRANDING_RESULT_STATUS("65009", + "Error while getting branding preference generation result status.", + "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_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; diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java index d56b37f912..892eef3508 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java @@ -18,7 +18,9 @@ package org.wso2.carbon.identity.api.server.branding.preference.management.common; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.branding.preference.management.core.BrandingPreferenceManager; +import org.wso2.carbon.identity.branding.preference.management.core.ai.BrandingAIPreferenceManager; /** * Service holder class for branding preference management. @@ -27,6 +29,12 @@ public class BrandingPreferenceServiceHolder { private static BrandingPreferenceManager brandingPreferenceManager; + private static class BrandingAIPreferenceManagerServiceHolder { + + static final BrandingAIPreferenceManager SERVICE = (BrandingAIPreferenceManager) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(BrandingAIPreferenceManager.class, null); + } + /** * Get BrandingPreferenceManager OSGi service. * @@ -46,4 +54,14 @@ public static void setBrandingPreferenceManager(BrandingPreferenceManager brandi BrandingPreferenceServiceHolder.brandingPreferenceManager = brandingPreferenceManager; } + + /** + * Get AIBrandingPreferenceManager OSGi service. + * + * @return AI Branding Preference Manager. + */ + public static BrandingAIPreferenceManager getBrandingPreferenceAiManager() { + + return BrandingAIPreferenceManagerServiceHolder.SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/pom.xml index 0cf7ed23ad..e375c8f153 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/pom.xml @@ -166,5 +166,15 @@ org.wso2.carbon.identity.branding.preference.management.core provided + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.application.authentication.framework + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.ai.service.mgt + provided + diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApi.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApi.java index f295f63617..8b0e23e5c7 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApi.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApi.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-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 @@ -24,6 +24,10 @@ import java.io.InputStream; import java.util.List; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationRequestModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResponseModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResultModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationStatusModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingPreferenceModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.CustomTextModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.Error; @@ -141,6 +145,77 @@ public Response deleteCustomText( @Valid@ApiParam(value = "Type to filter the return delegate.deleteCustomText(type, name, locale, screen ); } + @Valid + @POST + @Path("/generate") + @Consumes({ "application/json" }) + @Produces({ "application/json" }) + @ApiOperation(value = "Generate branding preferences using AI based on the organization's website.", notes = "This API endpoint initiates the generation of a new set of branding preferences by leveraging AI to analyze the organization's website. This is typically used when an organization wants to create branding preferences using AI. The endpoint requires a website URL and generates matching branding details based on the website's properties.
Scope(Permission) required: `internal_branding_preference_update` ", response = BrandingGenerationResponseModel.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Branding Preference", }) + @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 = "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) { + + return delegate.generateBrandingPreference(brandingGenerationRequestModel ); + } + + @Valid + @GET + @Path("/result/{operationId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Return the result of a branding generation operation.", notes = "This API endpoint returns the result of an AI branding generation operation for a given operation ID. Depending on the operation status, the response may include an error message or the generated branding preferences.
", response = BrandingGenerationResultModel.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Branding Preference", }) + @ApiResponses(value = { + @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) { + + return delegate.getBrandingGenerationResult(operationId ); + } + + @Valid + @GET + @Path("/status/{operationId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Get the status of a branding generation operation.", notes = "This API endpoint returns the status of the AI branding generation process that initiated using the `/generate` endpoint.
", response = BrandingGenerationStatusModel.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Branding Preference", }) + @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 = "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 getBrandingGenerationStatus(@ApiParam(value = "The unique identifier for the branding generation operation.",required=true) @PathParam("operationId") String operationId) { + + return delegate.getBrandingGenerationStatus(operationId ); + } + @Valid @GET diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApiService.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApiService.java index e2cfaf60ac..3ac1f0b2c4 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApiService.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/BrandingPreferenceApiService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2024, 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 @@ -24,6 +24,10 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart; import java.io.InputStream; import java.util.List; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationRequestModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResponseModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResultModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationStatusModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingPreferenceModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.CustomTextModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.Error; @@ -40,6 +44,12 @@ public interface BrandingPreferenceApiService { public Response deleteCustomText(String type, String name, String locale, String screen); + public Response generateBrandingPreference(BrandingGenerationRequestModel brandingGenerationRequestModel); + + public Response getBrandingGenerationResult(String operationId); + + public Response getBrandingGenerationStatus(String operationId); + public Response getBrandingPreference(String type, String name, String locale); public Response getCustomText(String type, String name, String locale, String screen); diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceApiServiceFactory.java index f9aa1cecb6..4d309a8be3 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceApiServiceFactory.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationRequestModel.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationRequestModel.java new file mode 100644 index 0000000000..3de1b48f08 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationRequestModel.java @@ -0,0 +1,99 @@ +/* + * 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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.branding.preference.management.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class BrandingGenerationRequestModel { + + private String websiteUrl; + + /** + * URL of the organization's website. + **/ + public BrandingGenerationRequestModel websiteUrl(String websiteUrl) { + + this.websiteUrl = websiteUrl; + return this; + } + + @ApiModelProperty(example = "https://wso2.com/", value = "URL of the organization's website.") + @JsonProperty("websiteUrl") + @Valid + public String getWebsiteUrl() { + return websiteUrl; + } + public void setWebsiteUrl(String websiteUrl) { + this.websiteUrl = websiteUrl; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BrandingGenerationRequestModel brandingGenerationRequestModel = (BrandingGenerationRequestModel) o; + return Objects.equals(this.websiteUrl, brandingGenerationRequestModel.websiteUrl); + } + + @Override + public int hashCode() { + return Objects.hash(websiteUrl); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class BrandingGenerationRequestModel {\n"); + + sb.append(" websiteUrl: ").append(toIndentedString(websiteUrl)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} + diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationResponseModel.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationResponseModel.java new file mode 100644 index 0000000000..53a9cdabd5 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationResponseModel.java @@ -0,0 +1,99 @@ +/* + * 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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.branding.preference.management.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class BrandingGenerationResponseModel { + + private String operationId; + + /** + * Operation id of the initiated branding generation process. + **/ + public BrandingGenerationResponseModel operationId(String operationId) { + + this.operationId = operationId; + return this; + } + + @ApiModelProperty(value = "Operation id of the initiated branding generation process.") + @JsonProperty("operationId") + @Valid + public String getOperationId() { + return operationId; + } + public void setOperationId(String operationId) { + this.operationId = operationId; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BrandingGenerationResponseModel brandingGenerationResponseModel = (BrandingGenerationResponseModel) o; + return Objects.equals(this.operationId, brandingGenerationResponseModel.operationId); + } + + @Override + public int hashCode() { + return Objects.hash(operationId); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class BrandingGenerationResponseModel {\n"); + + sb.append(" operationId: ").append(toIndentedString(operationId)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} + diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationResultModel.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationResultModel.java new file mode 100644 index 0000000000..ba9e1816d0 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationResultModel.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2024, 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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.branding.preference.management.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class BrandingGenerationResultModel { + + +@XmlType(name="StatusEnum") +@XmlEnum(String.class) +public enum StatusEnum { + + @XmlEnumValue("IN_PROGRESS") IN_PROGRESS(String.valueOf("IN_PROGRESS")), @XmlEnumValue("COMPLETED") COMPLETED(String.valueOf("COMPLETED")), @XmlEnumValue("FAILED") FAILED(String.valueOf("FAILED")); + + + private String value; + + StatusEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private StatusEnum status; + private Object data; + + /** + * The current result of the AI branding operation. + **/ + public BrandingGenerationResultModel status(StatusEnum status) { + + this.status = status; + return this; + } + + @ApiModelProperty(value = "The current result of the AI branding operation.") + @JsonProperty("status") + @Valid + public StatusEnum getStatus() { + return status; + } + public void setStatus(StatusEnum status) { + this.status = status; + } + + /** + * The payload of the response, which varies based on the operation status. - For IN_PROGRESS status, an empty JSON object is returned. - For COMPLETED status, the `BrandingPreferenceModel` is returned. - For FAILED status, an error message is returned. + **/ + public BrandingGenerationResultModel data(Object data) { + + this.data = data; + return this; + } + + @ApiModelProperty(value = "The payload of the response, which varies based on the operation status. - For IN_PROGRESS status, an empty JSON object is returned. - For COMPLETED status, the `BrandingPreferenceModel` is returned. - For FAILED status, an error message is returned. ") + @JsonProperty("data") + @Valid + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BrandingGenerationResultModel brandingGenerationResultModel = (BrandingGenerationResultModel) o; + return Objects.equals(this.status, brandingGenerationResultModel.status) && + Objects.equals(this.data, brandingGenerationResultModel.data); + } + + @Override + public int hashCode() { + return Objects.hash(status, data); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class BrandingGenerationResultModel {\n"); + + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" data: ").append(toIndentedString(data)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} + diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationStatusModel.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationStatusModel.java new file mode 100644 index 0000000000..fb78329661 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingGenerationStatusModel.java @@ -0,0 +1,99 @@ +/* + * 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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.branding.preference.management.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class BrandingGenerationStatusModel { + + private Object status; + + /** + * This is the JSON structured branding preference + **/ + public BrandingGenerationStatusModel status(Object status) { + + this.status = status; + return this; + } + + @ApiModelProperty(example = "{\"render_webpage\":true,\"extract_webpage_content\":true,\"webpage_extraction_completed\":true,\"generate_branding\":true,\"branding_generation_status\":{\"color_palette\":true,\"style_properties\":true},\"branding_generation_completed_status\":{\"color_palette\":false,\"style_properties\":false},\"create_branding_theme\":false,\"branding_generation_completed\":false}", value = "This is the JSON structured branding preference") + @JsonProperty("status") + @Valid + public Object getStatus() { + return status; + } + public void setStatus(Object status) { + this.status = status; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BrandingGenerationStatusModel brandingGenerationStatusModel = (BrandingGenerationStatusModel) o; + return Objects.equals(this.status, brandingGenerationStatusModel.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class BrandingGenerationStatusModel {\n"); + + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} + diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingPreferenceModel.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingPreferenceModel.java index 532c4bfbe2..e45593cfd2 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingPreferenceModel.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/model/BrandingPreferenceModel.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingAIPreferenceManagementService.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingAIPreferenceManagementService.java new file mode 100644 index 0000000000..920556c372 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingAIPreferenceManagementService.java @@ -0,0 +1,211 @@ +/* + * 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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.branding.preference.management.v1.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.identity.ai.service.mgt.exceptions.AIClientException; +import org.wso2.carbon.identity.ai.service.mgt.exceptions.AIServerException; +import org.wso2.carbon.identity.api.server.branding.preference.management.common.BrandingPreferenceServiceHolder; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationRequestModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResponseModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResultModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationStatusModel; +import org.wso2.carbon.identity.api.server.common.error.APIError; +import org.wso2.carbon.identity.api.server.common.error.ErrorResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.Response; + +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. + */ +public class BrandingAIPreferenceManagementService { + + private static final Log LOG = LogFactory.getLog(BrandingAIPreferenceManagementService.class); + + /** + * Initiates the branding preference generation process by invoking BrandingPreferenceManager. + * + * @param brandingGenerationRequestModel BrandingGenerationRequestModel. + * @return BrandingGenerationResponseModel. + */ + public BrandingGenerationResponseModel generateBrandingPreference( + BrandingGenerationRequestModel brandingGenerationRequestModel) { + + try { + String operationId = BrandingPreferenceServiceHolder.getBrandingPreferenceAiManager() + .generateBrandingPreference(brandingGenerationRequestModel.getWebsiteUrl()); + BrandingGenerationResponseModel response = new BrandingGenerationResponseModel(); + response.setOperationId(operationId); + return response; + } catch (AIServerException e) { + throw handleServerException(e); + } catch (AIClientException e) { + throw handleClientException(e); + } + } + + /** + * Retrieves the branding preference generation status by invoking BrandingPreferenceManager. + * + * @param operationId operation id of the branding preference generation process. + * @return BrandingGenerationStatusModel. + */ + public BrandingGenerationStatusModel getBrandingPreferenceGenerationStatus(String operationId) { + + try { + Object generationStatus = BrandingPreferenceServiceHolder.getBrandingPreferenceAiManager() + .getBrandingPreferenceGenerationStatus(operationId); + BrandingGenerationStatusModel response = new BrandingGenerationStatusModel(); + response.setStatus(convertObjectToMap(generationStatus)); + return response; + } catch (AIServerException e) { + throw handleServerException(e); + } catch (AIClientException e) { + throw handleClientException(e); + } + } + + /** + * Retrieves the branding preference generation result by invoking BrandingPreferenceManager. + * + * @param operationId operation id of the branding preference generation process. + * @return BrandingGenerationResultModel. + */ + public BrandingGenerationResultModel getBrandingPreferenceGenerationResult(String operationId) { + + try { + Object generationResult = BrandingPreferenceServiceHolder.getBrandingPreferenceAiManager() + .getBrandingPreferenceGenerationResult(operationId); + BrandingGenerationResultModel response = new BrandingGenerationResultModel(); + + Map resultMap = convertObjectToMap(generationResult); + response.setStatus(getStatusFromResult(resultMap)); + + if (!resultMap.containsKey("data")) { + throw new AIServerException(ERROR_CODE_ERROR_GETTING_BRANDING_RESULT_STATUS.getMessage(), + ERROR_CODE_ERROR_GETTING_BRANDING_RESULT_STATUS.getCode()); + } + + Map dataMap = (Map) resultMap.get("data"); + response.setData(dataMap); + return response; + } catch (AIServerException e) { + throw handleServerException(e); + } catch (AIClientException e) { + throw handleClientException(e); + } + } + + private BrandingGenerationResultModel.StatusEnum getStatusFromResult(Map resultMap) + throws AIServerException { + + if (resultMap.containsKey("status")) { + String status = (String) resultMap.get("status"); + if ("IN_PROGRESS".equals(status)) { + return BrandingGenerationResultModel.StatusEnum.IN_PROGRESS; + } else if ("COMPLETED".equals(status)) { + return BrandingGenerationResultModel.StatusEnum.COMPLETED; + } else if ("FAILED".equals(status)) { + return BrandingGenerationResultModel.StatusEnum.FAILED; + } + } + throw new AIServerException(ERROR_CODE_ERROR_GETTING_BRANDING_RESULT.getMessage(), + ERROR_CODE_ERROR_GETTING_BRANDING_RESULT.getCode()); + } + + + private APIError handleClientException(AIClientException error) { + + LOG.debug("Client error occurred while invoking AI service.", error); + ErrorResponse.Builder errorResponseBuilder = new ErrorResponse.Builder() + .withCode(error.getErrorCode()) + .withMessage(error.getMessage()); + if (error.getServerMessage() != null) { + Response.Status status = Response.Status.fromStatusCode(error.getServerStatusCode()); + errorResponseBuilder.withDescription(error.getServerMessage()); + return new APIError(status, errorResponseBuilder.build()); + } + return new APIError(Response.Status.BAD_REQUEST, errorResponseBuilder.build()); + } + + private APIError handleServerException(AIServerException error) { + + LOG.error("Server error occurred while generating branding preference.", error); + ErrorResponse.Builder errorResponseBuilder = new ErrorResponse.Builder() + .withCode(error.getErrorCode()) + .withMessage(error.getMessage()); + if (error.getServerMessage() != null) { + Response.Status status = Response.Status.fromStatusCode(error.getServerStatusCode()); + errorResponseBuilder.withDescription(error.getServerMessage()); + return new APIError(status, errorResponseBuilder.build()); + } + return new APIError(Response.Status.INTERNAL_SERVER_ERROR, errorResponseBuilder.build()); + } + + private static Map convertObjectToMap(Object object) throws AIServerException { + + if (object instanceof Map) { + Map map = new HashMap<>(); + for (Map.Entry entry : ((Map) object).entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + + if (value == null) { + map.put(key, ""); + } else if (value instanceof Map) { + map.put(key, convertObjectToMap(value)); + } else if (value instanceof List) { + map.put(key, convertListToArray((List) value)); + } else { + map.put(key, value); + } + } + return map; + } + 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) throws AIServerException { + + Object[] array = new Object[list.size()]; + for (int i = 0; i < list.size(); i++) { + Object value = list.get(i); + if (value == null) { + array[i] = ""; + } else if (value instanceof Map) { + array[i] = convertObjectToMap(value); + } else if (value instanceof List) { + array[i] = convertListToArray((List) value); + } else { + array[i] = value; + } + } + return array; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingAIPreferenceManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingAIPreferenceManagementServiceFactory.java new file mode 100644 index 0000000000..333de30673 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingAIPreferenceManagementServiceFactory.java @@ -0,0 +1,38 @@ +/* + * 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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.branding.preference.management.v1.factories; + +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingAIPreferenceManagementService; + +/** + * Factory class for Branding AI Preference Management Service. + */ +public class BrandingAIPreferenceManagementServiceFactory { + + private static final BrandingAIPreferenceManagementService SERVICE; + + static { + SERVICE = new BrandingAIPreferenceManagementService(); + } + + public static BrandingAIPreferenceManagementService getBrandingAIPreferenceManagementService() { + + return SERVICE; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java index faee49b12b..73539a69e6 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2024-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 @@ -22,6 +22,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.BrandingPreferenceApiService; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingPreferenceManagementService; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.factories.BrandingAIPreferenceManagementServiceFactory; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationRequestModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResponseModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResultModel; +import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationStatusModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingPreferenceModel; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.CustomTextModel; import org.wso2.carbon.identity.api.server.common.ContextLoader; @@ -32,6 +37,7 @@ import java.net.URI; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; + import javax.ws.rs.core.Response; import static org.wso2.carbon.identity.api.server.branding.preference.management.common.BrandingPreferenceManagementConstants.APPLICATION_TYPE; @@ -184,6 +190,34 @@ public Response getBrandingPreference(String type, String name, String locale) { .entity(brandingPreferenceManagementService.getBrandingPreference(type, name, locale)).build(); } + @Override + public Response generateBrandingPreference(BrandingGenerationRequestModel brandingGenerationRequestModel) { + + BrandingGenerationResponseModel response = BrandingAIPreferenceManagementServiceFactory + .getBrandingAIPreferenceManagementService().generateBrandingPreference( + brandingGenerationRequestModel); + return Response.accepted().entity(response).build(); + + } + + @Override + public Response getBrandingGenerationResult(String operationId) { + + BrandingGenerationResultModel response = BrandingAIPreferenceManagementServiceFactory + .getBrandingAIPreferenceManagementService() + .getBrandingPreferenceGenerationResult(operationId); + return Response.ok().entity(response).build(); + } + + @Override + public Response getBrandingGenerationStatus(String operationId) { + + BrandingGenerationStatusModel response = BrandingAIPreferenceManagementServiceFactory + .getBrandingAIPreferenceManagementService() + .getBrandingPreferenceGenerationStatus(operationId); + return Response.ok().entity(response).build(); + } + @Override public Response getCustomText(String type, String name, String locale, String screen) { diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/resources/branding-preference.yaml b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/resources/branding-preference.yaml index 724caf7150..651cfa6529 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/resources/branding-preference.yaml +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/resources/branding-preference.yaml @@ -199,6 +199,115 @@ paths: $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/ServerError' + '/branding-preference/generate': + post: + tags: + - Branding Preference + operationId: generateBrandingPreference + summary: Generate branding preferences using AI based on the organization's website. + description: | + This API endpoint initiates the generation of a new set of branding preferences by leveraging AI to analyze the organization's website. This is typically used when an organization wants to create branding preferences using AI. The endpoint requires a website URL and generates matching branding details based on the website's properties.
+ Scope(Permission) required: `internal_branding_preference_update` + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/BrandingGenerationRequestModel' + description: This represents the properties of the organization used to generate branding preferences, including the organization's website URL. + required: true + responses: + '202': + description: Branding generation process started + content: + 'application/json': + schema: + $ref: '#/components/schemas/BrandingGenerationResponseModel' + '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' + '500': + $ref: '#/components/responses/ServerError' + '/branding-preference/status/{operationId}': + get: + tags: + - Branding Preference + operationId: getBrandingGenerationStatus + summary: Get the status of a branding generation operation. + description: | + This API endpoint returns the status of the AI branding generation process that initiated using the `/generate` endpoint.
+ parameters: + - $ref: '#/components/parameters/operationId' + responses: + '200': + description: OK + content: + 'application/json': + schema: + $ref: '#/components/schemas/BrandingGenerationStatusModel' + '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/result/{operationId}': + get: + tags: + - Branding Preference + operationId: getBrandingGenerationResult + summary: Return the result of a branding generation operation. + description: | + This API endpoint returns the result of an AI branding generation operation for a given operation ID. Depending on the operation status, the response may include an error message or the generated branding preferences.
+ parameters: + - $ref: '#/components/parameters/operationId' + responses: + '200': + description: OK + content: + '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: @@ -417,6 +526,15 @@ components: type: boolean default: false example: true + operationId: + in: path + name: operationId + required: true + description: The unique identifier for the branding generation operation. + schema: + type: string + example: "945fa326-bf78-45f6-bfda-c9644650b821" + schemas: BrandingPreferenceModel: @@ -473,7 +591,58 @@ components: "selfSignUpEnabled": true } } - + BrandingGenerationRequestModel: + type: object + properties: + websiteUrl: + type: string + description: URL of the organization's website. + example: "https://wso2.com/" + BrandingGenerationResponseModel: + type: object + properties: + operationId: + type: string + description: Operation id of the initiated branding generation process. + BrandingGenerationStatusModel: + type: object + properties: + status: + type: object + description: "This is the JSON structured branding preference" + example: { + "render_webpage": true, + "extract_webpage_content": true, + "webpage_extraction_completed": true, + "generate_branding": true, + "branding_generation_status": { + "color_palette": true, + "style_properties": true + }, + "branding_generation_completed_status": { + "color_palette": false, + "style_properties": false + }, + "create_branding_theme": false, + "branding_generation_completed": false + } + BrandingGenerationResultModel: + type: object + properties: + status: + type: string + enum: + - IN_PROGRESS + - COMPLETED + - FAILED + description: The current result of the AI branding operation. + data: + type: object + description: | + The payload of the response, which varies based on the operation status. + - For IN_PROGRESS status, an empty JSON object is returned. + - For COMPLETED status, the `BrandingPreferenceModel` is returned. + - For FAILED status, an error message is returned. CustomTextModel: required: - type diff --git a/pom.xml b/pom.xml index 6d5d17e75f..ac62f16160 100644 --- a/pom.xml +++ b/pom.xml @@ -550,6 +550,12 @@ ${carbon.identity.framework.version} provided + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.ai.service.mgt + ${carbon.identity.framework.version} + provided + org.wso2.carbon org.wso2.carbon.admin.advisory.mgt @@ -836,7 +842,7 @@ 2.5.18 4.10.14 5.2.61 - 1.1.16 + 1.1.18 1.2.4