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 new file mode 100644 index 0000000000..9149828018 --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml @@ -0,0 +1,89 @@ + + + + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.parent + 5.0.31-SNAPSHOT + ../../../pom.xml + + 4.0.0 + io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api + war + WSO2 Carbon - API Device Organization Management API + This module extends the API manager's device organization management apis. + http://wso2.org + + + + + maven-compiler-plugin + + 1.8 + 1.8 + + + + maven-war-plugin + + WEB-INF/lib/*cxf*.jar + ${project.artifactId} + + + + + + + + org.springframework + spring-web + provided + + + org.apache.cxf + cxf-bundle-jaxrs + provided + + + org.codehaus.jackson + jackson-jaxrs + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.device.mgt.extensions.device.organization + ${io.entgra.device.mgt.core.version} + provided + + + com.google.code.gson + gson + + + io.swagger + swagger-annotations + + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.apimgt.annotations + provided + + + + 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 new file mode 100644 index 0000000000..06c6d5c53a --- /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/DeviceOrganizationMgtService.java @@ -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); + +} 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 new file mode 100644 index 0000000000..d51e4dbf3b --- /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/DeviceOrganizationMgtServiceImpl.java @@ -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 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 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 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(); + } + } +} 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/DeviceOrganizationRequest.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/DeviceOrganizationRequest.java new file mode 100644 index 0000000000..0342334924 --- /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/DeviceOrganizationRequest.java @@ -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; + } +} diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/permissions.xml new file mode 100644 index 0000000000..addd717eb6 --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/permissions.xml @@ -0,0 +1,32 @@ + + + + + + + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 0000000000..705c89edc9 --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,35 @@ + + + + + + + + + false + + + CXF3,Carbon + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 0000000000..752c1a08a9 --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..7ffe0a5806 --- /dev/null +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,109 @@ + + + + Grafana-API-Proxy-Webapp + + JAX-WS/JAX-RS Grafana API Management Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + + + swagger.security.filter + ApiAuthorizationFilterImpl + + 1 + + + CXFServlet + /* + + + 60 + + + + doAuthentication + false + + + basicAuth + false + + + + nonSecuredEndPoints + + /keymgt-test-api/.*, + + + + + + managed-api-enabled + true + + + managed-api-owner + admin + + + isSharedWithAllTenants + true + + + + HttpHeaderSecurityFilter + org.apache.catalina.filters.HttpHeaderSecurityFilter + + hstsEnabled + false + + + + + ContentTypeBasedCachePreventionFilter + org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter + + patterns + text/html" ,application/json" ,text/plain + + + filterAction + enforce + + + httpHeaders + Cache-Control: no-store, no-cache, must-revalidate, private + + + + + HttpHeaderSecurityFilter + /* + + + + ContentTypeBasedCachePreventionFilter + /* + + + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/DeviceOrganizationDAO.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/DeviceOrganizationDAO.java index b75776adac..7e31d7c70a 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/DeviceOrganizationDAO.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/DeviceOrganizationDAO.java @@ -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; } diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java index 76e9cf4d18..db17e0efca 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/impl/DeviceOrganizationDAOImpl.java @@ -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); - stmt.setInt(2, parentDeviceId); + 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); - stmt.setInt(2, parentDeviceId); + 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 " + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/util/DeviceOrganizationDaoUtil.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/util/DeviceOrganizationDaoUtil.java index 5cd1f0df82..cb7a32df10 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/util/DeviceOrganizationDaoUtil.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dao/util/DeviceOrganizationDaoUtil.java @@ -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) { diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dto/DeviceOrganization.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dto/DeviceOrganization.java index c90350c7a6..0bdf00e1e4 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dto/DeviceOrganization.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/dto/DeviceOrganization.java @@ -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; diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/impl/DeviceOrganizationServiceImpl.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/impl/DeviceOrganizationServiceImpl.java index 126e9bba29..9166401f00 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/impl/DeviceOrganizationServiceImpl.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/impl/DeviceOrganizationServiceImpl.java @@ -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 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; diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/spi/DeviceOrganizationService.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/spi/DeviceOrganizationService.java index b61e3fdd6d..52b2419d84 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/spi/DeviceOrganizationService.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/spi/DeviceOrganizationService.java @@ -62,15 +62,6 @@ public interface DeviceOrganizationService { List 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 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; /** diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/DAOTest.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/DAOTest.java index ded6ddcdf6..417fb66378 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/DAOTest.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/DAOTest.java @@ -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") diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceNegativeTest.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceNegativeTest.java index 5522e1ca99..432e755f3f 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceNegativeTest.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceNegativeTest.java @@ -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 " + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java index 57b1129a38..f17ffc13f9 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/java/io/entgra/device/mgt/core/device/mgt/extensions/device/organization/ServiceTest.java @@ -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") diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql index a3f298e77f..7817a328ee 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql @@ -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-- \ No newline at end of file diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/h2.sql b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/h2.sql index e6ac1a1333..d119ae18aa 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/h2.sql +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/h2.sql @@ -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-- 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 new file mode 100644 index 0000000000..4b58448d03 --- /dev/null +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + io.entgra.device.mgt.core + device-mgt-extensions-feature + 5.0.31-SNAPSHOT + + + org.example + io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/src/main/resources/build.properties b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..d724bde701 --- /dev/null +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/src/main/resources/build.properties @@ -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 \ No newline at end of file diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/src/main/resources/p2.inf b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..7ab37b9d7d --- /dev/null +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ \ No newline at end of file diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index 1681c3db74..f21ada0c2e 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -42,6 +42,7 @@ io.entgra.device.mgt.core.device.mgt.extensions.logger.feature io.entgra.device.mgt.core.device.mgt.extensions.stateengine.feature io.entgra.device.mgt.core.device.mgt.extensions.device.organization.feature + io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.feature diff --git a/pom.xml b/pom.xml index 07205ca653..1a065529aa 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,9 @@ features/subtype-mgt features/tenant-mgt features/operation-template-mgt-plugin-feature + + components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api +