From 78959f0cfb1e78fe8be068191be49efa42812f2a Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 20 Mar 2015 14:21:04 +0530 Subject: [PATCH 1/3] user management --- .../DeviceManagementServiceProviderImpl.java | 8 + .../core/service/DeviceManagementService.java | 2 + .../service/DeviceManagementServiceImpl.java | 6 + .../mgt/core/util/DeviceManagerUtil.java | 2 +- .../carbon/device/mgt/user/common/User.java | 191 ++++++++++++++++++ .../device/mgt/user/core/UserManagerImpl.java | 74 +++++-- .../main/resources/conf/license-config.xml | 24 +-- 7 files changed, 278 insertions(+), 29 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index d887fe3a98..4b00db5f87 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.*; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; @@ -211,6 +212,13 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ return devicesOfUser; } + @Override + public void sendEnrollInvitation(String emailAddress) throws DeviceManagementException { + EmailMessageProperties emailMessageProperties = new EmailMessageProperties(); + emailMessageProperties.setSubject(""); + // EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(); + } + @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManager dms = diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 1f156f4f62..efbb959323 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -38,4 +38,6 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager, List getDeviceListOfUser(String username) throws DeviceManagementException; + void sendEnrollInvitation(String emailAddress) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index e81e5c1410..48b6853b52 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; 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.core.internal.DeviceManagementDataHolder; +import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder; import java.util.List; @@ -85,6 +86,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDeviceListOfUser(username); } + @Override + public void sendEnrollInvitation(String emailAddress) throws DeviceManagementException { + DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().sendEnrollInvitation(emailAddress); + } + @Override public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 37f405bda4..a619a3e4e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -146,5 +146,5 @@ public final class DeviceManagerUtil { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); return ctx.getTenantId(); } - + } diff --git a/components/user-mgt/org.wso2.carbon.device.mgt.user.common/src/main/java/org/wso2/carbon/device/mgt/user/common/User.java b/components/user-mgt/org.wso2.carbon.device.mgt.user.common/src/main/java/org/wso2/carbon/device/mgt/user/common/User.java index 19e8682fb5..057bd2019f 100644 --- a/components/user-mgt/org.wso2.carbon.device.mgt.user.common/src/main/java/org/wso2/carbon/device/mgt/user/common/User.java +++ b/components/user-mgt/org.wso2.carbon.device.mgt.user.common/src/main/java/org/wso2/carbon/device/mgt/user/common/User.java @@ -24,6 +24,29 @@ public class User { private String userName; private String roleName; + private String firstName; + private String email; + private String lastName; + private String streatAddress; + private String locality; + private String region; + private String postalCode; + private String country; + private String hone; + private String im; + private String organization; + private String url; + private String title; + private String mobile; + private String nickName; + private String dateOfBirth; + private String gender; + private String accountStatus; + private String challengeQuestion; + private String identityClaimUri; + private String tempEmailAddress; + + private ArrayList claimList; public User(String userName) { @@ -58,4 +81,172 @@ public class User { public void setClaimList(ArrayList claimList) { this.claimList = claimList; } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getStreatAddress() { + return streatAddress; + } + + public void setStreatAddress(String streatAddress) { + this.streatAddress = streatAddress; + } + + public String getLocality() { + return locality; + } + + public void setLocality(String locality) { + this.locality = locality; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public String getPostalCode() { + return postalCode; + } + + public void setPostalCode(String postalCode) { + this.postalCode = postalCode; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getHone() { + return hone; + } + + public void setHone(String hone) { + this.hone = hone; + } + + public String getIm() { + return im; + } + + public void setIm(String im) { + this.im = im; + } + + public String getOrganization() { + return organization; + } + + public void setOrganization(String organization) { + this.organization = organization; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + public String getDateOfBirth() { + return dateOfBirth; + } + + public void setDateOfBirth(String dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getAccountStatus() { + return accountStatus; + } + + public void setAccountStatus(String accountStatus) { + this.accountStatus = accountStatus; + } + + public String getChallengeQuestion() { + return challengeQuestion; + } + + public void setChallengeQuestion(String challengeQuestion) { + this.challengeQuestion = challengeQuestion; + } + + public String getIdentityClaimUri() { + return identityClaimUri; + } + + public void setIdentityClaimUri(String identityClaimUri) { + this.identityClaimUri = identityClaimUri; + } + + public String getTempEmailAddress() { + return tempEmailAddress; + } + + public void setTempEmailAddress(String tempEmailAddress) { + this.tempEmailAddress = tempEmailAddress; + } } diff --git a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java index fc7a2d3210..14740a1229 100644 --- a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java +++ b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java @@ -28,14 +28,45 @@ import org.wso2.carbon.device.mgt.user.core.internal.DeviceMgtUserDataHolder; import org.wso2.carbon.user.api.Claim; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.user.core.UserCoreConstants; import java.util.ArrayList; import java.util.List; +import java.util.Map; public class UserManagerImpl implements UserManager { private static Log log = LogFactory.getLog(UserManagerImpl.class); + public static final String GIVEN_NAME = UserCoreConstants.ClaimTypeURIs.GIVEN_NAME; + public static final String EMAIL_ADDRESS = UserCoreConstants.ClaimTypeURIs.EMAIL_ADDRESS; + public static final String SURNAME = UserCoreConstants.ClaimTypeURIs.SURNAME; + public static final String STREET_ADDRESS = UserCoreConstants.ClaimTypeURIs.STREET_ADDRESS; + public static final String LOCALITY = UserCoreConstants.ClaimTypeURIs.LOCALITY; + public static final String REGION = UserCoreConstants.ClaimTypeURIs.REGION; + public static final String POSTAL_CODE = UserCoreConstants.ClaimTypeURIs.POSTAL_CODE; + public static final String COUNTRY = UserCoreConstants.ClaimTypeURIs.COUNTRY; + public static final String HONE = UserCoreConstants.ClaimTypeURIs.HONE; + public static final String IM = UserCoreConstants.ClaimTypeURIs.IM; + public static final String ORGANIZATION = UserCoreConstants.ClaimTypeURIs.ORGANIZATION; + public static final String URL = UserCoreConstants.ClaimTypeURIs.URL; + public static final String TITLE = UserCoreConstants.ClaimTypeURIs.TITLE; + public static final String ROLE = UserCoreConstants.ClaimTypeURIs.ROLE; + public static final String MOBILE = UserCoreConstants.ClaimTypeURIs.MOBILE; + public static final String NICKNAME = UserCoreConstants.ClaimTypeURIs.NICKNAME; + public static final String DATE_OF_BIRTH = UserCoreConstants.ClaimTypeURIs.DATE_OF_BIRTH; + public static final String GENDER = UserCoreConstants.ClaimTypeURIs.GENDER; + public static final String ACCOUNT_STATUS = UserCoreConstants.ClaimTypeURIs.ACCOUNT_STATUS; + public static final String CHALLENGE_QUESTION_URI = UserCoreConstants.ClaimTypeURIs.CHALLENGE_QUESTION_URI; + public static final String IDENTITY_CLAIM_URI = UserCoreConstants.ClaimTypeURIs.IDENTITY_CLAIM_URI; + public static final String TEMPORARY_EMAIL_ADDRESS = UserCoreConstants.ClaimTypeURIs.TEMPORARY_EMAIL_ADDRESS; + + public static final String[] DEFAULT_CLAIM_ARR = new String[]{GIVEN_NAME,EMAIL_ADDRESS,SURNAME,STREET_ADDRESS, + LOCALITY,REGION,REGION,POSTAL_CODE,COUNTRY,HONE,IM,ORGANIZATION,URL,TITLE,ROLE,MOBILE,NICKNAME, + DATE_OF_BIRTH,GENDER,ACCOUNT_STATUS,CHALLENGE_QUESTION_URI,IDENTITY_CLAIM_URI,TEMPORARY_EMAIL_ADDRESS}; + + // private static final String CLAIM_URL_ + @Override public List getUsersForTenantAndRole(int tenantId, String roleName) throws UserManagementException { @@ -51,7 +82,8 @@ public class UserManagerImpl implements UserManager { User newUser; for (String userName : userNames) { newUser = new User(userName); - setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, null)); + setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, DEFAULT_CLAIM_ARR, + UserCoreConstants.DEFAULT_PROFILE)); usersList.add(newUser); } } catch (UserStoreException userStoreEx) { @@ -103,7 +135,8 @@ public class UserManagerImpl implements UserManager { User newUser; for (String userName : userNames) { newUser = new User(userName); - setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, null)); + setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, DEFAULT_CLAIM_ARR, + UserCoreConstants.DEFAULT_PROFILE)); usersList.add(newUser); } } catch (UserStoreException userStoreEx) { @@ -115,19 +148,30 @@ public class UserManagerImpl implements UserManager { return usersList; } - private void setUserClaims(User newUser, Claim[] userClaimValues) { - - Claims userClaims; - ArrayList claimsList = new ArrayList(); - for (Claim claim : userClaimValues) { - userClaims = new Claims(); - userClaims.setClaimUrl(claim.getClaimUri()); - userClaims.setDescription(claim.getDescription()); - userClaims.setDialectUrl(claim.getDialectURI()); - userClaims.setValue(claim.getValue()); - claimsList.add(userClaims); - } - newUser.setClaimList(claimsList); + private void setUserClaims(User newUser, Map claimMap) { + + newUser.setRoleName(UserCoreConstants.ClaimTypeURIs.ROLE); + newUser.setAccountStatus(claimMap.get(ACCOUNT_STATUS)); + newUser.setChallengeQuestion(claimMap.get(CHALLENGE_QUESTION_URI)); + newUser.setCountry(claimMap.get(COUNTRY)); + newUser.setDateOfBirth(claimMap.get(DATE_OF_BIRTH)); + newUser.setEmail(claimMap.get(EMAIL_ADDRESS)); + newUser.setFirstName(claimMap.get(GIVEN_NAME)); + newUser.setGender(claimMap.get(GENDER)); + newUser.setHone(claimMap.get(HONE)); + newUser.setIm(claimMap.get(IM)); + newUser.setIdentityClaimUri(claimMap.get(IDENTITY_CLAIM_URI)); + newUser.setLastName(claimMap.get(SURNAME)); + newUser.setLocality(claimMap.get(LOCALITY)); + newUser.setEmail(claimMap.get(EMAIL_ADDRESS)); + newUser.setMobile(claimMap.get(MOBILE)); + newUser.setNickName(claimMap.get(NICKNAME)); + newUser.setOrganization(claimMap.get(ORGANIZATION)); + newUser.setPostalCode(claimMap.get(POSTAL_CODE)); + newUser.setRegion(claimMap.get(REGION)); + newUser.setStreatAddress(claimMap.get(STREET_ADDRESS)); + newUser.setTitle(claimMap.get(TITLE)); + newUser.setTempEmailAddress(claimMap.get(TEMPORARY_EMAIL_ADDRESS)); } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/license-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/license-config.xml index dfaa9db038..e182e58bb9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/license-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/license-config.xml @@ -1,22 +1,20 @@ From 7c0ca194a11aff26d7e54de1b4e0c0d35485a32a Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 20 Mar 2015 16:16:57 +0530 Subject: [PATCH 2/3] Email functionality --- .../mgt/common/DeviceManagementConstants.java | 6 ++ .../DeviceManagementServiceProviderImpl.java | 35 +++++--- .../config/DeviceConfigurationManager.java | 85 ++++++++++++------- .../src/main/resources/p2.inf | 1 + 4 files changed, 83 insertions(+), 44 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 23ff9d0c3a..6bd72a0e82 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -71,4 +71,10 @@ public final class DeviceManagementConstants { public static final String LICENSE_REGISTRY_KEY = "license"; } + public static final class NotificationProperties { + private NotificationProperties() { + throw new AssertionError(); + } + public static final String NOTIFICATION_CONFIG_FILE = "notification-messages.xml"; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 4b00db5f87..3b8a335691 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -18,22 +18,24 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +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.OperationManager; +import org.wso2.carbon.device.mgt.common.spi.DeviceManager; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.EnrolmentNotifications; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.core.dto.*; -import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; -import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.core.dto.Status; import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; -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.OperationManager; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; @@ -188,7 +190,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ List devicesOfUser = new ArrayList(); try { int tenantId = DeviceManagerUtil.getTenantId(); - List devicesList = this.deviceDAO.getDeviceListOfUser(username, tenantId); + List devicesList = this.deviceDAO + .getDeviceListOfUser(username, tenantId); for (int x = 0; x < devicesList.size(); x++) { org.wso2.carbon.device.mgt.core.dto.Device device = devicesList.get(x); device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId())); @@ -207,7 +210,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ } } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining devices for user " + - "'" + username + "'", e); + "'" + username + "'", e); } return devicesOfUser; } @@ -215,8 +218,14 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ @Override public void sendEnrollInvitation(String emailAddress) throws DeviceManagementException { EmailMessageProperties emailMessageProperties = new EmailMessageProperties(); - emailMessageProperties.setSubject(""); - // EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(); + EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance() + .getNotificationMessagesConfig() + .getEnrolmentNotifications(); + + emailMessageProperties.setMailTo(new String[]{emailAddress}); + emailMessageProperties.setSubject(enrolmentNotifications.getSubject()); + emailMessageProperties.setMessageBody(enrolmentNotifications.getMessage()); + EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties); } @Override @@ -288,7 +297,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ @Override public boolean addOperation(Operation operation, - List devices) throws OperationManagementException { + List devices) throws OperationManagementException { return operationManager.addOperation(operation, devices); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java index fa1ed6d72c..0348f8a7f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java @@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.utils.CarbonUtils; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import java.io.File; @@ -33,42 +34,64 @@ import java.io.File; */ public class DeviceConfigurationManager { - private DeviceManagementConfig currentDeviceConfig; - private static DeviceConfigurationManager deviceConfigManager; + private DeviceManagementConfig currentDeviceConfig; + private NotificationMessagesConfig notificationMessagesConfig; + private static DeviceConfigurationManager deviceConfigManager; - private static final String deviceMgtConfigXMLPath = - CarbonUtils.getCarbonConfigDirPath() + File.separator + - DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME; + private static final String deviceMgtConfigXMLPath = + CarbonUtils.getCarbonConfigDirPath() + File.separator + + DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME; + private static final String notificationMessagesConfigXMLPath = + CarbonUtils.getCarbonConfigDirPath() + File.separator + + DeviceManagementConstants.NotificationProperties.NOTIFICATION_CONFIG_FILE; - public static DeviceConfigurationManager getInstance() { - if (deviceConfigManager == null) { - synchronized (DeviceConfigurationManager.class) { - if (deviceConfigManager == null) { - deviceConfigManager = new DeviceConfigurationManager(); - } - } - } - return deviceConfigManager; - } + public static DeviceConfigurationManager getInstance() { + if (deviceConfigManager == null) { + synchronized (DeviceConfigurationManager.class) { + if (deviceConfigManager == null) { + deviceConfigManager = new DeviceConfigurationManager(); + } + } + } + return deviceConfigManager; + } - public synchronized void initConfig() throws DeviceManagementException { + public synchronized void initConfig() throws DeviceManagementException { - //catch generic exception.if any exception occurs wrap and throw DeviceManagementException - try { - File deviceMgtConfig = new File(deviceMgtConfigXMLPath); - Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig); + //catch generic exception.if any exception occurs wrap and throw DeviceManagementException + try { + File deviceMgtConfig = new File(deviceMgtConfigXMLPath); + Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig); /* Un-marshaling Device Management configuration */ - JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class); - Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); - this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc); - } catch (Exception e) { - throw new DeviceManagementException("Error occurred while initializing RSS config", e); - } - } - - public DeviceManagementConfig getDeviceManagementConfig() { - return currentDeviceConfig; - } + JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class); + Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); + this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc); + } catch (JAXBException jaxbEx) { + throw new DeviceManagementException("Error occurred while initializing Data Source config", jaxbEx); + } + + try { + File notificationConfig = new File(notificationMessagesConfigXMLPath); + Document doc = DeviceManagerUtil.convertToDocument(notificationConfig); + + /* Un-marshaling Notifications Management configuration */ + JAXBContext notificationContext = JAXBContext.newInstance(NotificationMessagesConfig.class); + Unmarshaller unmarshaller = notificationContext.createUnmarshaller(); + this.notificationMessagesConfig = (NotificationMessagesConfig) unmarshaller.unmarshal(doc); + }catch(JAXBException jaxbEx){ + throw new DeviceManagementException("Error occurred while initializing Notification settings config", + jaxbEx); + } + + } + + public DeviceManagementConfig getDeviceManagementConfig() { + return currentDeviceConfig; + } + + public NotificationMessagesConfig getNotificationMessagesConfig() { + return notificationMessagesConfig; + } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf index c00882bffa..51eb8e435a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/p2.inf @@ -1,5 +1,6 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/notification-messages.xml,target:${installFolder}/../../conf/notification-messages.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\ \ No newline at end of file From 28a00cd21cb7591cde247afecd586f64bfc0a6a7 Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 20 Mar 2015 16:17:51 +0530 Subject: [PATCH 3/3] Email functionality --- .../core/config/EnrolmentNotifications.java | 47 +++++++++++++++++++ .../config/NotificationMessagesConfig.java | 38 +++++++++++++++ .../resources/conf/notification-messages.xml | 26 ++++++++++ 3 files changed, 111 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/EnrolmentNotifications.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/NotificationMessagesConfig.java create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/EnrolmentNotifications.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/EnrolmentNotifications.java new file mode 100644 index 0000000000..70244ecd5d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/EnrolmentNotifications.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.core.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "EnrolmentNotifications") +public class EnrolmentNotifications { + + private String message; + private String subject; + + @XmlElement(name = "message", required = true) + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @XmlElement(name = "subject", required = true) + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/NotificationMessagesConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/NotificationMessagesConfig.java new file mode 100644 index 0000000000..0cd4b67c53 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/NotificationMessagesConfig.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.core.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "Notifications") +public class NotificationMessagesConfig { + + private EnrolmentNotifications enrolmentNotifications; + + @XmlElement(name = "EnrolmentNotifications", required = true) + public EnrolmentNotifications getEnrolmentNotifications() { + return enrolmentNotifications; + } + + public void setEnrolmentNotifications(EnrolmentNotifications enrolmentNotifications) { + this.enrolmentNotifications = enrolmentNotifications; + } + +} diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml new file mode 100644 index 0000000000..922e115333 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/notification-messages.xml @@ -0,0 +1,26 @@ + + + + + + + Please enroll your device + Enroll your device + + \ No newline at end of file