Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.identity.api.server.organization.management.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.organization.discovery.service.OrganizationDiscoveryManager;
import org.wso2.carbon.identity.organization.management.application.OrgApplicationManager;
Expand All @@ -28,6 +30,8 @@
*/
public class OrganizationManagementServiceHolder {

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

private OrganizationManagementServiceHolder() {}

private static class OrgApplicationManagerHolder {
Expand Down Expand Up @@ -55,6 +59,12 @@ private static class OrganizationDiscoveryManagerHolder {
*/
public static OrgApplicationManager getOrgApplicationManager() {

if (log.isDebugEnabled()) {
log.debug("Retrieving OrgApplicationManager service.");
}
if (OrgApplicationManagerHolder.SERVICE == null) {
log.warn("OrgApplicationManager service is not available.");
}
return OrgApplicationManagerHolder.SERVICE;
}

Expand All @@ -65,6 +75,12 @@ public static OrgApplicationManager getOrgApplicationManager() {
*/
public static OrganizationManager getOrganizationManager() {

if (log.isDebugEnabled()) {
log.debug("Retrieving OrganizationManager service.");
}
if (OrganizationManagerHolder.SERVICE == null) {
log.warn("OrganizationManager service is not available.");
}
return OrganizationManagerHolder.SERVICE;
}

Expand All @@ -75,6 +91,12 @@ public static OrganizationManager getOrganizationManager() {
*/
public static OrganizationDiscoveryManager getOrganizationDiscoveryManager() {

if (log.isDebugEnabled()) {
log.debug("Retrieving OrganizationDiscoveryManager service.");
}
if (OrganizationDiscoveryManagerHolder.SERVICE == null) {
log.warn("OrganizationDiscoveryManager service is not available.");
}
return OrganizationDiscoveryManagerHolder.SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.identity.api.server.organization.management.v1.exceptions;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.api.server.organization.management.v1.model.Error;

import javax.ws.rs.WebApplicationException;
Expand All @@ -30,14 +32,23 @@
*/
public class OrganizationManagementEndpointException extends WebApplicationException {

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

public OrganizationManagementEndpointException(Response.Status status, Error error) {

super(Response.status(status).entity(error).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.build());
if (LOG.isDebugEnabled()) {
LOG.debug("Organization management endpoint exception created with status: " + status +
" and error code: " + (error != null ? error.getCode() : "null"));
}
}

public OrganizationManagementEndpointException(Response.Status status) {

super(Response.status(status).build());
if (LOG.isDebugEnabled()) {
LOG.debug("Organization management endpoint exception created with status: " + status);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.api.server.organization.management.common.OrganizationManagementServiceHolder;
import org.wso2.carbon.identity.api.server.organization.management.v1.service.OrganizationManagementService;
import org.wso2.carbon.identity.organization.discovery.service.OrganizationDiscoveryManager;
Expand All @@ -29,28 +31,37 @@
*/
public class OrganizationManagementServiceFactory {

private static final Log LOG = LogFactory.getLog(OrganizationManagementServiceFactory.class);
private static final OrganizationManagementService SERVICE;

static {
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing OrganizationManagementServiceFactory");
}

OrgApplicationManager orgApplicationManager = OrganizationManagementServiceHolder.getOrgApplicationManager();
OrganizationManager organizationManager = OrganizationManagementServiceHolder.getOrganizationManager();
OrganizationDiscoveryManager organizationDiscoveryManager = OrganizationManagementServiceHolder
.getOrganizationDiscoveryManager();

if (orgApplicationManager == null) {
LOG.error("OrgApplicationManager service is not available from OSGi context");
throw new IllegalStateException("OrgApplicationManager service is not available from OSGi context.");
}

if (organizationManager == null) {
LOG.error("OrganizationManager service is not available from OSGi context");
throw new IllegalStateException("OrganizationManager service is not available from OSGi context.");
}

if (organizationDiscoveryManager == null) {
LOG.error("OrganizationDiscoveryManager service is not available from OSGi context");
throw new IllegalStateException("OrganizationDiscoveryManager service is not available from OSGi context.");
}

SERVICE = new OrganizationManagementService(orgApplicationManager,
organizationManager, organizationDiscoveryManager);
LOG.info("OrganizationManagementService initialized successfully in factory");
}

/**
Expand All @@ -60,6 +71,9 @@ public class OrganizationManagementServiceFactory {
*/
public static OrganizationManagementService getOrganizationManagementService() {

if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving OrganizationManagementService instance");
}
return SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.identity.api.server.organization.management.v1.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.api.server.organization.management.v1.OrganizationsApiService;
import org.wso2.carbon.identity.api.server.organization.management.v1.factories.OrganizationManagementServiceFactory;
import org.wso2.carbon.identity.api.server.organization.management.v1.model.ApplicationSharePOSTRequest;
Expand All @@ -40,27 +42,40 @@
*/
public class OrganizationsApiServiceImpl implements OrganizationsApiService {

private static final Log LOG = LogFactory.getLog(OrganizationsApiServiceImpl.class);
private final OrganizationManagementService organizationManagementService;

public OrganizationsApiServiceImpl() {

try {
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing OrganizationsApiServiceImpl");
}
this.organizationManagementService = OrganizationManagementServiceFactory
.getOrganizationManagementService();
LOG.info("OrganizationsApiServiceImpl initialized successfully");
} catch (IllegalStateException e) {
LOG.error("Error occurred while initiating organization management service", e);
throw new RuntimeException("Error occurred while initiating organization management service.", e);
}
}

@Override
public Response organizationsGet(String filter, Integer limit, String after, String before, Boolean recursive) {

if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving organizations with filter: " + filter + ", limit: " + limit +
", recursive: " + recursive);
}
return organizationManagementService.getOrganizations(filter, limit, after, before, recursive);
}

@Override
public Response organizationsOrganizationIdDelete(String organizationId) {

if (LOG.isDebugEnabled()) {
LOG.debug("Deleting organization with ID: " + organizationId);
}
return organizationManagementService.deleteOrganization(organizationId);
}

Expand Down Expand Up @@ -145,6 +160,14 @@ public Response organizationsMetaAttributesGet(String filter, Integer limit, Str
@Override
public Response organizationPost(OrganizationPOSTRequest organizationPOSTRequest) {

if (LOG.isDebugEnabled()) {
String orgName = organizationPOSTRequest != null ? organizationPOSTRequest.getName() : "null";
LOG.debug("Creating new organization with name: " + orgName);
}
if (organizationPOSTRequest == null) {
LOG.warn("Organization POST request is null. Cannot proceed with organization creation.");
return Response.status(Response.Status.BAD_REQUEST).entity("Invalid request").build();
}
return organizationManagementService.addOrganization(organizationPOSTRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ public OrganizationManagementService(OrgApplicationManager orgApplicationManager
OrganizationManager organizationManager,
OrganizationDiscoveryManager organizationDiscoveryManager) {

if (LOG.isDebugEnabled()) {
LOG.debug("Creating OrganizationManagementService instance");
}
this.orgApplicationManager = orgApplicationManager;
this.organizationManager = organizationManager;
this.organizationDiscoveryManager = organizationDiscoveryManager;
LOG.info("OrganizationManagementService initialized successfully");
}

/**
Expand All @@ -139,6 +143,10 @@ public OrganizationManagementService(OrgApplicationManager orgApplicationManager
public Response getOrganizations(String filter, Integer limit, String after, String before, Boolean recursive) {

try {
if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving organizations with parameters - filter: " + filter + ", limit: " + limit +
", recursive: " + recursive);
}
limit = validateLimit(limit);
String sortOrder = StringUtils.isNotBlank(before) ? ASC_SORT_ORDER : DESC_SORT_ORDER;
List<Organization> organizations = organizationManager.getOrganizationsList(limit + 1, after,
Expand Down Expand Up @@ -194,7 +202,11 @@ public Response checkOrganizationHandle(String orgHandle) {
public Response deleteOrganization(String organizationId) {

try {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting organization with ID: " + organizationId);
}
organizationManager.deleteOrganization(organizationId);
LOG.info("Organization deleted successfully with ID: " + organizationId);
return Response.noContent().build();
} catch (OrganizationManagementClientException e) {
return OrganizationManagementEndpointUtil.handleClientErrorResponse(e, LOG);
Expand Down Expand Up @@ -273,9 +285,19 @@ public Response updateOrganization(String organizationId, OrganizationPUTRequest
public Response addOrganization(OrganizationPOSTRequest organizationPOSTRequest) {

try {
if (LOG.isDebugEnabled()) {
String orgName = organizationPOSTRequest != null ? organizationPOSTRequest.getName() : "null";
LOG.debug("Adding new organization with name: " + orgName);
}
if (organizationPOSTRequest == null) {
LOG.error("Organization POST request cannot be null");
return Response.status(Response.Status.BAD_REQUEST).entity("Invalid request payload").build();
}
Organization organization = organizationManager.addOrganization(getOrganizationFromPostRequest
(organizationPOSTRequest));
String organizationId = organization.getId();
LOG.info("Organization created successfully with ID: " + organizationId +
" and name: " + organization.getName());
return Response.created(OrganizationManagementEndpointUtil.getResourceLocation(organizationId)).entity
(getOrganizationResponse(organization)).build();
} catch (OrganizationManagementClientException e) {
Expand Down Expand Up @@ -313,15 +335,23 @@ public Response shareOrganizationApplication(String organizationId, String appli
private void validateApplicationSharePostRequestBody(ApplicationSharePOSTRequest requestBody)
throws OrganizationManagementClientException {

if (LOG.isDebugEnabled()) {
LOG.debug("Validating application share request body");
}

if (requestBody == null) {
LOG.warn("Application share request body is null");
throw handleClientException(ERROR_CODE_INVALID_SHARE_APPLICATION_EMPTY_REQUEST_BODY);
}
if (requestBody.getShareWithAllChildren() == null && requestBody.getSharedOrganizations() == null) {
LOG.warn("Both shareWithAllChildren and sharedOrganizations are null in request body");
throw handleClientException(ERROR_CODE_INVALID_SHARE_APPLICATION_EMPTY_REQUEST_BODY);
}
if (requestBody.getShareWithAllChildren() != null
&& requestBody.getShareWithAllChildren()
&& CollectionUtils.isNotEmpty(requestBody.getSharedOrganizations())) {
LOG.warn("Invalid application share request: shareWithAllChildren is true but " +
"sharedOrganizations is also provided");
throw handleClientException(ERROR_CODE_INVALID_SHARE_APPLICATION_REQUEST_BODY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public class OrganizationManagementEndpointUtil {
*/
public static Response handleClientErrorResponse(OrganizationManagementClientException e, Log log) {

if (LOG.isDebugEnabled()) {
LOG.debug("Handling client error with code: " + e.getErrorCode());
}

if (isNotFoundError(e)) {
throw buildException(Response.Status.NOT_FOUND, log, e);
}
Expand All @@ -76,6 +80,9 @@ public static Response handleClientErrorResponse(OrganizationManagementClientExc
*/
public static Response handleServerErrorResponse(OrganizationManagementException e, Log log) {

if (LOG.isDebugEnabled()) {
LOG.debug("Handling server error with code: " + e.getErrorCode());
}
throw buildException(Response.Status.INTERNAL_SERVER_ERROR, log, e);
}

Expand Down