From 7967ab217b2121f40e8a001c93c8ffadd5053c53 Mon Sep 17 00:00:00 2001 From: isuri Date: Wed, 11 Oct 2023 14:43:24 +0530 Subject: [PATCH] device Organization API configs --- .../pom.xml | 137 ++++++- .../api/DeviceOrganizationMgtService.java | 358 +++++++++++++++++- .../api/DeviceOrganizationMgtServiceImpl.java | 16 +- .../organization/api/beans/ErrorListItem.java | 78 ++++ .../organization/api/beans/ErrorResponse.java | 193 ++++++++++ .../pom.xml | 121 +++++- 6 files changed, 875 insertions(+), 28 deletions(-) create mode 100644 components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorListItem.java create mode 100644 components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorResponse.java diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml index 9149828018..5d8ece9dbe 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml @@ -18,12 +18,14 @@ --> + + device-mgt-extensions io.entgra.device.mgt.core - io.entgra.device.mgt.core.parent 5.0.31-SNAPSHOT - ../../../pom.xml + ../pom.xml + 4.0.0 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api war @@ -44,12 +46,92 @@ maven-war-plugin WEB-INF/lib/*cxf*.jar - ${project.artifactId} + api#deviceOrganization-mgt#v1.0 + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + deploy + + compile + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + compile + + run + + + + + + + + + + + + + + + + + + client + + test + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + test + + java + + + + + + + + + org.springframework @@ -61,10 +143,31 @@ cxf-bundle-jaxrs provided + + + commons-codec.wso2 + commons-codec + + + commons-codec + commons-codec + + + org.codehaus.jackson jackson-jaxrs + + junit + junit + test + + + org.wso2.carbon + org.wso2.carbon.logging + provided + io.entgra.device.mgt.core io.entgra.device.mgt.core.device.mgt.extensions.device.organization @@ -79,6 +182,34 @@ io.swagger swagger-annotations + + io.swagger + swagger-core + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-annotations + + + org.slf4j + slf4j-api + + + + + io.swagger + swagger-jaxrs + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + + + org.slf4j + slf4j-api + + + io.entgra.device.mgt.core io.entgra.device.mgt.core.apimgt.annotations diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtService.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtService.java index 06c6d5c53a..22e82e1e4a 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtService.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtService.java @@ -19,16 +19,18 @@ package io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api; import io.entgra.device.mgt.core.apimgt.annotations.Scope; import io.entgra.device.mgt.core.apimgt.annotations.Scopes; +import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans.ErrorResponse; import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization; -import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Info; import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Api; import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.Info; -import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; +import io.swagger.annotations.ApiResponses; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -96,8 +98,8 @@ public interface DeviceOrganizationMgtService { produces = MediaType.TEXT_PLAIN, httpMethod = "POST", value = "Add a new device Organization.", - notes = "This will return a response to indicate when a new device organization is created.", - tags = "Device Management", + notes = "This endpoint allows you to add a new device organization.", + tags = "Device Organization Management", extensions = { @Extension(properties = { @ExtensionProperty(name = SCOPE, value = "perm:devices:view") @@ -108,8 +110,20 @@ public interface DeviceOrganizationMgtService { value = { @ApiResponse( code = 200, - message = "OK. \n Successfully fetched the device location.", + message = "OK. \n Successfully created the device organization.", response = String.class), + @ApiResponse( + code = 201, + message = "Created. Successfully created a new resource.", + response = Response.class), + @ApiResponse( + code = 400, + message = "Bad Request. Invalid input data.", + response = Response.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = Response.class) }) Response addDeviceOrganization(DeviceOrganizationRequest request); @@ -124,10 +138,39 @@ public interface DeviceOrganizationMgtService { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/children") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get Child Nodes of a Device Node", + notes = "This endpoint allows you to retrieve a list of child nodes of a given device node up to a specified depth.", + tags = "Device Organization Management" + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. Successfully retrieved the list of child nodes." + ), + @ApiResponse( + code = 400, + message = "Bad Request. Invalid input data.", + response = ErrorResponse.class + ), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class + ) + }) Response getChildrenOfDeviceNode( + @ApiParam(value = "The ID of the parent device node.", required = true) @QueryParam("deviceId") int deviceId, + @ApiParam(value = "The maximum depth of child nodes to retrieve.", required = true) @QueryParam("maxDepth") int maxDepth, - @QueryParam("includeDevice") boolean includeDevice); + @ApiParam(value = "Indicates whether to include device information in the retrieved nodes.", required = true) + @QueryParam("includeDevice") boolean includeDevice + ); + /** * Retrieves a list of parent nodes of a given device node, up to a specified depth. @@ -140,11 +183,41 @@ public interface DeviceOrganizationMgtService { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/parents") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Retrieve Parent Nodes of a Device Node", + notes = "Get a list of parent nodes of a specified child device node, up to a specified depth.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. Successfully retrieved the list of parent nodes."), + @ApiResponse( + code = 400, + message = "Bad Request. Invalid input data.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class) + }) Response getParentsOfDeviceNode( + @ApiParam(value = "The ID of the child device node.", required = true) @QueryParam("deviceId") int deviceId, + @ApiParam(value = "The maximum depth of parent nodes to retrieve.", required = true) @QueryParam("maxDepth") int maxDepth, + @ApiParam(value = "Indicates whether to include device information in the retrieved nodes.", required = true) @QueryParam("includeDevice") boolean includeDevice); + /** * Retrieves a list of all device organizations. * @@ -153,8 +226,31 @@ public interface DeviceOrganizationMgtService { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/all") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Retrieve All Device Organizations", + notes = "Get a list of all device organizations.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. Successfully retrieved the list of all device organizations."), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class) + }) Response getAllDeviceOrganizations(); + /** * Retrieves a specific device organization by its organization ID. * @@ -164,8 +260,35 @@ public interface DeviceOrganizationMgtService { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{organizationId}") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Retrieve Device Organization by ID", + notes = "Get a specific device organization by its ID.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. Successfully retrieved the device organization by ID."), + @ApiResponse( + code = 404, + message = "Not Found. The specified organization does not exist.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class) + }) Response getDeviceOrganizationById(@PathParam("organizationId") int organizationId); + /** * Checks if a device organization with the specified device and parent device IDs already exists. * @@ -176,10 +299,38 @@ public interface DeviceOrganizationMgtService { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/exists") - Response organizationExists( + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Check Device Organization Existence", + notes = "Check if a device organization with the specified device and parent device IDs exists.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. The organization exists.", + response = Response.class), + @ApiResponse( + code = 404, + message = "Not Found. The organization does not exist.", + response = Response.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class) + }) + Response isDeviceOrganizationExist( @QueryParam("deviceId") int deviceId, @QueryParam("parentDeviceId") int parentDeviceId); + /** * Retrieve a device organization by its unique key (deviceId and parentDeviceId). * @@ -190,6 +341,32 @@ public interface DeviceOrganizationMgtService { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/unique") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get Device Organization by Unique Key", + notes = "Retrieve a device organization by its unique key, which is a combination of deviceId and parentDeviceId.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. The organization exists.", + response = DeviceOrganization.class), + @ApiResponse( + code = 404, + message = "Not Found. The specified organization does not exist."), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class) + }) Response getDeviceOrganizationByUniqueKey( @QueryParam("deviceId") int deviceId, @QueryParam("parentDeviceId") int parentDeviceId); @@ -204,7 +381,73 @@ public interface DeviceOrganizationMgtService { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/device-exists") - Response doesDeviceIdExist(@QueryParam("deviceId") int deviceId); + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Check if Device ID Exists in Device Organization", + notes = "Checks whether a record with the specified device ID exists in the device organization table.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. The device exists in the device organization."), + @ApiResponse( + code = 404, + message = "Not Found. The device does not exist in the device organization."), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class) + }) + Response doesDeviceIdExist( + @ApiParam(value = "The ID of the device to check.", required = true) + @QueryParam("deviceId") int deviceId); + + /** + * Checks if a child device with the specified device ID already exists. + * + * @param deviceID The ID of the child device to check. + * @return A response indicating whether the child device exists or not. + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/child-exists") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Check if Child Device ID Exists in Device Organization", + notes = "Checks whether a child device with the specified device ID exists in the device organization.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. The child device exists in the device organization."), + @ApiResponse( + code = 404, + message = "Not Found. The child device does not exist in the device organization."), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = ErrorResponse.class) + }) + Response isChildDeviceIdExist( + @ApiParam(value = "The ID of the child device to check.", required = true) + @QueryParam("deviceID") int deviceID); + /** * Updates a device organization. @@ -216,7 +459,41 @@ public interface DeviceOrganizationMgtService { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("/update") - Response updateDeviceOrganization(DeviceOrganization deviceOrganization); + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Update a Device Organization", + notes = "This endpoint allows you to update a device organization.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:update") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. Successfully updated the device organization.", + response = Response.class), + @ApiResponse( + code = 400, + message = "Bad Request. Invalid input data.", + response = Response.class), + @ApiResponse( + code = 404, + message = "Not Found. The specified device organization does not exist.", + response = Response.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = Response.class) + }) + Response updateDeviceOrganization( + @ApiParam(value = "The updated device organization.", required = true) + DeviceOrganization deviceOrganization); + /** * Deletes a device organization by its organization ID. @@ -226,7 +503,34 @@ public interface DeviceOrganizationMgtService { */ @DELETE @Path("/delete/{organizationId}") - Response deleteDeviceOrganizationById(@PathParam("organizationId") int organizationId); + @ApiOperation( + httpMethod = "DELETE", + value = "Delete a Device Organization", + notes = "This endpoint allows you to delete a device organization by its organization ID.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:delete") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. Successfully deleted the device organization.", + response = Response.class), + @ApiResponse( + code = 404, + message = "Not Found. The specified device organization does not exist.", + response = Response.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = Response.class) + }) + Response deleteDeviceOrganizationById( + @ApiParam(value = "The organization ID of the device organization to delete.", required = true) + @PathParam("organizationId") int organizationId); /** * Deletes records associated with a particular device ID from the device organization table. @@ -238,6 +542,34 @@ public interface DeviceOrganizationMgtService { */ @DELETE @Path("/delete-associations/{deviceId}") - Response deleteDeviceAssociations(@PathParam("deviceId") int deviceId); + @ApiOperation( + httpMethod = "DELETE", + value = "Delete Device Associations", + notes = "This endpoint allows you to delete records associated with a particular device ID from the device organization table.", + tags = "Device Organization Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:devices:delete-associations") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. Successfully deleted the device associations.", + response = Response.class), + @ApiResponse( + code = 404, + message = "Not Found. No associations found for the specified device ID.", + response = Response.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. An error occurred while processing the request.", + response = Response.class) + }) + Response deleteDeviceAssociations( + @ApiParam(value = "The ID of the device for which associations should be deleted.", required = true) + @PathParam("deviceId") int deviceId); + } diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java index ed29fb3742..b32d09758c 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/DeviceOrganizationMgtServiceImpl.java @@ -129,7 +129,7 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe @GET @Produces(MediaType.APPLICATION_JSON) @Path("/exists") - public Response organizationExists( + public Response isDeviceOrganizationExist( @QueryParam("deviceId") int deviceId, @QueryParam("parentDeviceId") int parentDeviceId) { try { @@ -141,6 +141,20 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe } } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/child-exists") + public Response isChildDeviceIdExist(@QueryParam("deviceId") int deviceID) { + try { + DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl(); + boolean exists = deviceOrganizationService.isChildDeviceIdExist(deviceID); + return Response.status(Response.Status.OK).entity(gson.toJson(exists)).build(); + } catch (DeviceOrganizationMgtPluginException e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + } + + @GET @Produces(MediaType.APPLICATION_JSON) @Path("/unique") diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorListItem.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorListItem.java new file mode 100644 index 0000000000..9c0bbd8fad --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorListItem.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; + +@ApiModel(description = "Error List Item") +public class ErrorListItem { + + @NotNull + private String code = null; + @NotNull + private String message = null; + + @ApiModelProperty(required = true, value = "") + @JsonProperty("code") + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public ErrorListItem() { + } + + public ErrorListItem(String code, String msg) { + this.code = code; + this.message = msg; + } + + + /** + * Description about individual errors occurred + */ + @ApiModelProperty(required = true, value = "Description about individual errors occurred") + @JsonProperty("message") + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("errorItem {\n"); + + sb.append(" code: ").append(code).append("\n"); + sb.append(" message: ").append(message).append("\n"); + sb.append("}\n"); + return sb.toString(); + } + +} diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorResponse.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorResponse.java new file mode 100644 index 0000000000..c3769f5803 --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/api/beans/ErrorResponse.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +@ApiModel(description = "Error Response") +public class ErrorResponse { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List errorItems = new ArrayList<>(); + + private ErrorResponse() { + } + + @JsonProperty(value = "code") + @ApiModelProperty(required = true, value = "") + public Long getCode() { + return code; + } + + public void setCode(Long code) { + this.code = code; + } + + @JsonProperty(value = "message") + @ApiModelProperty(required = true, value = "ErrorResponse message.") + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @JsonProperty(value = "description") + @ApiModelProperty(value = "A detail description about the error message.") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @JsonProperty(value = "moreInfo") + @ApiModelProperty(value = "Preferably an url with more details about the error.") + public String getMoreInfo() { + return moreInfo; + } + + public void setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + } + + public void addErrorListItem(ErrorListItem item) { + this.errorItems.add(item); + } + + /** + * If there are more than one error list them out. \nFor example, list out validation errors by each field. + */ + @JsonProperty(value = "errorItems") + @ApiModelProperty(value = "If there are more than one error list them out. \n" + + "For example, list out validation errors by each field.") + public List getErrorItems() { + return errorItems; + } + + public void setErrorItems(List error) { + this.errorItems = error; + } + + @Override + public String toString() { +// StringBuilder sb = new StringBuilder(); +// sb.append("{"); +// boolean cont = false; +// if (code != null) { +// cont = true; +// sb.append(" \"code\": ").append(code); +// } +// if (message != null) { +// if (cont) { +// sb.append(","); +// } +// cont = true; +// sb.append(" \"message\": \"").append(message).append("\""); +// } +// if (description != null) { +// if (cont) { +// sb.append(","); +// } +// cont = true; +// sb.append(" \"description\": ").append(description).append("\""); +// } +// if (moreInfo != null) { +// if (cont) { +// sb.append(","); +// } +// cont = true; +// sb.append(" \"moreInfo\": \"").append(moreInfo).append("\""); +// } +// if (error != null && error.size() > 0) { +// if (cont) { +// sb.append(","); +// } +// sb.append(" \"errorItems\": ").append(error); +// } +// sb.append("}"); +// return sb.toString(); + return null; + } + + public static class ErrorResponseBuilder { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List error; + + + public ErrorResponseBuilder() { + this.error = new ArrayList<>(); + } + + public ErrorResponseBuilder setCode(long code) { + this.code = code; + return this; + } + + public ErrorResponseBuilder setMessage(String message) { + this.message = message; + return this; + } + + public ErrorResponseBuilder setDescription(String description) { + this.description = description; + return this; + } + + public ErrorResponseBuilder setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + return this; + } + + public ErrorResponseBuilder addErrorItem(String code, String msg) { + ErrorListItem item = new ErrorListItem(); + item.setCode(code); + item.setMessage(msg); + this.error.add(item); + return this; + } + + public ErrorResponse build() { + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setCode(code); + errorResponse.setMessage(message); + errorResponse.setErrorItems(error); + errorResponse.setDescription(description); + errorResponse.setMoreInfo(moreInfo); + return errorResponse; + } + } + +} + + diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/pom.xml index 4b58448d03..34fde6e56d 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/pom.xml @@ -1,21 +1,120 @@ - - - 4.0.0 + + + + + io.entgra.device.mgt.core device-mgt-extensions-feature 5.0.31-SNAPSHOT - org.example + 4.0.0 io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature + pom + WSO2 Carbon - Device Organization Management API Feature + http://wso2.org + This feature contains the APIs required for Device Organization Management. - - 8 - 8 - UTF-8 - + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + package + + copy + + + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api + + ${project.version} + war + true + + ${project.build.directory}/maven-shared-archive-resources/webapps + + api#deviceOrganization-mgt#v1.0.war + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api + ../../../features/etc/feature.properties + + + + org.wso2.carbon.p2.category.type:server + + org.eclipse.equinox.p2.type.group:false + + + + + + + + + \ No newline at end of file