device organization Api layer modifications

backup
Isuri Mendis 1 year ago
parent 0629bea128
commit 4ee0d3c512

@ -21,16 +21,16 @@ import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes; import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans.ErrorResponse; import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization; import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.DeviceOrganization;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Info;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.Api; import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension; import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag; import io.swagger.annotations.Tag;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -73,7 +73,7 @@ import javax.ws.rs.core.Response;
@Scope( @Scope(
name = "Device Organization", name = "Device Organization",
description = "Device Organization", description = "Device Organization",
key = "perm:devices:view", key = "perm:get-activity",
roles = {"Internal/devicemgt-user"}, roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/devices/owning-device/view"} permissions = {"/device-mgt/devices/owning-device/view"}
) )
@ -90,19 +90,17 @@ public interface DeviceOrganizationMgtService {
* @return A response indicating the success or failure of the operation. * @return A response indicating the success or failure of the operation.
*/ */
@POST @POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/add-device-organization") @Path("/add-device-organization")
@ApiOperation( @ApiOperation(
consumes = MediaType.TEXT_PLAIN, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.TEXT_PLAIN, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Add a new device Organization.", value = "Add a new device Organization.",
notes = "This endpoint allows you to add a new device organization.", notes = "This endpoint allows you to add a new device organization.",
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -125,7 +123,7 @@ public interface DeviceOrganizationMgtService {
message = "Internal Server Error. An error occurred while processing the request.", message = "Internal Server Error. An error occurred while processing the request.",
response = Response.class) response = Response.class)
}) })
Response addDeviceOrganization(DeviceOrganizationRequest request); Response addDeviceOrganization(DeviceOrganization request);
/** /**
* Retrieves a list of child nodes of a given device node, up to a specified depth. * Retrieves a list of child nodes of a given device node, up to a specified depth.
@ -136,10 +134,8 @@ public interface DeviceOrganizationMgtService {
* @return A response containing a list of child device nodes. * @return A response containing a list of child device nodes.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/children") @Path("/children")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get Child Nodes of a Device Node", value = "Get Child Nodes of a Device Node",
@ -181,10 +177,8 @@ public interface DeviceOrganizationMgtService {
* @return A response containing a list of parent device nodes. * @return A response containing a list of parent device nodes.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/parents") @Path("/parents")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Retrieve Parent Nodes of a Device Node", value = "Retrieve Parent Nodes of a Device Node",
@ -192,7 +186,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -224,10 +218,8 @@ public interface DeviceOrganizationMgtService {
* @return A response containing a list of all device organizations. * @return A response containing a list of all device organizations.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/all") @Path("/all")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Retrieve All Device Organizations", value = "Retrieve All Device Organizations",
@ -235,7 +227,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -259,13 +251,12 @@ public interface DeviceOrganizationMgtService {
* Retrieves a specific device organization by its organization ID. * Retrieves a specific device organization by its organization ID.
* *
* @param organizationId The organization ID of the device organization to retrieve. * @param organizationId The organization ID of the device organization to retrieve.
* @return A response containing the device organization with the specified ID. * @return A response containing the device organization with the specifi
* ed ID.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{organizationId}") @Path("/{organizationId}")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Retrieve Device Organization by ID", value = "Retrieve Device Organization by ID",
@ -273,7 +264,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -301,10 +292,8 @@ public interface DeviceOrganizationMgtService {
* @return A response indicating whether the organization exists or not. * @return A response indicating whether the organization exists or not.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/exists") @Path("/exists")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Check Device Organization Existence", value = "Check Device Organization Existence",
@ -312,7 +301,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -343,10 +332,8 @@ public interface DeviceOrganizationMgtService {
* @return A response containing the retrieved DeviceOrganization object, or null if not found. * @return A response containing the retrieved DeviceOrganization object, or null if not found.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/unique") @Path("/unique")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get Device Organization by Unique Key", value = "Get Device Organization by Unique Key",
@ -354,7 +341,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -383,10 +370,8 @@ public interface DeviceOrganizationMgtService {
* @return A response indicating whether the device exists or not. * @return A response indicating whether the device exists or not.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/device-exists") @Path("/device-exists")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Check if Device ID Exists in Device Organization", value = "Check if Device ID Exists in Device Organization",
@ -394,7 +379,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -421,10 +406,8 @@ public interface DeviceOrganizationMgtService {
* @return A response indicating whether the child device exists or not. * @return A response indicating whether the child device exists or not.
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/child-exists") @Path("/child-exists")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Check if Child Device ID Exists in Device Organization", value = "Check if Child Device ID Exists in Device Organization",
@ -432,7 +415,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:view") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -460,8 +443,6 @@ public interface DeviceOrganizationMgtService {
* @return A response indicating the success or failure of the operation. * @return A response indicating the success or failure of the operation.
*/ */
@PUT @PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/update") @Path("/update")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
@ -472,7 +453,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:update") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -514,7 +495,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:delete") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )
@ -553,7 +534,7 @@ public interface DeviceOrganizationMgtService {
tags = "Device Organization Management", tags = "Device Organization Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:devices:delete-associations") @ExtensionProperty(name = SCOPE, value = "perm:get-activity")
}) })
} }
) )

@ -23,6 +23,8 @@ import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.dto.D
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.exception.DeviceOrganizationMgtPluginException; 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.impl.DeviceOrganizationServiceImpl;
import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.spi.DeviceOrganizationService; import io.entgra.device.mgt.core.device.mgt.extensions.device.organization.spi.DeviceOrganizationService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -37,31 +39,32 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtService{ @Path("/deviceOrganization")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtService {
private static final Log log = LogFactory.getLog(DeviceOrganizationMgtServiceImpl.class);
Gson gson = new Gson(); Gson gson = new Gson();
@Override
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Override
@Consumes(MediaType.APPLICATION_JSON)
@Path("/add-device-organization") @Path("/add-device-organization")
public Response addDeviceOrganization(DeviceOrganizationRequest deviceOrganizationRequest) { public Response addDeviceOrganization(DeviceOrganization deviceOrganizationRequest) {
try { try {
DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl(); DeviceOrganizationService deviceOrganizationService = new DeviceOrganizationServiceImpl();
DeviceOrganization deviceOrganization = new DeviceOrganization(); // DeviceOrganization deviceOrganization = new DeviceOrganization();
deviceOrganization.setDeviceId(deviceOrganizationRequest.getDeviceId()); // deviceOrganization.setDeviceId(DeviceOrganization.getDeviceId());
deviceOrganization.setParentDeviceId(deviceOrganizationRequest.getParentDeviceId()); // deviceOrganization.setParentDeviceId(DeviceOrganization.getParentDeviceId());
boolean resp = deviceOrganizationService.addDeviceOrganization(deviceOrganization); boolean resp = deviceOrganizationService.addDeviceOrganization(deviceOrganizationRequest);
return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build(); return Response.status(Response.Status.OK).entity(gson.toJson(resp)).build();
} catch (DeviceOrganizationMgtPluginException e) { } catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
} }
} }
@Override
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/children") @Path("/children")
public Response getChildrenOfDeviceNode( public Response getChildrenOfDeviceNode(
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@ -78,9 +81,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/parents") @Path("/parents")
public Response getParentsOfDeviceNode( public Response getParentsOfDeviceNode(
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@ -97,9 +99,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/all") @Path("/all")
public Response getAllDeviceOrganizations() { public Response getAllDeviceOrganizations() {
try { try {
@ -111,9 +112,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/{organizationId}") @Path("/{organizationId}")
public Response getDeviceOrganizationById(@PathParam("organizationId") int organizationId) { public Response getDeviceOrganizationById(@PathParam("organizationId") int organizationId) {
try { try {
@ -125,9 +125,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/exists") @Path("/exists")
public Response isDeviceOrganizationExist( public Response isDeviceOrganizationExist(
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@ -142,7 +141,7 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/child-exists") @Path("/child-exists")
public Response isChildDeviceIdExist(@QueryParam("deviceId") int deviceID) { public Response isChildDeviceIdExist(@QueryParam("deviceId") int deviceID) {
try { try {
@ -156,7 +155,7 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/unique") @Path("/unique")
public Response getDeviceOrganizationByUniqueKey( public Response getDeviceOrganizationByUniqueKey(
@QueryParam("deviceId") int deviceId, @QueryParam("deviceId") int deviceId,
@ -170,10 +169,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Override
@Path("/device-exists") @Path("/device-exists")
public Response doesDeviceIdExist(@QueryParam("deviceId") int deviceId) { public Response doesDeviceIdExist(@QueryParam("deviceId") int deviceId) {
try { try {
@ -185,10 +182,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@PUT @PUT
@Produces(MediaType.APPLICATION_JSON) @Override
@Consumes(MediaType.APPLICATION_JSON)
@Path("/update") @Path("/update")
public Response updateDeviceOrganization(DeviceOrganization deviceOrganization) { public Response updateDeviceOrganization(DeviceOrganization deviceOrganization) {
try { try {
@ -200,8 +195,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@DELETE @DELETE
@Override
@Path("/delete/{organizationId}") @Path("/delete/{organizationId}")
public Response deleteDeviceOrganizationById(@PathParam("organizationId") int organizationId) { public Response deleteDeviceOrganizationById(@PathParam("organizationId") int organizationId) {
try { try {
@ -213,8 +208,8 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
} }
} }
@Override
@DELETE @DELETE
@Override
@Path("/delete-associations/{deviceId}") @Path("/delete-associations/{deviceId}")
public Response deleteDeviceAssociations(@PathParam("deviceId") int deviceId) { public Response deleteDeviceAssociations(@PathParam("deviceId") int deviceId) {
try { try {

Loading…
Cancel
Save