sql modifications

pull/238/head
Isuri Mendis 1 year ago
parent c8c7922e97
commit 7d0d7e4910

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.31-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - API Device Organization Management API</name>
<description>This module extends the API manager's device organization management apis.</description>
<url>http://wso2.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization</artifactId>
<version>${io.entgra.device.mgt.core.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,243 @@
/*
* 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;
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.dto.DeviceOrganization;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
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 javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* This interface defines the RESTful web service endpoints for managing device organizations.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DeviceOrganization Management"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/deviceOrganization"),
})
}
),
tags = {
@Tag(name = "deviceOrganization_management", description = "DeviceOrganization management related REST-API. " +
"This can be used to manipulate device organization related details.")
}
)
@Path("/deviceOrganization")
@Api(value = "DeviceOrganization Management", description = "This API carries all device Organization management " +
"related operations.")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Scopes(scopes = {
@Scope(
name = "Device Organization",
description = "Device Organization",
key = "perm:devices:view",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/devices/owning-device/view"}
)
}
)
public interface DeviceOrganizationMgtService {
String SCOPE = "scope";
/**
* Adds a new device organization.
*
* @param request The request containing the device organization information.
* @return A response indicating the success or failure of the operation.
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/add-device-organization")
@ApiOperation(
consumes = MediaType.TEXT_PLAIN,
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",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the device location.",
response = String.class),
})
Response addDeviceOrganization(DeviceOrganizationRequest request);
/**
* Retrieves a list of child nodes of a given device node, up to a specified depth.
*
* @param deviceId The ID of the parent device node.
* @param maxDepth The maximum depth of child nodes to retrieve.
* @param includeDevice Indicates whether to include device information in the retrieved nodes.
* @return A response containing a list of child device nodes.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/children")
Response getChildrenOfDeviceNode(
@QueryParam("deviceId") int deviceId,
@QueryParam("maxDepth") int maxDepth,
@QueryParam("includeDevice") boolean includeDevice);
/**
* Retrieves a list of parent nodes of a given device node, up to a specified depth.
*
* @param deviceId The ID of the child device node.
* @param maxDepth The maximum depth of parent nodes to retrieve.
* @param includeDevice Indicates whether to include device information in the retrieved nodes.
* @return A response containing a list of parent device nodes.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/parents")
Response getParentsOfDeviceNode(
@QueryParam("deviceId") int deviceId,
@QueryParam("maxDepth") int maxDepth,
@QueryParam("includeDevice") boolean includeDevice);
/**
* Retrieves a list of all device organizations.
*
* @return A response containing a list of all device organizations.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/all")
Response getAllDeviceOrganizations();
/**
* Retrieves a specific device organization by its organization ID.
*
* @param organizationId The organization ID of the device organization to retrieve.
* @return A response containing the device organization with the specified ID.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{organizationId}")
Response getDeviceOrganizationById(@PathParam("organizationId") int organizationId);
/**
* Checks if a device organization with the specified device and parent device IDs already exists.
*
* @param deviceId The ID of the device.
* @param parentDeviceId The ID of the parent device.
* @return A response indicating whether the organization exists or not.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/exists")
Response organizationExists(
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") int parentDeviceId);
/**
* Retrieve a device organization by its unique key (deviceId and parentDeviceId).
*
* @param deviceId The ID of the device.
* @param parentDeviceId The ID of the parent device.
* @return A response containing the retrieved DeviceOrganization object, or null if not found.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/unique")
Response getDeviceOrganizationByUniqueKey(
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") int parentDeviceId);
/**
* Checks whether a record with the specified device ID exists either in the deviceID column or
* parentDeviceID column in the device organization table.
*
* @param deviceId The ID of the device to check.
* @return A response indicating whether the device exists or not.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/device-exists")
Response doesDeviceIdExist(@QueryParam("deviceId") int deviceId);
/**
* Updates a device organization.
*
* @param deviceOrganization The updated device organization.
* @return A response indicating the success or failure of the operation.
*/
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/update")
Response updateDeviceOrganization(DeviceOrganization deviceOrganization);
/**
* Deletes a device organization by its organization ID.
*
* @param organizationId The organization ID of the device organization to delete.
* @return A response indicating the success or failure of the operation.
*/
@DELETE
@Path("/delete/{organizationId}")
Response deleteDeviceOrganizationById(@PathParam("organizationId") int organizationId);
/**
* Deletes records associated with a particular device ID from the device organization table.
* This method deletes records where the provided device ID matches either the deviceID column or
* parentDeviceID column in the device organization table.
*
* @param deviceId The ID of the device for which associations should be deleted.
* @return A response indicating the success or failure of the operation.
*/
@DELETE
@Path("/delete-associations/{deviceId}")
Response deleteDeviceAssociations(@PathParam("deviceId") int deviceId);
}

@ -0,0 +1,214 @@
/*
* 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;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceNode;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtPluginException;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.impl.DeviceOrganizationServiceImpl;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.spi.DeviceOrganizationService;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtService{
Gson gson = new Gson();
@Override
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/add-device-organization")
public Response addDeviceOrganization(DeviceOrganizationRequest deviceOrganizationRequest) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setDeviceId(deviceOrganizationRequest.getDeviceId());
deviceOrganization.setParentDeviceId(deviceOrganizationRequest.getParentDeviceId());
boolean resp = deviceOrganizationService.addDeviceOrganization(deviceOrganization);
return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/children")
public Response getChildrenOfDeviceNode(
@QueryParam("deviceId") int deviceId,
@QueryParam("maxDepth") int maxDepth,
@QueryParam("includeDevice") boolean includeDevice) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
DeviceNode deviceNode = new DeviceNode();
deviceNode.setDeviceId(deviceId);
List<DeviceNode> children = deviceOrganizationService.getChildrenOf(deviceNode, maxDepth, includeDevice);
return Response.status(Response.Status.OK).entity(gson.toJson(children)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/parents")
public Response getParentsOfDeviceNode(
@QueryParam("deviceId") int deviceId,
@QueryParam("maxDepth") int maxDepth,
@QueryParam("includeDevice") boolean includeDevice) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
DeviceNode deviceNode = new DeviceNode();
deviceNode.setDeviceId(deviceId);
List<DeviceNode> parents = deviceOrganizationService.getParentsOf(deviceNode, maxDepth, includeDevice);
return Response.status(Response.Status.OK).entity(gson.toJson(parents)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/all")
public Response getAllDeviceOrganizations() {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
List<DeviceOrganization> organizations = deviceOrganizationService.getAllDeviceOrganizations();
return Response.status(Response.Status.OK).entity(gson.toJson(organizations)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{organizationId}")
public Response getDeviceOrganizationById(@PathParam("organizationId") int organizationId) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByID(organizationId);
return Response.status(Response.Status.OK).entity(gson.toJson(organization)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/exists")
public Response organizationExists(
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") int parentDeviceId) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
boolean exists = deviceOrganizationService.isDeviceOrganizationExist(deviceId, parentDeviceId);
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")
public Response getDeviceOrganizationByUniqueKey(
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") int parentDeviceId) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(deviceId, parentDeviceId);
return Response.status(Response.Status.OK).entity(gson.toJson(organization)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/device-exists")
public Response doesDeviceIdExist(@QueryParam("deviceId") int deviceId) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
boolean exists = deviceOrganizationService.isDeviceIdExist(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();
}
}
@Override
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/update")
public Response updateDeviceOrganization(DeviceOrganization deviceOrganization) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
boolean resp = deviceOrganizationService.updateDeviceOrganization(deviceOrganization);
return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@DELETE
@Path("/delete/{organizationId}")
public Response deleteDeviceOrganizationById(@PathParam("organizationId") int organizationId) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
boolean resp = deviceOrganizationService.deleteDeviceOrganizationByID(organizationId);
return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@Override
@DELETE
@Path("/delete-associations/{deviceId}")
public Response deleteDeviceAssociations(@PathParam("deviceId") int deviceId) {
try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
boolean resp = deviceOrganizationService.deleteDeviceAssociations(deviceId);
return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
}

@ -0,0 +1,75 @@
/*
* 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;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
@XmlRootElement
@JsonIgnoreProperties(ignoreUnknown = true)
public class DeviceOrganizationRequest {
@XmlElement
private int organizationId;
@XmlElement
private int deviceId;
@XmlElement
private Integer parentDeviceId;
@XmlElement
private Date updateTime;
public int getOrganizationId() {
return organizationId;
}
public void setOrganizationId(int organizationId) {
this.organizationId = organizationId;
}
public int getDeviceId() {
return deviceId;
}
public void setDeviceId(int deviceId) {
this.deviceId = deviceId;
}
public Integer getParentDeviceId() {
return parentDeviceId;
}
public void setParentDeviceId(Integer parentDeviceId) {
this.parentDeviceId = parentDeviceId;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<!-- This file contains the list of permissions that are associated with URL end points
of the web app. Each permission should contain the name, permission path ,API path
(URL) , HTTP method and OAUTH2 authorization scope (not-required).
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
For ex:
Actual API endpoint: devicemgt_admin/1.0.0/devices/{device-id}
URL to be represented here: /devices/*
NOTE: All the endpoints of the web app should be available in this file. Otherwise
it will result 403 error at the runtime.
-->
<PermissionConfiguration>
<APIVersion></APIVersion>
</PermissionConfiguration>

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<!--
This file defines class loading policy of the whole container. But this behaviour can be overridden by individual webapps by putting this file into the META-INF/ directory.
-->
<Classloading xmlns="http://wso2.org/projects/as/classloading">
<!-- Parent-first or child-first. Default behaviour is child-first.-->
<ParentFirst>false</ParentFirst>
<!--
Default environments that contains provides to all the webapps. This can be overridden by individual webapps by specifing required environments
Tomcat environment is the default and every webapps gets it even if they didn't specify it.
e.g. If a webapps requires CXF, they will get both Tomcat and CXF.
-->
<Environments>CXF3,Carbon</Environments>
</Classloading>

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<jaxrs:server id="services" address="/">
<jaxrs:serviceBeans>
<ref bean="deviceOrganizationService"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="deviceOrganizationService" class="io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.DeviceOrganizationMgtServiceImpl"/>
</beans>

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>Grafana-API-Proxy-Webapp</display-name>
<servlet>
<description>JAX-WS/JAX-RS Grafana API Management Endpoint</description>
<display-name>JAX-WS/JAX-RS Servlet</display-name>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<!-- configure a security filter -->
<init-param>
<param-name>swagger.security.filter</param-name>
<param-value>ApiAuthorizationFilterImpl</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<context-param>
<param-name>doAuthentication</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>basicAuth</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>nonSecuredEndPoints</param-name>
<param-value>
/keymgt-test-api/.*,
</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
<context-param>
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class>
<init-param>
<param-name>patterns</param-name>
<param-value>text/html" ,application/json" ,text/plain</param-value>
</init-param>
<init-param>
<param-name>filterAction</param-name>
<param-value>enforce</param-value>
</init-param>
<init-param>
<param-name>httpHeaders</param-name>
<param-value>Cache-Control: no-store, no-cache, must-revalidate, private</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HttpHeaderSecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContentTypeBasedCachePreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -75,7 +75,7 @@ public interface DeviceOrganizationDAO {
* @return True if a record with the specified deviceId and parentDeviceId exists, false otherwise.
* @throws DeviceOrganizationMgtDAOException If an error occurs while checking the existence of the record.
*/
boolean organizationExists(int deviceId, int parentDeviceId) throws DeviceOrganizationMgtDAOException;
boolean isDeviceOrganizationExist(int deviceId, Integer parentDeviceId) throws DeviceOrganizationMgtDAOException;
/**
* Get a device organization by the CHILD_PARENT_COMP_KEY unique key.
@ -85,7 +85,7 @@ public interface DeviceOrganizationDAO {
* @return The DeviceOrganization object if found, null otherwise.
* @throws DeviceOrganizationMgtDAOException if an error occurs while accessing the database.
*/
DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, int parentDeviceId)
DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, Integer parentDeviceId)
throws DeviceOrganizationMgtDAOException;
/**
@ -135,5 +135,5 @@ public interface DeviceOrganizationDAO {
* @return true if a record with the given device ID exists, false otherwise.
* @throws DeviceOrganizationMgtDAOException If an error occurs while querying the database.
*/
boolean doesDeviceIdExist(int deviceId) throws DeviceOrganizationMgtDAOException;
boolean isDeviceIdExist(int deviceId) throws DeviceOrganizationMgtDAOException;
}

@ -219,7 +219,7 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
if (deviceOrganization.getParentDeviceId() != null) {
stmt.setInt(2, deviceOrganization.getParentDeviceId());
} else {
stmt.setNull(2, Types.INTEGER);
stmt.setInt(2, Types.NULL);
}
stmt.setTimestamp(3, timestamp);
return stmt.executeUpdate() > 0;
@ -241,7 +241,7 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
* {@inheritDoc}
*/
@Override
public boolean organizationExists(int deviceId, int parentDeviceId) throws DeviceOrganizationMgtDAOException {
public boolean isDeviceOrganizationExist(int deviceId, Integer parentDeviceId) throws DeviceOrganizationMgtDAOException {
try {
Connection conn = ConnectionManagerUtil.getDBConnection();
String sql = "SELECT 1 " +
@ -251,7 +251,11 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, deviceId);
if (parentDeviceId != null) {
stmt.setInt(2, parentDeviceId);
} else {
stmt.setInt(2,Types.NULL);
}
try (ResultSet rs = stmt.executeQuery()) {
return rs.next(); // Returns true if a match is found, false otherwise
@ -273,7 +277,7 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
/**
* {@inheritDoc}
*/
public DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, int parentDeviceId)
public DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, Integer parentDeviceId)
throws DeviceOrganizationMgtDAOException {
try {
String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID = ?";
@ -281,7 +285,11 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
Connection conn = ConnectionManagerUtil.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, deviceId);
if (parentDeviceId != null) {
stmt.setInt(2, parentDeviceId);
} else {
stmt.setInt(2,Types.NULL);
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
@ -450,7 +458,7 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
* {@inheritDoc}
*/
@Override
public boolean doesDeviceIdExist(int deviceId) throws DeviceOrganizationMgtDAOException {
public boolean isDeviceIdExist(int deviceId) throws DeviceOrganizationMgtDAOException {
try {
Connection conn = ConnectionManagerUtil.getDBConnection();
String sql = "SELECT 1 " +

@ -24,8 +24,7 @@ public class DeviceOrganizationDaoUtil {
* @throws SQLException If there's an issue reading data from the ResultSet.
*/
public static DeviceOrganization loadDeviceOrganization(ResultSet rs) throws SQLException {
DeviceOrganization deviceOrganization = new DeviceOrganization() {
};
DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setOrganizationId(rs.getInt("ID"));
deviceOrganization.setDeviceId(rs.getInt("DEVICE_ID"));
if (rs.getInt("PARENT_DEVICE_ID") != 0) {

@ -25,7 +25,7 @@ import java.util.Date;
* This abstract class represents a device organization entity used in DeviceOrganizationService.
* It serves as a base class for defining various organizational structures related to devices.
*/
public abstract class DeviceOrganization {
public class DeviceOrganization {
private int organizationId;
private int deviceId;

@ -148,7 +148,7 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
}
String msg;
int deviceID = deviceOrganization.getDeviceId();
int parentDeviceID = deviceOrganization.getParentDeviceId();
Integer parentDeviceID = deviceOrganization.getParentDeviceId();
try {
ConnectionManagerUtil.beginDBTransaction();
@ -187,21 +187,15 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
* {@inheritDoc}
*/
@Override
public void addDeviceOrganizationList(List<DeviceOrganization> deviceOrganizationList)
throws DeviceOrganizationMgtPluginException {
for (DeviceOrganization deviceOrganization : deviceOrganizationList) {
boolean result = addDeviceOrganization(deviceOrganization);
}
public boolean isDeviceOrganizationExist(int deviceID, Integer parentDeviceID) throws DeviceOrganizationMgtPluginException {
if (deviceID <= 0 || !(parentDeviceID == null || parentDeviceID > 0)) {
throw new BadRequestException("Invalid input parameters for deviceOrganization update. : "
+ ", deviceID = " + deviceID
+ ", parentDeviceID = " + parentDeviceID);
}
/**
* {@inheritDoc}
*/
@Override
public boolean organizationExists(int deviceID, int parentDeviceID) throws DeviceOrganizationMgtPluginException {
try {
ConnectionManagerUtil.openDBConnection();
return deviceOrganizationDao.organizationExists(deviceID, parentDeviceID);
return deviceOrganizationDao.isDeviceOrganizationExist(deviceID, parentDeviceID);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to check organization existence. " +
"Params : deviceID = " + deviceID + ", parentDeviceID = " + parentDeviceID;
@ -221,8 +215,13 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
* {@inheritDoc}
*/
@Override
public DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceID, int parentDeviceID)
public DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceID, Integer parentDeviceID)
throws DeviceOrganizationMgtPluginException {
if (deviceID <= 0 || !(parentDeviceID == null || parentDeviceID > 0)) {
throw new BadRequestException("Invalid input parameters for deviceOrganization update. : "
+ ", deviceID = " + deviceID
+ ", parentDeviceID = " + parentDeviceID);
}
try {
ConnectionManagerUtil.openDBConnection();
return deviceOrganizationDao.getDeviceOrganizationByUniqueKey(deviceID, parentDeviceID);
@ -391,7 +390,7 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
}
String msg;
boolean deviceIdExist = doesDeviceIdExist(deviceID);
boolean deviceIdExist = isDeviceIdExist(deviceID);
if (!deviceIdExist) {
msg = "Cannot find device organizations associated with deviceID = " + deviceID;
log.error(msg);
@ -434,7 +433,7 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
* {@inheritDoc}
*/
@Override
public boolean doesDeviceIdExist(int deviceID)
public boolean isDeviceIdExist(int deviceID)
throws DeviceOrganizationMgtPluginException {
if (deviceID <= 0) {
throw new BadRequestException("deviceID must be a positive number." +
@ -444,7 +443,7 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
try {
// Open a database connection
ConnectionManagerUtil.openDBConnection();
return deviceOrganizationDao.doesDeviceIdExist(deviceID);
return deviceOrganizationDao.isDeviceIdExist(deviceID);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to check deviceID existence " +
"in deviceOrganization : deviceID = " + deviceID;

@ -62,15 +62,6 @@ public interface DeviceOrganizationService {
List<DeviceNode> getParentsOf(DeviceNode node, int maxDepth, boolean includeDevice)
throws DeviceOrganizationMgtPluginException;
/**
* Adds a list of device organizations.
*
* @param deviceOrganizations The list of device organizations to add.
* @throws DeviceOrganizationMgtPluginException If an error occurs during the operation.
*/
void addDeviceOrganizationList(List<DeviceOrganization> deviceOrganizations)
throws DeviceOrganizationMgtPluginException;
/**
* Retrieves a list of all device organizations.
*
@ -97,7 +88,7 @@ public interface DeviceOrganizationService {
* @return True if the organization exists, false otherwise.
* @throws DeviceOrganizationMgtPluginException If an error occurs during the operation.
*/
boolean organizationExists(int deviceId, int parentDeviceId)
boolean isDeviceOrganizationExist(int deviceId, Integer parentDeviceId)
throws DeviceOrganizationMgtPluginException;
/**
@ -108,7 +99,7 @@ public interface DeviceOrganizationService {
* @return The retrieved DeviceOrganization object, or null if not found.
* @throws DeviceOrganizationMgtPluginException If an error occurs.
*/
DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, int parentDeviceId)
DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, Integer parentDeviceId)
throws DeviceOrganizationMgtPluginException;
/**
@ -119,7 +110,7 @@ public interface DeviceOrganizationService {
* @return True if the device exists, false otherwise.
* @throws DeviceOrganizationMgtPluginException If an error occurs during the operation.
*/
boolean doesDeviceIdExist(int deviceId)
boolean isDeviceIdExist(int deviceId)
throws DeviceOrganizationMgtPluginException;
/**

@ -66,8 +66,7 @@ public class DAOTest extends BaseDeviceOrganizationTest {
deviceOrganizationDAO.deleteDeviceAssociations(2);
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
DeviceOrganization deviceOrganization = new DeviceOrganization() {
};
DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setDeviceId(2);
deviceOrganization.setParentDeviceId(null);
deviceOrganization.setUpdateTime(new Date(System.currentTimeMillis()));
@ -75,8 +74,7 @@ public class DAOTest extends BaseDeviceOrganizationTest {
boolean result = deviceOrganizationDAO.addDeviceOrganization(deviceOrganization);
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
DeviceOrganization deviceOrganization1 = new DeviceOrganization() {
};
DeviceOrganization deviceOrganization1 = new DeviceOrganization();
deviceOrganization1.setDeviceId(4);
deviceOrganization1.setParentDeviceId(1);
deviceOrganization1.setUpdateTime(new Date(System.currentTimeMillis()));
@ -85,8 +83,7 @@ public class DAOTest extends BaseDeviceOrganizationTest {
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
DeviceOrganization deviceOrganization2 = new DeviceOrganization() {
};
DeviceOrganization deviceOrganization2 = new DeviceOrganization();
deviceOrganization1.setDeviceId(3);
deviceOrganization1.setParentDeviceId(1);
deviceOrganization1.setUpdateTime(new Date(System.currentTimeMillis()));
@ -95,16 +92,12 @@ public class DAOTest extends BaseDeviceOrganizationTest {
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
Assert.assertNotNull(result, "Cannot be null");
Assert.assertNotNull(result1, "Cannot be null");
}
@Test(dependsOnMethods = "testAddDeviceOrganizationDAO")
public void testUpdateDeviceOrganizationDAO() throws DBConnectionException, DeviceOrganizationMgtDAOException {
ConnectionManagerUtil.beginDBTransaction();
DeviceOrganization deviceOrganization = new DeviceOrganization() {
};
DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setDeviceId(2);
deviceOrganization.setParentDeviceId(1);
deviceOrganization.setOrganizationId(1);
@ -112,7 +105,6 @@ public class DAOTest extends BaseDeviceOrganizationTest {
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
Assert.assertNotNull(result, "Cannot be null");
}
@Test(dependsOnMethods = "testAddDeviceOrganizationDAO")
@ -129,10 +121,9 @@ public class DAOTest extends BaseDeviceOrganizationTest {
@Test(dependsOnMethods = "testAddDeviceOrganizationDAO")
public void testDoesDeviceIdExistDAO() throws DBConnectionException, DeviceOrganizationMgtDAOException {
ConnectionManagerUtil.beginDBTransaction();
boolean doesDeviceIdExist = deviceOrganizationDAO.doesDeviceIdExist(1);
boolean isDeviceIdExist = deviceOrganizationDAO.isDeviceIdExist(1);
ConnectionManagerUtil.closeDBConnection();
Assert.assertNotNull(doesDeviceIdExist, "Cannot be null");
}
@Test(dependsOnMethods = "testAddDeviceOrganizationDAO")
@ -141,7 +132,6 @@ public class DAOTest extends BaseDeviceOrganizationTest {
boolean result = deviceOrganizationDAO.deleteDeviceOrganizationByID(1);
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
Assert.assertNotNull(result, "Cannot be null");
}
@Test(dependsOnMethods = "testAddDeviceOrganizationDAO")
@ -150,7 +140,6 @@ public class DAOTest extends BaseDeviceOrganizationTest {
boolean result = deviceOrganizationDAO.deleteDeviceAssociations(1);
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
Assert.assertNotNull(result, "Cannot be null");
}
@Test(dependsOnMethods = "testAddDeviceOrganizationDAO")

@ -75,16 +75,15 @@ public class ServiceNegativeTest extends BaseDeviceOrganizationTest {
@Test(description = "This method tests Add Device Organization method under negative circumstances with null data",
expectedExceptions = {DeviceOrganizationMgtPluginException.class})
public void testAddDeviceOrganizationWithInvalidInput() throws DeviceOrganizationMgtPluginException {
DeviceOrganization invalidOrganization = new DeviceOrganization() {
};
DeviceOrganization invalidOrganization = new DeviceOrganization();
deviceOrganizationService.addDeviceOrganization(invalidOrganization);
}
@Test(description = "This method tests organizationExists method under negative circumstances with an organization that doesn't exist")
@Test(description = "This method tests isDeviceOrganizationExist method under negative circumstances with an organization that doesn't exist")
public void testOrganizationDoesNotExist() throws DeviceOrganizationMgtPluginException {
int nonExistentDeviceId = 9999; // An ID that doesn't exist
int nonExistentParentDeviceId = 8888; // An ID that doesn't exist
boolean exists = deviceOrganizationService.organizationExists(nonExistentDeviceId, nonExistentParentDeviceId);
boolean exists = deviceOrganizationService.isDeviceOrganizationExist(nonExistentDeviceId, nonExistentParentDeviceId);
Assert.assertFalse(exists, "Organization should not exist for non-existent IDs.");
}
@ -92,8 +91,7 @@ public class ServiceNegativeTest extends BaseDeviceOrganizationTest {
expectedExceptions = {DeviceOrganizationMgtPluginException.class})
public void testAddDuplicateDeviceOrganization() throws DeviceOrganizationMgtPluginException {
// Create a valid organization
DeviceOrganization validOrganization = new DeviceOrganization() {
};
DeviceOrganization validOrganization = new DeviceOrganization();
validOrganization.setDeviceId(1);
validOrganization.setParentDeviceId(0);
@ -112,16 +110,14 @@ public class ServiceNegativeTest extends BaseDeviceOrganizationTest {
@Test(description = "This method tests Update Device Organization method under negative circumstances with null " +
"data", expectedExceptions = {DeviceOrganizationMgtPluginException.class})
public void testUpdateDeviceOrganizationWithInvalidInput() throws DeviceOrganizationMgtPluginException {
DeviceOrganization invalidOrganization = new DeviceOrganization() {
};
DeviceOrganization invalidOrganization = new DeviceOrganization();
deviceOrganizationService.updateDeviceOrganization(invalidOrganization);
}
@Test(description = "This method tests Update Device Organization method under negative circumstances with an invalid organization ID",
expectedExceptions = {DeviceOrganizationMgtPluginException.class})
public void testUpdateDeviceOrganizationWithInvalidID() throws DeviceOrganizationMgtPluginException {
DeviceOrganization invalidOrganization = new DeviceOrganization() {
};
DeviceOrganization invalidOrganization = new DeviceOrganization();
invalidOrganization.setOrganizationId(-1); // Provide an invalid organization ID
deviceOrganizationService.updateDeviceOrganization(invalidOrganization);
}
@ -146,7 +142,7 @@ public class ServiceNegativeTest extends BaseDeviceOrganizationTest {
expectedExceptions = {BadRequestException.class})
public void testDoesDeviceIdExistWithInvalidInput() throws DeviceOrganizationMgtPluginException {
int invalidDeviceId = 0;
deviceOrganizationService.doesDeviceIdExist(invalidDeviceId);
deviceOrganizationService.isDeviceIdExist(invalidDeviceId);
}
@Test(description = "This method tests Delete Device Associations method under negative circumstances with invalid " +

@ -53,16 +53,13 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
@Test(priority = 1)
public void testAddDeviceOrganization() throws DeviceOrganizationMgtPluginException {
DeviceOrganization deviceOrganization = new DeviceOrganization() {
};
DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setDeviceId(4);
deviceOrganization.setParentDeviceId(3);
DeviceOrganization deviceOrganizationOne = new DeviceOrganization() {
};
DeviceOrganization deviceOrganizationOne = new DeviceOrganization();
deviceOrganizationOne.setDeviceId(3);
deviceOrganizationOne.setParentDeviceId(2);
DeviceOrganization deviceOrganizationTwo = new DeviceOrganization() {
};
DeviceOrganization deviceOrganizationTwo = new DeviceOrganization();
deviceOrganizationTwo.setDeviceId(4);
deviceOrganizationTwo.setParentDeviceId(2);
@ -83,8 +80,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
@Test(priority = 6, dependsOnMethods = "testAddDeviceOrganization")
public void testUpdateDeviceOrganization() throws DeviceOrganizationMgtPluginException {
DeviceOrganization deviceOrganization = new DeviceOrganization() {
};
DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setDeviceId(4);
deviceOrganization.setParentDeviceId(3);
deviceOrganization.setOrganizationId(1);
@ -100,7 +96,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
@Test(priority = 3, dependsOnMethods = "testAddDeviceOrganization")
public void testDoesDeviceIdExist() throws DeviceOrganizationMgtPluginException {
boolean deviceIdExist = deviceOrganizationService.doesDeviceIdExist(4);
boolean deviceIdExist = deviceOrganizationService.isDeviceIdExist(4);
}
@Test(priority = 7, dependsOnMethods = "testAddDeviceOrganization")

@ -863,8 +863,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_ID FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_DM_ID2 FOREIGN KEY (PARENT_DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
-- END OF DM_DEVICE_ORGANIZATION TABLE--

@ -27,8 +27,6 @@
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_ID FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_DM_ID2 FOREIGN KEY (PARENT_DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
-- END OF DM_DEVICE_ORGANIZATION TABLE--

@ -0,0 +1,21 @@
<?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"
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>
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>device-mgt-extensions-feature</artifactId>
<version>5.0.31-SNAPSHOT</version>
</parent>
<groupId>org.example</groupId>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

@ -0,0 +1,19 @@
#
# 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.
#
custom = true

@ -42,6 +42,7 @@
<module>io.entgra.device.mgt.core.device.mgt.extensions.logger.feature</module>
<module>io.entgra.device.mgt.core.device.mgt.extensions.stateengine.feature</module>
<module>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.feature</module>
<module>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature</module>
</modules>
</project>

@ -68,6 +68,9 @@
<module>features/subtype-mgt</module>
<module>features/tenant-mgt</module>
<module>features/operation-template-mgt-plugin-feature</module>
<module>
components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api
</module>
</modules>

Loading…
Cancel
Save