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..6ce566c0c6 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,6 +18,7 @@
package org.wso2.carbon.identity.api.server.branding.preference.management.common;
+import org.wso2.carbon.identity.branding.preference.management.core.AIBrandingPreferenceManager;
import org.wso2.carbon.identity.branding.preference.management.core.BrandingPreferenceManager;
/**
@@ -26,6 +27,7 @@
public class BrandingPreferenceServiceHolder {
private static BrandingPreferenceManager brandingPreferenceManager;
+ private static AIBrandingPreferenceManager aiBrandingPreferenceManager;
/**
* 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 AIBrandingPreferenceManager getAiBrandingPreferenceManager() {
+
+ return aiBrandingPreferenceManager;
+ }
+
+ /**
+ * Set AIBrandingPreferenceManager OSGi service.
+ *
+ * @param aiBrandingPreferenceManager AI Branding Preference Manager.
+ */
+ public static void setAiBrandingPreferenceManager(AIBrandingPreferenceManager aiBrandingPreferenceManager) {
+
+ BrandingPreferenceServiceHolder.aiBrandingPreferenceManager = aiBrandingPreferenceManager;
+ }
}
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/AIBrandingPreferenceMgtOSGiServiceFactory.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/AIBrandingPreferenceMgtOSGiServiceFactory.java
new file mode 100644
index 0000000000..63035a1ec3
--- /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/AIBrandingPreferenceMgtOSGiServiceFactory.java
@@ -0,0 +1,54 @@
+/*
+ * 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.AIBrandingPreferenceManager;
+
+/**
+ * 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 AIBrandingPreferenceMgtOSGiServiceFactory extends AbstractFactoryBean {
+
+ private AIBrandingPreferenceManager aiBrandingPreferenceManager;
+
+ @Override
+ public Class> getObjectType() {
+
+ return Object.class;
+ }
+
+ @Override
+ protected AIBrandingPreferenceManager createInstance() throws Exception {
+
+ if (this.aiBrandingPreferenceManager == null) {
+ AIBrandingPreferenceManager taskOperationService = (AIBrandingPreferenceManager) PrivilegedCarbonContext.
+ getThreadLocalCarbonContext().getOSGiService(AIBrandingPreferenceManager.class, null);
+
+ if (taskOperationService != null) {
+ this.aiBrandingPreferenceManager = taskOperationService;
+ } else {
+ throw new Exception("Unable to retrieve ConfigurationManager service.");
+ }
+ }
+ return this.aiBrandingPreferenceManager;
+ }
+}
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/AIBrandingPreferenceManagementService.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/AIBrandingPreferenceManagementService.java
new file mode 100644
index 0000000000..73b42b74e6
--- /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/AIBrandingPreferenceManagementService.java
@@ -0,0 +1,197 @@
+/*
+ * 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.json.JSONArray;
+import org.json.JSONObject;
+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.BrandingAIServiceException;
+
+import java.util.HashMap;
+import java.util.Iterator;
+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 AIBrandingPreferenceManagementService {
+
+ private static final Log log = LogFactory.getLog(AIBrandingPreferenceManagementService.class);
+
+ public BrandingGenerationResponseModel generateBrandingPreference(
+ BrandingGenerationRequestModel brandingGenerationRequestModel) {
+
+ try {
+ String operationId = BrandingPreferenceServiceHolder.getAiBrandingPreferenceManager()
+ .generateBrandingPreference(brandingGenerationRequestModel.getWebsiteUrl());
+ BrandingGenerationResponseModel response = new BrandingGenerationResponseModel();
+ response.setOperationId(operationId);
+ return response;
+ } catch (BrandingAIServiceException e) {
+ throw handleServerException(e);
+ } catch (BrandingAIClientException e) {
+ throw handleClientException(e);
+ }
+ }
+
+ public BrandingGenerationStatusModel getBrandingPreferenceGenerationStatus(String operationId) {
+
+ try {
+ JSONObject generationStatus = BrandingPreferenceServiceHolder.getAiBrandingPreferenceManager()
+ .getBrandingPreferenceGenerationStatus(operationId);
+ BrandingGenerationStatusModel response = new BrandingGenerationStatusModel();
+ Map dataMap = convertJSONObjectToMap(generationStatus);
+ response.setStatus(dataMap);
+ return response;
+ } catch (BrandingAIServiceException e) {
+ throw handleServerException(e);
+ } catch (BrandingAIClientException e) {
+ throw handleClientException(e);
+ }
+ }
+
+ public BrandingGenerationResultModel getBrandingPreferenceGenerationResult(String operationId) {
+
+ try {
+ JSONObject generationResult = BrandingPreferenceServiceHolder.getAiBrandingPreferenceManager()
+ .getBrandingPreferenceGenerationResult(operationId);
+ BrandingGenerationResultModel response = new BrandingGenerationResultModel();
+ response.setStatus(getStatusFromJsonResponse(generationResult));
+ if (!generationResult.has("data")) {
+ throw new BrandingAIServiceException(ERROR_CODE_ERROR_GETTING_BRANDING_RESULT_STATUS.getMessage(),
+ ERROR_CODE_ERROR_GETTING_BRANDING_RESULT_STATUS.getCode());
+ }
+ JSONObject data = generationResult.getJSONObject("data");
+ Map dataMap = convertJSONObjectToMap(data);
+ response.setData(dataMap);
+ return response;
+ } catch (BrandingAIServiceException e) {
+ throw handleServerException(e);
+ } catch (BrandingAIClientException e) {
+ throw handleClientException(e);
+ }
+ }
+
+ private BrandingGenerationResultModel.StatusEnum getStatusFromJsonResponse(JSONObject generationResult)
+ throws BrandingAIServiceException {
+
+ if (generationResult.has("status")) {
+ String status = generationResult.getString("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 BrandingAIServiceException(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(BrandingAIServiceException 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());
+ }
+
+ // Modified method to convert JSONObject to Map with null replacement
+ private static Map convertJSONObjectToMap(JSONObject jsonObject) {
+ Map map = new HashMap<>();
+ Iterator keys = jsonObject.keys();
+
+ while (keys.hasNext()) {
+ String key = keys.next();
+ Object value = jsonObject.get(key);
+
+ // Check and replace null values
+ if (value == JSONObject.NULL || "null".equals(value)) {
+ map.put(key, ""); // Replace null or "null" string with empty string
+ } else if (value instanceof JSONObject) {
+ // Recursive call for nested JSONObject.
+ map.put(key, convertJSONObjectToMap((JSONObject) value));
+ } else if (value instanceof JSONArray) {
+ // Recursive call for nested JSONArray.
+ map.put(key, convertJSONArrayToList((JSONArray) value));
+ } else {
+ map.put(key, value); // Directly put other types of values
+ }
+ }
+ return map;
+ }
+
+ // Helper method to convert JSONArray to a List with null replacement
+ private static Object convertJSONArrayToList(JSONArray jsonArray) {
+ Object[] array = new Object[jsonArray.length()];
+ for (int i = 0; i < jsonArray.length(); i++) {
+ Object value = jsonArray.get(i);
+ // Check and replace null values
+ if (value == JSONObject.NULL || "null".equals(value)) {
+ array[i] = ""; // Replace null or "null" string with empty string
+ } else if (value instanceof JSONObject) {
+ // Recursive call for nested JSONObject
+ array[i] = convertJSONObjectToMap((JSONObject) value);
+ } else if (value instanceof JSONArray) {
+ // Recursive call for nested JSONArray
+ array[i] = convertJSONArrayToList((JSONArray) value);
+ } else {
+ array[i] = value; // Directly put other types of values
+ }
+ }
+ 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..980a0e2cb5 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.AIBrandingPreferenceManagementService;
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 AIBrandingPreferenceManagementService aiBrandingPreferenceManagementService;
+
//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 = aiBrandingPreferenceManagementService.generateBrandingPreference(
+ brandingGenerationModel);
+ return Response.accepted().entity(response).build();
+
+ }
+
+ @Override
+ public Response getBrandingGenerationResult(String operationId) {
+
+ BrandingGenerationResultModel response = aiBrandingPreferenceManagementService
+ .getBrandingPreferenceGenerationResult(operationId);
+ return Response.ok().entity(response).build();
+ }
+
+ @Override
+ public Response getBrandingGenerationStatus(String operationId) {
+
+ BrandingGenerationStatusModel response = aiBrandingPreferenceManagementService
+ .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..e695c86ddb 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