Coorecting version import ranges

revert-70aa11f8
Ace 8 years ago
commit 674048ab27

@ -0,0 +1,50 @@
/*
* 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.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@ApiModel(value = "EnrollmentInvitation", description = "Holds data to send enrollment invitation to list of recipients.")
public class EnrollmentInvitation {
@ApiModelProperty(name = "deviceType", value = "Device type name.", required = true)
private String deviceType;
@ApiModelProperty(name = "recipients", value = "List of recipients.", required = true)
private List<String> recipients;
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public List<String> getRecipients() {
return recipients;
}
public void setRecipients(List<String> recipients) {
this.recipients = recipients;
}
}

@ -18,22 +18,39 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Extension;
import io.swagger.annotations.Tag;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.AuthorizationScope;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader; import io.swagger.annotations.ResponseHeader;
import org.wso2.carbon.device.mgt.jaxrs.beans.*; import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoList;
import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentInvitation;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo;
import javax.ws.rs.*; import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@ -65,7 +82,7 @@ public interface UserManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Adding a User", value = "Adding a User",
notes = "WSO2 EMM supports user management. Add a new user to the WSO2 EMM user management system via this REST API", notes = "WSO2 IoTS supports user management. Add a new user to the WSO2 IoTS user management system via this REST API",
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@Authorization( @Authorization(
@ -126,7 +143,7 @@ public interface UserManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of a User", value = "Getting Details of a User",
notes = "Get the details of a user registered with WSO2 EMM using the REST API.", notes = "Get the details of a user registered with WSO2 IoTS using the REST API.",
response = BasicUserInfo.class, response = BasicUserInfo.class,
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@ -267,7 +284,7 @@ public interface UserManagementService {
@ApiOperation( @ApiOperation(
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Deleting a User", value = "Deleting a User",
notes = "When an employee leaves the organization, you can remove the user details from WSO2 EMM using this REST API.", notes = "When an employee leaves the organization, you can remove the user details from WSO2 IoTS using this REST API.",
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@Authorization( @Authorization(
@ -280,7 +297,7 @@ public interface UserManagementService {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully removed the user from WSO2 EMM."), message = "OK. \n Successfully removed the user from WSO2 IoTS."),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "Not Found. \n The specified resource does not exist.", message = "Not Found. \n The specified resource does not exist.",
@ -312,7 +329,7 @@ public interface UserManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the Role Details of a User", value = "Getting the Role Details of a User",
notes = "A user can be assigned to one or more role in EMM. Using this REST API you can get the role/roles a user is assigned to.", notes = "A user can be assigned to one or more role in IoTS. Using this REST API you can get the role/roles a user is assigned to.",
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@Authorization( @Authorization(
@ -375,7 +392,7 @@ public interface UserManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of Users", value = "Getting Details of Users",
notes = "You are able to manage users in WSO2 EMM by adding, updating and removing users. If you wish to get the list of users registered with WSO2 EMM, you can do so " notes = "You are able to manage users in WSO2 IoTS by adding, updating and removing users. If you wish to get the list of users registered with WSO2 IoTS, you can do so "
+ "using this REST API", + "using this REST API",
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@ -389,7 +406,7 @@ public interface UserManagementService {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully fetched the list of users registered with WSO2 EMM.", message = "OK. \n Successfully fetched the list of users registered with WSO2 IoTS.",
response = BasicUserInfoList.class, response = BasicUserInfoList.class,
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
@ -414,7 +431,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the list of WSO2 EMM users.", message = "Internal Server Error. \n Server error occurred while fetching the list of WSO2 IoTS users.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getUsers( Response getUsers(
@ -449,7 +466,7 @@ public interface UserManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the User Count", value = "Getting the User Count",
notes = "Get the number of users in WSO2 EMM via this REST API.", notes = "Get the number of users in WSO2 IoTS via this REST API.",
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@Authorization( @Authorization(
@ -474,7 +491,7 @@ public interface UserManagementService {
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the total number of users in WSO2 EMM.", message = "Internal Server Error. \n Server error occurred while fetching the total number of users in WSO2 IoTS.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getUserCount(); Response getUserCount();
@ -608,7 +625,7 @@ public interface UserManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Changing the User Password", value = "Changing the User Password",
notes = "A user is able to change the password to secure their WSO2 EMM profile via this REST API.", notes = "A user is able to change the password to secure their WSO2 IoTS profile via this REST API.",
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@Authorization( @Authorization(
@ -653,8 +670,8 @@ public interface UserManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Sending Enrollment Invitations to Users", value = "Sending Enrollment Invitations to Users",
notes = "Send the users a mail inviting them to download the EMM mobile application on their devices using the REST API given below.\n" + notes = "Send the users a mail inviting them to enroll their devices using the REST API given below.\n" +
"Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 EMM as explained in step 4, under the WSO2 EMM general server configurations documentation.", "Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 IoTS as explained in step 4, under the WSO2 IoTS general server configurations documentation.",
tags = "User Management", tags = "User Management",
authorizations = { authorizations = {
@Authorization( @Authorization(
@ -691,4 +708,47 @@ public interface UserManagementService {
value = "List of users", value = "List of users",
required = true) List<String> usernames); required = true) List<String> usernames);
@POST
@Path("/enrollment-invite")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Sending Enrollment Invitations to email address",
notes = "Send the a mail inviting recipients to enroll devices.",
tags = "User Management",
authorizations = {
@Authorization(
value = "permission",
scopes = {@AuthorizationScope(scope = "/device-mgt/users/invite", description = "Invite Users")}
)
}
)
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully sent the invitation mail."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n The specified resource does not exist.\n",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The format of the requested entity was not supported.\n",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while updating the user credentials.",
response = ErrorResponse.class)
})
Response inviteToEnrollDevice(
@ApiParam(
name = "enrollmentInvitation",
value = "List of email address of recipients",
required = true)
@Valid EnrollmentInvitation enrollmentInvitation);
} }

@ -23,9 +23,16 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder; import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.*; import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoList;
import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentInvitation;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
@ -33,15 +40,33 @@ import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.utils.CarbonUtils;
import javax.ws.rs.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@Path("/users") @Path("/users")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -446,7 +471,7 @@ public class UserManagementServiceImpl implements UserManagementService {
* @param usernames Username list of the users to be invited * @param usernames Username list of the users to be invited
*/ */
@POST @POST
@Path("send-invitation") @Path("/send-invitation")
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public Response inviteExistingUsersToEnrollDevice(List<String> usernames) { public Response inviteExistingUsersToEnrollDevice(List<String> usernames) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -462,7 +487,8 @@ public class UserManagementServiceImpl implements UserManagementService {
props.setProperty("username", username); props.setProperty("username", username);
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props); EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
dms.sendEnrolmentInvitation(metaInfo); dms.sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE,
metaInfo);
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while inviting user to enrol their device"; String msg = "Error occurred while inviting user to enrol their device";
@ -476,6 +502,40 @@ public class UserManagementServiceImpl implements UserManagementService {
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
} }
@POST
@Path("/enrollment-invite")
@Override
public Response inviteToEnrollDevice(EnrollmentInvitation enrollmentInvitation) {
if (log.isDebugEnabled()) {
log.debug("Sending enrollment invitation mail to existing user.");
}
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
try {
Set<String> recipients = new HashSet<>();
for (String recipient : enrollmentInvitation.getRecipients()) {
recipients.add(recipient);
}
Properties props = new Properties();
String username = DeviceMgtAPIUtils.getAuthenticatedUser();
String firstName = getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME);
if (firstName == null) {
firstName = username;
}
props.setProperty("first-name", firstName);
props.setProperty("device-type", enrollmentInvitation.getDeviceType());
EmailMetaInfo metaInfo = new EmailMetaInfo(recipients, props);
dms.sendEnrolmentInvitation(getEnrollmentTemplateName(enrollmentInvitation.getDeviceType()), metaInfo);
} catch (DeviceManagementException e) {
String msg = "Error occurred while inviting user to enrol their device";
log.error(msg, e);
} catch (UserStoreException e) {
String msg = "Error occurred while getting claim values to invite user";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
}
private Map<String, String> buildDefaultUserClaims(String firstName, String lastName, String emailAddress) { private Map<String, String> buildDefaultUserClaims(String firstName, String lastName, String emailAddress) {
Map<String, String> defaultUserClaims = new HashMap<>(); Map<String, String> defaultUserClaims = new HashMap<>();
@ -522,4 +582,19 @@ public class UserManagementServiceImpl implements UserManagementService {
return userStoreManager.getUserClaimValue(username, claimUri, null); return userStoreManager.getUserClaimValue(username, claimUri, null);
} }
private String getEnrollmentTemplateName(String deviceType) {
String templateName = deviceType + "-enrollment-invitation";
File template = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator
+ "resources" + File.separator + "email-templates" + File.separator + templateName
+ ".vm");
if (template.exists()) {
return templateName;
} else {
if (log.isDebugEnabled()) {
log.debug("The template that is expected to use is not available. Therefore, using default template.");
}
}
return DeviceManagementConstants.EmailAttributes.DEFAULT_ENROLLMENT_TEMPLATE;
}
} }

@ -286,4 +286,14 @@ public class DeviceMgtAPIUtils {
} }
} }
public static String getAuthenticatedUser() {
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String username = threadLocalCarbonContext.getUsername();
String tenantDomain = threadLocalCarbonContext.getTenantDomain();
if (username != null && username.endsWith(tenantDomain)) {
return username.substring(0, username.lastIndexOf("@"));
}
return username;
}
} }

@ -42,6 +42,5 @@ public class MonitoringOperation {
this.recurrentTimes = recurrentTimes; this.recurrentTimes = recurrentTimes;
} }
} }

@ -52,6 +52,6 @@ public class OperationMonitoringTaskConfig {
public void setMonitoringOperation(List<MonitoringOperation> monitoringOperation) { public void setMonitoringOperation(List<MonitoringOperation> monitoringOperation) {
this.monitoringOperation = monitoringOperation; this.monitoringOperation = monitoringOperation;
}
}
} }

@ -75,6 +75,10 @@ public final class DeviceManagementConstants {
public static final String SERVER_BASE_URL_HTTPS = "base-url-https"; public static final String SERVER_BASE_URL_HTTPS = "base-url-https";
public static final String SERVER_BASE_URL_HTTP = "base-url-http"; public static final String SERVER_BASE_URL_HTTP = "base-url-http";
public static final String DOWNLOAD_URL = "download-url"; public static final String DOWNLOAD_URL = "download-url";
public static final String USER_REGISTRATION_TEMPLATE = "user-registration";
public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment";
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
} }
public static final class OperationAttributes { public static final class OperationAttributes {

@ -195,7 +195,6 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
} else { } else {
deviceTaskManagerService.startTask(deviceManagementService.getType(), deviceTaskManagerService.startTask(deviceManagementService.getType(),
operationMonitoringTaskConfig); operationMonitoringTaskConfig);
// TODO: In here a race condition can arise. Need to handle it.
} }
} }
} catch (DeviceMgtTaskException e) { } catch (DeviceMgtTaskException e) {

@ -58,11 +58,11 @@ public class DeviceTaskManagerServiceComponent {
log.debug("Initializing device details retrieving task manager bundle."); log.debug("Initializing device details retrieving task manager bundle.");
} }
// This will start the device details retrieving task. // This will start the device details retrieving task.
// DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl(); // DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
// DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService( // DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(
// deviceTaskManagerService); // deviceTaskManagerService);
// componentContext.getBundleContext().registerService(DeviceTaskManagerService.class, // componentContext.getBundleContext().registerService(DeviceTaskManagerService.class,
// deviceTaskManagerService, null); // deviceTaskManagerService, null);
getDeviceOperationMonitoringConfig(componentContext); getDeviceOperationMonitoringConfig(componentContext);
@ -76,12 +76,12 @@ public class DeviceTaskManagerServiceComponent {
} }
} }
private void getDeviceOperationMonitoringConfig(ComponentContext componentContext) throws DeviceMgtTaskException { private void getDeviceOperationMonitoringConfig(ComponentContext componentContext)
throws DeviceMgtTaskException {
DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl(); DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService( DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(deviceTaskManagerService);
deviceTaskManagerService);
componentContext.getBundleContext().registerService(DeviceTaskManagerService.class, componentContext.getBundleContext().registerService(DeviceTaskManagerService.class,
deviceTaskManagerService, null); deviceTaskManagerService, null);
@ -89,11 +89,10 @@ public class DeviceTaskManagerServiceComponent {
Map<String, OperationMonitoringTaskConfig> deviceConfigMap = DeviceMonitoringOperationDataHolder Map<String, OperationMonitoringTaskConfig> deviceConfigMap = DeviceMonitoringOperationDataHolder
.getInstance().getOperationMonitoringConfigFromMap(); .getInstance().getOperationMonitoringConfigFromMap();
for (String platformType : new ArrayList<String>(deviceConfigMap.keySet())) { for (String platformType : new ArrayList<>(deviceConfigMap.keySet())) {
deviceTaskManagerService.startTask(platformType, deviceConfigMap.get(platformType)); deviceTaskManagerService.startTask(platformType, deviceConfigMap.get(platformType));
deviceConfigMap.remove(platformType); deviceConfigMap.remove(platformType);
} }
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")

@ -81,7 +81,7 @@ public interface DeviceManagementProviderService {
*/ */
PaginationResult getAllDevices(PaginationRequest request) throws DeviceManagementException; PaginationResult getAllDevices(PaginationRequest request) throws DeviceManagementException;
void sendEnrolmentInvitation(EmailMetaInfo metaInfo) throws DeviceManagementException; void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException;
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException; void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException;

@ -50,6 +50,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; 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.DeviceManagementPluginRepository;
import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
@ -73,10 +74,12 @@ import org.wso2.carbon.user.api.UserStoreException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
@ -752,21 +755,25 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public void sendEnrolmentInvitation(EmailMetaInfo metaInfo) throws DeviceManagementException { public void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException {
Map<String, TypedValue<Class<?>, Object>> params = new HashMap<>(); Map<String, TypedValue<Class<?>, Object>> params = new HashMap<>();
params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.FIRST_NAME, Properties props = metaInfo.getProperties();
new TypedValue<Class<?>, Object>(String.class, metaInfo.getProperty("first-name"))); Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
params.put(key, new TypedValue<Class<?>, Object>(String.class, props.getProperty(key)));
}
params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTPS, params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTPS,
new TypedValue<Class<?>, Object>(String.class, DeviceManagerUtil.getServerBaseHttpsUrl())); new TypedValue<Class<?>, Object>(String.class, DeviceManagerUtil.getServerBaseHttpsUrl()));
params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTP, params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTP,
new TypedValue<Class<?>, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl())); new TypedValue<Class<?>, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl()));
try { try {
EmailContext ctx = EmailContext ctx =
new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-enrollment", params), new EmailContext.EmailContextBuilder(new ContentProviderInfo(templateName, params),
metaInfo.getRecipients()).build(); metaInfo.getRecipients()).build();
DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx);
} catch (EmailSendingFailedException e) { } catch (EmailSendingFailedException ex) {
throw new DeviceManagementException("Error occurred while sending enrollment invitation", e); throw new DeviceManagementException("Error occurred while sending enrollment invitation", ex);
} }
} }
@ -787,7 +794,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
new TypedValue<Class<?>, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl())); new TypedValue<Class<?>, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl()));
try { try {
EmailContext ctx = EmailContext ctx =
new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-registration", params), new EmailContext.EmailContextBuilder(
new ContentProviderInfo(
DeviceManagementConstants.EmailAttributes.USER_REGISTRATION_TEMPLATE,
params),
metaInfo.getRecipients()).build(); metaInfo.getRecipients()).build();
DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx);
} catch (EmailSendingFailedException e) { } catch (EmailSendingFailedException e) {
@ -1222,17 +1232,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public List<MonitoringOperation> getMonitoringOperationList(String deviceType) { public List<MonitoringOperation> getMonitoringOperationList(String deviceType) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
// Map<DeviceTypeIdentifier, DeviceManagementService> deviceManagementServiceMap =
// pluginRepository.getAllDeviceManagementServices(tenantId);
DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceType, tenantId); DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceType, tenantId);
// ;
// OperationMonitoringTaskConfig operationMonitoringTaskConfig;
//Map<String, List<MonitoringOperation>> deviceTypeSpecificMonitoringOperations = new HashMap<>();
// for(DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()){
// dms = deviceManagementServiceMap.get(dti);
//
// }
OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getOperationMonitoringConfig(); OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getOperationMonitoringConfig();
return operationMonitoringTaskConfig.getMonitoringOperation(); return operationMonitoringTaskConfig.getMonitoringOperation();
} }

@ -19,8 +19,10 @@
package org.wso2.carbon.device.mgt.core.task.impl; package org.wso2.carbon.device.mgt.core.task.impl;
import com.google.gson.Gson;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.ntask.core.Task;
@ -32,10 +34,18 @@ public class DeviceDetailsRetrieverTask implements Task {
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class); private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(); // private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl();
private String deviceType; private String deviceType;
private String oppConfig;
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
@Override @Override
public void setProperties(Map<String, String> map) { public void setProperties(Map<String, String> map) {
deviceType = map.get("DEVICE_TYPE"); deviceType = map.get("DEVICE_TYPE");
oppConfig = map.get("OPPCONFIG");
Gson gson = new Gson();
operationMonitoringTaskConfig = gson.fromJson(oppConfig,
OperationMonitoringTaskConfig.class);
} }
@Override @Override
@ -49,14 +59,18 @@ public class DeviceDetailsRetrieverTask implements Task {
log.debug("Device details retrieving task started to run."); log.debug("Device details retrieving task started to run.");
} }
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType); DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
operationMonitoringTaskConfig);
//pass the configurations also from here, monitoring tasks
try { try {
deviceTaskManager.addOperations(); deviceTaskManager.addOperations();
} catch (DeviceMgtTaskException e) { } catch (DeviceMgtTaskException e) {
log.error("Error occurred while trying to add the operations to device to retrieve device details.", e); log.error(
"Error occurred while trying to add the operations to device to retrieve device details.",
e);
} }
} }
} }

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.MonitoringOperation;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
@ -46,30 +47,26 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class); private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
private String deviceType; private String deviceType;
private static Map<Integer, Map<String, Long>> map = new HashMap<>(); private static Map<Integer, Map<String, Long>> map = new HashMap<>();
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
public DeviceTaskManagerImpl(String deviceType,
OperationMonitoringTaskConfig operationMonitoringTaskConfig) {
this.operationMonitoringTaskConfig = operationMonitoringTaskConfig;
this.deviceType = deviceType;
}
public DeviceTaskManagerImpl(String deviceType) { public DeviceTaskManagerImpl(String deviceType) {
this.deviceType = deviceType; this.deviceType = deviceType;
} }
//get device type specific operations //get device type specific operations
public List<MonitoringOperation> getOperationList() throws DeviceMgtTaskException { private List<MonitoringOperation> getOperationList() throws DeviceMgtTaskException {
return operationMonitoringTaskConfig.getMonitoringOperation();
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.getMonitoringOperationList(
deviceType);//Get task list from each device type
} }
@Override @Override
public int getTaskFrequency() throws DeviceMgtTaskException { public int getTaskFrequency() throws DeviceMgtTaskException {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder return operationMonitoringTaskConfig.getFrequency();
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.getDeviceMonitoringFrequency(deviceType);
} }
// @Override // @Override
@ -80,11 +77,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override @Override
public boolean isTaskEnabled() throws DeviceMgtTaskException { public boolean isTaskEnabled() throws DeviceMgtTaskException {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder return operationMonitoringTaskConfig.isEnabled();
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType);
} }
@ -149,13 +142,22 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
return opNames; return opNames;
} }
private List<MonitoringOperation> getOperationListforTask() throws DeviceMgtTaskException {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.getMonitoringOperationList(
deviceType);//Get task list from each device type
}
@Override @Override
public boolean isTaskOperation(String opName) { public boolean isTaskOperation(String opName) {
try { try {
List<MonitoringOperation> monitoringOperations = this.getOperationList(); List<MonitoringOperation> monitoringOperations = this.getOperationListforTask();
for (MonitoringOperation taop : monitoringOperations) { for (MonitoringOperation taop : monitoringOperations) {
if (taop.getTaskName().equalsIgnoreCase(opName)) { if (taop.getTaskName().equalsIgnoreCase(opName)) {
return true; return true;

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.core.task.impl; package org.wso2.carbon.device.mgt.core.task.impl;
import com.google.gson.Gson;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -46,9 +47,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
private static Log log = LogFactory.getLog(DeviceTaskManagerServiceImpl.class); private static Log log = LogFactory.getLog(DeviceTaskManagerServiceImpl.class);
@Override @Override
public void startTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException { public void startTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig)
throws DeviceMgtTaskException {
// String TASK_NAME = deviceType;
log.info("Task adding for " + deviceType); log.info("Task adding for " + deviceType);
@ -60,45 +60,52 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device details retrieving task is started for the tenant id " + tenantId); log.debug("Device details retrieving task is started for the tenant id " + tenantId);
// log.debug("Device details retrieving task is at frequency of : " + deviceTaskManager // log.debug("Device details retrieving task is at frequency of : " + deviceTaskManager
// .getTaskFrequency()); // .getTaskFrequency());
log.debug("Device details retrieving task is at frequency of : " + operationMonitoringTaskConfig log.debug(
.getFrequency()); "Device details retrieving task is at frequency of : " + operationMonitoringTaskConfig
.getFrequency());
} }
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE); TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo(); TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
// triggerInfo.setIntervalMillis(deviceTaskManager.getTaskFrequency()); // triggerInfo.setIntervalMillis(deviceTaskManager.getTaskFrequency());
triggerInfo.setIntervalMillis(operationMonitoringTaskConfig.getFrequency()); triggerInfo.setIntervalMillis(operationMonitoringTaskConfig.getFrequency());
triggerInfo.setRepeatCount(-1); triggerInfo.setRepeatCount(-1);
Gson gson = new Gson();
String operationConfigs = gson.toJson(operationMonitoringTaskConfig);
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
properties.put(TENANT_ID, String.valueOf(tenantId)); properties.put(TENANT_ID, String.valueOf(tenantId));
properties.put("DEVICE_TYPE", deviceType); properties.put("DEVICE_TYPE", deviceType);
properties.put("OPPCONFIG", operationConfigs);
String taskName = deviceType + String.valueOf(tenantId);
if (!taskManager.isTaskScheduled(deviceType)) { if (!taskManager.isTaskScheduled(deviceType)) {
TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, triggerInfo); TaskInfo taskInfo = new TaskInfo(taskName, TASK_CLASS, properties, triggerInfo);
taskManager.registerTask(taskInfo); taskManager.registerTask(taskInfo);
taskManager.rescheduleTask(taskInfo.getName()); taskManager.rescheduleTask(taskInfo.getName());
} else { } else {
throw new DeviceMgtTaskException("Device details retrieving task is already started for this tenant " + throw new DeviceMgtTaskException(
tenantId); "Device details retrieving task is already started for this tenant " + tenantId);
} }
} catch (TaskException e) { } catch (TaskException e) {
throw new DeviceMgtTaskException("Error occurred while creating the task for tenant " + tenantId, e); throw new DeviceMgtTaskException("Error occurred while creating the task for tenant " + tenantId,
e);
} }
} }
@Override @Override
public void stopTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException { public void stopTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig)
throws DeviceMgtTaskException {
// String TASK_NAME = deviceType;
try { try {
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService(); TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
@ -108,18 +115,18 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
} }
} catch (TaskException e) { } catch (TaskException e) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
throw new DeviceMgtTaskException("Error occurred while deleting the task for tenant " + tenantId, e); throw new DeviceMgtTaskException("Error occurred while deleting the task for tenant " + tenantId,
e);
} }
} }
@Override @Override
public void updateTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException { public void updateTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig)
throws DeviceMgtTaskException {
// String TASK_NAME = deviceType;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
// deviceTaskManager = new DeviceTaskManagerImpl(); // deviceTaskManager = new DeviceTaskManagerImpl();
try { try {
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService(); TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE); TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
@ -134,21 +141,20 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
properties.put(TENANT_ID, String.valueOf(tenantId)); properties.put(TENANT_ID, String.valueOf(tenantId));
TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, triggerInfo);
triggerInfo);
taskManager.registerTask(taskInfo); taskManager.registerTask(taskInfo);
taskManager.rescheduleTask(taskInfo.getName()); taskManager.rescheduleTask(taskInfo.getName());
} else { } else {
throw new DeviceMgtTaskException("Device details retrieving task has not been started for this tenant " + throw new DeviceMgtTaskException(
tenantId + ". Please start the task first."); "Device details retrieving task has not been started for this tenant " +
tenantId + ". Please start the task first.");
} }
} catch (TaskException e) { } catch (TaskException e) {
throw new DeviceMgtTaskException("Error occurred while updating the task for tenant " + tenantId, e); throw new DeviceMgtTaskException("Error occurred while updating the task for tenant " + tenantId,
e);
} }
} }
} }

@ -258,8 +258,10 @@ function loadDevices(searchType, searchParam) {
data: 'name', data: 'name',
class: 'remove-padding icon-only content-fill', class: 'remove-padding icon-only content-fill',
render: function (data, type, row, meta) { render: function (data, type, row, meta) {
return '<div class="thumbnail icon"><img class="square-element text fw " src="' + getDeviceTypeThumb( return '<a href="' + context + '/device/' + row.deviceType + '?id=' + row.deviceIdentifier
row.deviceType) + '"/></div>'; + '"><div class="thumbnail icon"><img class="square-element text fw " src="'
+ getDeviceTypeThumb(
row.deviceType) + '"/></div></a>';
} }
}, },
{ {
@ -333,22 +335,14 @@ function loadDevices(searchType, searchParam) {
var deviceIdentifier = row.deviceIdentifier; var deviceIdentifier = row.deviceIdentifier;
var html = '<span></span>'; var html = '<span></span>';
if (status != 'REMOVED') { if (status != 'REMOVED') {
html = html = '';
'<a href="device/' + deviceType + '?id=' + deviceIdentifier + '" data-click-event="remove-form"'
+
' class="btn padding-reduce-on-grid-view"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>'
+
'<i class="fw fw-view fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">View</span></a>';
if (analyticsEnabled(row.deviceType)) { if (analyticsEnabled(row.deviceType)) {
html += html += '<a href="' + context + '/device/' + deviceType + '/analytics?deviceId=' +
'<a href="device/' + deviceType + '/analytics?deviceId=' + deviceIdentifier + '&deviceName=' deviceIdentifier + '&deviceName=' + row.name + '" ' + 'data-click-event="remove-form"' +
+ row.name + '" ' + ' class="btn padding-reduce-on-grid-view"><span class="fw-stack">' +
'data-click-event="remove-form" class="btn padding-reduce-on-grid-view"><span class="fw-stack">' '<i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' +
+ '<span class="hidden-xs hidden-on-grid-view">Analytics</span>';
'<i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>'
+
'<span class="hidden-xs hidden-on-grid-view">Analytics</span>';
} }
if ((!groupName || !groupId) && groupingEnabled(row.deviceType)) { if ((!groupName || !groupId) && groupingEnabled(row.deviceType)) {

@ -120,14 +120,14 @@
<h4> <h4>
Select user roles to manage group sharing Select user roles to manage group sharing
<br><br> <br><br>
<div style="max-height: 200px; overflow: scroll" id="rolesListing"> <div style="max-height: 200px; overflow: auto" id="rolesListing">
</div> </div>
</h4> </h4>
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<div class="buttons"> <div class="buttons">
{{#if permissions.CREATE_GROUP_ROLES}} {{#if permissions.ADD_ROLE}}
<a href="{{@app.context}}/role/add" class="btn-operations"> <a href="{{@app.context}}/role/add" class="btn-operations">
New Role New Role
</a> </a>
@ -186,9 +186,9 @@
<div class="content"> <div class="content">
<div class="row"> <div class="row">
<div class="col-lg-5 col-md-6 col-centered"> <div class="col-lg-5 col-md-6 col-centered">
<h3>Group was successfully updated.</h3> <h3>Group successfully updated.</h3>
<br /> <br />
Do you need to Add / Remove users to the chosen roles? Do you want to manage users?
<div class="buttons"> <div class="buttons">
<a href="{{@app.context}}/users" id="share-group-add-users-yes-link" <a href="{{@app.context}}/users" id="share-group-add-users-yes-link"
class="btn-operations"> class="btn-operations">
@ -211,7 +211,7 @@
<div class="col-lg-5 col-md-6 col-centered"> <div class="col-lg-5 col-md-6 col-centered">
<h3>New Role was successfully created.</h3> <h3>New Role was successfully created.</h3>
<br /> <br />
Do you need to Add / Remove users to the chosen roles? Do you need to Add / Remove users from the chosen roles?
<div class="buttons"> <div class="buttons">
<a href="{{@app.context}}/users" id="share-group-add-users-yes-link" <a href="{{@app.context}}/users" id="share-group-add-users-yes-link"
class="btn-operations"> class="btn-operations">

@ -20,13 +20,11 @@ function onRequest(context) {
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var groupPermissions = require("/app/pages/cdmf.page.groups/public/group-permissions.json");
var currentUser = session.get(constants.USER_SESSION_KEY); var currentUser = session.get(constants.USER_SESSION_KEY);
var page = {}; var page = {};
if (currentUser) { if (currentUser) {
page.permissions = userModule.getUIPermissions(); page.permissions = userModule.getUIPermissions();
page.permissions.list = stringify(page.permissions); page.permissions.list = stringify(page.permissions);
page.groupPermissions = groupPermissions.permissionList;
page.currentUser = currentUser; page.currentUser = currentUser;
var groupCount = groupModule.getGroupCount(); var groupCount = groupModule.getGroupCount();
if (groupCount > 0) { if (groupCount > 0) {

@ -1,15 +0,0 @@
{
"permissionList":["device-mgt/admin/groups/view",
"device-mgt/groups/add",
"device-mgt/groups/devices/add",
"device-mgt/groups/devices/remove",
"device-mgt/groups/devices/view",
"device-mgt/groups/remove",
"device-mgt/groups/roles/create",
"device-mgt/groups/roles/view",
"device-mgt/groups/share",
"device-mgt/groups/update",
"device-mgt/groups/users/view",
"device-mgt/groups/view"
]
}

@ -96,7 +96,7 @@ function loadGroups() {
serviceURL = "/api/device-mgt/v1.0/admin/groups"; serviceURL = "/api/device-mgt/v1.0/admin/groups";
} else if ($.hasPermission("LIST_GROUPS")) { } else if ($.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups //Get authenticated users groups
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser; serviceURL = "/api/device-mgt/v1.0/groups";
} else { } else {
$("#loading-content").remove(); $("#loading-content").remove();
$('#device-table').addClass('hidden'); $('#device-table').addClass('hidden');

@ -15,54 +15,27 @@
specific language governing permissions and limitations specific language governing permissions and limitations
under the License. under the License.
}} }}
{{unit "cdmf.unit.ui.modal"}}
{{#zone "content"}} {{#zone "content"}}
<div id="invite-by-email-modal" class="hidden"> <div id="invite-by-email-modal" class="hidden">
<div class="modal-header"> <div id="invite-by-email-body" class="panel panel-default">
<h4 class="pull-left modal-title"> <div class="panel-body">
<span class="fw-stack add-margin-right-1x"> <div id="user-create-form" class="col-centered col-lg-8 wr-content">
<i class="fw fw-user fw-stack-2x"></i> <div class="text-left">
<span class="fw-stack fw-move-right fw-move-bottom"> <div class="wr-input-control">
<i class="fw fw-ring fw-stack-2x"></i> <select multiple="true" name="choose_usr_email[]" id="choose_usr_email"
<i class="fw fw-circle fw-stack-2x fw-stroke text-info"></i> class="form-control">
<i class="fw fw-add fw-stack-1x fw-inverse"></i> </select>
</span>
</span>
Send Invites
</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
</div>
<hr>
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
<div class="panel-body col-centered text-center">
<h5>
</h5>
<br>
<div class="panel panel-default">
<div class="panel-body">
<div id="user-create-form" class="col-centered col-lg-8 wr-content">
<div class="text-left">
<div class="wr-input-control">
<select multiple="true" name="choose_usr_email[]" id="choose_usr_email" class="form-control">
</select>
</div>
</div> </div>
</div> </div>
<p>Please add one or more email addresses seperated by a <b>comma ( , )</b> to send an email invitation which includes</br>
instructions on how to download the respective device agent.</p>
</div> </div>
<p>Please add one or more email addresses separated by a <b>comma ( , )</b> to send an email invitation
which includes</br>
instructions on how to download the respective device agent.</p>
</div> </div>
</br>
</br>
</div>
</div>
<div class="modal-footer">
<div class="buttons">
<a href="javascript:sendInvites()" class="btn-operations btn-default">Send Invite(s)</a>
</div> </div>
</div> </div>
</div>
{{/zone}} {{/zone}}
{{#zone "topCss"}} {{#zone "topCss"}}

@ -6,7 +6,17 @@
* Opens a modal popup with input to enter multiple email addresses to send invites * Opens a modal popup with input to enter multiple email addresses to send invites
*/ */
function toggleEmailInvite(){ function toggleEmailInvite(){
$(".modal-content").html($("#invite-by-email-modal").html()); modalDialog.header('<h4 class="pull-left modal-title"><span class="fw-stack add-margin-right-1x">' +
'<i class="fw fw-user fw-stack-2x"></i>' +
'<span class="fw-stack fw-move-right fw-move-bottom">' +
'<i class="fw fw-ring fw-stack-2x"></i>' +
'<i class="fw fw-circle fw-stack-2x fw-stroke text-info"></i>' +
'<i class="fw fw-add fw-stack-1x fw-inverse"></i></span></span>Send Invites</h4>');
modalDialog.content($("#invite-by-email-body").html());
modalDialog.footer('<div class="buttons">' +
'<a href="javascript:sendInvites()" class="btn-operations btn-default">Send Invite(s)</a>' +
'</div>');
modalDialog.show();
//$('.modal-content .select2-container').remove(); //$('.modal-content .select2-container').remove();
$('.modal-content #choose_usr_email').select2({ $('.modal-content #choose_usr_email').select2({
tags: true, tags: true,
@ -22,7 +32,6 @@ function toggleEmailInvite(){
return null; return null;
} }
}); });
showPopup();
} }
function validateEmail(email) { function validateEmail(email) {
@ -36,10 +45,7 @@ function validateEmail(email) {
*/ */
function sendInvites(){ function sendInvites(){
var emailObj = $('.modal-content #choose_usr_email').select2('data'), var emailObj = $('.modal-content #choose_usr_email').select2('data'),
emailArr = [], emailArr = [];
deviceEmailObj = {};
console.log(deviceTypeView);
if(emailObj.length <= 0){ if(emailObj.length <= 0){
console.log('no values to print'); console.log('no values to print');
@ -48,14 +54,33 @@ function sendInvites(){
emailObj.forEach(function(el){ emailObj.forEach(function(el){
emailArr.push(el.text); emailArr.push(el.text);
}) });
deviceEmailObj = { var deviceEmailObj = {
"deviceType" : deviceTypeView, "deviceType" : deviceTypeView,
"emailList" : emailArr "recipients": emailArr
} };
invokerUtil.post(
"/api/device-mgt/v1.0/users/enrollment-invite",
hidePopup(); deviceEmailObj,
console.log(deviceEmailObj); function () {
modalDialog.header("Invitations sent");
modalDialog.content("<h4>Invitation email for enrollment was successfully sent.</h4>");
modalDialog.footer('<div class="buttons"> <a href="#" id="invite-user-success-link" ' +
'class="btn-operations">Ok </a> </div>');
$("a#invite-user-success-link").click(function () {
modalDialog.hide();
});
},
function () {
modalDialog.header('<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i> <i class="fw ' +
'fw-error fw-stack-1x"></i> </span> Unexpected Error !');
modalDialog.content('An unexpected error occurred. Try again later.');
modalDialog.footer('<div class="buttons"> <a href="#" id="invite-user-error-link" ' +
'class="btn-operations">Ok </a> </div>');
$("a#invite-user-error-link").click(function () {
modalDialog.hide();
});
}
);
} }

@ -35,7 +35,7 @@
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i></button>
</div> </div>
<div class="modal-body add-margin-top-2x add-margin-bottom-2x"> <div class="modal-body add-margin-top-2x add-margin-bottom-2x">
<h4 id="modal-content-text"></h4> <div id="modal-content-text"></div>
</div> </div>
<div class="modal-footer" id="modal-footer-content"></div> <div class="modal-footer" id="modal-footer-content"></div>
</div> </div>

@ -6546,21 +6546,21 @@ select > option:hover {
} }
@media (min-width: 1200px){ @media (min-width: 1200px){
table tbody tr { table tbody tr {
width: 18% !important; width: 18% !important;
} }
.table .fw-stack{ .table .fw-stack{
font-size: 1.2vw; font-size: 1.2vw;
} }
} }
@media (min-width: 1500px){ @media (min-width: 1500px){
table tbody tr { table tbody tr {
width: 14% !important; width: 14% !important;
} }
.table .fw-stack{ .table .fw-stack{
font-size: 0.8vw; font-size: 0.8vw;
} }
} }
/** End **/ /** End **/

@ -0,0 +1,72 @@
#*
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.
*#
<EmailConfig>
<Subject>You have been invited to enroll your $device-type device in WSO2 IoT</Subject>
<Body>
<![CDATA[
<html>
<head>
<title>WSO2 IoT Server</title>
</head>
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
<div style="background-color:#cdcdcd; font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
<div style="background-color: #49c8f5; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 0px 10px 0px 0px;">
<div style="display: inline-block; line-height: 0px;">
<img src="http://b.content.wso2.com/sites/all/2015-june-theme/navigation/wso2-nav-logo.png"
alt="WSO2" style="margin: 0px 20px 0px 25px; width: 100%; max-width: 251px;"/>
</div>
</div>
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
Hi,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
You have been invited by $first-name to enrol your $device-type device in WSO2 IoT Server.
Click <a href="$base-url-https/devicemgt/device/$device-type/enroll">here</a> to begin device
enrolment.</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Should you need assistance, please contact your administrator.
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
Regards,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
WSO2 IoT Administrator
</p>
</div>
<div style="background-color: #333333; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="padding: 0px 20px 0px 0px;"><img
src="http://b.content.wso2.com/newsletter/images/wso2-logo-cloud-footer.png" alt="WSO2"
style="margin: 15px 0px 15px 25px; width: 100%; max-width: 258px;"/></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
]]>
</Body>
</EmailConfig>

@ -0,0 +1,71 @@
#*
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.
*#
<EmailConfig>
<Subject>You have been invited to enroll your device in WSO2 IoT</Subject>
<Body>
<![CDATA[
<html>
<head>
<title>WSO2 IoT Server</title>
</head>
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
<div style="background-color:#cdcdcd; font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
<div style="background-color: #49c8f5; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 0px 10px 0px 0px;">
<div style="display: inline-block; line-height: 0px;">
<img src="http://b.content.wso2.com/sites/all/2015-june-theme/navigation/wso2-nav-logo.png"
alt="WSO2" style="margin: 0px 20px 0px 25px; width: 100%; max-width: 251px;"/>
</div>
</div>
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
Hi $first-name,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
You have been invited to enrol your device in WSO2 IoT Server.
Click <a href="$base-url-https/devicemgt/device/enroll">here</a> to begin device enrolment.</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Should you need assistance, please contact your administrator.
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
Regards,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
WSO2 IoT Administrator
</p>
</div>
<div style="background-color: #333333; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="padding: 0px 20px 0px 0px;"><img
src="http://b.content.wso2.com/newsletter/images/wso2-logo-cloud-footer.png" alt="WSO2"
style="margin: 15px 0px 15px 25px; width: 100%; max-width: 258px;"/></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
]]>
</Body>
</EmailConfig>

@ -0,0 +1,81 @@
#*
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.
*#
<EmailConfig>
<Subject>You have successfully been registered in WSO2 IoT</Subject>
<Body>
<![CDATA[
<html>
<head>
<title>WSO2 IoT Server</title>
</head>
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
<div style="background-color:#cdcdcd; font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
<div style="background-color: #49c8f5; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 0px 10px 0px 0px;">
<div style="display: inline-block; line-height: 0px;">
<img src="http://b.content.wso2.com/sites/all/2015-june-theme/navigation/wso2-nav-logo.png"
alt="WSO2" style="margin: 0px 20px 0px 25px; width: 100%; max-width: 251px;"/>
</div>
</div>
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
Hi $first-name,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
You have been registered in WSO2 IoT and invited to enrol your device.
Click <a href="$base-url-https/devicemgt/device/enroll">here</a> to begin device enrolment.</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Use following credentials to log in to WSO2 IoT Device Management application.
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
<b>Username:</b> $username
<br/>
<b>Password:</b> $password
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Should you need assistance, please contact your administrator.
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
Regards,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
WSO2 IoT Administrator
</p>
</div>
<div style="background-color: #333333; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="padding: 0px 20px 0px 0px;"><img
src="http://b.content.wso2.com/newsletter/images/wso2-logo-cloud-footer.png" alt="WSO2"
style="margin: 15px 0px 15px 25px; width: 100%; max-width: 258px;"/></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
]]>
</Body>
</EmailConfig>

@ -1914,8 +1914,8 @@
<identity.inbound.auth.saml.version>5.2.14</identity.inbound.auth.saml.version> <identity.inbound.auth.saml.version>5.2.14</identity.inbound.auth.saml.version>
<!-- Carbon Identity import version ranges --> <!-- Carbon Identity import version ranges -->
<carbon.identity.imp.pkg.version>[5.1.0, 6.0.0)</carbon.identity.imp.pkg.version> <carbon.identity.imp.pkg.version>[5.6.0, 6.0.0)</carbon.identity.imp.pkg.version>
<carbon.identity-inbound-auth-oauth.imp.pkg.version>[5.1.0, 6.0.0)</carbon.identity-inbound-auth-oauth.imp.pkg.version> <carbon.identity-inbound-auth-oauth.imp.pkg.version>[5.2.0, 6.0.0)</carbon.identity-inbound-auth-oauth.imp.pkg.version>
<carbon.identity-user-ws.imp.pkg.version>[5.1.0, 6.0.0)</carbon.identity-user-ws.imp.pkg.version> <carbon.identity-user-ws.imp.pkg.version>[5.1.0, 6.0.0)</carbon.identity-user-ws.imp.pkg.version>
<!-- Carbon Multi-tenancy --> <!-- Carbon Multi-tenancy -->
@ -1941,7 +1941,7 @@
<!-- Carbon API Management --> <!-- Carbon API Management -->
<carbon.api.mgt.version>6.1.2</carbon.api.mgt.version> <carbon.api.mgt.version>6.1.2</carbon.api.mgt.version>
<carbon.api.mgt.version.range>(5.0.0,7.0.0]</carbon.api.mgt.version.range> <carbon.api.mgt.version.range>(6.0.0,7.0.0]</carbon.api.mgt.version.range>
<!-- Carbon Analytics Commons --> <!-- Carbon Analytics Commons -->
<carbon.analytics.common.version>5.1.3</carbon.analytics.common.version> <carbon.analytics.common.version>5.1.3</carbon.analytics.common.version>

Loading…
Cancel
Save