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 f6d27b8
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 99 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 @@ -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/> <b>Scope(Permission) required:</b> `internal_branding_preference_update` ", 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
@@ -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 Down Expand Up @@ -194,10 +194,10 @@ 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);
brandingGenerationRequestModel);
return Response.accepted().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 @@ -22,9 +22,7 @@
<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,8 @@ 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/>
<b>Scope(Permission) required:</b> `internal_branding_preference_update`
parameters:
- $ref: '#/components/parameters/operationId'
responses:
Expand Down Expand Up @@ -269,6 +270,7 @@ paths:
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.<br/>
<b>Scope(Permission) required:</b> `internal_branding_preference_update`
parameters:
- $ref: '#/components/parameters/operationId'
responses:
Expand All @@ -279,7 +281,6 @@ paths:
schema:
$ref: '#/components/schemas/BrandingGenerationResultModel'


'/branding-preference/text':
get:
tags:
Expand Down Expand Up @@ -567,15 +568,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 f6d27b8

Please sign in to comment.