Add api for self guide enrollment

fixes https://roadmap.entgra.net/issues/9939
try_it
osh 2 years ago
parent d715609b53
commit 66afe95fe9

@ -54,6 +54,7 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.geo.service.Alert;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; 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.policy.mgt.Policy; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
@ -66,6 +67,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest;
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
@ -553,12 +555,12 @@ public interface DeviceManagementService {
required = false, required = false,
defaultValue = "0") defaultValue = "0")
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam( @ApiParam(
name = "limit", name = "limit",
value = "Provide how many device details you require from the starting pagination index/offset.", value = "Provide how many device details you require from the starting pagination index/offset.",
required = false, required = false,
defaultValue = "100") defaultValue = "100")
@QueryParam("limit") int limit @QueryParam("limit") int limit
); );
@GET @GET
@ -802,6 +804,59 @@ public interface DeviceManagementService {
@QueryParam("requireDeviceInfo") @QueryParam("requireDeviceInfo")
boolean requireDeviceInfo); boolean requireDeviceInfo);
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/enrollment/guide")
@ApiOperation(
consumes = MediaType.MULTIPART_FORM_DATA,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Sending Enrollment Mode chosen by customer",
notes = "Enrollment mode selected and path is sent as parameters",
tags = "Device Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully mailed the Enrollment Guide of customer.",
response = Device.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while sending mail of the Enrollment Guide.",
response = ErrorResponse.class)
})
Response sendEnrollmentGuide(
@ApiParam(
name = "enrolmentGuide",
value = "The details of the enrolment path suggested.",
required = true)
MultipartFile enrolmentGuide);
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/type/any/list") @Path("/type/any/list")
@ -1399,15 +1454,15 @@ public interface DeviceManagementService {
@ResponseHeader( @ResponseHeader(
name = "ETag", name = "ETag",
description = "Entity Tag of the response resource.\n" + description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
@ResponseHeader( @ResponseHeader(
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource was last modified. \n" + description = "Date and time the resource was last modified. \n" +
"Used by caches, or in conditional requests.")}), "Used by caches, or in conditional requests.")}),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. \n " + message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource.\n"), "Empty body because the client already has the latest version of the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -1425,7 +1480,7 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while getting the device details.", "Server error occurred while getting the device details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response queryDevicesByProperties( Response queryDevicesByProperties(
@ -1447,7 +1502,7 @@ public interface DeviceManagementService {
name = "device property map", name = "device property map",
value = "properties by which devices need filtered", value = "properties by which devices need filtered",
required = true) required = true)
PropertyMap map); PropertyMap map);
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -1873,140 +1928,141 @@ public interface DeviceManagementService {
@Size(max = 45) @Size(max = 45)
String id); String id);
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/{type}/{id}/getstatushistory") @Path("/{type}/{id}/getstatushistory")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get Device status history", value = "Get Device status history",
notes = "Get a list of status history associated with the device type and id", notes = "Get a list of status history associated with the device type and id",
tags = "Device Management", tags = "Device Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
}) })
} }
) )
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully fetched the status history of matching devices.", message = "OK. \n Successfully fetched the status history of matching devices.",
response = List.class, response = List.class,
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), description = "The content type of the body"),
@ResponseHeader( @ResponseHeader(
name = "ETag", name = "ETag",
description = "Entity Tag of the response resource.\n" + description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
@ResponseHeader( @ResponseHeader(
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource was last modified.\n" + description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. Empty body because the client already has the latest version" + message = "Not Modified. Empty body because the client already has the latest version" +
" of the requested resource.\n"), " of the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 404, code = 404,
message = "Not Found. \n A device with the specified device type and id was not found.", message = "Not Found. \n A device with the specified device type and id was not found.",
response = ErrorResponse.class), response = ErrorResponse.class),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while retrieving the device details.", "Server error occurred while retrieving the device details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getDeviceStatusHistory( Response getDeviceStatusHistory(
@ApiParam( @ApiParam(
name = "type", name = "type",
value = "The device type, such as ios, android, or windows.", value = "The device type, such as ios, android, or windows.",
required = true) required = true)
@PathParam("type") @PathParam("type")
@Size(max = 45) @Size(max = 45)
String type, String type,
@ApiParam( @ApiParam(
name = "id", name = "id",
value = "Device ID.", value = "Device ID.",
required = true) required = true)
@PathParam("id") @PathParam("id")
@Size(max = 45) @Size(max = 45)
String id); String id);
@GET
@Produces(MediaType.APPLICATION_JSON) @GET
@Path("/{type}/{id}/getenrolmentstatushistory") @Produces(MediaType.APPLICATION_JSON)
@ApiOperation( @Path("/{type}/{id}/getenrolmentstatushistory")
produces = MediaType.APPLICATION_JSON, @ApiOperation(
httpMethod = "GET", produces = MediaType.APPLICATION_JSON,
value = "Get Device Current Enrolment status history", httpMethod = "GET",
notes = "Get a list of status history associated with the device type and id for the current enrolment", value = "Get Device Current Enrolment status history",
tags = "Device Management", notes = "Get a list of status history associated with the device type and id for the current enrolment",
extensions = { tags = "Device Management",
@Extension(properties = { extensions = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") @Extension(properties = {
}) @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
} })
) }
@ApiResponses( )
value = { @ApiResponses(
@ApiResponse( value = {
code = 200, @ApiResponse(
message = "OK. \n Successfully fetched the status history of matching devices.", code = 200,
response = List.class, message = "OK. \n Successfully fetched the status history of matching devices.",
responseHeaders = { response = List.class,
@ResponseHeader( responseHeaders = {
name = "Content-Type", @ResponseHeader(
description = "The content type of the body"), name = "Content-Type",
@ResponseHeader( description = "The content type of the body"),
name = "ETag", @ResponseHeader(
description = "Entity Tag of the response resource.\n" + name = "ETag",
"Used by caches, or in conditional requests."), description = "Entity Tag of the response resource.\n" +
@ResponseHeader( "Used by caches, or in conditional requests."),
name = "Last-Modified", @ResponseHeader(
description = "Date and time the resource was last modified.\n" + name = "Last-Modified",
"Used by caches, or in conditional requests."), description = "Date and time the resource was last modified.\n" +
}), "Used by caches, or in conditional requests."),
@ApiResponse( }),
code = 304, @ApiResponse(
message = "Not Modified. Empty body because the client already has the latest version" + code = 304,
" of the requested resource.\n"), message = "Not Modified. Empty body because the client already has the latest version" +
@ApiResponse( " of the requested resource.\n"),
code = 400, @ApiResponse(
message = "Bad Request. \n Invalid request or validation error.", code = 400,
response = ErrorResponse.class), message = "Bad Request. \n Invalid request or validation error.",
@ApiResponse( response = ErrorResponse.class),
code = 404, @ApiResponse(
message = "Not Found. \n A device with the specified device type and id was not found.", code = 404,
response = ErrorResponse.class), message = "Not Found. \n A device with the specified device type and id was not found.",
@ApiResponse( response = ErrorResponse.class),
code = 500, @ApiResponse(
message = "Internal Server Error. \n " + code = 500,
"Server error occurred while retrieving the device details.", message = "Internal Server Error. \n " +
response = ErrorResponse.class) "Server error occurred while retrieving the device details.",
}) response = ErrorResponse.class)
})
Response getCurrentEnrolmentDeviceStatusHistory( Response getCurrentEnrolmentDeviceStatusHistory(
@ApiParam( @ApiParam(
name = "type", name = "type",
value = "The device type, such as ios, android, or windows.", value = "The device type, such as ios, android, or windows.",
required = true) required = true)
@PathParam("type") @PathParam("type")
@Size(max = 45) @Size(max = 45)
String type, String type,
@ApiParam( @ApiParam(
name = "id", name = "id",
value = "Device ID.", value = "Device ID.",
required = true) required = true)
@PathParam("id") @PathParam("id")
@Size(max = 45) @Size(max = 45)
String id); String id);
@PUT @PUT
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -2171,16 +2227,16 @@ public interface DeviceManagementService {
@ResponseHeader( @ResponseHeader(
name = "ETag", name = "ETag",
description = "Entity Tag of the response resource.\n" + description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
@ResponseHeader( @ResponseHeader(
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource was last modified.\n" + description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. Empty body because the client already has the latest version" + message = "Not Modified. Empty body because the client already has the latest version" +
" of the requested resource.\n"), " of the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -2192,7 +2248,7 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while retrieving the device details.", "Server error occurred while retrieving the device details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getDeviceCountByStatus( Response getDeviceCountByStatus(
@ -2240,16 +2296,16 @@ public interface DeviceManagementService {
@ResponseHeader( @ResponseHeader(
name = "ETag", name = "ETag",
description = "Entity Tag of the response resource.\n" + description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
@ResponseHeader( @ResponseHeader(
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource was last modified.\n" + description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. Empty body because the client already has the latest version" + message = "Not Modified. Empty body because the client already has the latest version" +
" of the requested resource.\n"), " of the requested resource.\n"),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -2261,7 +2317,7 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while retrieving the device details.", "Server error occurred while retrieving the device details.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getDeviceIdentifiersByStatus( Response getDeviceIdentifiersByStatus(
@ -2310,16 +2366,16 @@ public interface DeviceManagementService {
@ResponseHeader( @ResponseHeader(
name = "ETag", name = "ETag",
description = "Entity Tag of the response resource.\n" + description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
@ResponseHeader( @ResponseHeader(
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" + description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }),
@ApiResponse( @ApiResponse(
code = 304, code = 304,
message = "Not Modified. Empty body because the client already has the latest " + message = "Not Modified. Empty body because the client already has the latest " +
"version of the requested resource."), "version of the requested resource."),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -2331,7 +2387,7 @@ public interface DeviceManagementService {
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server Error. \n " +
"Server error occurred while retrieving information requested device.", "Server error occurred while retrieving information requested device.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response bulkUpdateDeviceStatus( Response bulkUpdateDeviceStatus(
@ -2642,11 +2698,11 @@ public interface DeviceManagementService {
@ResponseHeader( @ResponseHeader(
name = "ETag", name = "ETag",
description = "Entity Tag of the response resource.\n" + description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
@ResponseHeader( @ResponseHeader(
name = "Last-Modified", name = "Last-Modified",
description = "Date and time the resource was last modified.\n" + description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."), "Used by caches, or in conditional requests."),
}), }),
@ApiResponse( @ApiResponse(
code = 500, code = 500,

@ -68,6 +68,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceData; import org.wso2.carbon.device.mgt.common.device.details.DeviceData;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
@ -101,6 +102,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
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.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService; import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService;
import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl; import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl;
@ -130,6 +132,7 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -144,6 +147,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -816,6 +820,43 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.OK).entity(device).build(); return Response.status(Response.Status.OK).entity(device).build();
} }
@POST
@Path("/enrollment/guide")
@Override
public Response sendEnrollmentGuide(MultipartFile enrolmentGuide) {
if (log.isDebugEnabled()) {
log.debug("Sending enrollment invitation mail to existing user.");
}
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
try {
// Set<String> recipients = new HashSet<>();
// recipients.add(email);
// Properties props = new Properties();
// props.setProperty("enrolment-guide", enrolmentGuide);
//
// EmailMetaInfo metaInfo = new EmailMetaInfo(recipients, props);
// dms.sendEnrolmentInvitation("enrolment-guide-template", metaInfo);
dms.sendEnrolmentGuide(enrolmentGuide);
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while inviting user to enrol their device";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (ConfigurationManagementException e) {
String msg = "Error occurred while sending the email invitations. Mail server not configured.";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (IOException e) {
e.printStackTrace();
String msg = "testtttt.";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
// return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
}
@POST @POST
@Path("/type/any/list") @Path("/type/any/list")
@Override @Override

@ -66,7 +66,9 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion;
import org.wso2.carbon.device.mgt.common.geo.service.GeoCluster; import org.wso2.carbon.device.mgt.common.geo.service.GeoCluster;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Collection; import java.util.Collection;
@ -645,6 +647,8 @@ public interface DeviceManagementProviderService {
void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException, void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException,
ConfigurationManagementException; ConfigurationManagementException;
void sendEnrolmentGuide(MultipartFile enrolmentGuide) throws DeviceManagementException, ConfigurationManagementException, IOException;
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException; void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException;
FeatureManager getFeatureManager(String deviceType) throws DeviceTypeNotFoundException; FeatureManager getFeatureManager(String deviceType) throws DeviceTypeNotFoundException;

@ -38,6 +38,7 @@ package org.wso2.carbon.device.mgt.core.service;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.commons.collections.map.SingletonMap; import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -160,12 +161,13 @@ import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService; import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.springframework.web.multipart.MultipartFile;
import javax.mail.*;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import java.io.IOException; import java.io.*;
import java.io.StringWriter;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -185,6 +187,12 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.ws.rs.core.MultivaluedMap;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
PluginInitializationListener { PluginInitializationListener {
@ -198,6 +206,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private final ApplicationDAO applicationDAO; private final ApplicationDAO applicationDAO;
private MetadataDAO metadataDAO; private MetadataDAO metadataDAO;
private final DeviceStatusDAO deviceStatusDAO; private final DeviceStatusDAO deviceStatusDAO;
int count = 0;
public DeviceManagementProviderServiceImpl() { public DeviceManagementProviderServiceImpl() {
this.pluginRepository = new DeviceManagementPluginRepository(); this.pluginRepository = new DeviceManagementPluginRepository();
@ -1551,6 +1560,178 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
} }
// save to somewhere
private void writeFile(byte[] content, String filename) throws IOException {
File file = new File(filename);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fop = new FileOutputStream(file);
fop.write(content);
fop.flush();
fop.close();
}
@Override
public void sendEnrolmentGuide(MultipartFile enrolmentGuide) throws DeviceManagementException, ConfigurationManagementException, IOException {
// String fileName = "";
// MultivaluedMap<String, String> multivaluedMap = null;
// String fileName = null;
// InputStream inputStream = null;
// String uploadFilePath = null;
//
// Map<String, List<InputPart>> map = enrolmentGuide.getFormDataMap();
// List<InputPart> inputParts = map.get("file");
//
// for (InputPart inputPart : inputParts) {
//
// try {
//
// multivaluedMap = inputPart.getHeaders();
// fileName = getFileName(multivaluedMap);
//
// //convert the uploaded file to inputstream
// InputStream inputStream = inputPart.getBody(InputStream.class,null);
//
// byte [] bytes = IOUtils.toByteArray(inputStream);
//
// //constructs upload file path
// fileName = UPLOADED_FILE_PATH + fileName;
//
// writeFile(bytes,fileName);
//
// System.out.println("Done");
//
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
// Recipient's email ID needs to be mentioned.
// String charset = enrolmentGuide.getFormDataMap().get("_charset_").get(0).getBodyAsString();
// File file = (File) enrolmentGuide.getFormDataMap().get("file").get(0);
String to = "oshani@entgra.io";
// Sender's email ID needs to be mentioned
String from = "oshsilva1996@gmail.com";
// Assuming you are sending email from through gmails smtp
String host = "smtp.gmail.com";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", "465");
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.auth", "true");
// Get the Session object.// and pass username and password
Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("oshsilva1996@gmail.com", "layzvxhcxlwzkgwf");
}
});
// Used to debug SMTP issues
session.setDebug(true);
try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// // Set Subject: header field
message.setSubject("Enrollment Guide Triggered " + ++count);
// message.setText(enrolmentGuide);
// Multipart multipart = new MimeMultipart();
//
// MimeBodyPart attachmentPart = new MimeBodyPart();
//
// MimeBodyPart textPart = new MimeBodyPart();
//
// try {
//
//// String charset = enrolmentGuide.getFormDataMap().get("_charset_").get(0).getBodyAsString();
//// InputPart file = enrolmentGuide.getFormDataMap().get("file").get(0);
//// InputStream inputStream = file.getBody(InputStream.class, null);
//// BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, charset));
//// String line;
//// StringBuilder content = new StringBuilder();
//// while ((line = br.readLine()) != null) {
//// content.append(line);
//// }
////
//// writeFile(content, "test");
////
//// File f =new File("H:\\pepipost_tutorials\\javaemail1.PNG");
//
// attachmentPart.attachFile(file);
// textPart.setText("This is text");
// multipart.addBodyPart(textPart);
// multipart.addBodyPart(attachmentPart);
//
// } catch (IOException e) {
//
// e.printStackTrace();
//
// }
//
// message.setContent(multipart);
System.out.println("sending...");
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException mex) {
mex.printStackTrace();
}
//
// try {
// // Create a default MimeMessage object.
// MimeMessage message = new MimeMessage(session);
//
// // Set From: header field of the header.
// message.setFrom(new InternetAddress(from));
//
// // Set To: header field of the header.
// message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
//
// // Set Subject: header field
// message.setSubject("Enrollment Guide Triggered " + ++count);
//
// // Now set the actual message
// message.setText("enrolmentGuide");
//
// System.out.println("sending...");
// // Send message
// Transport.send(message);
// System.out.println("Sent message successfully....");
// } catch (MessagingException mex) {
// mex.printStackTrace();
// }
}
@Override @Override
public void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, public void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException,
ConfigurationManagementException { ConfigurationManagementException {

Loading…
Cancel
Save