device Organization API configs

pull/238/head
Isuri Mendis 1 year ago
parent a67f9f1c4b
commit 7967ab217b

@ -18,12 +18,14 @@
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId> <groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.31-SNAPSHOT</version> <version>5.0.31-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api</artifactId> <artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
@ -44,12 +46,92 @@
<artifactId>maven-war-plugin</artifactId> <artifactId>maven-war-plugin</artifactId>
<configuration> <configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes> <packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>${project.artifactId}</warName> <warName>api#deviceOrganization-mgt#v1.0</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
</configuration> </configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>deploy</id>
<build>
<defaultGoal>compile</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
<fileset dir="${basedir}/target">
<include name="api-deviceOrganization-mgt-v1.0.war" />
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>client</id>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
@ -61,10 +143,31 @@
<artifactId>cxf-bundle-jaxrs</artifactId> <artifactId>cxf-bundle-jaxrs</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-codec.wso2</groupId>
<artifactId>commons-codec</artifactId>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId> <artifactId>jackson-jaxrs</artifactId>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>io.entgra.device.mgt.core</groupId> <groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization</artifactId> <artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization</artifactId>
@ -79,6 +182,34 @@
<groupId>io.swagger</groupId> <groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId> <artifactId>swagger-annotations</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.wso2.orbit.com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>io.entgra.device.mgt.core</groupId> <groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId> <artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId>

@ -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.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes; 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.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.ApiOperation;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.Api;
import io.swagger.annotations.Extension; import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag; import io.swagger.annotations.Tag;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -96,8 +98,8 @@ public interface DeviceOrganizationMgtService {
produces = MediaType.TEXT_PLAIN, produces = MediaType.TEXT_PLAIN,
httpMethod = "POST", httpMethod = "POST",
value = "Add a new device Organization.", value = "Add a new device Organization.",
notes = "This will return a response to indicate when a new device organization is created.", notes = "This endpoint allows you to add a new device organization.",
tags = "Device Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:devices:view")
@ -108,8 +110,20 @@ public interface DeviceOrganizationMgtService {
value = { value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully fetched the device location.", message = "OK. \n Successfully created the device organization.",
response = String.class), 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); Response addDeviceOrganization(DeviceOrganizationRequest request);
@ -124,10 +138,39 @@ public interface DeviceOrganizationMgtService {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/children") @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( Response getChildrenOfDeviceNode(
@ApiParam(value = "The ID of the parent device node.", required = true)
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@ApiParam(value = "The maximum depth of child nodes to retrieve.", required = true)
@QueryParam("maxDepth") int maxDepth, @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. * Retrieves a list of parent nodes of a given device node, up to a specified depth.
@ -140,11 +183,41 @@ public interface DeviceOrganizationMgtService {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/parents") @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( Response getParentsOfDeviceNode(
@ApiParam(value = "The ID of the child device node.", required = true)
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@ApiParam(value = "The maximum depth of parent nodes to retrieve.", required = true)
@QueryParam("maxDepth") int maxDepth, @QueryParam("maxDepth") int maxDepth,
@ApiParam(value = "Indicates whether to include device information in the retrieved nodes.", required = true)
@QueryParam("includeDevice") boolean includeDevice); @QueryParam("includeDevice") boolean includeDevice);
/** /**
* Retrieves a list of all device organizations. * Retrieves a list of all device organizations.
* *
@ -153,8 +226,31 @@ public interface DeviceOrganizationMgtService {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/all") @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(); Response getAllDeviceOrganizations();
/** /**
* Retrieves a specific device organization by its organization ID. * Retrieves a specific device organization by its organization ID.
* *
@ -164,8 +260,35 @@ public interface DeviceOrganizationMgtService {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/{organizationId}") @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); Response getDeviceOrganizationById(@PathParam("organizationId") int organizationId);
/** /**
* Checks if a device organization with the specified device and parent device IDs already exists. * Checks if a device organization with the specified device and parent device IDs already exists.
* *
@ -176,10 +299,38 @@ public interface DeviceOrganizationMgtService {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/exists") @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("deviceId") int deviceId,
@QueryParam("parentDeviceId") int parentDeviceId); @QueryParam("parentDeviceId") int parentDeviceId);
/** /**
* Retrieve a device organization by its unique key (deviceId and parentDeviceId). * Retrieve a device organization by its unique key (deviceId and parentDeviceId).
* *
@ -190,6 +341,32 @@ public interface DeviceOrganizationMgtService {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/unique") @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( Response getDeviceOrganizationByUniqueKey(
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") int parentDeviceId); @QueryParam("parentDeviceId") int parentDeviceId);
@ -204,7 +381,73 @@ public interface DeviceOrganizationMgtService {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/device-exists") @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. * Updates a device organization.
@ -216,7 +459,41 @@ public interface DeviceOrganizationMgtService {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/update") @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. * Deletes a device organization by its organization ID.
@ -226,7 +503,34 @@ public interface DeviceOrganizationMgtService {
*/ */
@DELETE @DELETE
@Path("/delete/{organizationId}") @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. * Deletes records associated with a particular device ID from the device organization table.
@ -238,6 +542,34 @@ public interface DeviceOrganizationMgtService {
*/ */
@DELETE @DELETE
@Path("/delete-associations/{deviceId}") @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);
} }

@ -129,7 +129,7 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/exists") @Path("/exists")
public Response organizationExists( public Response isDeviceOrganizationExist(
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") int parentDeviceId) { @QueryParam("parentDeviceId") int parentDeviceId) {
try { 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 @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/unique") @Path("/unique")

@ -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();
}
}

@ -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<ErrorListItem> 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<ErrorListItem> getErrorItems() {
return errorItems;
}
public void setErrorItems(List<ErrorListItem> 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<ErrorListItem> 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;
}
}
}

@ -1,21 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <!--
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ~ Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> ~
<modelVersion>4.0.0</modelVersion> ~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent> <parent>
<groupId>io.entgra.device.mgt.core</groupId> <groupId>io.entgra.device.mgt.core</groupId>
<artifactId>device-mgt-extensions-feature</artifactId> <artifactId>device-mgt-extensions-feature</artifactId>
<version>5.0.31-SNAPSHOT</version> <version>5.0.31-SNAPSHOT</version>
</parent> </parent>
<groupId>org.example</groupId> <modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature</artifactId> <artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Device Organization Management API Feature</name>
<url>http://wso2.org</url>
<description>This feature contains the APIs required for Device Organization Management.</description>
<properties> <build>
<maven.compiler.source>8</maven.compiler.source> <plugins>
<maven.compiler.target>8</maven.compiler.target> <plugin>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <groupId>org.apache.maven.plugins</groupId>
</properties> <artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api
</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>
${project.build.directory}/maven-shared-archive-resources/webapps
</outputDirectory>
<destFileName>api#deviceOrganization-mgt#v1.0.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources</outputDirectory>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>build.properties</include>
<include>p2.inf</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
<executions>
<execution>
<id>p2-feature-generation</id>
<phase>package</phase>
<goals>
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api</id>
<propertiesFile>../../../features/etc/feature.properties
</propertiesFile>
<adviceFile>
<properties>
<propertyDef>org.wso2.carbon.p2.category.type:server
</propertyDef>
<propertyDef>org.eclipse.equinox.p2.type.group:false
</propertyDef>
</properties>
</adviceFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>
Loading…
Cancel
Save