revert-70aa11f8
Shavindri 8 years ago
commit 1e32d5f89f

@ -18,7 +18,6 @@
package org.wso2.carbon.apimgt.application.extension.api;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.application.extension.api.util.RegistrationProfile;
import javax.ws.rs.*;
@ -28,9 +27,7 @@ import javax.ws.rs.core.Response;
/**
* This is the application registration service that exposed for apimApplicationRegistration
*/
@API(name = "API Registration Service", version = "1.0.0",
context = "api-application-registration",
tags = {"devicemgt_admin"})
public interface ApiApplicationRegistrationService {
/**

@ -30,6 +30,7 @@ import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.api.FaultGatewaysException;
import org.wso2.carbon.apimgt.api.model.*;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.governance.lcm.util.CommonUtil;
@ -78,15 +79,17 @@ public class APIPublisherServiceImpl implements APIPublisherService {
+ api.getId().getVersion() + "'");
}
} else {
if (provider.getAPI(api.getId()).getStatus() == APIStatus.CREATED) {
provider.changeLifeCycleStatus(api.getId(), PUBLISH_ACTION);
}
api.setStatus(APIStatus.PUBLISHED);
provider.updateAPI(api);
if (log.isDebugEnabled()) {
log.debug("An API already exists with the name '" + api.getId().getApiName() +
"', context '" + api.getContext() + "' and version '"
+ api.getId().getVersion() + "'. Thus, the API config is updated");
if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) {
if (provider.getAPI(api.getId()).getStatus() == APIStatus.CREATED) {
provider.changeLifeCycleStatus(api.getId(), PUBLISH_ACTION);
}
api.setStatus(APIStatus.PUBLISHED);
provider.updateAPI(api);
if (log.isDebugEnabled()) {
log.debug("An API already exists with the name '" + api.getId().getApiName() +
"', context '" + api.getContext() + "' and version '"
+ api.getId().getVersion() + "'. Thus, the API config is updated");
}
}
}
provider.saveSwagger20Definition(api.getId(), createSwaggerDefinition(api));

@ -32,6 +32,7 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(APIPublisherStartupHandler.class);
private static int retryTime = 2000;
private static final int CONNECTION_RETRY_FACTOR = 2;
private static final int MAX_RETRY_COUNT = 5;
private static Stack<API> failedAPIsStack = new Stack<>();
private static Stack<API> currentAPIsStack;
@ -44,33 +45,49 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
@Override
public void completedServerStartup() {
// APIPublisherDataHolder.getInstance().setServerStarted(true);
// currentAPIsStack = APIPublisherDataHolder.getInstance().getUnpublishedApis();
// Thread t = new Thread(new Runnable() {
// @Override
// public void run() {
// if (log.isDebugEnabled()) {
// log.debug("Server has just started, hence started publishing unpublished APIs");
// log.debug("Total number of unpublished APIs: "
// + APIPublisherDataHolder.getInstance().getUnpublishedApis().size());
// }
// publisher = APIPublisherDataHolder.getInstance().getApiPublisherService();
// while (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty()) {
// try {
// retryTime = retryTime * CONNECTION_RETRY_FACTOR;
// Thread.sleep(retryTime);
// } catch (InterruptedException te) {
// log.error("Error occurred while sleeping", te);
// }
// if (!APIPublisherDataHolder.getInstance().getUnpublishedApis().isEmpty()) {
// publishAPIs(currentAPIsStack, failedAPIsStack);
// } else {
// publishAPIs(failedAPIsStack, currentAPIsStack);
// }
// }
// }
// });
// t.start();
APIPublisherDataHolder.getInstance().setServerStarted(true);
currentAPIsStack = APIPublisherDataHolder.getInstance().getUnpublishedApis();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
if (log.isDebugEnabled()) {
log.debug("Server has just started, hence started publishing unpublished APIs");
log.debug("Total number of unpublished APIs: "
+ APIPublisherDataHolder.getInstance().getUnpublishedApis().size());
}
publisher = APIPublisherDataHolder.getInstance().getApiPublisherService();
int retryCount = 0;
while (retryCount < MAX_RETRY_COUNT && (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty())) {
try {
retryTime = retryTime * CONNECTION_RETRY_FACTOR;
Thread.sleep(retryTime);
} catch (InterruptedException te) {
//do nothing.
}
Stack<API> failedApis;
if (!APIPublisherDataHolder.getInstance().getUnpublishedApis().isEmpty()) {
publishAPIs(currentAPIsStack, failedAPIsStack);
failedApis = failedAPIsStack;
} else {
publishAPIs(failedAPIsStack, currentAPIsStack);
failedApis = currentAPIsStack;
}
retryCount++;
if (retryCount == MAX_RETRY_COUNT && !failedApis.isEmpty()) {
StringBuilder error = new StringBuilder();
error.append("Error occurred while publishing API ['");
while (!failedApis.isEmpty()) {
API api = failedApis.pop();
error.append(api.getId().getApiName() + ",");
}
error.append("']");
log.error(error.toString());
}
}
}
});
t.start();
}
private void publishAPIs(Stack<API> apis, Stack<API> failedStack) {
@ -79,7 +96,6 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
try {
publisher.publishAPI(api);
} catch (Exception e) {
log.error("Error occurred while publishing API '" + api.getId().getApiName() + "'");
failedStack.push(api);
}
}

@ -24,15 +24,12 @@ import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.api.model.*;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.core.util.Utils;
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementException;
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import javax.servlet.ServletContext;
import java.util.*;
@ -117,8 +114,6 @@ public class APIPublisherUtil {
// adding scopes to the api
Set<URITemplate> uriTemplates = config.getUriTemplates();
Map<String, Scope> apiScopes = new HashMap<>();
Scope existingScope;
String existingPermissions;
if (uriTemplates != null) {
// this creates distinct scopes list
for (URITemplate template : uriTemplates) {
@ -130,13 +125,6 @@ public class APIPublisherUtil {
}
}
Set<Scope> scopes = new HashSet<>(apiScopes.values());
// adding existing persisted roles to the scopes
try {
setExistingRoles(scopes);
} catch (ScopeManagementException | UserStoreException e) {
throw new APIManagementException("Error occurred while retrieving roles for the existing scopes");
}
// set current scopes to API
api.setScopes(scopes);
@ -152,6 +140,7 @@ public class APIPublisherUtil {
}
api.setUriTemplates(uriTemplates);
}
api.setCorsConfiguration(APIUtil.getDefaultCorsConfiguration());
return api;
}
@ -324,34 +313,4 @@ public class APIPublisherUtil {
return apiConfig;
}
/**
* This method is used to set the existing roles of the given scope.
*
* @param scopes List of scopes.
* @throws ScopeManagementException
*/
private static void setExistingRoles(Set<Scope> scopes) throws ScopeManagementException, UserStoreException {
String scopeKey;
String roles;
ScopeManagementService scopeManagementService = WebappPublisherUtil.getScopeManagementService();
UserRealm userRealm = WebappPublisherUtil.getUserRealm();
if (scopeManagementService == null) {
throw new ScopeManagementException("Error occurred while initializing scope management service");
} else if (userRealm == null) {
throw new UserStoreException("Error occurred while initializing realm service");
} else {
String adminRole = userRealm.getRealmConfiguration().getAdminRoleName();
for (Scope scope : scopes) {
scopeKey = scope.getKey();
roles = scopeManagementService.getRolesOfScope(scopeKey);
if (roles == null) {
roles = adminRole;
}
scope.setRoles(roles);
}
}
}
}

@ -18,16 +18,7 @@
package org.wso2.carbon.apimgt.webapp.publisher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.service.RealmService;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
@ -40,10 +31,6 @@ import java.io.File;
*/
public class WebappPublisherUtil {
private static Log log = LogFactory.getLog(WebappPublisherUtil.class);
private static final int CARBON_SUPER = -1234;
public static Document convertToDocument(File file) throws WebappPublisherConfigurationFailedException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
@ -57,32 +44,4 @@ public class WebappPublisherUtil {
}
}
public static ScopeManagementService getScopeManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ScopeManagementService scopeManagementService =
(ScopeManagementService) ctx.getOSGiService(ScopeManagementService.class, null);
if (scopeManagementService == null) {
String msg = "Scope Management Service has not been initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return scopeManagementService;
}
/**
* Getting the current tenant's user realm
*/
public static UserRealm getUserRealm() throws UserStoreException {
RealmService realmService;
UserRealm realm;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
if (realmService == null) {
throw new IllegalStateException("Realm service not initialized");
}
realm = realmService.getTenantUserRealm(CARBON_SUPER);
return realm;
}
}

@ -40,6 +40,7 @@ public class WebappPublisherConfig {
private String host;
private boolean isPublished;
private boolean isEnabledUpdateApi;
private Profiles profiles;
private static WebappPublisherConfig config;
@ -77,6 +78,15 @@ public class WebappPublisherConfig {
return profiles;
}
@XmlElement(name = "EnabledUpdateApi", required = true)
public boolean isEnabledUpdateApi() {
return isEnabledUpdateApi;
}
public void setEnabledUpdateApi(boolean isEnabledUpdateApi) {
this.isEnabledUpdateApi = isEnabledUpdateApi;
}
public void setPublished(boolean published) {
isPublished = published;
}

@ -49,72 +49,72 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
@Override
public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
// if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType()) && WebappPublisherConfig.getInstance()
// .isPublished()) {
// StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
// ServletContext servletContext = context.getServletContext();
// String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
// boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
//
// String profile = System.getProperty(PROPERTY_PROFILE);
//
// if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase())
// && isManagedApi) {
// try {
// AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
// Set<String> annotatedAPIClasses = annotationProcessor.
// scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
//
// List<APIResourceConfiguration> apiDefinitions = annotationProcessor.extractAPIInfo(servletContext,
// annotatedAPIClasses);
//
// for (APIResourceConfiguration apiDefinition : apiDefinitions) {
//
// APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition);
//
// try {
// int tenantId = APIPublisherDataHolder.getInstance().getTenantManager().
// getTenantId(apiConfig.getTenantDomain());
//
// boolean isTenantActive = APIPublisherDataHolder.getInstance().
// getTenantManager().isTenantActive(tenantId);
//
// if (isTenantActive) {
// apiConfig.init();
// API api = APIPublisherUtil.getAPI(apiConfig);
// boolean isServerStarted = APIPublisherDataHolder.getInstance().isServerStarted();
// if (isServerStarted) {
// APIPublisherService apiPublisherService =
// APIPublisherDataHolder.getInstance().getApiPublisherService();
// if (apiPublisherService == null) {
// throw new IllegalStateException(
// "API Publisher service is not initialized properly");
// }
// apiPublisherService.publishAPI(api);
// } else {
// if (log.isDebugEnabled()) {
// log.debug("Server has not started yet. Hence adding API '" +
// api.getId().getApiName() + "' to the queue");
// }
// APIPublisherDataHolder.getInstance().getUnpublishedApis().push(api);
// }
// } else {
// log.error("No tenant [" + apiConfig.getTenantDomain() + "] " +
// "found when publishing the Web app");
// }
// } catch (Throwable e) {
// log.error("Error occurred while publishing API '" + apiConfig.getName() +
// "' with the context '" + apiConfig.getContext() +
// "' and version '" + apiConfig.getVersion() + "'", e);
// }
// }
// } catch (IOException e) {
// log.error("Error encountered while discovering annotated classes", e);
// } catch (ClassNotFoundException e) {
// log.error("Error while scanning class for annotations", e);
// }
// }
// }
if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType()) && WebappPublisherConfig.getInstance()
.isPublished()) {
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
ServletContext servletContext = context.getServletContext();
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
String profile = System.getProperty(PROPERTY_PROFILE);
if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase())
&& isManagedApi) {
try {
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
Set<String> annotatedAPIClasses = annotationProcessor.
scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
List<APIResourceConfiguration> apiDefinitions = annotationProcessor.extractAPIInfo(servletContext,
annotatedAPIClasses);
for (APIResourceConfiguration apiDefinition : apiDefinitions) {
APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition);
try {
int tenantId = APIPublisherDataHolder.getInstance().getTenantManager().
getTenantId(apiConfig.getTenantDomain());
boolean isTenantActive = APIPublisherDataHolder.getInstance().
getTenantManager().isTenantActive(tenantId);
if (isTenantActive) {
apiConfig.init();
API api = APIPublisherUtil.getAPI(apiConfig);
boolean isServerStarted = APIPublisherDataHolder.getInstance().isServerStarted();
if (isServerStarted) {
APIPublisherService apiPublisherService =
APIPublisherDataHolder.getInstance().getApiPublisherService();
if (apiPublisherService == null) {
throw new IllegalStateException(
"API Publisher service is not initialized properly");
}
apiPublisherService.publishAPI(api);
} else {
if (log.isDebugEnabled()) {
log.debug("Server has not started yet. Hence adding API '" +
api.getId().getApiName() + "' to the queue");
}
APIPublisherDataHolder.getInstance().getUnpublishedApis().push(api);
}
} else {
log.error("No tenant [" + apiConfig.getTenantDomain() + "] " +
"found when publishing the Web app");
}
} catch (Throwable e) {
log.error("Error occurred while publishing API '" + apiConfig.getName() +
"' with the context '" + apiConfig.getContext() +
"' and version '" + apiConfig.getVersion() + "'", e);
}
}
} catch (IOException e) {
log.error("Error encountered while discovering annotated classes", e);
} catch (ClassNotFoundException e) {
log.error("Error while scanning class for annotations", e);
}
}
}
}
//TODO : Need to implemented, to merge API Definitions in cases where implementation of an API Lies in two classes

@ -33,7 +33,7 @@ import javax.ws.rs.core.Response;
/**
* Activity related REST-API implementation.
*/
@API(name = "Activity Info Provider", version = "1.0.0", context = "/api/device-mgt/v1.0/activities", tags = {"devicemgt_admin"})
@API(name = "ActivityInfoProvider", version = "1.0.0", context = "/api/device-mgt/v1.0/activities", tags = {"device_management"})
@Path("/activities")
@Api(value = "Activity Info Provider", description = "Activity related information manipulation. For example operation details " +

@ -31,7 +31,7 @@ import javax.ws.rs.core.Response;
/**
* General Tenant Configuration REST-API.
*/
@API(name = "Configuration Management", version = "1.0.0", context = "/api/device-mgt/v1.0/configuration", tags = {"devicemgt_admin"})
@API(name = "ConfigurationManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/configuration", tags = {"device_management"})
@Path("/configuration")
@Api(value = "Configuration Management", description = "The general platform configuration management capabilities are exposed " +

@ -30,8 +30,8 @@ import javax.ws.rs.core.Response;
/**
* Device Analytics Dashboard related REST-APIs. This can be used to obtain device related analytics.
*/
@API(name = "Device Analytics Dashboard",
version = "1.0.0", context = "/api/device-mgt/v1.0/dashboard", tags = {"devicemgt_admin"})
@API(name = "DeviceAnalyticsDashboard",
version = "1.0.0", context = "/api/device-mgt/v1.0/dashboard", tags = {"device_management"})
@Path("/dashboard")
@Api(value = "Device Analytics Dashboard",

@ -39,7 +39,7 @@ import javax.ws.rs.core.Response;
/**
* Device related REST-API. This can be used to manipulated device related details.
*/
@API(name = "Device Management", version = "1.0.0", context = "/api/device-mgt/v1.0/devices", tags = {"devicemgt_admin"})
@API(name = "DeviceManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/devices", tags = {"device_management"})
@Path("/devices")
@Api(value = "Device Management", description = "This API carries all device management related operations " +

@ -39,8 +39,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "Device Type Management", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/device-types",
tags = {"devicemgt_admin"})
@API(name = "DeviceTypeManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/device-types",
tags = {"device_management"})
@Path("/device-types")
@Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " +

@ -35,7 +35,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "Group Management", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"devicemgt_admin"})
@API(name = "GroupManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"device_management"})
@Path("/groups")
@Produces(MediaType.APPLICATION_JSON)

@ -35,8 +35,8 @@ import javax.ws.rs.core.Response;
/**
* Notifications related REST-API.
*/
@API(name = "Device Notification Management", version = "1.0.0", context = "/api/device-mgt/v1.0/notifications",
tags = {"devicemgt_admin"})
@API(name = "DeviceNotificationManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/notifications",
tags = {"device_management"})
@Api(value = "Device Notification Management", description = "Device notification related operations can be found here.")
@Path("/notifications")
@Produces(MediaType.APPLICATION_JSON)

@ -37,8 +37,8 @@ import java.util.List;
* Policy related REST-API. This can be used to manipulated policies and associate them with devices, users, roles,
* groups.
*/
@API(name = "Device Policy Management", version = "1.0.0", context = "/api/device-mgt/v1.0/policies",
tags = {"devicemgt_admin"})
@API(name = "DevicePolicyManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/policies",
tags = {"device_management"})
@Api(value = "Device Policy Management", description = "This API includes the functionality around device policy management")
@Path("/policies")

@ -32,7 +32,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@API(name = "Role Management", version = "1.0.0", context = "/api/device-mgt/v1.0/roles", tags = {"devicemgt_admin"})
@API(name = "RoleManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/roles", tags = {"device_management"})
@Path("/roles")
@Api(value = "Role Management", description = "Role management related operations can be found here.")

@ -29,7 +29,7 @@ import javax.ws.rs.core.Response;
import java.util.List;
@API(name = "User Management", version = "1.0.0", context = "/api/device-mgt/v1.0/users", tags = {"devicemgt_admin"})
@API(name = "UserManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/users", tags = {"device_management"})
@Path("/users")
@Api(value = "User Management", description = "User management related operations can be found here.")

@ -33,7 +33,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "Application Management Admin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/applications", tags = {"devicemgt_admin"})
@API(name = "ApplicationManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/applications", tags = {"device_management"})
@Path("/admin/applications")
@Api(value = "Application Management Administrative Service", description = "This an API intended to be used by " +

@ -29,8 +29,8 @@ import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "Device Management Admin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/devices",
tags = {"devicemgt_admin"})
@API(name = "DeviceManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/devices",
tags = {"device_management"})
@Path("/admin/devices")
@Api(value = "Device Management Administrative Service", description = "This an API intended to be used by " +
"'internal' components to log in as an admin user and do a selected number of operations. " +

@ -37,7 +37,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "Group Management Admin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/groups", tags = {"devicemgt_admin"})
@API(name = "GroupManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/groups", tags = {"device_management"})
@Path("/admin/groups")
@Produces(MediaType.APPLICATION_JSON)

@ -30,7 +30,7 @@ import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@API(name = "User Management Admin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/users", tags = {"devicemgt_admin"})
@API(name = "UserManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/users", tags = {"device_management"})
@Path("/admin/users")
@Produces(MediaType.APPLICATION_JSON)

@ -79,6 +79,8 @@ public class TaskConfiguration {
private String operationName;
private int recurrency;
private List<String> platforms;
@XmlElement(name = "Name", required = true)
public String getOperationName() {
@ -97,5 +99,16 @@ public class TaskConfiguration {
public void setRecurrency(int recurrency) {
this.recurrency = recurrency;
}
@XmlElementWrapper(name = "Platforms")
@XmlElement(name = "platform", required = true)
public List<String> getPlatforms() {
return platforms;
}
public void setPlatforms(List<String> platforms) {
this.platforms = platforms;
}
}
}

@ -57,14 +57,6 @@ public class DeviceManagementDataHolder {
private EmailSenderService emailSenderService;
private PushNotificationProviderRepository pushNotificationProviderRepository;
public APIManagerConfiguration getApiManagerConfiguration() {
return apiManagerConfiguration;
}
public void setApiManagerConfiguration(APIManagerConfiguration apiManagerConfiguration) {
this.apiManagerConfiguration = apiManagerConfiguration;
}
private APIManagerConfiguration apiManagerConfiguration;
private DeviceManagementDataHolder() {}

@ -21,7 +21,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
@ -33,7 +32,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
@ -51,7 +49,6 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import org.wso2.carbon.device.mgt.core.push.notification.mgt.PushNotificationProviderRepository;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
@ -61,10 +58,8 @@ import org.wso2.carbon.email.sender.core.service.EmailSenderService;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -120,10 +115,6 @@ public class DeviceManagementServiceComponent {
private static List<PluginInitializationListener> listeners = new ArrayList<>();
private static List<DeviceManagementService> deviceManagers = new ArrayList<>();
private static List<DeviceManagerStartupListener> startupListeners = new ArrayList<>();
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
private static final String APIM_CONFIGURATION_PATH = CarbonUtils.getCarbonHome() + File.separator + "repository" +
File.separator + "conf" + File.separator + "api-manager.xml";
private static final String DATA_SOURCE_NAME = "DataSourceName";
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
synchronized (LOCK) {
@ -157,18 +148,11 @@ public class DeviceManagementServiceComponent {
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
APIManagerConfiguration apiManagerConfiguration = new APIManagerConfiguration();
apiManagerConfiguration.load(APIM_CONFIGURATION_PATH);
DeviceManagementDataHolder.getInstance().setApiManagerConfiguration(apiManagerConfiguration);
DeviceManagementDAOFactory.init(dsConfig);
GroupManagementDAOFactory.init(dsConfig);
NotificationManagementDAOFactory.init(dsConfig);
OperationManagementDAOFactory.init(dsConfig);
String apiManagerDataSource = apiManagerConfiguration.getFirstProperty(DATA_SOURCE_NAME);
ScopeManagementDAOFactory.init(apiManagerDataSource);
/* Initialize Operation Manager */
this.initOperationsManager();

@ -24,10 +24,7 @@ import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagement
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@ -35,6 +32,36 @@ import java.util.List;
* This class holds the Oracle implementation of NotificationDAO which can be used to support Oracle db syntax.
*/
public class OracleNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public int addNotification(int deviceId, int tenantId, Notification notification) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs;
int notificationId = -1;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_NOTIFICATION(DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION, TENANT_ID) "
+ "VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, new int[] { 1 });
stmt.setInt(1, deviceId);
stmt.setInt(2, notification.getOperationId());
stmt.setString(3, notification.getStatus().toString());
stmt.setString(4, notification.getDescription());
stmt.setInt(5, tenantId);
stmt.execute();
rs = stmt.getGeneratedKeys();
if (rs.next()) {
notificationId = rs.getInt(1);
}
} catch (Exception e) {
throw new NotificationManagementException(
"Error occurred while adding the " + "Notification for device id : " + deviceId, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, null);
}
return notificationId;
}
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws

@ -314,7 +314,7 @@ public class OperationManagerImpl implements OperationManager {
deviceId.getId() + "'");
}
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId);
if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type" +

@ -1,173 +0,0 @@
/*
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.core.scope.mgt;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.apimgt.api.model.Scope;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementException;
import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAO;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOException;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOFactory;
import java.lang.annotation.Inherited;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This is an implementation of a Scope Management Service.
*/
public class ScopeManagementServiceImpl implements ScopeManagementService {
private ScopeManagementDAO scopeManagementDAO;
public ScopeManagementServiceImpl() {
this.scopeManagementDAO = ScopeManagementDAOFactory.getScopeManagementDAO();
}
@Override
public void updateScopes(List<Scope> scopes) throws ScopeManagementException {
try {
ScopeManagementDAOFactory.beginTransaction();
scopeManagementDAO.updateScopes(scopes);
ScopeManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
ScopeManagementDAOFactory.rollbackTransaction();
throw new ScopeManagementException("Transactional error occurred while adding the scopes.", e);
} catch (ScopeManagementDAOException e) {
ScopeManagementDAOFactory.rollbackTransaction();
throw new ScopeManagementException("Error occurred while adding the scopes to database.", e);
} finally {
ScopeManagementDAOFactory.closeConnection();
}
}
@Override
public void updateScopes(List<String> scopeKeys, String roleName) throws ScopeManagementException {
List<Scope> scopes = new ArrayList<>();
try {
List<Scope> allScopes = this.getAllScopes();
for (Scope scope : allScopes) {
for (String key : scopeKeys) {
if (scope.getKey().equals(key)) {
scope.setRoles(scope.getRoles() + "," + roleName);
scopes.add(scope);
}
}
}
ScopeManagementDAOFactory.beginTransaction();
scopeManagementDAO.updateScopes(scopes);
ScopeManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
ScopeManagementDAOFactory.rollbackTransaction();
throw new ScopeManagementException("Transactional error occurred while adding the scopes.", e);
} catch (ScopeManagementDAOException e) {
ScopeManagementDAOFactory.rollbackTransaction();
throw new ScopeManagementException("Error occurred while adding the scopes to database.", e);
} finally {
ScopeManagementDAOFactory.closeConnection();
}
}
@Override
public List<Scope> getAllScopes() throws ScopeManagementException {
List<Scope> scopes = new ArrayList<>();
try {
ScopeManagementDAOFactory.openConnection();
scopes = scopeManagementDAO.getAllScopes();
} catch (SQLException e) {
throw new ScopeManagementException("SQL error occurred while retrieving scopes from database.", e);
} catch (ScopeManagementDAOException e) {
throw new ScopeManagementException("Error occurred while retrieving scopes from database.", e);
} finally {
ScopeManagementDAOFactory.closeConnection();
}
return scopes;
}
@Override
public String getRolesOfScope(String scopeKey) throws ScopeManagementException {
String roles;
if (scopeKey == null || scopeKey.isEmpty()) {
throw new ScopeManagementException("Scope key is null or empty");
}
try {
ScopeManagementDAOFactory.openConnection();
roles = scopeManagementDAO.getRolesOfScope(scopeKey);
} catch (SQLException e) {
throw new ScopeManagementException("SQL error occurred while retrieving roles of scope from database.", e);
} catch (ScopeManagementDAOException e) {
throw new ScopeManagementException("Error occurred while retrieving roles of scope from database.", e);
} finally {
ScopeManagementDAOFactory.closeConnection();
}
return roles;
}
@Override
public List<Scope> getScopesOfRole(String roleName) throws ScopeManagementException {
if (roleName == null || roleName.isEmpty()) {
throw new ScopeManagementException("Role name is null or empty");
}
List<Scope> filteredScopes = new ArrayList<>();
try {
ScopeManagementDAOFactory.openConnection();
List<Scope> allScopes = scopeManagementDAO.getScopesHavingRole(roleName);
String roles[];
for (Scope scope : allScopes) {
roles = scope.getRoles().split(",");
for (String role : roles) {
if (roleName.equals(role.trim())) {
filteredScopes.add(scope);
}
}
}
} catch (SQLException e) {
throw new ScopeManagementException("SQL error occurred while retrieving scopes of role from database.", e);
} catch (ScopeManagementDAOException e) {
throw new ScopeManagementException("Error occurred while retrieving scopes of role from database.", e);
} finally {
ScopeManagementDAOFactory.closeConnection();
}
return filteredScopes;
}
@Override
public void removeScopes(String roleName) throws ScopeManagementException {
List<Scope> scopes = this.getScopesOfRole(roleName);
String roles[];
ArrayList<String> filteredRoles = new ArrayList<>();
for (Scope scope : scopes) {
roles = scope.getRoles().split(",");
for (String role : roles) {
if (!roleName.equals(role.trim())) {
filteredRoles.add(role);
}
}
scope.setRoles(StringUtils.join(filteredRoles, ","));
filteredRoles.clear();
}
this.updateScopes(scopes);
}
}

@ -1,64 +0,0 @@
/*
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.core.scope.mgt.dao;
import org.wso2.carbon.apimgt.api.model.Scope;
import java.util.List;
/**
* This interface contains the basic database operations related to scope management.
*/
public interface ScopeManagementDAO {
/**
* This method is used to update the list of scopes.
*
* @param scopes List of scopes to be updated.
* @throws ScopeManagementDAOException
*/
void updateScopes(List<Scope> scopes) throws ScopeManagementDAOException;
/**
* This method is used to retrieve all the scopes.
*
* @return List of scopes.
* @throws ScopeManagementDAOException
*/
List<Scope> getAllScopes() throws ScopeManagementDAOException;
/**
* This method is to retrieve the roles of the given scope
* @param scopeKey key of the scope
* @return List of roles
* @throws ScopeManagementDAOException
*/
String getRolesOfScope(String scopeKey) throws ScopeManagementDAOException;
/**
* This method is to retrieve all the scopes of the given role name.
* Thus it returns the scopes even if the part of the given name is matched.
*
* @param roleName Role name
* @return List of scopes
* @throws ScopeManagementDAOException
*/
List<Scope> getScopesHavingRole(String roleName) throws ScopeManagementDAOException;
}

@ -1,57 +0,0 @@
/*
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.core.scope.mgt.dao;
public class ScopeManagementDAOException extends Exception {
private static final long serialVersionUID = -315127931137771199L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public ScopeManagementDAOException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public ScopeManagementDAOException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public ScopeManagementDAOException(String msg) {
super(msg);
setErrorMessage(msg);
}
public ScopeManagementDAOException() {
super();
}
public ScopeManagementDAOException(Throwable cause) {
super(cause);
}
}

@ -1,139 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.core.scope.mgt.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.impl.ScopeManagementDAOImpl;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class ScopeManagementDAOFactory {
private static final Log log = LogFactory.getLog(ScopeManagementDAOFactory.class);
private static DataSource dataSource;
private static String databaseEngine;
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
public static ScopeManagementDAO getScopeManagementDAO() {
return new ScopeManagementDAOImpl();
}
public static void init(String dataSourceName) {
dataSource = resolveDataSource(dataSourceName);
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
}
public static void beginTransaction() throws TransactionManagementException {
try {
Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);
currentConnection.set(conn);
} catch (SQLException e) {
throw new TransactionManagementException(
"Error occurred while retrieving config.datasource connection", e);
}
}
public static void openConnection() throws SQLException {
currentConnection.set(dataSource.getConnection());
}
public static Connection getConnection() throws SQLException {
if (currentConnection.get() == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally caused by not properly initiating the transaction via " +
"'beginTransaction'/'openConnection' methods");
}
return currentConnection.get();
}
public static void closeConnection() {
Connection con = currentConnection.get();
if (con != null) {
try {
con.close();
} catch (SQLException e) {
log.error("Error occurred while close the connection");
}
currentConnection.remove();
}
}
public static void commitTransaction() {
try {
Connection conn = currentConnection.get();
if (conn != null) {
conn.commit();
} else {
if (log.isDebugEnabled()) {
log.debug("Datasource connection associated with the current thread is null, hence commit " +
"has not been attempted");
}
}
} catch (SQLException e) {
log.error("Error occurred while committing the transaction", e);
}
}
public static void rollbackTransaction() {
try {
Connection conn = currentConnection.get();
if (conn != null) {
conn.rollback();
} else {
if (log.isDebugEnabled()) {
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
"has not been attempted");
}
}
} catch (SQLException e) {
log.error("Error occurred while roll-backing the transaction", e);
}
}
/**
* Resolve data source from the data source name.
*
* @param dataSourceName data source name
* @return data source resolved from the data source definition
*/
private static DataSource resolveDataSource(String dataSourceName) {
DataSource dataSource;
if (dataSourceName == null || dataSourceName.isEmpty()) {
throw new RuntimeException("Scope Management Repository data source configuration is null and " +
"thus, is not initialized");
}
if (log.isDebugEnabled()) {
log.debug("Initializing Scope Management Repository data source using the JNDI Lookup Definition");
}
dataSource = DeviceManagementDAOUtil.lookupDataSource(dataSourceName, null);
return dataSource;
}
}

@ -1,57 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.core.scope.mgt.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ScopeManagementDAOUtil {
private static final Log log = LogFactory.getLog(ScopeManagementDAOUtil.class);
public static void cleanupResources(Statement stmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
log.warn("Error occurred while closing the result set", e);
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
log.warn("Error occurred while closing the statement", e);
}
}
}
public static void cleanupResources(Statement stmt) {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
log.warn("Error occurred while closing the statement", e);
}
}
}
}

@ -1,148 +0,0 @@
/*
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.core.scope.mgt.dao.impl;
import org.wso2.carbon.apimgt.api.model.Scope;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAO;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOException;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.scope.mgt.dao.ScopeManagementDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class ScopeManagementDAOImpl implements ScopeManagementDAO {
@Override
public void updateScopes(List<Scope> scopes) throws ScopeManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getConnection();
String sql = "UPDATE IDN_OAUTH2_SCOPE SET ROLES=? WHERE SCOPE_KEY=?";
stmt = conn.prepareStatement(sql);
// creating a batch request
for (Scope scope : scopes) {
stmt.setString(1, scope.getRoles());
stmt.setString(2, scope.getKey());
stmt.addBatch();
}
stmt.executeBatch();
} catch (SQLException e) {
throw new ScopeManagementDAOException("Error occurred while updating the details of the scopes.", e);
} finally {
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
}
}
public List<Scope> getAllScopes() throws ScopeManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Scope> scopes;
try {
conn = this.getConnection();
String sql = "SELECT * FROM IDN_OAUTH2_SCOPE";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
scopes = this.getScopesFromResultSet(rs);
return scopes;
} catch (SQLException e) {
throw new ScopeManagementDAOException("Error occurred while fetching the details of the scopes.", e);
} finally {
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
}
}
@Override
public String getRolesOfScope(String scopeKey) throws ScopeManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String roles = null;
try {
conn = this.getConnection();
String sql = "SELECT ROLES FROM IDN_OAUTH2_SCOPE WHERE SCOPE_KEY = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, scopeKey);
rs = stmt.executeQuery();
if (rs.next()) {
roles = rs.getString("ROLES");
}
return roles;
} catch (SQLException e) {
throw new ScopeManagementDAOException("Error occurred while fetching the details of the scopes.", e);
} finally {
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
}
}
@Override
public List<Scope> getScopesHavingRole(String roleName) throws ScopeManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Scope> scopes;
try {
conn = this.getConnection();
String sql = "SELECT * FROM IDN_OAUTH2_SCOPE WHERE ROLES LIKE ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, "%" + roleName + "%");
rs = stmt.executeQuery();
scopes = this.getScopesFromResultSet(rs);
return scopes;
} catch (SQLException e) {
throw new ScopeManagementDAOException("Error occurred while fetching the details of the scopes.", e);
} finally {
ScopeManagementDAOUtil.cleanupResources(stmt, rs);
}
}
private Connection getConnection() throws SQLException {
return ScopeManagementDAOFactory.getConnection();
}
private List<Scope> getScopesFromResultSet(ResultSet rs) throws SQLException {
List<Scope> scopes = new ArrayList<>();
Scope scope;
while (rs.next()) {
scope = new Scope();
scope.setKey(rs.getString("SCOPE_KEY"));
scope.setName(rs.getString("NAME"));
scope.setDescription(rs.getString("DESCRIPTION"));
scope.setRoles(rs.getString("ROLES"));
scopes.add(scope);
}
return scopes;
}
}

@ -20,6 +20,8 @@
package org.wso2.carbon.device.mgt.core.task;
import java.util.List;
/**
* This is the bean for the operations added by the task.
*/
@ -27,6 +29,15 @@ public class TaskOperation {
private String taskName;
private int recurrentTimes;
private List<String> taskPlatforms;
public List<String> getTaskPlatforms() {
return taskPlatforms;
}
public void setTaskPlatforms(List<String> taskPlatforms) {
this.taskPlatforms = taskPlatforms;
}
public String getTaskName() {
return taskName;
@ -43,5 +54,6 @@ public class TaskOperation {
public void setRecurrentTimes(int recurrentTimes) {
this.recurrentTimes = recurrentTimes;
}
}

@ -53,16 +53,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations();
List<TaskOperation> taskOperations = new ArrayList<>();
for (TaskConfiguration.Operation op : ops) {
TaskOperation taskOperation = new TaskOperation();
taskOperation.setTaskName(op.getOperationName());
taskOperation.setRecurrentTimes(op.getRecurrency());
taskOperation.setTaskPlatforms(op.getPlatforms());
taskOperations.add(taskOperation);
}
return taskOperations;
}
public List<String> getPlatformsForOperations(String opName) {
List<String> operationPlatforms = new ArrayList<>();
TaskConfiguration taskConfiguration =
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration();
List<TaskConfiguration.Operation> ops = taskConfiguration.getOperations();
for (TaskConfiguration.Operation op : ops) {
if (op.getOperationName().equals(opName)) {
List<String> platform = op.getPlatforms();
for (String operationPlatform : platform) {
operationPlatforms.add(operationPlatform);
}
}
}
return operationPlatforms;
}
@Override
public int getTaskFrequency() throws DeviceMgtTaskException {
return DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getTaskConfiguration().
@ -84,29 +100,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override
public void addOperations() throws DeviceMgtTaskException {
List<String> deviceTypes;
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider();
try {
List<String> deviceTypes = deviceManagementProviderService.getAvailableDeviceTypes();
List<Device> devices;
List<String> operations = this.getValidOperationNames();
for (String deviceType : deviceTypes) {
devices = deviceManagementProviderService.getAllDevices(deviceType);
if (!devices.isEmpty()) {
for (String str : operations) {
CommandOperation operation = new CommandOperation();
operation.setEnabled(true);
operation.setType(Operation.Type.COMMAND);
operation.setCode(str);
deviceManagementProviderService.addOperation(deviceType, operation,
DeviceManagerUtil.getValidDeviceIdentifiers(devices));
}
} else {
if (log.isDebugEnabled()) {
log.debug("No devices are available to perform the operations.");
}
}
for (String taskOperation : operations) {
deviceTypes = getPlatformsForOperations(taskOperation);
for (String deviceType : deviceTypes) {
devices = deviceManagementProviderService.getAllDevices(deviceType);
if (!devices.isEmpty()) {
for (String str : operations) {
CommandOperation operation = new CommandOperation();
operation.setEnabled(true);
operation.setType(Operation.Type.COMMAND);
operation.setCode(str);
deviceManagementProviderService.addOperation(deviceType, operation,
DeviceManagerUtil.getValidDeviceIdentifiers(devices));
}
} else {
if (log.isDebugEnabled()) {
log.debug("No devices are available to perform the operations.");
}
}
}
}
} catch (InvalidDeviceException e) {
throw new DeviceMgtTaskException("Invalid DeviceIdentifiers found.", e);
@ -145,6 +164,8 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
return opNames;
}
@Override
public boolean isTaskOperation(String opName) {
try {

@ -19,7 +19,7 @@
"owner": "admin@carbon.super",
"dynamicClientAppRegistrationServiceURL": "%https.ip%/dynamic-client-web/register",
"apiManagerClientAppRegistrationServiceURL": "%https.ip%/api-application-registration/register/tenants",
"grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer",
"grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer urn:ietf:params:oauth:grant-type:jwt-bearer",
"tokenScope": "admin",
"callbackUrl": "%https.ip%/api/device-mgt/v1.0"
},

@ -226,13 +226,14 @@ deviceModule = function () {
publicMethods.getDevices = function (userName) {
var url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/user/" + userName;
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
for (var i = 0; i < responsePayload.length; i++) {
responsePayload[i].thumb = utility.getDeviceThumb(responsePayload[i].type);
var devices = JSON.parse(responsePayload.responseText).devices;
for (var i = 0; i < devices.length; i++) {
devices[i].thumb = utility.getDeviceThumb(devices[i].type);
}
return responsePayload;
return devices;
},
function (responsePayload) {
log.error(responsePayload);

@ -15,8 +15,20 @@
specific language governing permissions and limitations
under the License.
}}
{{unit "cdmf.unit.data-tables-extended"}}
{{unit "cdmf.unit.ui.title" pageTitle="Notification Listing"}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/notification-listing">
Notifications
</a>
</li>
{{/zone}}
{{#zone "content"}}
{{unit "cdmf.unit.notification.listing"}}
{{/zone}}

@ -20,7 +20,10 @@
var sortUpdateBtn = "#sortUpdateBtn";
var sortedIDs;
var dataTableSelection = '.DTTT_selected';
$('#policy-grid').datatables_extended();
var settings = {
"sorting": false
};
$('#policy-grid').datatables_extended(settings);
$(".icon .text").res_text(0.2);
var saveNewPrioritiesButton = "#save-new-priorities-button";
@ -90,7 +93,7 @@ function showPopup() {
function hidePopup() {
$(modalPopupContent).html('');
$(modalPopup).modal('hide');
$('body').removeClass('modal-open').css('padding-right','0px');
$('body').removeClass('modal-open').css('padding-right', '0px');
$('.modal-backdrop').remove();
}
@ -208,7 +211,7 @@ $(document).ready(function () {
},
function () {
$("#save-policy-priorities-error-content").find(".message-from-server").html(
"Message From Server : " + data["statusText"]);
"Message From Server : " + data["statusText"]);
$(modalPopupContent).html($('#save-policy-priorities-error-content').html());
showPopup();
$("a#save-policy-priorities-error-link").click(function () {
@ -222,7 +225,7 @@ $(document).ready(function () {
$(".policy-unpublish-link").click(function () {
var policyList = getSelectedPolicies();
var statusList = getSelectedPolicyStates();
if ( ($.inArray( 'Inactive/Updated', statusList ) > -1) || ($.inArray( 'Inactive', statusList ) > -1) ) {
if (($.inArray('Inactive/Updated', statusList) > -1) || ($.inArray('Inactive', statusList) > -1)) {
$(modalPopupContent).html($("#errorPolicyUnPublishSelection").html());
showPopup();
} else {
@ -266,7 +269,7 @@ $(document).ready(function () {
$(".policy-publish-link").click(function () {
var policyList = getSelectedPolicies();
var statusList = getSelectedPolicyStates();
if ( ($.inArray( 'Active/Updated', statusList ) > -1) || ($.inArray( 'Active', statusList ) > -1) ) {
if (($.inArray('Active/Updated', statusList) > -1) || ($.inArray('Active', statusList) > -1)) {
$(modalPopupContent).html($("#errorPolicyPublishSelection").html());
showPopup();
} else {

@ -45,9 +45,9 @@ var isInit = true;
* the font icons change the size to respective screen resolution.
*
*/
$(document).on( 'draw.dt', function () {
$(document).on('draw.dt', function () {
$(".icon .text").res_text(0.2);
} );
});
/*
@ -72,7 +72,7 @@ function showPopup() {
function hidePopup() {
$(modalPopupContent).html('');
$(modalPopup).modal('hide');
$('body').removeClass('modal-open').css('padding-right','0px');
$('body').removeClass('modal-open').css('padding-right', '0px');
$('.modal-backdrop').remove();
}
@ -95,7 +95,7 @@ function loadRoles() {
var objects = [];
$(data.roles).each(function( index ) {
$(data.roles).each(function (index) {
objects.push(
{
name: data.roles[index],
@ -182,10 +182,13 @@ function loadRoles() {
var options = {
"placeholder": "Search By Role Name",
"searchKey" : "filter"
"searchKey": "filter"
};
var settings = {
"sorting": false
};
$('#role-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/roles', dataFilter, columns, fnCreatedRow, null, options);
$('#role-grid').datatables_extended_serverside_paging(settings, '/api/device-mgt/v1.0/roles', dataFilter, columns, fnCreatedRow, null, options);
loadingContent.hide();
}

@ -5,13 +5,14 @@
<i class="square-element text fw fw-user"></i>
</div>
</td>
<td class="fade-edge remove-padding-top" >{{roleName}}</td>
<td class="fade-edge remove-padding-top">{{roleName}}</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
{{#unequal adminRole roleName }}
{{#if canEdit}}
<a onclick="javascript:loadRoleBasedActionURL('edit', '{{roleName}}')" data-role="{{roleName}}" data-click-event="edit-form"
class="btn padding-reduce-on-grid-view edit-role-link">
{{#if canEdit}}
<a onclick="javascript:loadRoleBasedActionURL('edit', '{{roleName}}')" data-role="{{roleName}}"
data-click-event="edit-form"
class="btn padding-reduce-on-grid-view edit-role-link" title="Edit Role">
<span class="fw-stack fw-lg">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-user fw-stack-1x"></i>
@ -21,10 +22,12 @@
<i class="fw fw-edit fw-stack-1x fw-inverse"></i>
</span>
</span>
<span class="hidden-xs hidden-on-grid-view">Edit</span>
</a>
<a onclick="javascript:loadRoleBasedActionURL('edit-permission', '{{roleName}}')" data-role="{{roleName}}"
data-click-event="edit-form" class="btn padding-reduce-on-grid-view edit-permission-link">
<span class="hidden-xs hidden-on-grid-view">Edit</span>
</a>
<a onclick="javascript:loadRoleBasedActionURL('edit-permission', '{{roleName}}')"
data-role="{{roleName}}"
data-click-event="edit-form" class="btn padding-reduce-on-grid-view edit-permission-link"
title="Edit Role Permissions">
<span class="fw-stack fw-lg">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-security-policy fw-stack-1x"></i>
@ -34,18 +37,19 @@
<i class="fw fw-edit fw-stack-1x fw-inverse"></i>
</span>
</span>
<span class="hidden-xs hidden-on-grid-view">Edit Permission</span>
</a>
{{/if}}
{{#if canRemove}}
<a data-role="{{roleName}}" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-role-link">
<span class="hidden-xs hidden-on-grid-view">Edit Permission</span>
</a>
{{/if}}
{{#if canRemove}}
<a data-role="{{roleName}}" data-click-event="remove-form"
class="btn padding-reduce-on-grid-view remove-role-link" title="Remove Role">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-delete fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Remove</span>
</a>
{{/if}}
<span class="hidden-xs hidden-on-grid-view">Remove</span>
</a>
{{/if}}
{{/unequal}}
</td>
</tr>

@ -50,9 +50,9 @@ var body = "body";
* the font icons change the size to respective screen resolution.
*
*/
$(document).on( 'draw.dt', function () {
$(document).on('draw.dt', function () {
$(".icon .text").res_text(0.2);
} );
});
/*
* set popup maximum height function.
@ -75,7 +75,7 @@ function showPopup() {
function hidePopup() {
$(modalPopupContent).html('');
$(modalPopup).modal('hide');
$('body').removeClass('modal-open').css('padding-right','0px');
$('body').removeClass('modal-open').css('padding-right', '0px');
$('.modal-backdrop').remove();
}
@ -270,13 +270,14 @@ function loadUsers() {
var objects = [];
$(data.users).each( function (index) {
$(data.users).each(function (index) {
objects.push({
filter: data.users[index].username,
firstname: data.users[index].firstname ? data.users[index].firstname : "" ,
firstname: data.users[index].firstname ? data.users[index].firstname : "",
lastname: data.users[index].lastname ? data.users[index].lastname : "",
emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress : "",
DT_RowId : "user-" + data.users[index].username})
emailAddress: data.users[index].emailAddress ? data.users[index].emailAddress : "",
DT_RowId: "user-" + data.users[index].username
})
});
var json = {
@ -300,7 +301,7 @@ function loadUsers() {
class: "remove-padding icon-only content-fill",
data: null,
render: function (data, type, row, meta) {
return '<div class="thumbnail icon viewEnabledIcon" data-url="' + context +'/user/view?username=' + data.filter + '">' +
return '<div class="thumbnail icon viewEnabledIcon" data-url="' + context + '/user/view?username=' + data.filter + '">' +
'<i class="square-element text fw fw-user" style="font-size: 74px;"></i>' +
'</div>';
}
@ -338,7 +339,7 @@ function loadUsers() {
class: "text-right content-fill text-left-on-grid-view no-wrap",
data: null,
render: function (data, type, row, meta) {
var editbtn= '&nbsp;<a data-toggle="tooltip" data-placement="bottom" title="Edit User"href="' + context + '/user/edit?username=' + data.filter + '" data-username="' + data.filter + '" ' +
var editbtn = '&nbsp;<a data-toggle="tooltip" data-placement="bottom" title="Edit User"href="' + context + '/user/edit?username=' + data.filter + '" data-username="' + data.filter + '" ' +
'data-click-event="edit-form" ' +
'class="btn padding-reduce-on-grid-view edit-user-link"> ' +
'<span class="fw-stack"> ' +
@ -377,13 +378,13 @@ function loadUsers() {
'</a>';
var returnbtnSet = '';
if($("#can-edit").length > 0) {
if ($("#can-edit").length > 0) {
returnbtnSet = returnbtnSet + editbtn;
}
if($("#can-reset-password").length > 0) {
if ($("#can-reset-password").length > 0) {
returnbtnSet = returnbtnSet + resetPasswordbtn;
}
if($("#can-remove").length > 0) {
if ($("#can-remove").length > 0) {
returnbtnSet = returnbtnSet + removebtn;
}
@ -395,10 +396,14 @@ function loadUsers() {
var options = {
"placeholder": "Search By Username",
"searchKey" : "filter"
"searchKey": "filter"
};
var settings = {
"sorting": false
};
$('#user-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null, options);
$('#user-grid').datatables_extended_serverside_paging(settings, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null, options);
$(loadingContentView).hide();
}

@ -29,6 +29,15 @@ $.fn.datatables_extended = function(settings){
}
//--- End of EMM related codes
/*
* Work around for accessing settings params inside datatable functions
*/
if(settings != null && settings.sorting != null && settings.sorting != undefined && settings.sorting){
elem.addClass('sorting-enabled');
}else{
elem.addClass('sorting-disabled');
}
$(elem).DataTable(
$.extend({},{
bSortCellsTop: true,
@ -131,24 +140,41 @@ $.fn.datatables_extended = function(settings){
/**
* create sorting dropdown menu for list table advance operations
*/
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
$('.sort-row th', elem).each(function(){
if(!$(this).hasClass('no-sort')){
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>');
}
});
var table = this;
if(table.hasClass('sorting-enabled')){
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
$('.sort-row th', elem).each(function () {
if (!$(this).hasClass('no-sort')) {
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>');
}
});
}
function getAdvanceToolBar(){
if(table.hasClass('sorting-enabled')){
return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>' + dropdownmenu[0].outerHTML + '</li>' +
'</ul>'
}else{
return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'</ul>'
};
}
/**
* append advance operations to list table toolbar
*/
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' +
'<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>'+dropdownmenu[0].outerHTML+'</li>' +
'</ul>'
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html(
getAdvanceToolBar()
);
/**
@ -186,14 +212,14 @@ $.fn.datatables_extended = function(settings){
$(button).addClass("active").html('Cancel');
$(button).parent().next().children("button").removeClass("disabled");
// EMM related code
$(".viewEnabledIcon").unbind("click");
$(document).off('click','.viewEnabledIcon');
//--- End of EMM related codes
} else if ($(button).html() == 'Cancel'){
thisTable.removeClass("table-selectable");
$(button).addClass("active").html('Select');
$(button).parent().next().children().addClass("disabled");
// EMM related function
$(".viewEnabledIcon").bind("click", InitiateViewOption);
$(document).on('click','.viewEnabledIcon',InitiateViewOption);
//--- End of EMM related codes
}
});

@ -29,13 +29,23 @@
* For ex: $(this) means jQuery(this) and S.fn.x means jQuery.fn.x
*/
$.fn.datatables_extended_serverside_paging = function (settings , url, dataFilter,
$.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter,
columns, fnCreatedRow, fnDrawCallback, options) {
var elem = $(this);
// EMM related function
if (InitiateViewOption) {
$(document).on('click','.viewEnabledIcon',InitiateViewOption);
$(document).on('click', '.viewEnabledIcon', InitiateViewOption);
}
//--- End of EMM related codes
/*
* Work around for accessing settings params inside datatable functions
*/
if (settings != null && settings.sorting != null && settings.sorting != undefined && settings.sorting) {
elem.addClass('sorting-enabled');
} else {
elem.addClass('sorting-disabled');
}
var deviceType;
@ -44,22 +54,22 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte
//--- End of EMM related codes
$(elem).DataTable(
$.extend({},{
$.extend({}, {
serverSide: true,
processing: false,
searching: true,
ordering: false,
ordering: false,
filter: false,
bSortCellsTop: true,
ajax : {
ajax: {
url: context + "/api/data-tables/invoker",
data : function (params) {
data: function (params) {
var i;
var searchParams = {};
for (i = 0; i < params.columns.length; i++) {
searchParams[params.columns[i].data] = encodeURIComponent(params.columns[i].search.value);
}
if(options) {
if (options) {
searchParams[options.searchKey] = encodeURIComponent(params.search.value);
}
params.filter = JSON.stringify(searchParams);
@ -78,14 +88,14 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte
columns: columns,
responsive: false,
autoWidth: false,
dom:'<"dataTablesTop"' +
'f' +
'<"dataTables_toolbar">' +
'>' +
'rt' +
'<"dataTablesBottom"' +
'lip' +
'>',
dom: '<"dataTablesTop"' +
'f' +
'<"dataTables_toolbar">' +
'>' +
'rt' +
'<"dataTablesBottom"' +
'lip' +
'>',
language: {
searchPlaceholder: options.placeholder,
search: ''
@ -110,7 +120,7 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte
);
column
//.search(val ? '^' + val + '$' : '', true, false)
//.search(val ? '^' + val + '$' : '', true, false)
.search(val ? val : '', true, false)
.draw();
@ -184,24 +194,42 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte
/**
* create sorting dropdown menu for list table advance operations
*/
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
$('.sort-row th', elem).each(function () {
if (!$(this).hasClass('no-sort')) {
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>');
var table = this;
if (table.hasClass('sorting-enabled')) {
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
$('.sort-row th', elem).each(function () {
if (!$(this).hasClass('no-sort')) {
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>');
}
});
}
function getAdvanceToolBar() {
if (table.hasClass('sorting-enabled')) {
return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>' + dropdownmenu[0].outerHTML + '</li>' +
'</ul>'
} else {
return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'</ul>'
}
});
;
}
/**
* append advance operations to list table toolbar
*/
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' +
'<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>' + dropdownmenu[0].outerHTML + '</li>' +
'</ul>'
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html(
getAdvanceToolBar()
);
/**
@ -239,14 +267,14 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte
$(button).addClass("active").html('Cancel');
$(button).parent().next().children("button").removeClass("disabled");
// EMM related code
$(document).off('click','.viewEnabledIcon');
$(document).off('click', '.viewEnabledIcon');
//--- End of EMM related codes
} else if ($(button).html() == 'Cancel') {
thisTable.removeClass("table-selectable");
$(button).addClass("active").html('Select');
$(button).parent().next().children().addClass("disabled");
// EMM related function
$(document).on('click','.viewEnabledIcon',InitiateViewOption);
$(document).on('click', '.viewEnabledIcon', InitiateViewOption);
//--- End of EMM related codes
}
});
@ -305,6 +333,6 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte
}
})
}
},settings)
}, settings)
);
};

@ -1,203 +1,515 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. 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.
}}
{{unit "mdm.unit.lib.leaflet"}}
{{unit "cdmf.unit.lib.qrcode"}}
{{unit "mdm.unit.device.qr-modal"}}
{{#zone "content"}}
<h1 class="page-sub-title device-id device-select" data-deviceid="{{device.deviceIdentifier}}" data-type="{{device.type}}">
Device {{device.name}}
{{#if device.viewModel.model}}
<span class="lbl-device">
( {{device.viewModel.vendor}} {{device.viewModel.model}} )
</span>
{{/if}}
</h1>
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
<div class="media">
<div id="device_overview">
<div class="media-left media-middle asset-image col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail icon">
{{#defineZone "device-thumbnail"}}
<i class="square-element text fw fw-mobile"></i>
{{/defineZone}}
{{#if deviceFound}}
{{#if isAuthorized}}
<h1 class="page-sub-title device-id device-select"
data-deviceid="{{deviceView.deviceIdentifier}}" data-type="{{deviceView.deviceType}}"
data-ownership="{{deviceView.ownership}}">
Device {{deviceView.name}}
{{#if deviceView.model}}
<span class="lbl-device">
( {{deviceView.vendor}} {{deviceView.model}} )
</span>
{{/if}}
</h1>
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
<div class="media">
<div class="media-left media-middle asset-image col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>
</div>
</div>
<div class="media-body asset-desc add-padding-left-5x">
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
Device Overview - {{label}}</div>
{{unit "cdmf.unit.device.overview-section" device=device}}
{{#defineZone "operation-status"}}{{/defineZone}}
{{#defineZone "device-opetations"}}
<div class="media-body asset-desc add-padding-left-5x">
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">Device
Overview
</div>
{{#defineZone "device-detail-properties"}}
<table class="table table-responsive table-striped" id="members">
<tbody>
{{#if deviceView.deviceIdentifier}}
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Device ID</td>
<td style="padding:10px 15px;">{{deviceView.deviceIdentifier}}</td>
</tr>
{{/if}}
{{#if deviceView.name}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Name</td>
<td style="padding:10px 15px;">{{deviceView.name}}</td>
</tr>
{{/if}}
{{#if deviceView.vendor}}
{{#if deviceView.model}}
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Model</td>
<td style="padding:10px 15px;">{{deviceView.vendor}} {{deviceView.model}}</td>
</tr>
{{/if}}
{{/if}}
{{#if deviceView.status}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Status</td>
<td style="padding:10px 15px;">
{{#equal deviceView.status "ACTIVE"}}<span><i
class="fw fw-ok icon-success"></i>Active</span>{{/equal}}
{{#equal deviceView.status "INACTIVE"}}<span><i
class="fw fw-warning icon-warning"></i>Inactive</span>{{/equal}}
{{#equal deviceView.status "BLOCKED"}}<span><i
class="fw fw-remove icon-danger"></i>Blocked</span>{{/equal}}
{{#equal deviceView.status "REMOVED"}}<span><i
class="fw fw-delete icon-danger"></i>Removed</span>{{/equal}}
</td>
</tr>
{{/if}}
{{#if deviceView.owner}}
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Owner</td>
<td style="padding:10px 15px;">{{deviceView.owner}}</td>
</tr>
{{/if}}
{{#if deviceView.ownership}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Ownership</td>
<td style="padding:10px 15px;">{{deviceView.ownership}}</td>
</tr>
{{/if}}
{{#if deviceView.imei}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">IMEI</td>
<td style="padding:10px 15px;">{{deviceView.imei}}</td>
</tr>
{{/if}}
{{#if deviceView.udid}}
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">UDID</td>
<td style="padding:10px 15px;">{{deviceView.udid}}</td>
</tr>
{{/if}}
{{#if deviceView.osBuildDate}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Firmware Build
Date
</td>
<td style="padding:10px 15px;">{{deviceView.osBuildDate}}</td>
</tr>
{{/if}}
{{#if deviceView.phoneNumber}}
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Phone Number</td>
<td style="padding:10px 15px;">{{deviceView.phoneNumber}}</td>
</tr>
{{/if}}
{{#if deviceView.lastUpdatedTime}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Last Update</td>
<td style="padding:10px 15px;">{{deviceView.lastUpdatedTime}}</td>
</tr>
{{/if}}
</tbody>
</table>
{{/defineZone}}
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
Operations
</div>
<div class="add-margin-top-4x" style="height: 90px;">
{{unit "cdmf.unit.device.operation-bar" device=device}}
<div class="add-margin-top-4x">
{{unit "mdm.unit.device.operation-bar" deviceType=deviceView.deviceType ownership=deviceView.ownership}}
</div>
{{/defineZone}}
</div>
</div>
</div>
</div>
<div class="media tab-responsive">
<div class="media-left col-xs-1 col-sm-1 col-md-2 col-lg-2 hidden-xs">
<ul class="list-group nav nav-pills nav-stacked" role="tablist">
{{#if deviceView.isNotWindows}}
<li role="presentation" class="list-group-item active">
<a href="#device_details_tab" role="tab" data-toggle="tab"
aria-controls="device_details_tab">
<i class="icon fw fw-mobile"></i><span class="hidden-sm">Device Details</span>
</a>
</li>
{{/if}}
{{#if deviceView.isNotWindows}}
<li role="presentation" class="list-group-item">
{{else}}
<li role="presentation" class="list-group-item active">
{{/if}}
<li role="presentation" class="list-group-item">
<a href="#policy_compliance_tab" role="tab" data-toggle="tab"
aria-controls="policy_compliance_tab">
<i class="icon fw fw-policy"></i><span class="hidden-sm">Policy Compliance</span>
</a>
</li>
{{#if deviceView.isNotWindows}}
<li role="presentation" class="list-group-item">
<a href="#device_location_tab" role="tab" data-toggle="tab"
data-lat="{{deviceView.location.latitude}}"
data-long="{{deviceView.location.longitude}}"
aria-controls="device_location_tab">
<i class="icon fw fw-map-location"></i><span
class="hidden-sm">Device Location</span>
</a>
</li>
<li role="presentation" class="list-group-item">
<a href="#installed_applications_tab" role="tab" data-toggle="tab"
aria-controls="installed_applications_tab">
<i class="icon fw fw-application"></i><span class="hidden-sm">Installed Applications</span>
</a>
</li>
{{/if}}
{{#if deviceView.isNotRemoved}}
{{#defineZone "device-detail-properties"}}
<div class="media">
<div class="media-left col-xs-12 col-sm-2 col-md-2 col-lg-2">
<ul class="list-group" role="tablist">
<li class="active"><a class="list-group-item"
href="#device_details"
role="tab" data-toggle="tab"
aria-controls="device_details">Device
Details</a>
</li>
<li><a class="list-group-item" href="#policies"
role="tab"
data-toggle="tab" aria-controls="policies">Policies</a>
</li>
<li><a class="list-group-item" href="#policy_compliance"
role="tab"
data-toggle="tab" aria-controls="policy_compliance">Policy
Compliance</a>
</li>
<li><a class="list-group-item" href="#device_location"
role="tab"
data-toggle="tab" aria-controls="device_location">Device
Location</a>
</li>
<li><a class="list-group-item" href="#event_log" role="tab"
data-toggle="tab" aria-controls="event_log">Operations
Log</a></li>
</ul>
</div>
<div class="media-body add-padding-left-5x remove-padding-xs tab-content">
<div class="panel-group tab-content">
<li role="presentation" class="list-group-item">
<a href="#event_log_tab" role="tab" data-toggle="tab"
aria-controls="event_log_tab">
<i class="icon fw fw-text"></i><span class="hidden-sm">Operations Log</span>
</a>
</li>
<div class="panel panel-default tab-pane active"
id="device_details" role="tabpanel"
aria-labelledby="device_details">
{{unit "cdmf.unit.device.details" device=device}}
{{/if}}
</ul>
</div>
<div class="panel panel-default tab-pane" id="policies" role="tabpanel"
aria-labelledby="policies">
<div class="panel-heading">Policies</div>
<div class="panel-body">
<div id="policy-spinner" class="wr-advance-operations-init hidden">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policies . . .
<br>
<br>
</div>
<div id="policy-list-container">
<div class="panel-body">
No policies found
{{#defineZone "device-detail-properties"}}
<div class="media-body add-padding-left-5x remove-padding-xs">
<div class="panel-group tab-content remove-padding" id="tabs" data-status="{{deviceView.isNotRemoved}}"role="tablist"
aria-multiselectable="true">
<div class="arrow-left hidden-xs"></div>
{{#if deviceView.isNotWindows}}
<div class="panel panel-default" role="tabpanel" id="device_details_tab">
<div class="panel-heading visible-xs collapsed" id="device_details">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#tabs"
href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="fw fw-mobile fw-2x"></i>
Device Details
<i class="caret-updown fw fw-down"></i>
</a>
</h4>
</div>
<div class="panel-heading display-none-xs">Device Details</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel"
aria-labelledby="device_details">
<div class="panel-body ">
<div class="device-detail-body">
<!-- device summary -->
{{#equal deviceView.deviceType "windows"}}
<div class="message message-info">
<h4 class="remove-margin"><i class="icon fw fw-info"></i>Not
available yet</h4>
</div>
{{/equal}}
{{#if deviceView.deviceInfoAvailable}}
{{#if deviceView.BatteryLevel}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">BATTERY</div>
<div>
<div class="tile-icon"><i
class="fw fw-battery"></i></div>
<div class="tile-stats">
{{deviceView.BatteryLevel.value}} %
</div>
</div>
</div>
</div>
</div>
{{/if}}
<!--{{#if deviceView.cpuUsage}}-->
<!--<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">-->
<!--<div class="col-md-12">-->
<!--<div class="wr-stats-board-tile">-->
<!--<div class="tile-name">CPU Usage</div>-->
<!--<div>-->
<!--<div class="tile-icon"><i class="fw fw-dashboard"></i></div>-->
<!--<div class="tile-stats">-->
<!--{{deviceView.cpuUsage.value}} %-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--{{/if}}-->
{{#if deviceView.ramUsage}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">RAM Usage</div>
<div>
<div class="tile-icon"><i
class="fw fw-hardware"></i></div>
<div class="tile-stats">
{{deviceView.ramUsage.value}} %
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{#if deviceView.internalMemory}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">Local Storage</div>
<div>
<div class="tile-icon"><i
class="fw fw-hdd"></i>
</div>
<div class="tile-stats">
{{deviceView.internalMemory.usage}} %
<span class="tile-stats-free">
TOTAL OF {{deviceView.internalMemory.total}} GB
</span>
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{#if deviceView.externalMemory}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">External Storage</div>
<div>
<div class="tile-icon"><i
class="fw fw-usb-drive"></i></div>
<div class="tile-stats">
{{deviceView.externalMemory.usage}} %
<span class="tile-stats-free">
TOTAL OF {{deviceView.externalMemory.total}} GB
</span>
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{else}}
<div class="message message-info">
<h4 class="remove-margin">
<i class="icon fw fw-info"></i>
Battery, RAM and Storage related information are not
available yet.
</h4>
</div>
{{/if}}
</div>
</div>
</div>
</div>
{{/if}}
<div class="panel panel-default visible-xs-block" role="tabpanel"
id="policy_compliance_tab">
<div class="panel-heading visible-xs collapsed" id="policy_compliance">
<h4 class="panel-title">
<a role="button"
data-toggle="collapse" data-parent="#tabs" href="#collapseTwo"
aria-expanded="true" aria-controls="collapseTwo">
<i class="fw fw-policy fw-2x"></i>
Policy Compliance
<i class="caret-updown fw fw-down"></i>
</a>
</h4>
</div>
<div class="panel-heading display-none-xs">
Policy Compliance
<span>
<a href="javascript:void(0);" id="refresh-policy">
<i class="fw fw-refresh"></i>
</a>
</span>
</div>
<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel"
aria-labelledby="policy_compliance">
<div class="panel-body ">
<span class="visible-xs add-padding-2x text-right">
<a href="javascript:void(0);" id="refresh-policy">
<i class="fw fw-refresh"></i>
</a>
</span>
<div id="policy-spinner"
class="wr-advance-operations-init add-padding-bottom-2x add-padding-bottom-4x hidden">
<i class="fw fw-settings fw-spin fw-2x"></i>Loading Policy
Compliance...
</div>
<div id="policy-list-container">
</div>
</div>
</div>
</div>
<br class="c-both"/>
</div>
</div>
<a class="padding-left"
href="{{@app.context}}/policy/add/{{device.type}}?deviceId={{device.deviceIdentifier}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-policy fw-stack-1x"></i>
</span> Add device specific policy</a>
</div>
<div class="panel panel-default visible-xs-block" role="tabpanel"
id="device_location_tab">
<div class="panel-heading visible-xs collapsed" id="device_location">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#tabs"
href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">
<i class="fw fw-map-location fw-2x"></i>
Device Location
<i class="caret-updown fw fw-down"></i>
</a>
</h4>
</div>
<div class="panel-heading display-none-xs">Device Location</div>
<div id="collapseThree" class="panel-collapse collapse in" role="tabpanel"
aria-labelledby="device_location">
<div class="panel-body">
{{#if deviceView.location}}
<div id="device-location"
data-lat="{{deviceView.location.latitude}}"
data-long="{{deviceView.location.longitude}}">
</div>
{{else}}
<div id="map-error" class="message message-warning">
<h4 class="remove-margin">
<i class="icon fw fw-warning"></i>
Device location information is not available.
</h4>
</div>
<p class="add-padding-5x"></p>
<p class="add-padding-5x"></p>
<p class="add-padding-5x"></p>
{{/if}}
</div>
</div>
</div>
<div class="panel panel-default visible-xs-block" role="tabpanel"
id="installed_applications_tab">
<div class="panel-heading visible-xs collapsed" id="installed_applications">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#tabs"
href="#collapseFour" aria-expanded="true" aria-controls="collapseFour">
<i class="fw fw-application fw-2x"></i>
Installed Applications
<i class="caret-updown fw fw-down"></i>
</a>
</h4>
</div>
<div class="panel-heading display-none-xs">
Installed Applications
<div class="panel panel-default tab-pane" id="policy_compliance"
role="tabpanel" aria-labelledby="policy_compliance">
<div class="panel-heading">Policy Compliance <span><a
href="#" id="refresh-policy"><i
class="fw fw-refresh"></i></a></span></div>
<div class="panel-body">
<div id="policy-spinner"
class="wr-advance-operations-init hidden">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policy Compliance . . .
<br>
<br>
</div>
<div id="policy-list-container">
<div class="panel-body">
Not available yet
<span>
<a href="javascript:void(0);" id="refresh-apps">
<i class="fw fw-refresh"></i>
</a>
</span>
</div>
<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel"
aria-labelledby="installed_applications">
<div class="panel-body">
<span class="visible-xs add-padding-2x text-right">
<a href="javascript:void(0);" id="refresh-apps">
<i class="fw fw-refresh"></i>
</a>
</span>
<div id="apps-spinner" class="wr-advance-operations-init hidden">
<i class="fw fw-settings fw-spin fw-2x"></i> Loading Applications
List...
</div>
<div id="applications-list-container">
<div class="message message-info">
<h4>
<i class="icon fw fw-info"></i>
No applications found.
</h4>
<p>Please try refreshing in a while.</p>
</div>
</div>
</div>
</div>
</div>
<br class="c-both"/>
</div>
</div>
</div>
<div class="panel panel-default tab-pane" id="device_location"
role="tabpanel" aria-labelledby="device_location">
<div class="panel-heading">Device Location</div>
<div class="panel-body">
<div id="device-location"
data-lat="{{device.viewModel.location.latitude}}"
data-long="{{device.viewModel.location.longitude}}"
style="height:450px" class="panel-body">
</div>
<div id="map-error" class="panel-body">
Not available yet
</div>
<br class="c-both"/>
</div>
</div>
<div class="panel panel-default tab-pane" id="event_log"
role="tabpanel" aria-labelledby="event_log">
<div class="panel-heading">Operations Log <span><a href="#"
id="refresh-operations"><i
class="fw fw-refresh"></i></a></span></div>
<div class="panel-body">
<div id="operations-spinner"
class="wr-advance-operations-init hidden">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Operations Log . . .
<br>
<br>
</div>
<div id="operations-log-container">
<div class="panel-body">
Not available yet
<div class="panel panel-default visible-xs-block" role="tabpanel" id="event_log_tab">
<div class="panel-heading visible-xs collapsed" id="event_log">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#tabs"
href="#collapseFive" aria-expanded="true" aria-controls="collapseFive">
<i class="fw fw-text fw-2x"></i>
Operations Log
<i class="caret-updown fw fw-down"></i>
</a>
</h4>
</div>
<div class="panel-heading display-none-xs">
Operations Log
<span>
<a href="javascript:void(0);" id="refresh-operations">
<i class="fw fw-refresh"></i>
</a>
</span>
</div>
<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel"
aria-labelledby="event_log">
<div class="panel-body">
<span class="visible-xs add-padding-2x text-right">
<a href="javascript:void(0);" id="refresh-operations">
<i class="fw fw-refresh"></i>
</a>
</span>
<div id="operations-spinner" class="wr-advance-operations-init hidden">
<i class="fw fw-settings fw-spin fw-2x"></i> Loading Operations Log...
</div>
<div id="operations-log-container">
<div class="message message-info">
<h4 class="remove-margin">
<i class="icon fw fw-info"></i>
There are no operations, performed yet on this device.
</h4>
</div>
</div>
<table class="table table-striped table-hover table-bordered display data-table"
id="operations-log-table">
<thead>
<tr class="sort-row">
<th>Operation Code</th>
<th>Status</th>
<th>Request created at</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<br class="c-both"/>
</div>
</div>
</div>
{{/defineZone}}
</div>
</div>
</div>
{{/defineZone}}
</div>
{{else}}
<h1 class="page-sub-title">
Permission Denied
</h1>
<br>
You are not authorized to view specified device in the system.
{{/if}}
{{else}}
<h1 class="page-sub-title">
Device not found
</h1>
<br>
You have tried to access either a removed or non-existing device.
{{/if}}
{{/zone}}
{{#zone "bottomJs"}}
{{js "js/device-view.js"}}
<script id="policy-view" src="{{@unit.publicUri}}/templates/policy-compliance.hbs"
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
type="text/x-handlebars-template"></script>
<script id="policy-list" src="{{@unit.publicUri}}/templates/policy-list.hbs"
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
type="text/x-handlebars-template"></script>
<script id="applications-list" src="{{@unit.publicUri}}/templates/applications-list.hbs"
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
type="text/x-handlebars-template"></script>
<script id="operations-log" src="{{@unit.publicUri}}/templates/operations-log.hbs"
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
type="text/x-handlebars-template"></script>
{{#if isAuthorized}}
<!--suppress HtmlUnknownTarget -->
<script id="policy-view" src="{{@unit.publicUri}}/templates/policy-compliance.hbs"
data-device-id="{{deviceView.deviceIdentifier}}" data-device-type="{{deviceView.deviceType}}"
type="text/x-handlebars-template"></script>
<!--suppress HtmlUnknownTarget -->
<script id="applications-list" src="{{@unit.publicUri}}/templates/applications-list.hbs"
data-device-id="{{deviceView.deviceIdentifier}}" data-device-type="{{deviceView.deviceType}}"
type="text/x-handlebars-template"></script>
<!--suppress HtmlUnknownTarget -->
<script id="operations-log" src="{{@unit.publicUri}}/templates/operations-log.hbs"
data-device-id="{{deviceView.deviceIdentifier}}" data-device-type="{{deviceView.deviceType}}"
type="text/x-handlebars-template"></script>
{{js "js/device-detail.js"}}
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
{{js "js/load-map.js"}}
{{/if}}
{{/zone}}

@ -21,10 +21,10 @@
<div class="col-md-12">
<!-- content -->
<div id="config-save-form" class="container col-centered wr-content">
<br>
<h4> Device Notifications </h4>
<br>
<br>
<h1 class="page-sub-title">
Device Notifications
</h1>
</br>
<div class="wr-advance-operations">
<div class="row no-gutter">
<div class="wr-hidden-operations-nav col-lg-4">
@ -43,7 +43,7 @@
</div>
<div class="wr-hidden-operations-content col-lg-8" id="ast-container">
<div class="panel-body">
<div id="noNotificationtxt" class="panel-body">
No unread messages
</div>
</div>

@ -47,8 +47,11 @@ function loadNotifications() {
viewModel["appContext"] = context;
var content = template(viewModel);
$("#ast-container").html(content);
$("#unread-notifications").datatables_extended();
$("#all-notifications").datatables_extended();
var settings = {
"sorting" : false
};
$("#unread-notifications").datatables_extended(settings);
$("#all-notifications").datatables_extended(settings);
}
}
},
@ -65,15 +68,13 @@ function loadNotifications() {
function showAdvanceOperation(operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
if ($(button).attr("id") == 'allNotifications') {
$("#ast-container").html('<div class="panel-body">You do not have any unread notifications </div>');
$("#noNotificationtxt").html('You do not have any unread notifications ');
} else if ($(button).attr("id") == 'unReadNotifications') {
$("#ast-container").html('<div class="panel-body">You do not have any notifications </div>');
$("#noNotificationtxt").html('You do not have any notifications ');
} else {
$("#ast-container").html('<div class="panel-body">You do not have any notifications </div>');
$("#noNotificationtxt").html('You do not have any notifications ');
}
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
@ -91,7 +92,7 @@ $(document).ready(function () {
loadNotifications();
$("#ast-container").on("click", ".new-notification", function (e) {
$("#ast-container").on("click", ".new-notification", function(e) {
var notificationId = $(this).data("id");
// var redirectUrl = $(this).data("url");
var query = deviceMgtAPIBaseURI + "/notifications" + "/" + notificationId + "/mark-checked";

@ -28,6 +28,16 @@ function inputIsValid(regExp, inputString) {
return regExp.test(inputString);
}
/*
* Fix for the modal popup overlay disappear bug
*/
$('.modal').on('hidden.bs.modal', function () {
if ($('.modal-backdrop').length == 2) {
$('.modal-backdrop')[0].remove()
}
});
$(document).ready(function () {
var modalPopup = ".modal";
// var modalPopupContainer = modalPopup + " .modal-content";
@ -82,7 +92,8 @@ $(document).ready(function () {
$(errorMsg).text("Your current password does not match with the provided value.");
$(errorMsgWrapper).removeClass("hidden");
} else {
$(errorMsg).text("An unexpected error occurred. Please try again later.");
var response = JSON.parse(jqXHR.responseText).message;
$(errorMsg).text(response);
$(errorMsgWrapper).removeClass("hidden");
}
}

@ -31,12 +31,8 @@
{{/if}}
</span>
</a>
<ul class="dropdown-menu dropdown-menu-right float-remove-xs position-static-xs text-center-xs remove-margin-xs slideInDown"
<ul class="dropdown-menu dropdown-menu-right slideInDown"
role="menu">
<li class="dropdown-header visible-xs">
{{@user.username}}<span class="caret"></span>
</li>
<li class="divider visible-xs"></li>
<li>
<a href="javascript:void(0)" id="change-password">Change password</a>
</li>

@ -5180,18 +5180,17 @@ a:hover.multi-view.remove.enabled {
}
a.grid-input-add {
padding-top: 10px;
padding-bottom: 8px;
color: #9F9F9F;
text-decoration: none;
float: left;
font-size: 15px;
margin-top:10px;
margin-bottom:10px;
font-size: 14px;
border:1px solid #526A84;
}
a:hover.grid-input-add {
color: #A7E43A;
a.grid-input-add:hover, a.grid-input-add:active,a.grid-input-add:focus {
color:#333;
border:1px solid #fff;
}
a.grid-input-remove {
padding-top: 4px;
padding-right: 10px;

@ -30,13 +30,11 @@
</button>
{{defineZone "navbarHeader"}}
</div>
<div class="navbar-collapse collapse" aria-expanded="false">
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false">
<ul class="nav navbar-nav">
{{defineZone "navbarCollapsableLeftItems"}}
</ul>
<ul class="nav navbar-nav navbar-right">
{{defineZone "navbarCollapsableRightItems"}}
</ul>
{{defineZone "navbarCollapsableRightItems"}}
</div>
</div>
{{defineZone "navbarBelow"}}

@ -3054,7 +3054,7 @@ tbody.collapse.in {
right: auto;
}
}
@media (max-width : 480px) {
@media (max-width : 768px) {
.navbar-right .dropdown-menu-right {
left: auto;
right: 0;
@ -3901,6 +3901,33 @@ tbody.collapse.in {
margin-right: 0;
}
}
@media (max-width: 768px) {
.navbar-right {
margin-right: -15px;
}
.navbar-default .navbar-toggle{
}
.navbar-default .navbar-toggle .icon-bar{
background-color:#fff!important;
}
.navbar-default .navbar-toggle:hover, .navbar-default .navbar-toggle:focus{
background-color:#526a84!important;
}
.navbar-default .navbar-toggle:hover .icon-bar, .navbar-default .navbar-toggle:focus .icon-bar{
background-color:#798EA5!important;
}
.navbar-toggle {
margin-right: 10px;
padding: 13px;
margin-top: 0px;
margin-bottom: 0px;
}
#navbar .navbar-nav{
margin:0px;
border-bottom:1px solid #798EA5;
}
}
.navbar-default {
background-color: #f8f8f8;
border-color: #e7e7e7;

@ -109,7 +109,7 @@ public class EmailSenderServiceImpl implements EmailSenderService {
Options options = new Options();
options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
options.setProperty("FORCE_CONTENT_TYPE_BASED_FORMATTER", "true");
options.setProperty(Constants.Configuration.MESSAGE_TYPE, "text/html");
options.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml");
options.setProperty(Constants.Configuration.CONTENT_TYPE, "text/html");
options.setTo(new EndpointReference(EMAIL_URI_SCHEME + to));

@ -0,0 +1,32 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.oauth.extensions.handlers.grant;
import org.wso2.carbon.device.mgt.oauth.extensions.OAuthExtUtils;
import org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext;
@SuppressWarnings("unused")
public class ExtendedPasswordGrantHandler extends org.wso2.carbon.apimgt.keymgt.handlers.ExtendedPasswordGrantHandler {
@Override
public boolean validateScope(OAuthTokenReqMessageContext tokReqMsgCtx) {
return OAuthExtUtils.setScopes(tokReqMsgCtx);
}
}

@ -129,10 +129,13 @@ public class JWTClient {
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
accessTokenInfo.setAccessToken((String) jsonObject.get(JWTConstants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME));
accessTokenInfo.setRefreshToken((String) jsonObject.get(JWTConstants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME));
accessTokenInfo.setExpiresIn((Long) jsonObject.get(JWTConstants.OAUTH_EXPIRES_IN));
accessTokenInfo.setTokenType((String) jsonObject.get(JWTConstants.OAUTH_TOKEN_TYPE));
String accessToken = (String) jsonObject.get(JWTConstants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME);
if (accessToken != null && !accessToken.isEmpty()) {
accessTokenInfo.setAccessToken(accessToken);
accessTokenInfo.setRefreshToken((String) jsonObject.get(JWTConstants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME));
accessTokenInfo.setExpiresIn((Long) jsonObject.get(JWTConstants.OAUTH_EXPIRES_IN));
accessTokenInfo.setTokenType((String) jsonObject.get(JWTConstants.OAUTH_TOKEN_TYPE));
}
return accessTokenInfo;
} catch (MalformedURLException e) {
throw new JWTClientException("Invalid URL for token endpoint " + jwtConfig.getTokenEndpoint(), e);

@ -147,7 +147,7 @@ public class PolicyManagerImpl implements PolicyManager {
List<ProfileFeature> existingFeaturesList = new ArrayList<>();
List<ProfileFeature> newFeaturesList = new ArrayList<>();
List<ProfileFeature> feturesToDelete = new ArrayList<>();
List<ProfileFeature> featuresToDelete = new ArrayList<>();
List<String> temp = new ArrayList<>();
List<String> updateDFes = new ArrayList<>();
@ -169,7 +169,7 @@ public class PolicyManagerImpl implements PolicyManager {
// Check for the features to delete
for (ProfileFeature feature : existingProfileFeaturesList) {
if (!updateDFes.contains(feature.getFeatureCode())) {
feturesToDelete.add(feature);
featuresToDelete.add(feature);
}
}
@ -194,8 +194,8 @@ public class PolicyManagerImpl implements PolicyManager {
featureDAO.addProfileFeatures(newFeaturesList, profileId);
}
if (!feturesToDelete.isEmpty()) {
for (ProfileFeature pf : feturesToDelete)
if (!featuresToDelete.isEmpty()) {
for (ProfileFeature pf : featuresToDelete)
featureDAO.deleteProfileFeatures(pf.getId());
}
@ -892,9 +892,9 @@ public class PolicyManagerImpl implements PolicyManager {
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
if (policySaved != null && policySaved.getId() != 0) {
if (policy.getId() != policySaved.getId()) {
// if (policy.getId() != policySaved.getId()) {
policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
}
// }
} else {
policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
}

@ -28,6 +28,10 @@
<!-- If it is true, the APIs of this instance will be published to the defined host -->
<PublishAPI>true</PublishAPI>
<!-- If it is true, the APIs of this instance will be updated when the webapps are redeployed -->
<EnabledUpdateApi>true</EnabledUpdateApi>
<!--Webapp will be published only when running below profiles-->
<Profiles>
<Profile>default</Profile>

@ -51,14 +51,26 @@
<Operation>
<Name>DEVICE_INFO</Name>
<RecurrentTimes>1</RecurrentTimes>
<Platforms>
<platform>android</platform>
<platform>ios</platform>
</Platforms>
</Operation>
<Operation>
<Name>APPLICATION_LIST</Name>
<RecurrentTimes>5</RecurrentTimes>
<Platforms>
<platform>android</platform>
<platform>ios</platform>
</Platforms>
</Operation>
<Operation>
<Name>DEVICE_LOCATION</Name>
<RecurrentTimes>1</RecurrentTimes>
<Platforms>
<platform>android</platform>
<platform>ios</platform>
</Platforms>
</Operation>
</Operations>
</TaskConfiguration>

@ -102,8 +102,8 @@ CREATE TABLE DM_ENROLMENT_OP_MAPPING (
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL,
CREATED_TIMESTAMP INTEGER NOT NULL,
UPDATED_TIMESTAMP INTEGER NOT NULL,
CREATED_TIMESTAMP BIGINT NOT NULL,
UPDATED_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_OPERATION_MAPPING_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
@ -436,7 +436,7 @@ CREATE TABLE DM_DEVICE_LOCATION (
ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP INTEGER NOT NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
@ -465,7 +465,7 @@ CREATE TABLE DM_DEVICE_DETAIL (
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INTEGER NULL,
UPDATE_TIMESTAMP INTEGER NOT NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

@ -1791,8 +1791,8 @@
<carbon.deployment.version>4.7.0</carbon.deployment.version>
<!-- Carbon Identity -->
<carbon.identity.framework.version>5.2.0</carbon.identity.framework.version>
<identity.inbound.auth.oauth.version>5.1.2</identity.inbound.auth.oauth.version>
<carbon.identity.framework.version>5.2.1</carbon.identity.framework.version>
<identity.inbound.auth.oauth.version>5.1.3</identity.inbound.auth.oauth.version>
<identity.inbound.auth.saml.version>5.1.1</identity.inbound.auth.saml.version>
<!-- Carbon Multi-tenancy -->

Loading…
Cancel
Save