Skip to content

Commit

Permalink
Remove spring dependency and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Jan 23, 2025
1 parent bfcfc5b commit c951329
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.api.server.branding.preference.management.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.branding.preference.management.core.BrandingPreferenceManager;
import org.wso2.carbon.identity.branding.preference.management.core.ai.BrandingAIPreferenceManager;

Expand All @@ -27,7 +28,12 @@
public class BrandingPreferenceServiceHolder {

private static BrandingPreferenceManager brandingPreferenceManager;
private static BrandingAIPreferenceManager brandingPreferenceAiManager;

private static class BrandingAIPreferenceManagerServiceHolder {

static final BrandingAIPreferenceManager SERVICE = (BrandingAIPreferenceManager) PrivilegedCarbonContext.
getThreadLocalCarbonContext().getOSGiService(BrandingAIPreferenceManager.class, null);
}

/**
* Get BrandingPreferenceManager OSGi service.
Expand Down Expand Up @@ -56,16 +62,6 @@ public static void setBrandingPreferenceManager(BrandingPreferenceManager brandi
*/
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;
return BrandingAIPreferenceManagerServiceHolder.SERVICE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -175,7 +175,7 @@ public Response generateBrandingPreference(@ApiParam(value = "This represents th
@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.<br/> <b>Scope(Permission) required:</b> `internal_branding_preference_update` ", response = BrandingGenerationResultModel.class, authorizations = {
@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.<br/> ", response = BrandingGenerationResultModel.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

Expand All @@ -186,16 +186,15 @@ public Response generateBrandingPreference(@ApiParam(value = "This represents th
})
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;
return delegate.getBrandingGenerationResult(operationId );
}

@Valid
@GET
@Path("/status/{operationId}")

@Produces({ "application/json" })
@ApiOperation(value = "Get the status of a branding generation operation.", notes = "This API endpoint return the status of the AI branding generation process that initiated using the `/generate` endpoint.<br/> <b>Scope(Permission) required:</b> `internal_branding_preference_update` ", response = BrandingGenerationStatusModel.class, authorizations = {
@ApiOperation(value = "Get the status of a branding generation operation.", notes = "This API endpoint returns the status of the AI branding generation process that initiated using the `/generate` endpoint.<br/> ", response = BrandingGenerationStatusModel.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -44,7 +44,7 @@ public BrandingGenerationRequestModel websiteUrl(String websiteUrl) {
}

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

@ApiModelProperty(value = "Operation id of the initiated branding generation process.")
@JsonProperty("operation_id")
@JsonProperty("operationId")
@Valid
public String getOperationId() {
return operationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class BrandingAIPreferenceManagementService {

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

/**
* Initiates the branding preference generation process by invoking BrandingPreferenceManager.
Expand Down Expand Up @@ -140,6 +140,7 @@ private BrandingGenerationResultModel.StatusEnum getStatusFromResult(Map<String,

private APIError handleClientException(AIClientException error) {

LOG.debug("Client error occurred while invoking AI service.", error);
ErrorResponse.Builder errorResponseBuilder = new ErrorResponse.Builder()
.withCode(error.getErrorCode())
.withMessage(error.getMessage());
Expand All @@ -153,6 +154,7 @@ private APIError handleClientException(AIClientException error) {

private APIError handleServerException(AIServerException error) {

LOG.error("Server error occurred while generating branding preference.", error);
ErrorResponse.Builder errorResponseBuilder = new ErrorResponse.Builder()
.withCode(error.getErrorCode())
.withMessage(error.getMessage());
Expand Down Expand Up @@ -184,7 +186,7 @@ private static Map<String, Object> convertObjectToMap(Object object) {
}
return map;
}
log.warn("Object is not an instance of Map. Returning an empty map.");
LOG.warn("Object is not an instance of Map. Returning an empty map.");
return new HashMap<>();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.server.branding.preference.management.v1.factories;

import org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingAIPreferenceManagementService;

/**
* Factory class for Branding AI Preference Management Service.
*/
public class BrandingAIPreferenceManagementServiceFactory {

private static final BrandingAIPreferenceManagementService SERVICE;

static {
SERVICE = new BrandingAIPreferenceManagementService();
}

public static BrandingAIPreferenceManagementService getBrandingAIPreferenceManagementService() {

return SERVICE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2024-2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -21,8 +21,8 @@
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.factories.BrandingAIPreferenceManagementServiceFactory;
import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationRequestModel;
import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResponseModel;
import org.wso2.carbon.identity.api.server.branding.preference.management.v1.model.BrandingGenerationResultModel;
Expand Down Expand Up @@ -59,9 +59,6 @@ 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
Expand Down Expand Up @@ -194,26 +191,29 @@ public Response getBrandingPreference(String type, String name, String locale) {
}

@Override
public Response generateBrandingPreference(BrandingGenerationRequestModel brandingGenerationModel) {
public Response generateBrandingPreference(BrandingGenerationRequestModel brandingGenerationRequestModel) {

BrandingGenerationResponseModel response = brandingAIPreferenceManagementService.generateBrandingPreference(
brandingGenerationModel);
BrandingGenerationResponseModel response = BrandingAIPreferenceManagementServiceFactory
.getBrandingAIPreferenceManagementService().generateBrandingPreference(
brandingGenerationRequestModel);
return Response.accepted().entity(response).build();

}

@Override
public Response getBrandingGenerationResult(String operationId) {

BrandingGenerationResultModel response = brandingAIPreferenceManagementService
BrandingGenerationResultModel response = BrandingAIPreferenceManagementServiceFactory
.getBrandingAIPreferenceManagementService()
.getBrandingPreferenceGenerationResult(operationId);
return Response.ok().entity(response).build();
}

@Override
public Response getBrandingGenerationStatus(String operationId) {

BrandingGenerationStatusModel response = brandingAIPreferenceManagementService
BrandingGenerationStatusModel response = BrandingAIPreferenceManagementServiceFactory
.getBrandingAIPreferenceManagementService()
.getBrandingPreferenceGenerationStatus(operationId);
return Response.ok().entity(response).build();
}
Expand Down Expand Up @@ -287,18 +287,7 @@ public Response updateBrandingPreference(BrandingPreferenceModel brandingPrefere
@Override
public Response updateCustomText(CustomTextModel customTextModel) {

if (StringUtils.isBlank(customTextModel.getType().toString())) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (!ORGANIZATION_TYPE.equals(customTextModel.getType().toString())) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (StringUtils.isBlank(customTextModel.getScreen())) {
return Response.status(Response.Status.BAD_REQUEST).build();
}

CustomTextModel updatedCustomTextModel =
brandingPreferenceManagementService.updateCustomTextPreference(customTextModel);
return Response.ok().entity(updatedCustomTextModel).build();
// do some magic!
return Response.ok().entity("magic!").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean class="org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingPreferenceManagementService"/>
<bean class="org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingAIPreferenceManagementService"/>
<bean class="org.wso2.carbon.identity.api.server.branding.preference.management.v1.impl.BrandingPreferenceApiServiceImpl"/>
<bean id="brandingPreferenceManagerFactoryBean" class="org.wso2.carbon.identity.api.server.branding.preference.management.common.factory.BrandingPreferenceMgtOSGiServiceFactory"/>
<bean id="brandingPreferenceAiManagerFactoryBean" class="org.wso2.carbon.identity.api.server.branding.preference.management.common.factory.BrandingPreferenceAIMgtOSGiServiceFactory"/>
<bean id="brandingPreferenceServiceImplDataHolderBean" class="org.wso2.carbon.identity.api.server.branding.preference.management.common.BrandingPreferenceServiceHolder">
<property name="brandingPreferenceManager" ref="brandingPreferenceManagerFactoryBean"/>
<property name="brandingPreferenceAiManager" ref="brandingPreferenceAiManagerFactoryBean"/>
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ paths:
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.<br/>
This API endpoint returns the status of the AI branding generation process that initiated using the `/generate` endpoint.<br/>
parameters:
- $ref: '#/components/parameters/operationId'
responses:
Expand Down Expand Up @@ -279,7 +279,6 @@ paths:
schema:
$ref: '#/components/schemas/BrandingGenerationResultModel'


'/branding-preference/text':
get:
tags:
Expand Down Expand Up @@ -567,15 +566,15 @@ components:
properties:
# Define properties related to the organization that are used to generate branding preferences
# Example property:
website_url:
websiteUrl:
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:
operationId:
type: string
description: Operation id of the initiated branding generation process.
BrandingGenerationStatusModel:
Expand Down

0 comments on commit c951329

Please sign in to comment.