diff --git a/src/main/java/biz/neustar/pc/ui/constants/UIRestPathConstants.java b/src/main/java/biz/neustar/pc/ui/constants/UIRestPathConstants.java index 84b2e56..e59fd1f 100644 --- a/src/main/java/biz/neustar/pc/ui/constants/UIRestPathConstants.java +++ b/src/main/java/biz/neustar/pc/ui/constants/UIRestPathConstants.java @@ -42,6 +42,7 @@ public class UIRestPathConstants { public static final String CSP_CLOUD_NAME = "cspCloudName"; public static final String CLOUD_NAME = "cloudName"; public static final String PRODUCT_NAME = "productName"; + public static final String EMAIL = "email"; public static final String BASE_URI_NAME_AVAILABILITY_API = PATH_WITH_CURRENT_API_VERSION + "/clouds/personalClouds/{cloudName}/available"; @@ -76,7 +77,8 @@ public class UIRestPathConstants { public static final String PERSONAL_CLOUD_CHANGE_PASSWORD_URI = REGISTER_PERSONAL_CLOUD_URI + "/{cloudName}/changePassword"; - + public static final String PERSONAL_CLOUD_PROV_FEEDBACK_URI = PATH_WITH_CURRENT_API_VERSION + + "/feedback"; public static final String GET_DEPENDENTS_URI = REGISTER_PERSONAL_CLOUD_URI + "/{cloudName}/dependents"; public static final String NAME_AVAILABILITY_API = PATH_WITH_CURRENT_API_VERSION @@ -89,10 +91,10 @@ public class UIRestPathConstants { public static final String GET_DEPENDENTS_API = PATH_WITH_CURRENT_API_VERSION + "/csp/{0}/clouds/personalClouds/{1}/dependents"; public static final String PERSONAL_CLOUD_FORGOT_PASSWORD_API = PATH_WITH_CURRENT_API_VERSION - + "/csp/{0}/clouds/personalCloud/{1}/forgotPassword"; + + "/csp/{0}/clouds/personalClouds/{1}/forgotPassword"; public static final String PERSONAL_CLOUD_RESET_PASSWORD_API = PATH_WITH_CURRENT_API_VERSION - + "/csp/{0}/clouds/personalCloud/{1}/resetPassword"; + + "/csp/{0}/clouds/personalClouds/{1}/resetPassword"; public static final String PERSONAL_CLOUD_AUTH_API = PATH_WITH_CURRENT_API_VERSION + "/csp/{0}/clouds/personalClouds/{1}/authenticate"; public static final String PAYMENT_API = PATH_WITH_CURRENT_API_VERSION + "/products/{0}/payments"; diff --git a/src/main/java/biz/neustar/pc/ui/controller/PersonalCloudRegistrationController.java b/src/main/java/biz/neustar/pc/ui/controller/PersonalCloudRegistrationController.java index 72a82d4..8bfc8df 100644 --- a/src/main/java/biz/neustar/pc/ui/controller/PersonalCloudRegistrationController.java +++ b/src/main/java/biz/neustar/pc/ui/controller/PersonalCloudRegistrationController.java @@ -24,12 +24,12 @@ of this software and associated documentation files (the "Software"), to deal package biz.neustar.pc.ui.controller; import java.io.IOException; -import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.FormParam; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,9 +40,11 @@ of this software and associated documentation files (the "Software"), to deal import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import biz.neustar.pc.ui.constants.UIRestPathConstants; +import biz.neustar.pc.ui.exception.PCloudErrorsUIException; import biz.neustar.pc.ui.exception.PCloudUIException; import biz.neustar.pc.ui.manager.impl.PCloudResponse; import biz.neustar.pc.ui.manager.impl.PersonalCloudManager; @@ -50,6 +52,8 @@ of this software and associated documentation files (the "Software"), to deal import biz.neustar.pcloud.rest.dto.CloudInfo; import biz.neustar.pcloud.rest.dto.CloudValidation; import biz.neustar.pcloud.rest.dto.DependentList; +import biz.neustar.pcloud.rest.dto.FeedbackInfo; +import biz.neustar.pcloud.rest.dto.PCloudError; import biz.neustar.pcloud.rest.dto.PaymentInfo; import biz.neustar.pcloud.rest.dto.PaymentResponse; import biz.neustar.pcloud.rest.dto.Synonym; @@ -164,15 +168,43 @@ PCloudResponse processChangePassword( return personalCloudManagerImpl.changePassword(cspCloudName, cloudName, cloudValidation); } + + @RequestMapping(value = UIRestPathConstants.PERSONAL_CLOUD_PROV_FEEDBACK_URI, method = RequestMethod.POST) + public @ResponseBody + PCloudResponse processFeedback(@RequestBody final FeedbackInfo feedbackInfo) { + return personalCloudManagerImpl.processFeedback(feedbackInfo); + + } + @SuppressWarnings("unchecked") @ExceptionHandler(PCloudUIException.class) - public @ResponseBody String handleUltraException(PCloudUIException exception, HttpServletRequest request, HttpServletResponse response) throws IOException { + public @ResponseBody + String handleException(PCloudUIException exception, HttpServletRequest request, HttpServletResponse response) + throws IOException { response.setStatus(exception.getStatusCode()); - + JSONArray errors = new JSONArray(); JSONObject error = new JSONObject(); - error.put("errorCode", exception.getErrorCode()); - error.put("errorMessage", exception.getErrorMessage()); - LOGGER.error("Error : {}", exception.getLocalizedMessage(), exception); - return error.toJSONString(); + error.put("errorCode", exception.getErrorCode()); + error.put("errorMessage", exception.getErrorMessage()); + errors.add(error); + LOGGER.debug("Errors : {}", exception.getLocalizedMessage(), exception); + return errors.toJSONString(); + } + + @SuppressWarnings("unchecked") + @ExceptionHandler(PCloudErrorsUIException.class) + public @ResponseBody + String handleUIException(PCloudErrorsUIException exception, HttpServletRequest request, HttpServletResponse response) + throws IOException { + response.setStatus(exception.getStatusCode()); + JSONArray errors = new JSONArray(); + for (PCloudError pCloudError : exception.getErrors()) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("errorCode", pCloudError.getErrorCode()); + jsonObject.put("errorMessage", pCloudError.getErrorMessage()); + errors.add(jsonObject); + } + LOGGER.debug("Errors : {}", errors, exception); + return errors.toJSONString(); } } diff --git a/src/main/java/biz/neustar/pc/ui/exception/PCloudErrorsUIException.java b/src/main/java/biz/neustar/pc/ui/exception/PCloudErrorsUIException.java new file mode 100644 index 0000000..a669e5d --- /dev/null +++ b/src/main/java/biz/neustar/pc/ui/exception/PCloudErrorsUIException.java @@ -0,0 +1,50 @@ +package biz.neustar.pc.ui.exception; + +import java.util.List; + +import biz.neustar.pc.ui.utils.PCloudErrorUtil; +import biz.neustar.pcloud.rest.dto.PCloudError; + +public class PCloudErrorsUIException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private List errors; + private int statusCode; + + public List getErrors() { + if (errors != null) { + for (PCloudError pCloudError : errors) { + pCloudError.setErrorMessage(PCloudErrorUtil.getProperty(Integer.toString(pCloudError.getErrorCode()))); + } + } + return errors; + } + + public void setErrors(List errors) { + this.errors = errors; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public PCloudErrorsUIException(List errors, int statusCode) { + super(); + this.errors = errors; + this.statusCode = statusCode; + } + + @Override + public String toString() { + return "PCloudErrorsUIException [errors=" + errors + ", statusCode=" + statusCode + "]"; + } + +} diff --git a/src/main/java/biz/neustar/pc/ui/exception/PCloudUIException.java b/src/main/java/biz/neustar/pc/ui/exception/PCloudUIException.java index 8f684c9..8403665 100644 --- a/src/main/java/biz/neustar/pc/ui/exception/PCloudUIException.java +++ b/src/main/java/biz/neustar/pc/ui/exception/PCloudUIException.java @@ -1,53 +1,65 @@ package biz.neustar.pc.ui.exception; -public class PCloudUIException extends RuntimeException{ +import biz.neustar.pc.ui.utils.PCloudErrorUtil; - /** +public class PCloudUIException extends RuntimeException { + + /** * */ private static final long serialVersionUID = 1L; int errorCode; String errorMessage; - int statusCode; - - /** + int statusCode; + + /** * @return the errorCode */ public int getErrorCode() { return errorCode; } + /** - * @param errorCode the errorCode to set + * @param errorCode + * the errorCode to set */ public void setErrorCode(int errorCode) { this.errorCode = errorCode; } + public String getErrorMessage() { - return errorMessage; - } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public int getStatusCode() { - return statusCode; - } - public void setStatusCode(int statusCode) { - this.statusCode = statusCode; - } - public PCloudUIException(int errorCode, String errorMessage, int statusCode) { - super(); - this.errorCode = errorCode; - this.errorMessage = errorMessage; - this.statusCode = statusCode; - } - public PCloudUIException(String errorMessage) { - super(); - this.errorMessage = errorMessage; - } - @Override - public String toString() { - return "PCloudUIException [errorCode="+errorCode+",errorMessage=" + errorMessage - + ", statusCode=" + statusCode + "]"; - } - + return PCloudErrorUtil.getProperty(Integer.toString(errorCode)); + + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public PCloudUIException(int errorCode, String errorMessage, int statusCode) { + super(); + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.statusCode = statusCode; + } + + public PCloudUIException(String errorMessage) { + super(); + this.errorMessage = errorMessage; + } + + @Override + public String toString() { + return "PCloudUIException [errorCode=" + errorCode + ",errorMessage=" + errorMessage + ", statusCode=" + + statusCode + "]"; + } + } diff --git a/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManager.java b/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManager.java index 2350b32..cecdabf 100644 --- a/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManager.java +++ b/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManager.java @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal import biz.neustar.pcloud.rest.dto.CloudInfo; import biz.neustar.pcloud.rest.dto.CloudValidation; import biz.neustar.pcloud.rest.dto.DependentList; +import biz.neustar.pcloud.rest.dto.FeedbackInfo; import biz.neustar.pcloud.rest.dto.PaymentInfo; import biz.neustar.pcloud.rest.dto.PaymentResponse; import biz.neustar.pcloud.rest.dto.Synonym; @@ -58,4 +59,6 @@ public interface PersonalCloudManager { public abstract PaymentResponse processPayment(ProductNames productName, PaymentInfo paymentInfo); public abstract PCloudResponse changePassword(String cspCloudName, String cloudName, CloudValidation cloudValidation); + + public abstract PCloudResponse processFeedback(FeedbackInfo feedbackInfo); } \ No newline at end of file diff --git a/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManagerImpl.java b/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManagerImpl.java index 1c1e207..5ac928f 100644 --- a/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManagerImpl.java +++ b/src/main/java/biz/neustar/pc/ui/manager/impl/PersonalCloudManagerImpl.java @@ -25,12 +25,14 @@ of this software and associated documentation files (the "Software"), to deal import java.io.IOException; import java.text.MessageFormat; +import java.util.List; import org.apache.http.HttpStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import biz.neustar.pc.ui.constants.UIRestPathConstants; +import biz.neustar.pc.ui.exception.PCloudErrorsUIException; import biz.neustar.pc.ui.exception.PCloudUIException; import biz.neustar.pcloud.PCRestClient; import biz.neustar.pcloud.ResponseData; @@ -38,6 +40,7 @@ of this software and associated documentation files (the "Software"), to deal import biz.neustar.pcloud.rest.dto.CloudInfo; import biz.neustar.pcloud.rest.dto.CloudValidation; import biz.neustar.pcloud.rest.dto.DependentList; +import biz.neustar.pcloud.rest.dto.FeedbackInfo; import biz.neustar.pcloud.rest.dto.PCloudError; import biz.neustar.pcloud.rest.dto.PaymentInfo; import biz.neustar.pcloud.rest.dto.PaymentResponse; @@ -45,6 +48,7 @@ of this software and associated documentation files (the "Software"), to deal import biz.neustar.pcloud.rest.dto.SynonymInfo; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; import com.sun.jersey.api.representation.Form; /** @@ -56,9 +60,10 @@ public class PersonalCloudManagerImpl implements PersonalCloudManager { * */ private PCRestClient pcRestClient; - - public PersonalCloudManagerImpl(PCRestClient pcRestClient) { + private String feedbackEmail; + public PersonalCloudManagerImpl(PCRestClient pcRestClient, String feedbackEmail) { this.pcRestClient = pcRestClient; + this.feedbackEmail = feedbackEmail; } /* @@ -212,23 +217,30 @@ public Entity handleException(ResponseData responsedata, Class error = new ObjectMapper().readValue(responsedata.getBody(), PCloudError.class); throw new PCloudUIException(error.getErrorCode(), error.getErrorMessage(), responsedata.getStatus()); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.error("Might be list of errors :"); + List errors; + try { + errors = new ObjectMapper().readValue(responsedata.getBody(), TypeFactory.defaultInstance() + .constructCollectionType(List.class, PCloudError.class)); + throw new PCloudErrorsUIException(errors, responsedata.getStatus()); + } catch (IOException e1) { + LOGGER.error("Error while parsing response data for error condition", e1); + } } - } else { - try { - entity = entityType.cast(new ObjectMapper().readValue(responsedata.getBody(), entityType)); - } catch (Exception e) { - LOGGER.info("inside exception"); - e.printStackTrace(); + LOGGER.error("Error while parsing response data for success", e); } - } return entity; + } + @Override + public PCloudResponse processFeedback(FeedbackInfo feedbackInfo) { + feedbackInfo.setToEmail(feedbackEmail); + return handleException(pcRestClient.post(UIRestPathConstants.PERSONAL_CLOUD_PROV_FEEDBACK_URI, feedbackInfo), + PCloudResponse.class); } } diff --git a/src/main/java/biz/neustar/pc/ui/utils/PCloudErrorUtil.java b/src/main/java/biz/neustar/pc/ui/utils/PCloudErrorUtil.java new file mode 100644 index 0000000..6d40b59 --- /dev/null +++ b/src/main/java/biz/neustar/pc/ui/utils/PCloudErrorUtil.java @@ -0,0 +1,58 @@ +package biz.neustar.pc.ui.utils; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PCloudErrorUtil { + private Logger LOGGER = LoggerFactory.getLogger(PCloudErrorUtil.class); + private static Properties props; + + static { + props = new Properties(); + try { + PCloudErrorUtil util = new PCloudErrorUtil(); + props = util.getPropertiesFromClasspath("errors.properties"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // private constructor + private PCloudErrorUtil() { + } + + public static String getProperty(String key) { + return props.getProperty(key).trim(); + } + + public static Set getkeys() { + return props.keySet(); + } + + /** + * Loads properties file from classpath + * + * @param fileName + * @return + * @throws IOException + */ + private Properties getPropertiesFromClasspath(String fileName) throws IOException { + Properties props = new Properties(); + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileName); + + if (inputStream == null) { + LOGGER.error("Property file '" + fileName + "' not found in the classpath"); + throw new FileNotFoundException("Property file '" + fileName + "' not found in the classpath"); + } + props.load(inputStream); + return props; + } +} diff --git a/src/main/resources/errors.properties b/src/main/resources/errors.properties new file mode 100644 index 0000000..048db32 --- /dev/null +++ b/src/main/resources/errors.properties @@ -0,0 +1,65 @@ +1001=Invalid cynja id. +1002= is required field. +1003=Invalid input: +1004=Invalid phone number. +1005=Invalid email address. +1006=Invalid password. +1007=Password and confirm password should be same. +1008=Cynja id is not available. +1008=Invalid request type. +1009=is null +1010=Invalid identifier. +1011=Cynja id does not exist. +1012=payment ID does not exist. +1013=Object already exist in the system. +1014=Invalid cynja id or password. +1015=Guardian cynja id does not exist. +1016=Cloud entity id {} does not exist. +1017=Invalid guardian cynja id or password. +1018=Guardian cynja id provided not authorized. +// CSP related errors +2001=CSP provided does not exist in the system. +// Error messages +3001=Error while registering cynja id in user cloud. +3002=Error while registering phone and email in user cloud. +3003=Error while registering cynja id in csp cloud. +3004=Error while registering user cloud in csp cloud. +3005=Error while registering services in csp cloud. +3006=Error while registering cynja id in XDI registry. +3007=Error while registering cynja id in RN. +3008=Error while updating password. +3009=Error while fetching dependent cynja ids. +3010=Error while fetching synonym cynja ids. +3011=Error while setting guardianship in CSP. +3012=Error while setting guardianship in cloud. +3013=Problem with cynja id provided to retrieve signature private key. +3014=Problem in retrieving signature private key. +3015=You need to login first to logout. +// Auth error messages +6001=Token not found, expired or invalid +6002=User not Active +6003=Token format expected in header is \"Token: Bearer \" +6004=Authorization Header required +6005=grantType not supported +6006=invalid request +6007=invalid_request:username parameter is required for grantType=password +6008=invalid_request:password parameter is required for grantType=password +6009=invalid_request:refreshToken parameter is required for grantType=refreshToken +6010=Problem with authentication. +6011=The CSP cynja id or password is incorrect. +// Uniqueness check +7000=Email and phone number has already been used for a cynja id. +7001=Email has already been used for a cynja id. +7002=Phone number has already been used for a cynja id. +7003=Problem checking Phone/Email Uniqueness. +7004=System Error sending validation messages. Please check email and mobile phone number. +7005=Given email address does not match with registered email address. +7006=Given phone number does not match with registered phone number. +7007=The cynja id provided does not exist in CynjaSpace. +7008=No dependents found +7009=No synonyms found + +// Validation code +8001=Invalid codes. +8002=Problem validating code. +500=Sorry! Unable to process your request. Please contact customer support or try again after sometime. \ No newline at end of file diff --git a/src/main/resources/pcloud.default.properties b/src/main/resources/pcloud.default.properties index 7c9c699..68b90c2 100644 --- a/src/main/resources/pcloud.default.properties +++ b/src/main/resources/pcloud.default.properties @@ -2,4 +2,5 @@ pcloud.csp.cspUserName=+testcsp pcloud.csp.password=whitelabel123 pcloud.csp.cspTCURL=http://www.onexus.com/terms.html pcloud.csp.baseUrl=http://localhost:8080 -pcloud.csp.authUrl=/v1/authorization/token \ No newline at end of file +pcloud.csp.authUrl=/v1/authorization/token +pcloud.csp.feedbackEmail=feedback@cynjaspace.com \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/spring_context.xml b/src/main/webapp/WEB-INF/spring_context.xml index 981fdbb..cc69d70 100644 --- a/src/main/webapp/WEB-INF/spring_context.xml +++ b/src/main/webapp/WEB-INF/spring_context.xml @@ -57,8 +57,10 @@ + + +
+
+
+ + +
+ + + + + + + + +
Back   + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ {{successMessageAddDep}}
Guardian nameActionConfirmation status
{{guardianCloudName}} Yes
{{ addList }}Delete
No item found.
{{addGuardianCloud.cloudName}} No
+ +
+ + +
+ + +
+ + +
+ +
+ \ No newline at end of file diff --git a/src/main/webapp/angular/views/additionalCloud.html b/src/main/webapp/angular/views/additionalCloud.html index dbe9c24..4ef8988 100644 --- a/src/main/webapp/angular/views/additionalCloud.html +++ b/src/main/webapp/angular/views/additionalCloud.html @@ -77,7 +77,7 @@ -