From b39be48919980698c7428a29fcea9c3c8730c57c Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 18 Oct 2018 11:31:10 +0530 Subject: [PATCH] Adding constants --- .../impl/GeoLocationBasedServiceImpl.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index fecf3ea6b4c..955b3386808 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -63,6 +63,12 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { private static Log log = LogFactory.getLog(GeoLocationBasedServiceImpl.class); + public static final String EMAIL_DOMAIN_SEPARATOR = "@"; + + public static final String EMAIL_DOMAIN_SEPARATOR_REPLACEMENT = "-AT-"; + public static final String SECONDERY_USER_STORE_SEPERATOR = ":"; + public static final String SECONDERY_USER_STORE_DEFAULT_SEPERATOR = "/"; + @Path("stats/{deviceType}/{deviceId}") @GET @Consumes("application/json") @@ -96,7 +102,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { sortByFields.add(sortByField); // this is the user who initiates the request - String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + + String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername() + EMAIL_DOMAIN_SEPARATOR + CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); try { @@ -577,4 +583,46 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { eventBean.setValues(record.getValues()); return eventBean; } + + + + /** + * When an input is having '@',replace it with '-AT-' [This is required to + * persist WebApp data in registry,as registry paths don't allow '@' sign.] + * + * @param input + * inputString + * @return String modifiedString + */ + public static String replaceEmailDomain(String input) { + if (input != null && input.contains(EMAIL_DOMAIN_SEPARATOR)) { + input = + input.replace(EMAIL_DOMAIN_SEPARATOR, + EMAIL_DOMAIN_SEPARATOR_REPLACEMENT); + } + return input; + } + + /** + * When an input is having '-AT-',replace it with @ [This is required to + * persist WebApp data between registry and database] + * + * @param input + * inputString + * @return String modifiedString + */ + public static String replaceEmailDomainBack(String input) { + if (input != null){ + if (input.contains(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT)) { + input = + input.replace(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT, + EMAIL_DOMAIN_SEPARATOR); + }else if (input.contains(SECONDERY_USER_STORE_SEPERATOR)){ + input = + input.replace(SECONDERY_USER_STORE_SEPERATOR, + SECONDERY_USER_STORE_DEFAULT_SEPERATOR); + } + } + return input; + } }