mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #584 from charithag/IOT-436
Fix https://wso2.org/jira/browse/IOTS-436
This commit is contained in:
commit
58d47928fb
@ -38,7 +38,7 @@ import java.util.List;
|
|||||||
public class GCMNotificationStrategy implements NotificationStrategy {
|
public class GCMNotificationStrategy implements NotificationStrategy {
|
||||||
|
|
||||||
private static final String GCM_TOKEN = "GCM_TOKEN";
|
private static final String GCM_TOKEN = "GCM_TOKEN";
|
||||||
private final static String GCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send";
|
private static final String GCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send";
|
||||||
private static final String GCM_API_KEY = "gcmAPIKey";
|
private static final String GCM_API_KEY = "gcmAPIKey";
|
||||||
private static final int TIME_TO_LIVE = 60;
|
private static final int TIME_TO_LIVE = 60;
|
||||||
private static final int HTTP_STATUS_CODE_OK = 200;
|
private static final int HTTP_STATUS_CODE_OK = 200;
|
||||||
|
|||||||
@ -281,6 +281,12 @@
|
|||||||
<groupId>javax.ws.rs</groupId>
|
<groupId>javax.ws.rs</groupId>
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.identity.user.store.count</artifactId>
|
||||||
|
<version>${carbon.identity.framework.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -30,13 +30,13 @@ public class BasePaginatedResult {
|
|||||||
value = "Number of total resources.",
|
value = "Number of total resources.",
|
||||||
example = "1")
|
example = "1")
|
||||||
@JsonProperty("count")
|
@JsonProperty("count")
|
||||||
private int count;
|
private long count;
|
||||||
|
|
||||||
public int getCount() {
|
public long getCount() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCount(int count) {
|
public void setCount(long count) {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,6 +38,8 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|||||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
|
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever;
|
||||||
|
import org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
@ -395,6 +397,30 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|||||||
@Path("/count")
|
@Path("/count")
|
||||||
@Override
|
@Override
|
||||||
public Response getUserCount() {
|
public Response getUserCount() {
|
||||||
|
try {
|
||||||
|
UserStoreCountRetriever userStoreCountRetrieverService = DeviceMgtAPIUtils.getUserStoreCountRetrieverService();
|
||||||
|
if (userStoreCountRetrieverService != null) {
|
||||||
|
long count = userStoreCountRetrieverService.countUsers("");
|
||||||
|
if (count != -1) {
|
||||||
|
BasicUserInfoList result = new BasicUserInfoList();
|
||||||
|
result.setCount(count);
|
||||||
|
return Response.status(Response.Status.OK).entity(result).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UserStoreCounterException e) {
|
||||||
|
String msg =
|
||||||
|
"Error occurred while retrieving the count of users that exist within the current tenant";
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
return getUserCountViaUserStoreManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the count of users using UserStoreManager.
|
||||||
|
*
|
||||||
|
* @return user count
|
||||||
|
*/
|
||||||
|
private Response getUserCountViaUserStoreManager() {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the user count");
|
log.debug("Getting the user count");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,13 +37,20 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|||||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
|
||||||
|
import org.wso2.carbon.identity.user.store.count.AbstractCountRetrieverFactory;
|
||||||
|
import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever;
|
||||||
|
import org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException;
|
||||||
|
import org.wso2.carbon.identity.user.store.count.jdbc.JDBCCountRetrieverFactory;
|
||||||
|
import org.wso2.carbon.identity.user.store.count.jdbc.internal.InternalCountRetrieverFactory;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
import org.wso2.carbon.user.api.AuthorizationManager;
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
||||||
|
import org.wso2.carbon.user.api.RealmConfiguration;
|
||||||
import org.wso2.carbon.user.api.UserRealm;
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
import org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
@ -105,6 +112,32 @@ public class DeviceMgtAPIUtils {
|
|||||||
return deviceManagementProviderService;
|
return deviceManagementProviderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UserStoreCountRetriever getUserStoreCountRetrieverService()
|
||||||
|
throws UserStoreCounterException {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
List<Object> countRetrieverFactories = ctx.getOSGiServices(AbstractCountRetrieverFactory.class, null);
|
||||||
|
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||||
|
RealmConfiguration realmConfiguration = realmService.getBootstrapRealmConfiguration();
|
||||||
|
String userStoreType;
|
||||||
|
//Ignoring Sonar warning as getUserStoreClass() returning string name of the class. So cannot use 'instanceof'.
|
||||||
|
if (JDBCUserStoreManager.class.getName().equals(realmConfiguration.getUserStoreClass())) {
|
||||||
|
userStoreType = JDBCCountRetrieverFactory.JDBC;
|
||||||
|
} else {
|
||||||
|
userStoreType = InternalCountRetrieverFactory.INTERNAL;
|
||||||
|
}
|
||||||
|
AbstractCountRetrieverFactory countRetrieverFactory = null;
|
||||||
|
for (Object countRetrieverFactoryObj : countRetrieverFactories) {
|
||||||
|
countRetrieverFactory = (AbstractCountRetrieverFactory) countRetrieverFactoryObj;
|
||||||
|
if (userStoreType.equals(countRetrieverFactory.getCounterType())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (countRetrieverFactory == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return countRetrieverFactory.buildCountRetriever(realmConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {
|
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
|
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
@ApiModel(value = "Condition", description = "Contains the advance search parameters.")
|
@ApiModel(value = "Condition", description = "Contains the advance search parameters.")
|
||||||
public class Condition {
|
public class Condition {
|
||||||
|
|
||||||
@ApiModelProperty(name = "conditions", value = "Provide the operation code. You can assign the following operation " +
|
@ApiModelProperty(name = "key", value = "Provide the operation code. You can assign the following operation " +
|
||||||
"codes:\n" +
|
"codes:\n" +
|
||||||
"DEVICE_MODEL : The model of the device.\n" +
|
"DEVICE_MODEL : The model of the device.\n" +
|
||||||
"VENDOR : The name of the device vendor.\n" +
|
"VENDOR : The name of the device vendor.\n" +
|
||||||
|
|||||||
@ -174,7 +174,7 @@ var userModule = function () {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=1";
|
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/count";
|
||||||
return serviceInvokers.XMLHttp.get(
|
return serviceInvokers.XMLHttp.get(
|
||||||
url, function (responsePayload) {
|
url, function (responsePayload) {
|
||||||
return parse(responsePayload["responseText"])["count"];
|
return parse(responsePayload["responseText"])["count"];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user