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 cb36f4c5b7..134b0dec5f 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..524e51516b 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,13 @@ 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."); 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..74bc562dbf 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 @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.api.server.branding.preference.management.common; 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. @@ -26,6 +27,7 @@ public class BrandingPreferenceServiceHolder { private static BrandingPreferenceManager brandingPreferenceManager; + private static BrandingAIPreferenceManager brandingPreferenceAiManager; /** * Get BrandingPreferenceManager OSGi service. @@ -46,4 +48,24 @@ public static void setBrandingPreferenceManager(BrandingPreferenceManager brandi BrandingPreferenceServiceHolder.brandingPreferenceManager = brandingPreferenceManager; } + + /** + * Get AIBrandingPreferenceManager OSGi service. + * + * @return AI Branding Preference Manager. + */ + public static BrandingAIPreferenceManager getBrandingPreferenceAiManager() { + + return brandingPreferenceAiManager; + } + + /** + * Set AIBrandingPreferenceManager OSGi service. + * + * @param brandingPreferenceAIManager AI Branding Preference Manager. + */ + public static void setBrandingPreferenceAiManager(BrandingAIPreferenceManager brandingPreferenceAIManager) { + + BrandingPreferenceServiceHolder.brandingPreferenceAiManager = brandingPreferenceAIManager; + } } 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/factory/BrandingPreferenceAIMgtOSGiServiceFactory.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/factory/BrandingPreferenceAIMgtOSGiServiceFactory.java new file mode 100644 index 0000000000..a85654d5cc --- /dev/null +++ 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/factory/BrandingPreferenceAIMgtOSGiServiceFactory.java @@ -0,0 +1,55 @@ +/* + * 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.common.factory; + +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.branding.preference.management.core.ai.BrandingAIPreferenceManager; + + +/** + * Factory Beans serve as a factory for creating other beans within the IOC container. This factory bean is used to + * instantiate the AIBrandingPreferenceManager type of object inside the container. + */ +public class BrandingPreferenceAIMgtOSGiServiceFactory extends AbstractFactoryBean { + + private BrandingAIPreferenceManager brandingAiPreferenceManager; + + @Override + public Class getObjectType() { + + return Object.class; + } + + @Override + protected BrandingAIPreferenceManager createInstance() throws Exception { + + if (this.brandingAiPreferenceManager == null) { + BrandingAIPreferenceManager taskOperationService = (BrandingAIPreferenceManager) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(BrandingAIPreferenceManager.class, null); + + if (taskOperationService != null) { + this.brandingAiPreferenceManager = taskOperationService; + } else { + throw new Exception("Unable to retrieve ConfigurationManager service."); + } + } + return this.brandingAiPreferenceManager; + } +} 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 d4c1efbbd2..07f357da04 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,10 @@ org.wso2.carbon.identity.branding.preference.management.core provided + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.application.authentication.framework + 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..e517d64d2a 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) 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 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,75 @@ 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 = "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) + }) + 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.
Scope(Permission) required: `internal_branding_preference_update` ", response = BrandingGenerationResultModel.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Branding Preference", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK", response = BrandingGenerationResultModel.class) + }) + public Response getBrandingGenerationResult(@ApiParam(value = "The unique identifier for the branding generation operation.",required=true) @PathParam("operationId") String operationId) { + + Response brandingGenerationResult = delegate.getBrandingGenerationResult(operationId); + return brandingGenerationResult; + } + + @Valid + @GET + @Path("/status/{operationId}") + + @Produces({ "application/json" }) + @ApiOperation(value = "Get the status of a branding generation operation.", notes = "This API endpoint return the status of the AI branding generation process that initiated using the `/generate` endpoint.
Scope(Permission) required: `internal_branding_preference_update` ", 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 = "Authentication information is missing or invalid.", response = Void.class), + @ApiResponse(code = 403, message = "Access forbidden.", response = Void.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..9f781d4a0b --- /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) 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 BrandingGenerationRequestModel { + + private String websiteUrl; + + /** + * URL of the company's website. + **/ + public BrandingGenerationRequestModel websiteUrl(String websiteUrl) { + + this.websiteUrl = websiteUrl; + return this; + } + + @ApiModelProperty(value = "URL of the company's website.") + @JsonProperty("website_url") + @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..8447aa1699 --- /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) 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 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("operation_id") + @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..17e72e9ffe --- /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) 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 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..5fd6e030cf 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) 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/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..f402800051 --- /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) 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.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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 org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingAIClientException; +import org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingAIServerException; + +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; + +/** + * 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 (BrandingAIServerException e) { + throw handleServerException(e); + } catch (BrandingAIClientException 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 (BrandingAIServerException e) { + throw handleServerException(e); + } catch (BrandingAIClientException 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 BrandingAIServerException(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 (BrandingAIServerException e) { + throw handleServerException(e); + } catch (BrandingAIClientException e) { + throw handleClientException(e); + } + } + + private BrandingGenerationResultModel.StatusEnum getStatusFromResult(Map resultMap) + throws BrandingAIServerException { + + 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 BrandingAIServerException(ERROR_CODE_ERROR_GETTING_BRANDING_RESULT.getMessage(), + ERROR_CODE_ERROR_GETTING_BRANDING_RESULT.getCode()); + } + + + private APIError handleClientException(BrandingAIClientException error) { + + ErrorResponse.Builder errorResponseBuilder = new ErrorResponse.Builder() + .withCode(error.getErrorCode()) + .withMessage(error.getMessage()); + if (error.getBrandingAIResponse() != null) { + Response.Status status = Response.Status.fromStatusCode(error.getBrandingAIResponse().getStatusCode()); + errorResponseBuilder.withDescription(error.getBrandingAIResponse().getResponseBody()); + return new APIError(status, errorResponseBuilder.build()); + } + return new APIError(Response.Status.BAD_REQUEST, errorResponseBuilder.build()); + } + + private APIError handleServerException(BrandingAIServerException error) { + + ErrorResponse.Builder errorResponseBuilder = new ErrorResponse.Builder() + .withCode(error.getErrorCode()) + .withMessage(error.getMessage()); + if (error.getBrandingAIResponse() != null) { + Response.Status status = Response.Status.fromStatusCode(error.getBrandingAIResponse().getStatusCode()); + errorResponseBuilder.withDescription(error.getBrandingAIResponse().getResponseBody()); + return new APIError(status, errorResponseBuilder.build()); + } + return new APIError(Response.Status.INTERNAL_SERVER_ERROR, errorResponseBuilder.build()); + } + + private static Map convertObjectToMap(Object object) { + + 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; + } + log.warn("Object is not an instance of Map. Returning an empty map."); + return new HashMap<>(); + } + + private static Object[] convertListToArray(List list) { + + 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/core/BrandingPreferenceManagementService.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/BrandingPreferenceManagementService.java index 133e1d240e..d9362307ac 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/core/BrandingPreferenceManagementService.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/BrandingPreferenceManagementService.java @@ -71,7 +71,6 @@ public class BrandingPreferenceManagementService { private static final Log log = LogFactory.getLog(BrandingPreferenceManagementService.class); - /** * Create a branding preference resource with a resource file. * 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..e267a594f5 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 @@ -21,7 +21,12 @@ import org.apache.commons.lang3.StringUtils; 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.BrandingAIPreferenceManagementService; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingPreferenceManagementService; +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; @@ -53,6 +59,9 @@ public class BrandingPreferenceApiServiceImpl implements BrandingPreferenceApiSe @Autowired private BrandingPreferenceManagementService brandingPreferenceManagementService; + @Autowired + private BrandingAIPreferenceManagementService brandingAIPreferenceManagementService; + //TODO: Improve API to manage application level & language level theming resources in addition to the tenant level. @Override @@ -184,6 +193,31 @@ public Response getBrandingPreference(String type, String name, String locale) { .entity(brandingPreferenceManagementService.getBrandingPreference(type, name, locale)).build(); } + @Override + public Response generateBrandingPreference(BrandingGenerationRequestModel brandingGenerationModel) { + + BrandingGenerationResponseModel response = brandingAIPreferenceManagementService.generateBrandingPreference( + brandingGenerationModel); + return Response.accepted().entity(response).build(); + + } + + @Override + public Response getBrandingGenerationResult(String operationId) { + + BrandingGenerationResultModel response = brandingAIPreferenceManagementService + .getBrandingPreferenceGenerationResult(operationId); + return Response.ok().entity(response).build(); + } + + @Override + public Response getBrandingGenerationStatus(String operationId) { + + BrandingGenerationStatusModel response = brandingAIPreferenceManagementService + .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/META-INF/cxf/branding-preference-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/resources/META-INF/cxf/branding-preference-server-v1-cxf.xml index eb6cd7dd09..f626a0ab2f 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/META-INF/cxf/branding-preference-server-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/resources/META-INF/cxf/branding-preference-server-v1-cxf.xml @@ -19,9 +19,12 @@ + + + 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..0de30de8e3 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,86 @@ 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': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '409': + $ref: '#/components/responses/Conflict' + '500': + $ref: '#/components/responses/ServerError' + '501': + $ref: '#/components/responses/NotImplemented' + '/branding-preference/status/{operationId}': + get: + tags: + - Branding Preference + operationId: getBrandingGenerationStatus + summary: Get the status of a branding generation operation. + description: | + This API endpoint return 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': + $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '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' + '/branding-preference/text': get: @@ -417,6 +497,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 +562,61 @@ components: "selfSignUpEnabled": true } } - + BrandingGenerationRequestModel: + type: object + properties: + # Define properties related to the organization that are used to generate branding preferences + # Example property: + website_url: + type: string + description: URL of the company's website. + BrandingGenerationResponseModel: + type: object + properties: + # Define properties related to the organization that are used to generate branding preferences + # Example property: + operation_id: + 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