Compare commits

Invalid templates have been ignored

1 invalid template(s) found pull_request_template.md: frontmatter must start with a separator line

...

5 Commits

@ -1,14 +1,5 @@
# carbon-device-mgt
# Entgra Device Management Core
<a href='https://opensource.org/licenses/Apache-2.0'><img src='https://img.shields.io/badge/License-Apache%202.0-blue.svg'></a><br/>
[![pipeline status](https://gitlab.com/entgra/carbon-device-mgt/badges/master/pipeline.svg)](https://gitlab.com/entgra/carbon-device-mgt/commits/master)
Entgra CONNECTED DEVICE MANAGEMENT COMPONENTS
Entgra Connected Device Manager (Entgra CDM) is a comprehensive platform that helps solve mobile computing challenges
enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program.
Whether it is device provisioning, device configuration management, policy enforcement, mobile application
management, device data security, or compliance monitoring, Entgra CDM offers a single enterprise-grade platform to
develop extensions for IOT related device types.
[![pipeline status](https://gitlab.com/entgra/carbon-device-mgt/badges/master/pipeline.svg)](https://gitlab.com/entgra/carbon-device-mgt/commits/master)

@ -192,6 +192,13 @@ import java.util.List;
key = "perm:groups:device",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/groups/devices/view"}
),
@Scope(
name = "View whether the groups has relevant device types",
description = "View whether the groups has relevant device types",
key = "perm:groups:devices-types",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/groups/devices/types"}
)
}
)
@ -1185,4 +1192,59 @@ public interface GroupManagementService {
@QueryParam("requireGroupProps")
boolean requireGroupProps);
@Path("/device-types")
@GET
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "Getting Details whether the groups has relevant device type or not",
notes = "Getting Details whether the groups has relevant device type or not.",
tags = "Device Group Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:groups:devices-types")
})
},
nickname = "getGroupByGroupNameFilter"
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device types of groups.",
response = DeviceGroup.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "Error occurred",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the group details.",
response = ErrorResponse.class)
})
Response getGroupHasDeviceTypes(
@ApiParam(
name = "identifiers",
value = "list of identifiers.",
required = true)
@QueryParam("identifiers")
List<String> identifiers);
}

@ -48,6 +48,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceTypesOfGroups;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
@ -429,4 +430,24 @@ public class GroupManagementServiceImpl implements GroupManagementService {
}
}
@GET
@Path("/device-types")
@Override
public Response getGroupHasDeviceTypes(@QueryParam("identifiers") List<String> identifiers) {
try {
DeviceTypesOfGroups deviceTypesOfGroups = DeviceMgtAPIUtils.getGroupManagementProviderService()
.getDeviceTypesOfGroups(identifiers);
return Response.status(Response.Status.OK).entity(deviceTypesOfGroups).build();
} catch (GroupManagementException e) {
String msg = "Only numbers can exists in a group ID or Invalid Group ID provided.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2022, Entgra (pvt) Ltd. (https://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 org.wso2.carbon.device.mgt.common.group.mgt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
@ApiModel(value = "DeviceTypesOfGroups", description = "This class carries whether the groups has device type or not.")
public class DeviceTypesOfGroups implements Serializable {
private static final long serialVersionUID = 5562356373277828099L;
@ApiModelProperty(name = "hasAndroid", value = "groups has Android devices.")
private boolean hasAndroid;
@ApiModelProperty(name = "id", value = "groups has iOS devices.")
private boolean hasIos;
@ApiModelProperty(name = "hasAndroid", value = "groups has Windows devices.")
private boolean hasWindows;
public boolean isHasAndroid() {
return hasAndroid;
}
public void setHasAndroid(boolean hasAndroid) {
this.hasAndroid = hasAndroid;
}
public boolean isHasIos() {
return hasIos;
}
public void setHasIos(boolean hasIos) {
this.hasIos = hasIos;
}
public boolean isHasWindows() {
return hasWindows;
}
public void setHasWindows(boolean hasWindows) {
this.hasWindows = hasWindows;
}
}

@ -41,6 +41,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceTypesOfGroups;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
@ -335,4 +336,5 @@ public interface GroupManagementProviderService {
*/
boolean isDeviceMappedToGroup(int groupId, DeviceIdentifier deviceIdentifier) throws GroupManagementException;
DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException;
}

@ -43,6 +43,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
@ -50,6 +51,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceTypesOfGroups;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
@ -82,6 +84,7 @@ import java.util.stream.Collectors;
public class GroupManagementProviderServiceImpl implements GroupManagementProviderService {
private static final Log log = LogFactory.getLog(GroupManagementProviderServiceImpl.class);
private static final String DEVICE_STATUS_REMOVED = "REMOVED";
private final GroupDAO groupDAO;
private final DeviceDAO deviceDAO;
@ -1371,4 +1374,60 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
createGroupWithChildren(nextParentGroup, childrenGroups, requireGroupProps, tenantId, depth, counter);
}
}
@Override
public DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException {
DeviceTypesOfGroups deviceTypesOfGroups = new DeviceTypesOfGroups();
List<Integer> groupsIDs = new ArrayList<>();
try {
for (String id : identifiers) {
groupsIDs.add(Integer.parseInt(id));
}
List<String> deviceIDs = new ArrayList<>();
List<Device> allDevices = new ArrayList<>();
for (Integer groupID : groupsIDs) {
DeviceGroup deviceGroup = getGroup(groupID, false);
if (deviceGroup == null) {
String errorMessage = "Invalid Group ID provided.";
log.error(errorMessage);
throw new GroupManagementException(errorMessage);
}
List<Device> devices = getAllDevicesOfGroup(deviceGroup.getName(), false);
for (Device device : devices) {
if (!DEVICE_STATUS_REMOVED.equals(device.getEnrolmentInfo().getStatus().toString())
&& !deviceIDs.contains(device.getDeviceIdentifier())) {
deviceIDs.add(device.getDeviceIdentifier());
allDevices.add(device);
}
}
}
for (Device device : allDevices) {
if (DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID.equals(device.getType())) {
deviceTypesOfGroups.setHasAndroid(true);
break;
}
}
for (Device device : allDevices) {
if (DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS.equals(device.getType())) {
deviceTypesOfGroups.setHasIos(true);
break;
}
}
for (Device device : allDevices) {
if (DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS.equals(device.getType())) {
deviceTypesOfGroups.setHasWindows(true);
break;
}
}
} catch (NumberFormatException e) {
String errorMessage = "Only numbers can exists in a group ID";
log.error(errorMessage);
throw new GroupManagementException(errorMessage, e);
}
return deviceTypesOfGroups;
}
}

Loading…
Cancel
Save