Skip to content

Commit

Permalink
Add admin advisory API
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Sep 3, 2023
1 parent 690f16d commit d6a4f30
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.model.Error;

import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PATCH;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import io.swagger.annotations.ApiParam;

/**
* Admin Advisory Management API.
Expand Down Expand Up @@ -60,4 +63,20 @@ public Response getAdminAdvisoryConfig() {
return delegate.getAdminAdvisoryConfig();
}

@Valid
@PATCH
@Path("/banner")
@Consumes({ "application/json" })
@Produces({ "application/json", "*/*" })
@ApiOperation(value = "Update admin advisory banner related configurations.", notes = "Update admin advisory banner related configurations.<br> <b>Permission required:</b> <br> * None <br> <b>Scope required:</b> <br> * None requestBody: ", response = AdminAdvisoryConfig.class, tags={ "Management" })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Admin advisory banner configuration.", response = AdminAdvisoryConfig.class),
@ApiResponse(code = 400, message = "Invalid input in the request.", response = Error.class),
@ApiResponse(code = 500, message = "Internal Server Error.", response = Error.class)
})
public Response updateAdminAdvisoryConfig(@ApiParam(value = "" ,required=true) @Valid AdminAdvisoryConfig adminAdvisoryConfig) {

return delegate.updateAdminAdvisoryConfig(adminAdvisoryConfig );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.identity.api.server.admin.advisory.management.v1;

import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.model.AdminAdvisoryConfig;

import javax.ws.rs.core.Response;

/**
Expand All @@ -26,4 +28,6 @@
public interface AdminAdvisoryManagementApiService {

public Response getAdminAdvisoryConfig();

public Response updateAdminAdvisoryConfig(AdminAdvisoryConfig adminAdvisoryConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.wso2.carbon.identity.api.server.admin.advisory.management.v1.core;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.admin.advisory.mgt.dto.AdminAdvisoryBannerDTO;
Expand Down Expand Up @@ -61,6 +62,29 @@ public AdminAdvisoryConfig getAdminAdvisoryConfig() {
}
}

/**
* Update admin advisory configuration.
*
* @param adminAdvisoryConfig Admin advisory configuration.
*/
public void saveAdminAdvisoryConfig(AdminAdvisoryConfig adminAdvisoryConfig) {

try {
AdminAdvisoryManagementService adminAdvisoryManagementService = AdminAdvisoryManagementServiceHolder
.getAdminAdvisoryManagementService();
AdminAdvisoryBannerDTO modifiedAdminAdvisoryBannerDTO = createModifiedAdminAdvisoryBannerDTO(
adminAdvisoryManagementService.getAdminAdvisoryConfig(), adminAdvisoryConfig);

adminAdvisoryManagementService.saveAdminAdvisoryConfig(modifiedAdminAdvisoryBannerDTO);

} catch (AdminAdvisoryMgtException e) {
AdminAdvisoryConstants.ErrorMessage errorEnum =
AdminAdvisoryConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_BANNER_CONFIG;
Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
throw handleException(e, errorEnum, status);
}
}

private AdminAdvisoryConfig buildAdminAdvisoryConfigResponse(AdminAdvisoryBannerDTO adminAdvisoryBannerDTO) {

AdminAdvisoryConfig adminAdvisoryConfig = new AdminAdvisoryConfig();
Expand Down Expand Up @@ -90,4 +114,35 @@ private String buildErrorDescription(AdminAdvisoryConstants.ErrorMessage errorEn
}
return errorEnum.getDescription();
}

/**
* Create AdminAdvisoryBannerDTO for given admin advisory configurations.
*
* @param adminAdvisoryConfig Admin advisory configurations.
* @return AdminAdvisoryBannerDTO.
*/
private AdminAdvisoryBannerDTO createModifiedAdminAdvisoryBannerDTO(AdminAdvisoryBannerDTO
currentAdminAdvisoryBannerDTO, AdminAdvisoryConfig adminAdvisoryConfig) throws AdminAdvisoryMgtException {

AdminAdvisoryBannerDTO modifiedAdminAdvisoryBannerDTO = new AdminAdvisoryBannerDTO();
boolean isEnableBanner;
String bannerContent;

if (adminAdvisoryConfig.getEnableBanner() == null) {
isEnableBanner = currentAdminAdvisoryBannerDTO.getEnableBanner();
} else {
isEnableBanner = adminAdvisoryConfig.getEnableBanner();
}

if (StringUtils.isBlank(adminAdvisoryConfig.getBannerContent())) {
bannerContent = currentAdminAdvisoryBannerDTO.getBannerContent();
} else {
bannerContent = adminAdvisoryConfig.getBannerContent();
}

modifiedAdminAdvisoryBannerDTO.setEnableBanner(isEnableBanner);
modifiedAdminAdvisoryBannerDTO.setBannerContent(bannerContent);

return modifiedAdminAdvisoryBannerDTO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.AdminAdvisoryManagementApiService;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.core.ServerAdminAdvisoryManagementService;
import org.wso2.carbon.identity.api.server.admin.advisory.management.v1.model.AdminAdvisoryConfig;

import javax.ws.rs.core.Response;

Expand All @@ -42,4 +43,18 @@ public Response getAdminAdvisoryConfig() {

return Response.ok().entity(adminAdvisoryManagementService.getAdminAdvisoryConfig()).build();
}

/**
* Endpoint to update the admin advisory banner configuration.
*
* @param adminAdvisoryConfig Admin advisory configuration.
*
* @return Response instance.
*/
@Override
public Response updateAdminAdvisoryConfig(AdminAdvisoryConfig adminAdvisoryConfig) {

adminAdvisoryManagementService.saveAdminAdvisoryConfig(adminAdvisoryConfig);
return Response.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ paths:
$ref: '#/components/responses/BadRequest'
'500':
$ref: '#/components/responses/ServerError'
patch:
tags:
- Management
summary: Update admin advisory banner related configurations.
operationId: updateAdminAdvisoryConfig
description: |
Update admin advisory banner related configurations.<br>
<b>Permission required:</b> <br>
* /permission/admin/manage/identity/configmgt/update <br>
<b>Scope required:</b> <br>
* internal_config_mgt_update
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AdminAdvisoryConfig'
required: true
responses:
'200':
description: Admin advisory banner configuration.
content:
application/json:
schema:
$ref: '#/components/schemas/AdminAdvisoryConfig'
'400':
$ref: '#/components/responses/BadRequest'
'500':
$ref: '#/components/responses/ServerError'

servers:
- url: https://localhost:9443/t/{tenant-domain}/api/server/v1/
Expand Down

0 comments on commit d6a4f30

Please sign in to comment.