From 1af4b2c9e435ce85ee4437668dd114f1658b890b Mon Sep 17 00:00:00 2001 From: sblsreddy Date: Sun, 31 Oct 2021 10:54:56 -0500 Subject: [PATCH 01/10] Create StringHelper.java --- src/main/java/com/example/StringHelper.java | 361 ++++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 src/main/java/com/example/StringHelper.java diff --git a/src/main/java/com/example/StringHelper.java b/src/main/java/com/example/StringHelper.java new file mode 100644 index 0000000..aa399a0 --- /dev/null +++ b/src/main/java/com/example/StringHelper.java @@ -0,0 +1,361 @@ +package utils; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + + + +import javax.xml.bind.DatatypeConverter; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import java.text.DateFormat; +import java.text.NumberFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.regex.Pattern; + +/** + * String helper class. + */ +public final class StringHelper { + /** + * EMPTY_STRING. + */ + private static final String EMPTY_STRING = ""; + /** + * The LOGGER. + */ + private static Logger LOGGER = LogFactory.getLogger(StringHelper.class); + + /** + * Build a comma separated String for a java.util.List of String objects. + * + * @param stringList java.util.List of String objects + * @return comma separated String + */ + public static String buildCSStringFromList(final List stringList) { + StringBuilder csString = new StringBuilder(""); + if (stringList != null && !stringList.isEmpty()) { + for (String string : stringList) { + if (csString.length() > 0) { + csString.append(", "); + } + csString.append(string.trim()); + } + } + return csString.toString(); + } + + /** + * Build a full name from first name and last name in first last format. + * + * @param firstName First name + * @param lastName Last name + * @return Full name in first last format + */ + public static String buildFirstLastName(final String firstName, final String lastName) { + String name = null; + if (firstName != null || lastName != null) { + final StringBuilder builder = new StringBuilder(""); + if (firstName != null && !firstName.trim().equals("")) { + builder.append(firstName.trim()); + } + if (lastName != null && !lastName.trim().equals("")) { + if (builder.length() > 0) { + builder.append(" "); + } + builder.append(lastName.trim()); + } + name = builder.toString(); + } + return name; + } + + /** + * Build a full name from first name and last name in first last format. + * + * @param firstName First name + * @param middleName Middle name + * @param lastName Last name + * @return Full name in first last format + */ + public static String buildFirstMiddleLastName(final String firstName, final String middleName, final String lastName) { + String name = null; + if (firstName != null || lastName != null) { + final StringBuilder builder = new StringBuilder(""); + if (firstName != null && !firstName.trim().equals("")) { + builder.append(firstName.trim()); + } + if (middleName != null && !middleName.trim().equals("")) { + if (builder.length() > 0) { + builder.append(" "); + } + builder.append(middleName.trim()); + } + if (lastName != null && !lastName.trim().equals("")) { + if (builder.length() > 0) { + builder.append(" "); + } + builder.append(lastName.trim()); + } + name = builder.toString(); + } + return name; + } + + /** + * Build a full name from first name and last name in last, first format. + * + * @param firstName First name + * @param lastName Last name + * @return Full name in last, first format + */ + public static String buildLastFirstName(final String firstName, final String lastName) { + String name = null; + if (firstName != null || lastName != null) { + final StringBuilder builder = new StringBuilder(""); + if (lastName != null && !lastName.trim().equals("")) { + builder.append(lastName.trim()); + } + if (firstName != null && !firstName.trim().equals("")) { + if (builder.length() > 0) { + builder.append(", "); + } + builder.append(firstName.trim()); + } + name = builder.toString(); + } + return name; + } + + /** + * Format object as a currency. + * + * @param obj Object + * @return Object formatted as currency + */ + public static String formatCurrency(final Object obj) { + return NumberFormat.getCurrencyInstance().format(obj); + } + + /** + * Format a SSN String 123456789 as 123-45-6789 format. + * + * @param ssnString SSN String to format + * @return formatted SSN String or null if ssnString argument is null + */ + /*public static String formatSSN(final String ssnString) { + String string = null; + if (ssnString != null) { + final StringBuilder builder = new StringBuilder(""); + builder.append(ssnString.substring(0, 3)).append('-').append(ssnString.substring(3, StopLossClaimsConstants.INT_5)).append('-').append(ssnString.substring(StopLossClaimsConstants.INT_5)); + string = builder.toString(); + } + return string; + } +*/ + /** + * Determine if a java.lang.String is empty or not. + * + * @param stringIn String to test + * @return true if stringIn is null or length is 0, false otherwise + */ + public static boolean isEmptyString(final String stringIn) { + boolean result = true; + if (stringIn != null && !stringIn.trim().equals(EMPTY_STRING) && !stringIn.equalsIgnoreCase("null")) { + result = false; + } + return result; + } + + /** + * Parse a Base64 encoded String. + * + * @param stringIn Base64 encoded String + * @return parse value + */ + public static String parseBase64Binary(final String stringIn) { + return new String(DatatypeConverter.parseBase64Binary(stringIn)); + } + + /** + * Trims the String value if not null. + * + * @param s String to be trimmed + * @return null or trimmed string value + */ + public static String safeTrim(final String s) { + String str = s; + if (s != null) { + str = s.trim(); + } + return str; + } + + /** + * Check if two String objects are equal. + * + * @param stringOne First String to compare + * @param stringTwo Second String to compare + * @return true if equal, false otherwise + */ + public static boolean stringEquals(final String stringOne, final String stringTwo) { + boolean result = false; + if (stringOne == null) { + if (stringTwo == null) { + result = true; + } + } + else if (stringTwo != null) { + result = stringOne.trim().equalsIgnoreCase(stringTwo.trim()); + } + return result; + } + + /** + * Check if a string exists in a var arg of Strings. + * + * @param string String object to look for + * @param strings Vararg of String objects to search + * @return true if string found, otherwise false + */ + public static boolean stringIn(final String string, final String... strings) { + boolean found = false; + if (strings != null) { + for (String stringsString : strings) { + if (stringsString != null && StringHelper.stringEquals(string, stringsString)) { + found = true; + break; + } + } + } + return found; + } + + /** + * Attempt to translate a Boolean to a String literal. + * + * @param booleanObject Boolean to translate + * @return "Y" if booleanObject is not null and equals Boolean.TRUE, "N" otherwise + */ + public static String translateBooleanToString(final Boolean booleanObject) { + if (booleanObject != null && booleanObject.equals(Boolean.TRUE)) { + return "Y"; + } + return "N"; + } + + /** + * Attempt to translate a String literal into a Boolean value. + * + * @param string String to translate + * @return Boolean.TRUE if String can be translated and value is "Y" or "YES", Boolean.FALSE otherwise + */ + public static Boolean translateStringToBoolean(final String string) { + if (string != null && (string.trim().equalsIgnoreCase("Y") || string.trim().equalsIgnoreCase("YES"))) { + return Boolean.TRUE; + } + return Boolean.FALSE; + } + + /** + * Translate Object to String. + * + * @param obj Object to be translated + * @return string value + */ + public static String translateObjectToString(final Object obj) { + return (obj == null) ? EMPTY_STRING : obj.toString(); + } + + /** + * Jira ACC-1821 + */ + public static String trimUserID(String loggedinUser) { + String name = ""; + if (!(StringUtils.isAlphanumeric(loggedinUser))) { + String email2UserId = StringUtils.remove(loggedinUser, "@SUNLIFE.COM"); + System.out.println(email2UserId); + } else { + System.out.println(loggedinUser); + } + return name; + } + + /** + * Check if a user id passed contains @ and is more than 30 character. + * + * @param userId String object to look for + * @return user id without @SUNLIFE.COM or GCSUser if its still more than 30 character + */ + public static String syncEventTableUserIdValidation(String userId) { + String user = userId; + if (userId != null && userId.contains("@")) { + // Remove the @sunlife.com from user name as we have limit on userId column length in GCS database + user = userId.split(Pattern.quote("@"))[0]; + } + if (user != null && user.length()>30){ + MCUtilities.logIfDebug(LOGGER,"Setting User ID as : GCSUser. Since user id : " + user + " is still grater than 30 character " ); + user = "GCS"; + } + + return user; + } + + /** + * Convert creation date string to XMLGregorianCalendar format . + * + * @param dateString creation date string object to convert + * @return XMLGregorianCalendar for the given date string. + */ + public static XMLGregorianCalendar getXMLGregorianCalendarFromCreationDate(String dateString) { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + XMLGregorianCalendar xmlDate = null; + try { + Date date = dateFormat.parse(dateString); + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(date); + xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); + } catch (Exception e) { + MCUtilities.logIfDebug(LOGGER, "Exception in getXMLGregorianCalendarFromCreationDate :- " + e.getMessage()); + + } + MCUtilities.logIfDebug(LOGGER, "XMLGregorianCalendar :- " + xmlDate); + return xmlDate; + } + + public static String currentDateAndTimeWithAmPmmarker() { + //Displaying current date and time in 12 hour format with AM/PM + DateFormat dateFormat2 = new SimpleDateFormat( "MM/dd/yyyy hh.mm aa" ); + String dateString2 = dateFormat2.format( new Date() ).toString(); + MCUtilities.logIfDebug( LOGGER, "Displaying current date and time in AM/PM: " + dateString2 ); + return dateString2; + } + + public static String getCurrentDateAndTimeString() { + DateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:sss" ); + GregorianCalendar gregorianCalendar = new GregorianCalendar(); + XMLGregorianCalendar now = null; + DatatypeFactory datatypeFactory = null; + try { + datatypeFactory = DatatypeFactory.newInstance(); + now = datatypeFactory.newXMLGregorianCalendar( gregorianCalendar ); + } catch (DatatypeConfigurationException e) { + MCUtilities.logIfDebug( LOGGER, "Current date and time in DatatypeConfigurationException block : " + e ); + } + GregorianCalendar gCalendar = now.toGregorianCalendar(); + //Converted to date object + Date date = gCalendar.getTime(); + //Formatted to String value + String dateString = df.format( date ); + MCUtilities.logIfDebug( LOGGER, "Current Date & time string is : " + dateString ); + return dateString; + } + /** + * Private constructor. + */ + private StringHelper() { } +} From 62f8884f9684b66798d12589c19edc9be4a1aa99 Mon Sep 17 00:00:00 2001 From: sblsreddy Date: Sun, 31 Oct 2021 10:58:33 -0500 Subject: [PATCH 02/10] Update SalesForceURLTest.java --- .../java/com/example/SalesForceURLTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/SalesForceURLTest.java b/src/main/java/com/example/SalesForceURLTest.java index 610356f..8e012ca 100644 --- a/src/main/java/com/example/SalesForceURLTest.java +++ b/src/main/java/com/example/SalesForceURLTest.java @@ -34,17 +34,17 @@ public static String getStatus(String url) throws IOException { code = connection.getResponseCode();*/ // With Proxy Settings - /* System.setProperty("http.proxyHost", "proxy-mwg-http.ca.sunlife"); + /* System.setProperty("http.proxyHost", "Proxy url"); System.setProperty("http.proxyPort", "8080"); - System.setProperty("http.proxyUser", "user.qps@sunlife.com.intsb"); - System.setProperty("http.proxyPassword", "4qps1997aj1nGNuDAVOHqo6iLAxlSTYe");*/ + System.setProperty("http.proxyUser", "username"); + System.setProperty("http.proxyPassword", "some password");*/ URL siteURL = new URL(url); - /*Proxy proxy1 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-mwg-http.ca.sunlife", 8080)); + /*Proxy proxy1 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyurl", 8080)); HttpURLConnection connection1 = (HttpURLConnection) siteURL.openConnection(proxy1); connection1.setRequestMethod("GET"); connection1.setConnectTimeout(3000); - connection1.setRequestProperty( "http.proxyUser", "user.qps@sunlife.com.intsb" ); - connection1.setRequestProperty( "http.proxyPassword", "4qps1997aj1nGNuDAVOHqo6iLAxlSTYe" ); + connection1.setRequestProperty( "http.proxyUser", "user" ); + connection1.setRequestProperty( "http.proxyPassword", "some password" ); connection1.connect(); code = connection1.getResponseCode(); System.out.println(url + "\t\t Connection is using proxy with port 8080 :" + connection1.usingProxy()); @@ -56,12 +56,12 @@ public static String getStatus(String url) throws IOException { result = "-> Yellow <-\t" + "Code: " + code; }*/ - Proxy proxy2 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-mwg-http.ca.sunlife", 8443)); + Proxy proxy2 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy url", 8443)); HttpURLConnection connection2 = (HttpURLConnection) siteURL.openConnection(proxy2); connection2.setRequestMethod("GET"); connection2.setConnectTimeout(3000); - connection2.setRequestProperty( "http.proxyUser", "user.qps@sunlife.com.intsb" ); - connection2.setRequestProperty( "http.proxyPassword", "4qps1997aj1nGNuDAVOHqo6iLAxlSTYe" ); + connection2.setRequestProperty( "http.proxyUser", "user" ); + connection2.setRequestProperty( "http.proxyPassword", "some pass" ); connection2.connect(); code = connection2.getResponseCode(); From cc15f68e9790d78eea94b70bbb35240f15c38906 Mon Sep 17 00:00:00 2001 From: sblsreddy Date: Sun, 31 Oct 2021 11:00:11 -0500 Subject: [PATCH 03/10] Create ListRequest.java --- src/main/java/com/example/ListRequest.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/example/ListRequest.java diff --git a/src/main/java/com/example/ListRequest.java b/src/main/java/com/example/ListRequest.java new file mode 100644 index 0000000..2939a87 --- /dev/null +++ b/src/main/java/com/example/ListRequest.java @@ -0,0 +1,33 @@ + + +import java.util.*; + +public class ListRequest { + //Activity Processor Request {policy=204393, party=112, doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=null} + public static void main(String[] args) { + String existingRequest = "policy=204393, party=112, doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=null"; + String caseRequest = "policy=[204393,204390,204292], party=[95,100,112,200], doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=null"; + String policyRequest = "policy=[204393], party=[112,95,200], doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=[NTN-19-DI-10,NTN-23-DI-11]"; + String partyRequest = "policy=[204393,204390,204292], party=[112], doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=[NTN-19-DI-10,NTN-23-DI-11]"; + + String[] kvPairs = existingRequest.split(",\\s+"); + for(String kvPair : kvPairs){ + System.out.println(kvPair + "\n"); + String[] kv = kvPair.split("="); + String key = kv[0]; + String value = kv[1]; + // String items[] = value.split(","); + String replace = value.replace("[",""); + String replace1 = replace.replace("]",""); + List itemsList = new ArrayList(Arrays.asList(replace1.split(","))); + Map requestMap = new HashMap(); + Map detailsMap = new HashMap(); + for(String itemValue : itemsList){ + System.out.println( "Key is : " + key + " ::: Value is : " + itemValue); + detailsMap.put(key,itemValue); + } + + } + } + +} From a09bc67adc54d254129dd40176ed291f20d23a4f Mon Sep 17 00:00:00 2001 From: sblsreddy Date: Sun, 31 Oct 2021 11:05:01 -0500 Subject: [PATCH 04/10] Create build.gradle --- src/main/java/com/example/build.gradle | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/com/example/build.gradle diff --git a/src/main/java/com/example/build.gradle b/src/main/java/com/example/build.gradle new file mode 100644 index 0000000..299d524 --- /dev/null +++ b/src/main/java/com/example/build.gradle @@ -0,0 +1,56 @@ +configurations { + all*.exclude module: 'spring-boot-starter-logging' +} + +// Defines the dependencies for this build +dependencies { + // Sunlife dependency jars + compile(group: 'some.us.dc.utility', name: 'log', version: '0.2') + compile(group: 'some.us.dc.utility', name: 'dbc', version: '1.0') + compile(group: 'some.us.dc.mescenter', name: 'mcplugin-framework', version: '2.17.0.3-20201007.202552-1') + { + exclude module: 'camel-core' + exclude module: 'camel-cxf' + exclude module: 'camel-cxf-transport' + exclude module: 'camel-ejb' + exclude module: 'camel-jms' + exclude module: 'camel-spring' + exclude module: 'jdom' + exclude module: 'partner' + exclude module: 'spring-oxm' + exclude module: 'commons-codec' + exclude module: 'commons-collections' + exclude module: 'commons-io' + exclude module: 'cxf' + } + compile(group: 'some.us.dc.mescenter', name: 'mcplugin-common', version: '2.17.0') + { + exclude module: 'mcplugin-framework' + exclude module: 'partner' + exclude module: 'commons-io' + } + + } + + /****************************************************************************************************************** + JAVA-PLUGIN: Creates an output JAR with MANIFEST based on the classes and resources within this project + @Link: https://docs.gradle.org/current/userguide/java_plugin.html#sec:jar + ***************************************************************************************************************** */ +group = currentGroupId +version = currentVersion +jar { + manifest { + attributes( + "Member": "Enterprise Application Development", + "Implementation-Group": group, + "Provider": "Application Development", + "Implementation-Title": currentArtifactId, + "Implementation-Version": currentVersion, + "Implementation-Vendor": "Sunlife", + "Created-By": System.getProperty('java.version') + ' (' + System.getProperty('java.vendor') + ')', + "Built-With": "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}", + "Built-Time": new Date().format('dd-MMM-yyyy HH:mm:ss') + ) + } + baseName 'my-gateway-plugin' +} From da518f1798357fedabca642cc8c8592e1f6b523c Mon Sep 17 00:00:00 2001 From: SSangala Date: Tue, 13 May 2025 17:47:10 -0500 Subject: [PATCH 05/10] Adding web & tomcat dependency ( which were missing ) to fix as clean slate spring boot project. --- pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6b0ac4c..4ede1e2 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,14 @@ org.springframework.boot spring-boot-starter - + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + org.springframework.boot spring-boot-starter-test From 7ae1de461d253996f2bd664d7cc452797836b10a Mon Sep 17 00:00:00 2001 From: SSangala Date: Tue, 13 May 2025 17:48:01 -0500 Subject: [PATCH 06/10] Commented unwanted files --- .../java/com/example/SplitStringTest.java | 58 +++++--- src/main/java/com/example/StringHelper.java | 132 ++++++++++++------ src/main/java/com/example/Utilities.java | 4 +- src/main/java/com/example/XMLHelper.java | 60 +++++--- 4 files changed, 174 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/example/SplitStringTest.java b/src/main/java/com/example/SplitStringTest.java index 52c03cf..9e8fc4a 100644 --- a/src/main/java/com/example/SplitStringTest.java +++ b/src/main/java/com/example/SplitStringTest.java @@ -1,3 +1,4 @@ +/* package sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.sample.processor; @@ -41,14 +42,16 @@ private static Object deserialize(String s) throws IOException, return o;//(o.toString().substring(1, o.toString().length()-1)); } - /** + */ +/** * To get a value from string of hashmap by passing key that existed in Hashmap before converting to String. * Sample string: {fld_category=Principal category, test=test 1, fld_categoryID=1} * * @param string * @param key * @return value - */ + *//* + public static String getValueFromStringOfHashMap(String string, String key) { @@ -62,7 +65,8 @@ public static String getValueFromStringOfHashMap(String string, String key) { return value; } - /*@Test + */ +/*@Test public void testStringHelper() { InteractiveCreateDocumentRequestContract contract = StringHelper.translateStringToObject(alpha); System.out.println( " print contract : Policies " + contract.getPolicy().get(0) + ":::" + contract.getPolicy().get(1)); @@ -70,7 +74,8 @@ public void testStringHelper() { System.out.println( " print contract : docType " + contract.getDoctype()); System.out.println( " print contract : user " + contract.getUser()); System.out.println( " print contract : case " + contract.getCaseNumber().get(0)); - }*/ + }*//* + @Test public void testStringSplits() { @@ -135,7 +140,9 @@ public void testEmailIdSplit() { @Test public void testXMLGregorianCalendar() { - /* Create Date Object */ + */ +/* Create Date Object *//* + Date date = new Date(); XMLGregorianCalendar xmlDate = null; GregorianCalendar gc = new GregorianCalendar(); @@ -192,9 +199,12 @@ public void testRegexStartEndCharacter() { System.out.println("hello"); } } - /* + */ +/* public void testMap1() { - *//* HashMap mapQueryParams = new HashMap<>(); + *//* +*/ +/* HashMap mapQueryParams = new HashMap<>(); mapQueryParams.put("doctype", "doc"); mapQueryParams.put("party", "[[218454,267858]]"); mapQueryParams.put("policy", new ArrayList<>().add("115")); @@ -207,6 +217,8 @@ public void testMap1() { System.out.println(result); System.out.println(party); System.out.println(policy);*//* +*/ +/* try { JSONObject jsonObject = new JSONObject("{policy=[[218445,204245]], party=[[115,266,57]], doctype=Claim Approval Letter, user=null, caseNumber=[NTN-19-DI-01]}"); @@ -216,7 +228,8 @@ public void testMap1() { }catch (JSONException err){ System.out.println(err.getMessage()); } - }*/ + }*//* + @Test public void testListItems() { @@ -236,7 +249,8 @@ public void testListItems() { } - /* @Test + */ +/* @Test public void testjsonString(){ String jsonString = null; try { @@ -250,9 +264,11 @@ public void testjsonString(){ } System.out.println(jsonString); - }*/ + }*//* + - /*@Test + */ +/*@Test public void testmapjson() { JSONObject jsonObject = null; JSONArray array = null; @@ -281,7 +297,8 @@ public void testmapjson() { e.printStackTrace(); } - }*/ + }*//* + @Test public void testStringList() { @@ -374,9 +391,11 @@ public void testPrefixRemove() { if (documentId.matches("[0-9]+")) { System.out.println(" yes it is Number" + documentId); } else { - /*System.out.println(" No it is not a Number " + documentId); + */ +/*System.out.println(" No it is not a Number " + documentId); documentId = documentId.replaceAll("DG_", ""); - System.out.println(" Number " + documentId);*/ + System.out.println(" Number " + documentId);*//* + if (documentId.startsWith("DG_")) { String ddocumentId = documentId.replaceAll("DG_", ""); System.out.println("Inside condition " + ddocumentId); @@ -392,10 +411,12 @@ public void testKeyValuePairSplit() { Map map = new HashMap(); String removeBrackets = jsonObjectString.substring(1, jsonObjectString.length() - 1); String[] keyValueStrings = removeBrackets.split(","); - /*for(int i =0; i < keyValueStrings.length ; i++) { + */ +/*for(int i =0; i < keyValueStrings.length ; i++) { String[] items =keyValueStrings[i].split("="); System.out.println("Key : " + items[0] + " and Value : " + items[1]); - }*/ + }*//* + for (String eachString : keyValueStrings) { String[] keyValue = eachString.split(" *= *"); @@ -456,7 +477,9 @@ public void testList() { } private XMLGregorianCalendar getXMLGregorianCalendar() { - /* Create Date Object */ + */ +/* Create Date Object *//* + Date date = new Date(); XMLGregorianCalendar xmlDate = null; GregorianCalendar gc = new GregorianCalendar(); @@ -473,3 +496,4 @@ private XMLGregorianCalendar getXMLGregorianCalendar() { return xmlDate; } } +*/ diff --git a/src/main/java/com/example/StringHelper.java b/src/main/java/com/example/StringHelper.java index aa399a0..1babc5d 100644 --- a/src/main/java/com/example/StringHelper.java +++ b/src/main/java/com/example/StringHelper.java @@ -1,3 +1,4 @@ +/* package utils; import org.apache.commons.lang.StringUtils; @@ -17,25 +18,33 @@ import java.util.List; import java.util.regex.Pattern; +*/ /** * String helper class. - */ + *//* + public final class StringHelper { - /** + */ +/** * EMPTY_STRING. - */ + *//* + private static final String EMPTY_STRING = ""; - /** + */ +/** * The LOGGER. - */ + *//* + private static Logger LOGGER = LogFactory.getLogger(StringHelper.class); - /** + */ +/** * Build a comma separated String for a java.util.List of String objects. * * @param stringList java.util.List of String objects * @return comma separated String - */ + *//* + public static String buildCSStringFromList(final List stringList) { StringBuilder csString = new StringBuilder(""); if (stringList != null && !stringList.isEmpty()) { @@ -49,13 +58,15 @@ public static String buildCSStringFromList(final List stringList) { return csString.toString(); } - /** + */ +/** * Build a full name from first name and last name in first last format. * * @param firstName First name * @param lastName Last name * @return Full name in first last format - */ + *//* + public static String buildFirstLastName(final String firstName, final String lastName) { String name = null; if (firstName != null || lastName != null) { @@ -74,14 +85,16 @@ public static String buildFirstLastName(final String firstName, final String las return name; } - /** + */ +/** * Build a full name from first name and last name in first last format. * * @param firstName First name * @param middleName Middle name * @param lastName Last name * @return Full name in first last format - */ + *//* + public static String buildFirstMiddleLastName(final String firstName, final String middleName, final String lastName) { String name = null; if (firstName != null || lastName != null) { @@ -106,13 +119,15 @@ public static String buildFirstMiddleLastName(final String firstName, final Stri return name; } - /** + */ +/** * Build a full name from first name and last name in last, first format. * * @param firstName First name * @param lastName Last name * @return Full name in last, first format - */ + *//* + public static String buildLastFirstName(final String firstName, final String lastName) { String name = null; if (firstName != null || lastName != null) { @@ -131,23 +146,28 @@ public static String buildLastFirstName(final String firstName, final String las return name; } - /** + */ +/** * Format object as a currency. * * @param obj Object * @return Object formatted as currency - */ + *//* + public static String formatCurrency(final Object obj) { return NumberFormat.getCurrencyInstance().format(obj); } - /** + */ +/** * Format a SSN String 123456789 as 123-45-6789 format. * * @param ssnString SSN String to format * @return formatted SSN String or null if ssnString argument is null - */ - /*public static String formatSSN(final String ssnString) { + *//* + + */ +/*public static String formatSSN(final String ssnString) { String string = null; if (ssnString != null) { final StringBuilder builder = new StringBuilder(""); @@ -156,13 +176,16 @@ public static String formatCurrency(final Object obj) { } return string; } -*/ - /** +*//* + + */ +/** * Determine if a java.lang.String is empty or not. * * @param stringIn String to test * @return true if stringIn is null or length is 0, false otherwise - */ + *//* + public static boolean isEmptyString(final String stringIn) { boolean result = true; if (stringIn != null && !stringIn.trim().equals(EMPTY_STRING) && !stringIn.equalsIgnoreCase("null")) { @@ -171,22 +194,26 @@ public static boolean isEmptyString(final String stringIn) { return result; } - /** + */ +/** * Parse a Base64 encoded String. * * @param stringIn Base64 encoded String * @return parse value - */ + *//* + public static String parseBase64Binary(final String stringIn) { return new String(DatatypeConverter.parseBase64Binary(stringIn)); } - /** + */ +/** * Trims the String value if not null. * * @param s String to be trimmed * @return null or trimmed string value - */ + *//* + public static String safeTrim(final String s) { String str = s; if (s != null) { @@ -195,13 +222,15 @@ public static String safeTrim(final String s) { return str; } - /** + */ +/** * Check if two String objects are equal. * * @param stringOne First String to compare * @param stringTwo Second String to compare * @return true if equal, false otherwise - */ + *//* + public static boolean stringEquals(final String stringOne, final String stringTwo) { boolean result = false; if (stringOne == null) { @@ -215,13 +244,15 @@ else if (stringTwo != null) { return result; } - /** + */ +/** * Check if a string exists in a var arg of Strings. * * @param string String object to look for * @param strings Vararg of String objects to search * @return true if string found, otherwise false - */ + *//* + public static boolean stringIn(final String string, final String... strings) { boolean found = false; if (strings != null) { @@ -235,12 +266,14 @@ public static boolean stringIn(final String string, final String... strings) { return found; } - /** + */ +/** * Attempt to translate a Boolean to a String literal. * * @param booleanObject Boolean to translate * @return "Y" if booleanObject is not null and equals Boolean.TRUE, "N" otherwise - */ + *//* + public static String translateBooleanToString(final Boolean booleanObject) { if (booleanObject != null && booleanObject.equals(Boolean.TRUE)) { return "Y"; @@ -248,12 +281,14 @@ public static String translateBooleanToString(final Boolean booleanObject) { return "N"; } - /** + */ +/** * Attempt to translate a String literal into a Boolean value. * * @param string String to translate * @return Boolean.TRUE if String can be translated and value is "Y" or "YES", Boolean.FALSE otherwise - */ + *//* + public static Boolean translateStringToBoolean(final String string) { if (string != null && (string.trim().equalsIgnoreCase("Y") || string.trim().equalsIgnoreCase("YES"))) { return Boolean.TRUE; @@ -261,19 +296,23 @@ public static Boolean translateStringToBoolean(final String string) { return Boolean.FALSE; } - /** + */ +/** * Translate Object to String. * * @param obj Object to be translated * @return string value - */ + *//* + public static String translateObjectToString(final Object obj) { return (obj == null) ? EMPTY_STRING : obj.toString(); } - /** + */ +/** * Jira ACC-1821 - */ + *//* + public static String trimUserID(String loggedinUser) { String name = ""; if (!(StringUtils.isAlphanumeric(loggedinUser))) { @@ -285,12 +324,14 @@ public static String trimUserID(String loggedinUser) { return name; } - /** + */ +/** * Check if a user id passed contains @ and is more than 30 character. * * @param userId String object to look for * @return user id without @SUNLIFE.COM or GCSUser if its still more than 30 character - */ + *//* + public static String syncEventTableUserIdValidation(String userId) { String user = userId; if (userId != null && userId.contains("@")) { @@ -305,12 +346,14 @@ public static String syncEventTableUserIdValidation(String userId) { return user; } - /** + */ +/** * Convert creation date string to XMLGregorianCalendar format . * * @param dateString creation date string object to convert * @return XMLGregorianCalendar for the given date string. - */ + *//* + public static XMLGregorianCalendar getXMLGregorianCalendarFromCreationDate(String dateString) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); XMLGregorianCalendar xmlDate = null; @@ -354,8 +397,11 @@ public static String getCurrentDateAndTimeString() { MCUtilities.logIfDebug( LOGGER, "Current Date & time string is : " + dateString ); return dateString; } - /** + */ +/** * Private constructor. - */ + *//* + private StringHelper() { } } +*/ diff --git a/src/main/java/com/example/Utilities.java b/src/main/java/com/example/Utilities.java index 03158c0..5c5ba34 100644 --- a/src/main/java/com/example/Utilities.java +++ b/src/main/java/com/example/Utilities.java @@ -3,7 +3,8 @@ * @Date : 10/31/2021 * @Time : 10:38 AM * @project : learning - */ + *//* + public class Utilities { final static String hey = " Hello "; @@ -92,3 +93,4 @@ private String removeInvalidCharacters(String input) { } +*/ diff --git a/src/main/java/com/example/XMLHelper.java b/src/main/java/com/example/XMLHelper.java index a905fca..cec5264 100644 --- a/src/main/java/com/example/XMLHelper.java +++ b/src/main/java/com/example/XMLHelper.java @@ -1,3 +1,4 @@ +/* package sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.utils; import com.ctc.wstx.exc.WstxIOException; @@ -20,20 +21,24 @@ import javax.xml.transform.stream.StreamSource; import java.io.*; +*/ /** * XMLHelper class. - */ + *//* + public final class XMLHelper { private static Logger LOGGER = LogFactory.getLogger(XMLHelper.class); - /** + */ +/** * Marshal input Object to String xml. * * @param type Class type to be marshaled. * @param object Object to be marshaled. * @return String xml. - */ + *//* + public static String marshalObjToXml(final Class type, final Object object) { LOGGER.debug("XMLHelper.marshalObjToXml()"); final StringWriter writer = new StringWriter(); @@ -50,14 +55,16 @@ public static String marshalObjToXml(final Class type, final Object object) { return writer.toString(); } - /** + */ +/** * Unmarshal target element of input String xml to Class type object. * * @param type Class type to unmarshal. * @param inputXml String input xml to unmarshal. * @param element String target element of input xml to unmarshal. * @return Object object. - */ + *//* + public static Object unmarshalXmlToObj(final Class type, final String inputXml, final String element) { LOGGER.debug("XMLHelper.unmarshalXmlToObj()"); @@ -88,13 +95,15 @@ public static Object unmarshalXmlToObj(final Class type, final String inputXml, return object; } - /** + */ +/** * Get target element value of input String xml. * * @param inputXml String input xml. * @param element String target element of input xml. * @return String value. - */ + *//* + public static String getElementValue(final String inputXml, final String element) { //LOGGER.debug("XMLHelper.getElementValue()"); @@ -119,12 +128,14 @@ public static String getElementValue(final String inputXml, final String element return value; } - /** + */ +/** * Encode String xml. * * @param str xml to be encoded. * @return string value - */ + *//* + public static String encodeXmlAttribute(final String str) { if (str == null) { return null; @@ -160,23 +171,27 @@ else if (c == '&') { return encoded.toString(); } - /** + */ +/** * Removes xml tag and ns2 prefix * @param input * @return - */ + *//* + public static String removeInvalidCharacters(String input) { String x = input.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim(); return x; } - /** + */ +/** * @param inputXML * @param * @param * @return Object * @throws Exception - */ + *//* + public static Object unMarshallerXMLtoJavaObject(final String inputXML){ try { JAXBContextFactory factory = JAXBContextFactory.getInstance(); @@ -200,13 +215,15 @@ public static Object unMarshallerXMLtoJavaObject(final String inputXML){ return null; } - /** + */ +/** * @param inputXML * @param * @param * @return Object * @throws Exception - */ + *//* + public static Document convertStringToXMLDocument(final String inputXML){ //Parser that produces DOM object trees from XML content @@ -234,13 +251,15 @@ public static String invalidCharacters(String input) { return input.replaceAll(precedingUTFCharactersReplacement,""); } - /** + */ +/** * * @param xml * @param cls * @return * @throws Exception - */ + *//* + public static Object transformWebComposerXmlToObject(final String xml, final Class cls) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(sunlife.us.dc.messagecenter.ws.webservice.impl.gcs.readdocdata.ReadDocData.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); @@ -272,8 +291,11 @@ public static boolean checkIfElementPresent(final String inputXml, final String return value; } - /** + */ +/** * Private constructor. - */ + *//* + private XMLHelper() { } } +*/ From 931ac95e412c9b905c83144727bfc4c986d710ab Mon Sep 17 00:00:00 2001 From: SSangala Date: Tue, 13 May 2025 18:29:08 -0500 Subject: [PATCH 07/10] Removed unwanted files and simple Inversion of Control example. How did we fix "Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException". --- pom.xml | 4 +- .../java/com/example/ApplicationStart.java | 21 + .../java/com/example/HpdemoApplication.java | 12 - src/main/java/com/example/ListRequest.java | 33 -- .../java/com/example/SalesForceURLTest.java | 85 --- .../java/com/example/SplitStringTest.java | 499 ------------------ src/main/java/com/example/StringHelper.java | 407 -------------- src/main/java/com/example/Utilities.java | 96 ---- src/main/java/com/example/XMLHelper.java | 301 ----------- src/main/java/com/example/build.gradle | 56 -- src/main/java/com/hom/StoreConfiguration.java | 22 + src/main/java/com/hom/services/Andriod.java | 16 + src/main/java/com/hom/services/Apple.java | 16 + src/main/java/com/hom/services/Mobile.java | 7 + src/main/webapp/views/display.jsp | 0 src/main/webapp/views/home.jsp | 0 src/main/webapp/views/sucess.jsp | 0 ...nTests.java => ApplicationStartTests.java} | 8 +- 18 files changed, 88 insertions(+), 1495 deletions(-) create mode 100644 src/main/java/com/example/ApplicationStart.java delete mode 100644 src/main/java/com/example/HpdemoApplication.java delete mode 100644 src/main/java/com/example/ListRequest.java delete mode 100644 src/main/java/com/example/SalesForceURLTest.java delete mode 100644 src/main/java/com/example/SplitStringTest.java delete mode 100644 src/main/java/com/example/StringHelper.java delete mode 100644 src/main/java/com/example/Utilities.java delete mode 100644 src/main/java/com/example/XMLHelper.java delete mode 100644 src/main/java/com/example/build.gradle create mode 100644 src/main/java/com/hom/StoreConfiguration.java create mode 100644 src/main/java/com/hom/services/Andriod.java create mode 100644 src/main/java/com/hom/services/Apple.java create mode 100644 src/main/java/com/hom/services/Mobile.java create mode 100644 src/main/webapp/views/display.jsp create mode 100644 src/main/webapp/views/home.jsp create mode 100644 src/main/webapp/views/sucess.jsp rename src/test/java/com/example/{HpdemoApplicationTests.java => ApplicationStartTests.java} (74%) diff --git a/pom.xml b/pom.xml index 4ede1e2..ffa9bce 100644 --- a/pom.xml +++ b/pom.xml @@ -4,11 +4,11 @@ 4.0.0 com.example - demo + admin 0.0.1-SNAPSHOT jar - hpdemo + AdminProject Demo project for Spring Boot diff --git a/src/main/java/com/example/ApplicationStart.java b/src/main/java/com/example/ApplicationStart.java new file mode 100644 index 0000000..2ba2b62 --- /dev/null +++ b/src/main/java/com/example/ApplicationStart.java @@ -0,0 +1,21 @@ +package com.example; + +import com.hom.StoreConfiguration; +import com.hom.services.Mobile; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +@SpringBootApplication +public class ApplicationStart { + + public static void main(String[] args) { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(StoreConfiguration.class); + Mobile mobile1 = (Mobile) context.getBean("getAndriod"); + System.out.println(mobile1.getModel()); + Mobile mobile11 = (Mobile) context.getBean("getApple"); + System.out.println(mobile11.getModel()); + + SpringApplication.run(ApplicationStart.class, args); + } +} diff --git a/src/main/java/com/example/HpdemoApplication.java b/src/main/java/com/example/HpdemoApplication.java deleted file mode 100644 index 0b991fe..0000000 --- a/src/main/java/com/example/HpdemoApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.example; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HpdemoApplication { - - public static void main(String[] args) { - SpringApplication.run(HpdemoApplication.class, args); - } -} diff --git a/src/main/java/com/example/ListRequest.java b/src/main/java/com/example/ListRequest.java deleted file mode 100644 index 2939a87..0000000 --- a/src/main/java/com/example/ListRequest.java +++ /dev/null @@ -1,33 +0,0 @@ - - -import java.util.*; - -public class ListRequest { - //Activity Processor Request {policy=204393, party=112, doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=null} - public static void main(String[] args) { - String existingRequest = "policy=204393, party=112, doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=null"; - String caseRequest = "policy=[204393,204390,204292], party=[95,100,112,200], doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=null"; - String policyRequest = "policy=[204393], party=[112,95,200], doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=[NTN-19-DI-10,NTN-23-DI-11]"; - String partyRequest = "policy=[204393,204390,204292], party=[112], doctype=Change in Definition of Disability Approval Letter, user=null, caseNumber=[NTN-19-DI-10,NTN-23-DI-11]"; - - String[] kvPairs = existingRequest.split(",\\s+"); - for(String kvPair : kvPairs){ - System.out.println(kvPair + "\n"); - String[] kv = kvPair.split("="); - String key = kv[0]; - String value = kv[1]; - // String items[] = value.split(","); - String replace = value.replace("[",""); - String replace1 = replace.replace("]",""); - List itemsList = new ArrayList(Arrays.asList(replace1.split(","))); - Map requestMap = new HashMap(); - Map detailsMap = new HashMap(); - for(String itemValue : itemsList){ - System.out.println( "Key is : " + key + " ::: Value is : " + itemValue); - detailsMap.put(key,itemValue); - } - - } - } - -} diff --git a/src/main/java/com/example/SalesForceURLTest.java b/src/main/java/com/example/SalesForceURLTest.java deleted file mode 100644 index 8e012ca..0000000 --- a/src/main/java/com/example/SalesForceURLTest.java +++ /dev/null @@ -1,85 +0,0 @@ -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.URL; - -public class SalesForceURLTest { - - public static void main(String args[]) throws Exception { - - String[] hostList = { "https://test.salesforce.com"}; - - for (int i = 0; i < hostList.length; i++) { - - String url = hostList[i]; - getStatus(url); - - } - - System.out.println("Task completed..."); - } - - public static String getStatus(String url) throws IOException { - - String result = ""; - int code = 200; - try { - /* Without proxy settings code - URL siteURL = new URL(url); - HttpURLConnection connection = (HttpURLConnection) siteURL.openConnection(); - connection.setRequestMethod("GET"); - connection.setConnectTimeout(3000); - connection.connect(); - code = connection.getResponseCode();*/ - - // With Proxy Settings - /* System.setProperty("http.proxyHost", "Proxy url"); - System.setProperty("http.proxyPort", "8080"); - System.setProperty("http.proxyUser", "username"); - System.setProperty("http.proxyPassword", "some password");*/ - URL siteURL = new URL(url); - /*Proxy proxy1 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyurl", 8080)); - HttpURLConnection connection1 = (HttpURLConnection) siteURL.openConnection(proxy1); - connection1.setRequestMethod("GET"); - connection1.setConnectTimeout(3000); - connection1.setRequestProperty( "http.proxyUser", "user" ); - connection1.setRequestProperty( "http.proxyPassword", "some password" ); - connection1.connect(); - code = connection1.getResponseCode(); - System.out.println(url + "\t\t Connection is using proxy with port 8080 :" + connection1.usingProxy()); - - if (code == 200) { - result = "-> Green <-\t" + "Code: " + code; - ; - } else { - result = "-> Yellow <-\t" + "Code: " + code; - }*/ - - Proxy proxy2 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy url", 8443)); - HttpURLConnection connection2 = (HttpURLConnection) siteURL.openConnection(proxy2); - connection2.setRequestMethod("GET"); - connection2.setConnectTimeout(3000); - connection2.setRequestProperty( "http.proxyUser", "user" ); - connection2.setRequestProperty( "http.proxyPassword", "some pass" ); - connection2.connect(); - code = connection2.getResponseCode(); - - System.out.println(url + "\t\t Connection is using proxy with port 8443:" + connection2.usingProxy()); - - - if (code == 200) { - result = "-> Green <-\t" + "Code: " + code; - ; - } else { - result = "-> Yellow <-\t" + "Code: " + code; - } - } catch (Exception e) { - e.printStackTrace(); - result = "-> Red <-\t" + "Wrong domain - Exception: " + e.getMessage(); - - } - System.out.println(url + "\t\tStatus:" + result); - return result; - } -} diff --git a/src/main/java/com/example/SplitStringTest.java b/src/main/java/com/example/SplitStringTest.java deleted file mode 100644 index 9e8fc4a..0000000 --- a/src/main/java/com/example/SplitStringTest.java +++ /dev/null @@ -1,499 +0,0 @@ -/* -package sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.sample.processor; - - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.junit.Test; - -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; -import java.beans.XMLDecoder; -import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -public class SplitStringTest { - String completeString = "1.0~96449~[EventResponse]"; - //String alpha = "{policy=[[218445,865231]], party=[115], doctype=Claim Approval Letter, user=null, caseNumber=[NTN-19-DI-01]}"; - - private static String serialize(Serializable o) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(o); - oos.close(); - return Base64.encodeBase64String(baos.toByteArray()); - } - - private static Object deserialize(String s) throws IOException, - ClassNotFoundException { - byte[] data = Base64.decodeBase64(s); - ObjectInputStream ois = new ObjectInputStream( - new ByteArrayInputStream(data)); - Object o = ois.readObject(); - ois.close(); - return o;//(o.toString().substring(1, o.toString().length()-1)); - } - - */ -/** - * To get a value from string of hashmap by passing key that existed in Hashmap before converting to String. - * Sample string: {fld_category=Principal category, test=test 1, fld_categoryID=1} - * - * @param string - * @param key - * @return value - *//* - - public static String getValueFromStringOfHashMap(String string, String key) { - - - int start_index = string.indexOf(key) + key.length() + 1; - int end_index = string.indexOf(",", start_index); - if (end_index == -1) { // because last key value pair doesn't have trailing comma (,) - end_index = string.indexOf("}"); - } - String value = string.substring(start_index, end_index); - - return value; - } - - */ -/*@Test - public void testStringHelper() { - InteractiveCreateDocumentRequestContract contract = StringHelper.translateStringToObject(alpha); - System.out.println( " print contract : Policies " + contract.getPolicy().get(0) + ":::" + contract.getPolicy().get(1)); - System.out.println( " print contract : Party " + contract.getParty().get(0)); - System.out.println( " print contract : docType " + contract.getDoctype()); - System.out.println( " print contract : user " + contract.getUser()); - System.out.println( " print contract : case " + contract.getCaseNumber().get(0)); - }*//* - - - @Test - public void testStringSplits() { - String versionNum = completeString.split("~")[0]; - System.out.println(versionNum); - String docId = completeString.split("~")[1]; - System.out.println(docId); - - } - - @Test - public void testFirstNameSplit() { - String firstName = null; - // String name = "SRIDHAR REDDY SANGALA"; - String name = "DIIntaketext5 Approval6"; - String[] parts = name.trim().split( "\\s+" ); - System.out.println( "FirstName out of name tag is : " + parts[0] ); - System.out.println( "FirstName out of name tag is : " + parts[1] ); - firstName = parts[0]; - System.out.println( firstName ); - - } - - @Test - public void testCaseNumberSplit() { - //String caseNumber1 = "NTN-100423-ABS-01"; - //String caseNumber1 = "NTN-57930-DI-02-SA-01"; - String caseNumber1 = "NTN-57930"; - String[] parts1 = caseNumber1.split( "-" ); - //String[] parts2 = caseNumber2.split("-"); - //String[] parts3 = caseNumber3.split("-"); - System.out.println( parts1.length ); - //System.out.println( parts2.length); - //System.out.println( parts3.length); - if (parts1.length > 2) { - System.out.println( parts1[0] ); - String case1 = caseNumber1.substring( caseNumber1.indexOf( caseNumber1.split( "-" )[0] ), caseNumber1.indexOf( caseNumber1.split( "-" )[2] ) - 1 ); - System.out.println( case1 ); - } else { - String case1 = caseNumber1; - System.out.println( case1 ); - } - } - - @Test - public void testEmailIdSplit() { - String emailid = "CHRIS.KERR@SUNLIFE.COM"; - //String emailid = "SYSADMIN"; - Pattern pattern = Pattern.compile("[a-zA-Z0-9]*"); - //Pattern pattern = Pattern.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"); - Matcher mat = pattern.matcher(emailid); - if (!(StringUtils.isAlphanumeric(emailid))) { - System.out.println("Inside the block "); - String email2UserId = StringUtils.remove(emailid, "@SUNLIFE.COM"); - System.out.println(email2UserId); - } else { - System.out.println("Outside the block "); - System.out.println(emailid); - } - - } - - @Test - public void testXMLGregorianCalendar() { - */ -/* Create Date Object *//* - - Date date = new Date(); - XMLGregorianCalendar xmlDate = null; - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - - try { - xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); - } catch (Exception e) { - e.printStackTrace(); - } - - System.out.println("XMLGregorianCalendar :- " + xmlDate); - } - - @Test - public void testMap() { - ObjectMapper oMapper = new ObjectMapper(); - HashMap mapQueryParams = new HashMap<>(); - mapQueryParams.put("doctype", "doc"); - mapQueryParams.put("party", "[[218454,267858]]"); - mapQueryParams.put("policy", "[[115,112]]"); - mapQueryParams.put("caseNumber", "[100]"); - mapQueryParams.put("user", "user"); - try { - String serstring = serialize(mapQueryParams); - - //Map map = oMapper.convertValue(deserialize("rO0ABXQAjntwb2xpY3k9W1syMTg0NDUsMjA0MjQ1XV0sIHBhcnR5PVtbMTE1LDQ3XV0sIGRvY3R5cGU9Q2hhbmdlIGluIERlZmluaXRpb24gb2YgRGlzYWJpbGl0eSBBcHByb3ZhbCBMZXR0ZXIsIHVzZXI9bnVsbCwgY2FzZU51bWJlcj1bTlROLTE5LURJLTAxXX0="),new TypeReference>() {}); - XMLDecoder xmlDecoder = new XMLDecoder(new ByteArrayInputStream(serstring.getBytes())); - Map parsedMap = (Map) xmlDecoder.readObject(); - for (Map.Entry entry : parsedMap.entrySet()) { - System.out.println(entry.getKey() + ":" + entry.getValue().toString()); - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testRegexStartEndCharacter() { - String party = "[115,111,200,300]"; - if (party.startsWith("[")) { - StringBuilder sb = new StringBuilder(party); // starts with [ ends with ] - String result = sb.deleteCharAt(0).toString(); - result = sb.deleteCharAt(result.lastIndexOf(']')).toString(); - System.out.println(result); - List items = Arrays.asList(result.split("\\s*,\\s*")); - System.out.println(items.size()); - for (String s : items) { - System.out.println(s); - } - - } else { - System.out.println("hello"); - } - } - */ -/* - public void testMap1() { - *//* -*/ -/* HashMap mapQueryParams = new HashMap<>(); - mapQueryParams.put("doctype", "doc"); - mapQueryParams.put("party", "[[218454,267858]]"); - mapQueryParams.put("policy", new ArrayList<>().add("115")); - mapQueryParams.put("caseNumber", "[100]"); - mapQueryParams.put("user", "user"); - String string = "rO0ABXQAjntwb2xpY3k9W1syMTg0NDUsMjA0MjQ1XV0sIHBhcnR5PVtbMTE1LDQ3XV0sIGRvY3R5cGU9Q2hhbmdlIGluIERlZmluaXRpb24gb2YgRGlzYWJpbGl0eSBBcHByb3ZhbCBMZXR0ZXIsIHVzZXI9bnVsbCwgY2FzZU51bWJlcj1bTlROLTE5LURJLTAxXX0"; - String result = getValueFromStringOfHashMap(string, "doctype"); - String party = getValueFromStringOfHashMap(string, "party"); - String policy = getValueFromStringOfHashMap(string, "policy"); - System.out.println(result); - System.out.println(party); - System.out.println(policy);*//* -*/ -/* - - try { - JSONObject jsonObject = new JSONObject("{policy=[[218445,204245]], party=[[115,266,57]], doctype=Claim Approval Letter, user=null, caseNumber=[NTN-19-DI-01]}"); - // JSONObject jObject = new JSONObject(output); // json - JSONObject data = jObject.getJSONObject("data"); - System.out.println(jsonObject.get("policy")); - }catch (JSONException err){ - System.out.println(err.getMessage()); - } - }*//* - - - @Test - public void testListItems() { - List list1 = new ArrayList<>(); - //list1.add("218454"); - list1.add(" "); - list1.add("267858"); - list1.add("267958"); - - for (String eachParty : list1) { - if (eachParty.equals(list1.get(0))) { - System.out.println(list1.get(0)); - } else { - System.out.println(" not first in the list " + eachParty); - } - } - - } - - */ -/* @Test - public void testjsonString(){ - String jsonString = null; - try { - jsonString = new JSONObject() - .put("JSON1", "Hello World!") - .put("JSON2", "Hello my World!") - .put("JSON3", new JSONObject() - .put("key1", "value1")).toString(); - } catch (Exception e) { - e.printStackTrace(); - } - - System.out.println(jsonString); - }*//* - - - */ -/*@Test - public void testmapjson() { - JSONObject jsonObject = null; - JSONArray array = null; - try { - List list1 = new ArrayList<>(); - list1.add(218454); - list1.add(267858); - list1.add(267958); - array = new JSONArray(); - jsonObject = new JSONObject(); - - jsonObject.put("doctype", "doc"); - jsonObject .put("policy", "218454, 267858, 267958"); - jsonObject.put("party", "115"); - jsonObject.put("caseNumber", "100,101"); - jsonObject.put("user", "user"); - - //jsonObject.put("pluginMap", mapQueryParams); - //System.out.println(jsonObject.toString()); - ObjectMapper mapper = new ObjectMapper(); - JSONParser parser = new JSONParser(); - System.out.println(parser.parse(jsonObject.toString())); - Map map = mapper.readValue(jsonObject.toString(), Map.class); - System.out.println(map); - } catch (Exception e) { - e.printStackTrace(); - } - - }*//* - - - @Test - public void testStringList() { - ArrayList list = new ArrayList(); - list.add(""); - list.add(" "); - list.add("three"); - StringBuilder sb = new StringBuilder(); - for (String s : list) { - if (sb.length() != 0 && s.isEmpty()) { - sb.append(","); - } - sb.append(s); - } - System.out.println(sb.toString()); - } - - @Test - public void testRemovingCommaSplchars() { - List s1 = getListFromString("[ ,\"212\"]"); - for (String s : s1) { - if (s.isEmpty()) { - System.out.println(" s is empty " + s); - } else { - System.out.println(" s is empty " + s); - } - } - } - - private List getListFromString(String alphaNumeric) { - StringBuilder sb = new StringBuilder(alphaNumeric); // starts with [ ends with ] - String result = sb.deleteCharAt(0).toString(); - result = sb.deleteCharAt(result.lastIndexOf(']')).toString(); - return Arrays.asList(result.split("\\s*,\\s*")); - } - - @Test - public void testMultiple() { - List s3 = getListFromString("[\"212\"]"); - System.out.println(" size is " + s3.size()); - for (String s : s3) { - if (s.isEmpty()) { - System.out.println(" s is empty " + s); - } else { - System.out.println(" s is empty " + s); - } - } - - List s4 = getListFromString("[\"212\",\"215\"]"); - System.out.println(" size is " + s4.size()); - for (String s : s4) { - if (s.isEmpty()) { - System.out.println(" s is empty " + s); - } else { - System.out.println(" s is empty " + s); - } - } - } - - - @Test - public void testRemoveSpecialChars() { - String party = "[212]"; - - if (party.startsWith("[")) { - StringBuilder sb = new StringBuilder(party); // starts with [ ends with ] - String result = sb.deleteCharAt(0).toString(); - result = sb.deleteCharAt(result.lastIndexOf(']')).toString(); - System.out.println(result); - } - } - - - @Test - public void testRegex() { - String partyKey = "55f2fd19-1f38-4569-aa96-22b1e2aa3b69"; - Pattern pattern = Pattern.compile("[^A-Za-z0-9]"); - Matcher matcher = pattern.matcher(partyKey); - - boolean b = matcher.find(); - if (b == true) - System.out.println("There is a special character in my string:- " + partyKey); - else - System.out.println("There is no special character in my String :- " + partyKey); - } - - @Test - public void testPrefixRemove() { - String documentId = "DG_12345678"; - if (documentId.matches("[0-9]+")) { - System.out.println(" yes it is Number" + documentId); - } else { - */ -/*System.out.println(" No it is not a Number " + documentId); - documentId = documentId.replaceAll("DG_", ""); - System.out.println(" Number " + documentId);*//* - - if (documentId.startsWith("DG_")) { - String ddocumentId = documentId.replaceAll("DG_", ""); - System.out.println("Inside condition " + ddocumentId); - } else { - System.out.println(" what's up "); - } - } - } - - @Test - public void testKeyValuePairSplit() { - String jsonObjectString = "{status=completed, documentid=DG_1234}"; - Map map = new HashMap(); - String removeBrackets = jsonObjectString.substring(1, jsonObjectString.length() - 1); - String[] keyValueStrings = removeBrackets.split(","); - */ -/*for(int i =0; i < keyValueStrings.length ; i++) { - String[] items =keyValueStrings[i].split("="); - System.out.println("Key : " + items[0] + " and Value : " + items[1]); - }*//* - - - for (String eachString : keyValueStrings) { - String[] keyValue = eachString.split(" *= *"); - map.put(keyValue[0], keyValue[1]); - System.out.println("Key : " + keyValue[0] + " - Value : " + keyValue[1]); - } - - } - - @Test - public void testEscapeCharcs() throws MalformedURLException, UnsupportedEncodingException { - String mcurl = "http://dev-dgpapps.us.sunlife/doc-manager/index.xhtml?source-system=GCSDI&requester-code=GCSDI&requester-token=EKgPuy8lsKNH%2FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr&user-id=k344&doc-id=DG_98800"; - String pluginUrl1 = "http://dev-dgpapps.us.sunlife/doc-manager/index.xhtml?source-system=GCSDI&requester-code=GCSDI&requester-token=EKgPuy8lsKNH%2FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr&user-id=k344&doc-id=DG_98800"; - String mc = StringEscapeUtils.unescapeXml(mcurl); - //String plugin = StringEscapeUtils.escapeJava(pluginUrl1); - System.out.println(new URL(mc)); - //System.out.println(plugin); - - String token = "EKgPuy8lsKNH%2FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr"; - String convertToken1 = StringEscapeUtils.unescapeXml(token); - // System.out.println(convertToken1); - String result = java.net.URLDecoder.decode(mcurl, StandardCharsets.UTF_8.name()); - // System.out.println(result); - Map myMap = new HashMap<>(); - - String nextTest = "{requester-code=GCSDI, source-system=GCSDI, contentid=DG_98801, doc-id=98801, status=null, user-id=k344, requester-token=EKgPuy8lsKNH/FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr, appid=GCSDI}"; - String[] pairs = nextTest.split(","); - for (String pair : pairs) { - //String pair = pairs[i]; - String[] keyValue = pair.split("="); - myMap.put(keyValue[0], keyValue[1]); - } - System.out.println(myMap); - - for (String entry : myMap.keySet()) { - if (entry.equalsIgnoreCase(myMap.get("doc-id"))) { - String conId = myMap.get("doc-id"); - System.out.println(conId); - } - } - - } - - - @Test - public void testList() { - List stringList = new ArrayList<>(); - stringList.add("913"); - stringList.add("708"); - // stringList.add("2748"); - if (stringList.size() == 1) { - System.out.println(" only 1"); - } else if (stringList.size() > 1) { - System.out.println(" two items"); - } else { - System.out.println(" only 2"); - } - } - - private XMLGregorianCalendar getXMLGregorianCalendar() { - */ -/* Create Date Object *//* - - Date date = new Date(); - XMLGregorianCalendar xmlDate = null; - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime( date ); - - try { - xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar( gc ); - xmlDate.setTimezone( -2147483648 ); - xmlDate.setMillisecond( -2147483648 ); - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println( "XMLGregorianCalendar :- " + xmlDate ); - return xmlDate; - } -} -*/ diff --git a/src/main/java/com/example/StringHelper.java b/src/main/java/com/example/StringHelper.java deleted file mode 100644 index 1babc5d..0000000 --- a/src/main/java/com/example/StringHelper.java +++ /dev/null @@ -1,407 +0,0 @@ -/* -package utils; - -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; - - - -import javax.xml.bind.DatatypeConverter; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; -import java.text.DateFormat; -import java.text.NumberFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.regex.Pattern; - -*/ -/** - * String helper class. - *//* - -public final class StringHelper { - */ -/** - * EMPTY_STRING. - *//* - - private static final String EMPTY_STRING = ""; - */ -/** - * The LOGGER. - *//* - - private static Logger LOGGER = LogFactory.getLogger(StringHelper.class); - - */ -/** - * Build a comma separated String for a java.util.List of String objects. - * - * @param stringList java.util.List of String objects - * @return comma separated String - *//* - - public static String buildCSStringFromList(final List stringList) { - StringBuilder csString = new StringBuilder(""); - if (stringList != null && !stringList.isEmpty()) { - for (String string : stringList) { - if (csString.length() > 0) { - csString.append(", "); - } - csString.append(string.trim()); - } - } - return csString.toString(); - } - - */ -/** - * Build a full name from first name and last name in first last format. - * - * @param firstName First name - * @param lastName Last name - * @return Full name in first last format - *//* - - public static String buildFirstLastName(final String firstName, final String lastName) { - String name = null; - if (firstName != null || lastName != null) { - final StringBuilder builder = new StringBuilder(""); - if (firstName != null && !firstName.trim().equals("")) { - builder.append(firstName.trim()); - } - if (lastName != null && !lastName.trim().equals("")) { - if (builder.length() > 0) { - builder.append(" "); - } - builder.append(lastName.trim()); - } - name = builder.toString(); - } - return name; - } - - */ -/** - * Build a full name from first name and last name in first last format. - * - * @param firstName First name - * @param middleName Middle name - * @param lastName Last name - * @return Full name in first last format - *//* - - public static String buildFirstMiddleLastName(final String firstName, final String middleName, final String lastName) { - String name = null; - if (firstName != null || lastName != null) { - final StringBuilder builder = new StringBuilder(""); - if (firstName != null && !firstName.trim().equals("")) { - builder.append(firstName.trim()); - } - if (middleName != null && !middleName.trim().equals("")) { - if (builder.length() > 0) { - builder.append(" "); - } - builder.append(middleName.trim()); - } - if (lastName != null && !lastName.trim().equals("")) { - if (builder.length() > 0) { - builder.append(" "); - } - builder.append(lastName.trim()); - } - name = builder.toString(); - } - return name; - } - - */ -/** - * Build a full name from first name and last name in last, first format. - * - * @param firstName First name - * @param lastName Last name - * @return Full name in last, first format - *//* - - public static String buildLastFirstName(final String firstName, final String lastName) { - String name = null; - if (firstName != null || lastName != null) { - final StringBuilder builder = new StringBuilder(""); - if (lastName != null && !lastName.trim().equals("")) { - builder.append(lastName.trim()); - } - if (firstName != null && !firstName.trim().equals("")) { - if (builder.length() > 0) { - builder.append(", "); - } - builder.append(firstName.trim()); - } - name = builder.toString(); - } - return name; - } - - */ -/** - * Format object as a currency. - * - * @param obj Object - * @return Object formatted as currency - *//* - - public static String formatCurrency(final Object obj) { - return NumberFormat.getCurrencyInstance().format(obj); - } - - */ -/** - * Format a SSN String 123456789 as 123-45-6789 format. - * - * @param ssnString SSN String to format - * @return formatted SSN String or null if ssnString argument is null - *//* - - */ -/*public static String formatSSN(final String ssnString) { - String string = null; - if (ssnString != null) { - final StringBuilder builder = new StringBuilder(""); - builder.append(ssnString.substring(0, 3)).append('-').append(ssnString.substring(3, StopLossClaimsConstants.INT_5)).append('-').append(ssnString.substring(StopLossClaimsConstants.INT_5)); - string = builder.toString(); - } - return string; - } -*//* - - */ -/** - * Determine if a java.lang.String is empty or not. - * - * @param stringIn String to test - * @return true if stringIn is null or length is 0, false otherwise - *//* - - public static boolean isEmptyString(final String stringIn) { - boolean result = true; - if (stringIn != null && !stringIn.trim().equals(EMPTY_STRING) && !stringIn.equalsIgnoreCase("null")) { - result = false; - } - return result; - } - - */ -/** - * Parse a Base64 encoded String. - * - * @param stringIn Base64 encoded String - * @return parse value - *//* - - public static String parseBase64Binary(final String stringIn) { - return new String(DatatypeConverter.parseBase64Binary(stringIn)); - } - - */ -/** - * Trims the String value if not null. - * - * @param s String to be trimmed - * @return null or trimmed string value - *//* - - public static String safeTrim(final String s) { - String str = s; - if (s != null) { - str = s.trim(); - } - return str; - } - - */ -/** - * Check if two String objects are equal. - * - * @param stringOne First String to compare - * @param stringTwo Second String to compare - * @return true if equal, false otherwise - *//* - - public static boolean stringEquals(final String stringOne, final String stringTwo) { - boolean result = false; - if (stringOne == null) { - if (stringTwo == null) { - result = true; - } - } - else if (stringTwo != null) { - result = stringOne.trim().equalsIgnoreCase(stringTwo.trim()); - } - return result; - } - - */ -/** - * Check if a string exists in a var arg of Strings. - * - * @param string String object to look for - * @param strings Vararg of String objects to search - * @return true if string found, otherwise false - *//* - - public static boolean stringIn(final String string, final String... strings) { - boolean found = false; - if (strings != null) { - for (String stringsString : strings) { - if (stringsString != null && StringHelper.stringEquals(string, stringsString)) { - found = true; - break; - } - } - } - return found; - } - - */ -/** - * Attempt to translate a Boolean to a String literal. - * - * @param booleanObject Boolean to translate - * @return "Y" if booleanObject is not null and equals Boolean.TRUE, "N" otherwise - *//* - - public static String translateBooleanToString(final Boolean booleanObject) { - if (booleanObject != null && booleanObject.equals(Boolean.TRUE)) { - return "Y"; - } - return "N"; - } - - */ -/** - * Attempt to translate a String literal into a Boolean value. - * - * @param string String to translate - * @return Boolean.TRUE if String can be translated and value is "Y" or "YES", Boolean.FALSE otherwise - *//* - - public static Boolean translateStringToBoolean(final String string) { - if (string != null && (string.trim().equalsIgnoreCase("Y") || string.trim().equalsIgnoreCase("YES"))) { - return Boolean.TRUE; - } - return Boolean.FALSE; - } - - */ -/** - * Translate Object to String. - * - * @param obj Object to be translated - * @return string value - *//* - - public static String translateObjectToString(final Object obj) { - return (obj == null) ? EMPTY_STRING : obj.toString(); - } - - */ -/** - * Jira ACC-1821 - *//* - - public static String trimUserID(String loggedinUser) { - String name = ""; - if (!(StringUtils.isAlphanumeric(loggedinUser))) { - String email2UserId = StringUtils.remove(loggedinUser, "@SUNLIFE.COM"); - System.out.println(email2UserId); - } else { - System.out.println(loggedinUser); - } - return name; - } - - */ -/** - * Check if a user id passed contains @ and is more than 30 character. - * - * @param userId String object to look for - * @return user id without @SUNLIFE.COM or GCSUser if its still more than 30 character - *//* - - public static String syncEventTableUserIdValidation(String userId) { - String user = userId; - if (userId != null && userId.contains("@")) { - // Remove the @sunlife.com from user name as we have limit on userId column length in GCS database - user = userId.split(Pattern.quote("@"))[0]; - } - if (user != null && user.length()>30){ - MCUtilities.logIfDebug(LOGGER,"Setting User ID as : GCSUser. Since user id : " + user + " is still grater than 30 character " ); - user = "GCS"; - } - - return user; - } - - */ -/** - * Convert creation date string to XMLGregorianCalendar format . - * - * @param dateString creation date string object to convert - * @return XMLGregorianCalendar for the given date string. - *//* - - public static XMLGregorianCalendar getXMLGregorianCalendarFromCreationDate(String dateString) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - XMLGregorianCalendar xmlDate = null; - try { - Date date = dateFormat.parse(dateString); - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); - } catch (Exception e) { - MCUtilities.logIfDebug(LOGGER, "Exception in getXMLGregorianCalendarFromCreationDate :- " + e.getMessage()); - - } - MCUtilities.logIfDebug(LOGGER, "XMLGregorianCalendar :- " + xmlDate); - return xmlDate; - } - - public static String currentDateAndTimeWithAmPmmarker() { - //Displaying current date and time in 12 hour format with AM/PM - DateFormat dateFormat2 = new SimpleDateFormat( "MM/dd/yyyy hh.mm aa" ); - String dateString2 = dateFormat2.format( new Date() ).toString(); - MCUtilities.logIfDebug( LOGGER, "Displaying current date and time in AM/PM: " + dateString2 ); - return dateString2; - } - - public static String getCurrentDateAndTimeString() { - DateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:sss" ); - GregorianCalendar gregorianCalendar = new GregorianCalendar(); - XMLGregorianCalendar now = null; - DatatypeFactory datatypeFactory = null; - try { - datatypeFactory = DatatypeFactory.newInstance(); - now = datatypeFactory.newXMLGregorianCalendar( gregorianCalendar ); - } catch (DatatypeConfigurationException e) { - MCUtilities.logIfDebug( LOGGER, "Current date and time in DatatypeConfigurationException block : " + e ); - } - GregorianCalendar gCalendar = now.toGregorianCalendar(); - //Converted to date object - Date date = gCalendar.getTime(); - //Formatted to String value - String dateString = df.format( date ); - MCUtilities.logIfDebug( LOGGER, "Current Date & time string is : " + dateString ); - return dateString; - } - */ -/** - * Private constructor. - *//* - - private StringHelper() { } -} -*/ diff --git a/src/main/java/com/example/Utilities.java b/src/main/java/com/example/Utilities.java deleted file mode 100644 index 5c5ba34..0000000 --- a/src/main/java/com/example/Utilities.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * @author : Sridhar Reddy Sangala - * @Date : 10/31/2021 - * @Time : 10:38 AM - * @project : learning - *//* - -public class Utilities { - final static String hey = " Hello "; - - public static void main(String[] args) { - Animal aDog = new Dog(); - aDog.eat(); - aDog.makeSound(); - aDog.sleep(); - - Animal aCat = new Cat(); - aCat.eat(); - aCat.makeSound(); - aCat.sleep(); - - Vehicle car = new Car(); - car.start(); - car.stop(); - - Vehicle aero = new Aeroplane(); - aero.start(); - aero.stop(); - String[] recipientDataWithDataRootXml = stringData.split( Pattern.quote( "$$" ) ); - - } - - // To handle special character in sender Name, profileName and senderDepartment field etc - private static String getSpecialCharInFieldValueHandled(String exRecepientInfoDataString) { - exRecepientInfoDataString = handleSpecialCharacterForFieldName(exRecepientInfoDataString, "firstName", "\"firstName\":", "\"firstName\":\""); - exRecepientInfoDataString = handleSpecialCharacterForFieldName(exRecepientInfoDataString, "lastName", "\"lastName\":", "\"lastName\":\""); - } - - public static String handleSpecialCharacterForFieldName(String exRecepientInfoDataString, String fieldName, String s, String s1) { - if (exRecepientInfoDataString.contains(fieldName)) { - String cdcJsonExtractString1 = exRecepientInfoDataString.substring(0, exRecepientInfoDataString.indexOf(s)); - String cdcJsonExtractString2 = exRecepientInfoDataString.substring(exRecepientInfoDataString.indexOf(s)); - String fieldNameSectionValue = StringUtils.substringBetween(cdcJsonExtractString2, s, ",\""); - if (!StringHelper.isEmptyString(fieldNameSectionValue) && !fieldNameSectionValue.equalsIgnoreCase("null")) { - exRecepientInfoDataString = cdcJsonExtractString1 + s1 + getCharacterConverted(fieldNameSectionValue.replace("\"", "")) - + cdcJsonExtractString2.substring(cdcJsonExtractString2.indexOf("\",\"")); - } - } - return exRecepientInfoDataString; - } - - // get special character converted to character sequence - public static String getCharSequenceForSpecialCharatcer(String recipientInfoString) { - String recipientInfoStringUpdated = recipientInfoString; - try { - recipientInfoStringUpdated = recipientInfoString.replaceAll("&(?![a-z]{1,6};)", "&").replaceAll("'(?![a-z]{1,6};)", "'"); - MCUtilities.logIfDebug( LOGGER, "Special character converted for just & and ' string looks like : " + recipientInfoStringUpdated ); - } catch (Exception e) { - MCUtilities.logIfDebug( LOGGER, "exception is : " + e ); - } - return recipientInfoStringUpdated; - } - - // get special character allowed ( 1!2"34$5%6^7&8*9()10_11+12}{13{}14:15@16?17>18<#19@20]21^_~á ñ ò ú & ' "- ) converted for any string - public static String getCharacterConverted(String inputString) { - String convertedString = inputString; - try { - // MCUtilities.logIfDebug( LOGGER, "Special character received looks like : " + convertedString ); - convertedString = StringEscapeUtils.escapeXml(new String((inputString.getBytes("ISO-8859-1")), "UTF-8")); - // MCUtilities.logIfDebug( LOGGER, "Special character after conversion looks like : " + convertedString ); - } catch (Exception e) { - MCUtilities.logIfDebug( LOGGER, "exception is : " + e ); - } - return convertedString; - } - - - @Test - public void removeNS2andXMlTag() { - String request = " \n" + - "\n" + - " DocumentRESTBroadcast\n" + - " hello"; - String afterRemoval = removeInvalidCharacters(request); - System.out.println(afterRemoval); - } - - private String removeInvalidCharacters(String input) { - String x = input.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim(); - return x; - } - - - -} -*/ diff --git a/src/main/java/com/example/XMLHelper.java b/src/main/java/com/example/XMLHelper.java deleted file mode 100644 index cec5264..0000000 --- a/src/main/java/com/example/XMLHelper.java +++ /dev/null @@ -1,301 +0,0 @@ -/* -package sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.utils; - -import com.ctc.wstx.exc.WstxIOException; -import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import sunlife.us.dc.log.LogFactory; -import sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.processor.JAXBContextFactory; -import sunlife.us.dc.messagecenter.ws.webservice.impl.gcs.readclaimdata.ReadClaimData; - -import javax.xml.bind.*; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.stream.StreamSource; -import java.io.*; - -*/ -/** - * XMLHelper class. - *//* - -public final class XMLHelper { - - private static Logger LOGGER = LogFactory.getLogger(XMLHelper.class); - - */ -/** - * Marshal input Object to String xml. - * - * @param type Class type to be marshaled. - * @param object Object to be marshaled. - * @return String xml. - *//* - - public static String marshalObjToXml(final Class type, final Object object) { - LOGGER.debug("XMLHelper.marshalObjToXml()"); - final StringWriter writer = new StringWriter(); - try { - final JAXBContext jaxbContext = JAXBContext.newInstance(type); - final Marshaller marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); - marshaller.marshal(object, writer); - } - catch (JAXBException e) { - LOGGER.error(e.getMessage(), e); - } - - return writer.toString(); - } - - */ -/** - * Unmarshal target element of input String xml to Class type object. - * - * @param type Class type to unmarshal. - * @param inputXml String input xml to unmarshal. - * @param element String target element of input xml to unmarshal. - * @return Object object. - *//* - - public static Object unmarshalXmlToObj(final Class type, final String inputXml, final String element) { - LOGGER.debug("XMLHelper.unmarshalXmlToObj()"); - - final InputStream is = IOUtils.toInputStream(inputXml); - final XMLInputFactory factory = XMLInputFactory.newInstance(); - - Object object = null; - try { - final XMLStreamReader reader = factory.createXMLStreamReader(is); - while (reader.hasNext()) { - final int event = reader.next(); - if (event == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(element)) { - break; - } - } - - final JAXBContext jaxbContext = JAXBContext.newInstance(type); - final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - JAXBElement jaxbElement = (JAXBElement) jaxbUnmarshaller.unmarshal(reader, type); - object = jaxbElement.getValue(); - }catch (WstxIOException e){ - LOGGER.debug("Exception in XMLHelper.unmarshalXmlToObj() : "+ e.toString()); - } - catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - - return object; - } - - */ -/** - * Get target element value of input String xml. - * - * @param inputXml String input xml. - * @param element String target element of input xml. - * @return String value. - *//* - - public static String getElementValue(final String inputXml, final String element) { - //LOGGER.debug("XMLHelper.getElementValue()"); - - String value = null; - final InputStream is = IOUtils.toInputStream(inputXml); - final XMLInputFactory factory = XMLInputFactory.newInstance(); - - try { - final XMLStreamReader reader = factory.createXMLStreamReader(is); - while (reader.hasNext()) { - final int event = reader.next(); - if (event == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(element)) { - value = StringHelper.safeTrim(reader.getElementText()); - break; - } - } - } - catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - - return value; - } - - */ -/** - * Encode String xml. - * - * @param str xml to be encoded. - * @return string value - *//* - - public static String encodeXmlAttribute(final String str) { - if (str == null) { - return null; - } - - final int len = str.length(); - if (len == 0) { - return str; - } - - final StringBuffer encoded = new StringBuffer(); - for (int i = 0; i < len; i++) { - char c = str.charAt(i); - if (c == '<') { - encoded.append("<"); - } - else if (c == '\"') { - encoded.append("""); - } - else if (c == '>') { - encoded.append(">"); - } - else if (c == '\'') { - encoded.append("'"); - } - else if (c == '&') { - encoded.append("&"); - } - else { - encoded.append(c); - } - } - return encoded.toString(); - } - - */ -/** - * Removes xml tag and ns2 prefix - * @param input - * @return - *//* - - public static String removeInvalidCharacters(String input) { - String x = input.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim(); - return x; - } - - */ -/** - * @param inputXML - * @param - * @param - * @return Object - * @throws Exception - *//* - - public static Object unMarshallerXMLtoJavaObject(final String inputXML){ - try { - JAXBContextFactory factory = JAXBContextFactory.getInstance(); - JAXBContext jaxbContext = factory.getJaxBContext(ReadClaimData.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); - InputStreamReader inputStreamReader = new InputStreamReader(new ByteArrayInputStream(inputXML.getBytes())); - XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStreamReader); - JAXBElement jaxbElement = unmarshaller.unmarshal(xmlStreamReader, Object.class); - // MCUtilities.logIfDebug(LOGGER, "Inside unmarshall method " ); - return jaxbElement.getValue(); - - } catch (JAXBException e){ - e.printStackTrace(); - LOGGER.error(LOGGER, e); - } catch (XMLStreamException xmle) { - LOGGER.error(LOGGER, xmle); - } catch (Exception oe){ - LOGGER.error(LOGGER, oe); - } - return null; - } - - */ -/** - * @param inputXML - * @param - * @param - * @return Object - * @throws Exception - *//* - - public static Document convertStringToXMLDocument(final String inputXML){ - - //Parser that produces DOM object trees from XML content - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - - //API to obtain DOM Document instance - DocumentBuilder builder = null; - Document doc = null; - try - { - //Create DocumentBuilder with default configuration - builder = factory.newDocumentBuilder(); - - //Parse the content to Document object - doc = builder.parse( new InputSource( new StringReader( inputXML ) ) ); - } - catch (Exception e) - { - e.printStackTrace(); - } - return doc; - } - private final static String precedingUTFCharactersReplacement = "\\[|\\]"; - public static String invalidCharacters(String input) { - return input.replaceAll(precedingUTFCharactersReplacement,""); - } - - */ -/** - * - * @param xml - * @param cls - * @return - * @throws Exception - *//* - - public static Object transformWebComposerXmlToObject(final String xml, final Class cls) throws JAXBException { - JAXBContext jaxbContext = JAXBContext.newInstance(sunlife.us.dc.messagecenter.ws.webservice.impl.gcs.readdocdata.ReadDocData.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - StringReader reader = new StringReader(xml); - final StreamSource source = new StreamSource(reader); - JAXBElement jaxbElement = unmarshaller.unmarshal(source, cls); - return jaxbElement.getValue(); - } - - public static boolean checkIfElementPresent(final String inputXml, final String elementTag) { - //LOGGER.debug("XMLHelper.getElementValue()"); - - Boolean value = false; - - try { - Document document = convertStringToXMLDocument( inputXml ); - if (document != null) { - NodeList nodeList = document.getElementsByTagName( "*" ); - for (int i = 0; i < nodeList.getLength(); i++) { - if (nodeList.item( i ).getNodeName().equalsIgnoreCase( elementTag )) { - value = Boolean.TRUE; - } - } - } - - } catch (Exception e) { - LOGGER.error( e.getMessage(), e ); - } - - return value; - } - */ -/** - * Private constructor. - *//* - - private XMLHelper() { } -} -*/ diff --git a/src/main/java/com/example/build.gradle b/src/main/java/com/example/build.gradle deleted file mode 100644 index 299d524..0000000 --- a/src/main/java/com/example/build.gradle +++ /dev/null @@ -1,56 +0,0 @@ -configurations { - all*.exclude module: 'spring-boot-starter-logging' -} - -// Defines the dependencies for this build -dependencies { - // Sunlife dependency jars - compile(group: 'some.us.dc.utility', name: 'log', version: '0.2') - compile(group: 'some.us.dc.utility', name: 'dbc', version: '1.0') - compile(group: 'some.us.dc.mescenter', name: 'mcplugin-framework', version: '2.17.0.3-20201007.202552-1') - { - exclude module: 'camel-core' - exclude module: 'camel-cxf' - exclude module: 'camel-cxf-transport' - exclude module: 'camel-ejb' - exclude module: 'camel-jms' - exclude module: 'camel-spring' - exclude module: 'jdom' - exclude module: 'partner' - exclude module: 'spring-oxm' - exclude module: 'commons-codec' - exclude module: 'commons-collections' - exclude module: 'commons-io' - exclude module: 'cxf' - } - compile(group: 'some.us.dc.mescenter', name: 'mcplugin-common', version: '2.17.0') - { - exclude module: 'mcplugin-framework' - exclude module: 'partner' - exclude module: 'commons-io' - } - - } - - /****************************************************************************************************************** - JAVA-PLUGIN: Creates an output JAR with MANIFEST based on the classes and resources within this project - @Link: https://docs.gradle.org/current/userguide/java_plugin.html#sec:jar - ***************************************************************************************************************** */ -group = currentGroupId -version = currentVersion -jar { - manifest { - attributes( - "Member": "Enterprise Application Development", - "Implementation-Group": group, - "Provider": "Application Development", - "Implementation-Title": currentArtifactId, - "Implementation-Version": currentVersion, - "Implementation-Vendor": "Sunlife", - "Created-By": System.getProperty('java.version') + ' (' + System.getProperty('java.vendor') + ')', - "Built-With": "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}", - "Built-Time": new Date().format('dd-MMM-yyyy HH:mm:ss') - ) - } - baseName 'my-gateway-plugin' -} diff --git a/src/main/java/com/hom/StoreConfiguration.java b/src/main/java/com/hom/StoreConfiguration.java new file mode 100644 index 0000000..0e0d33d --- /dev/null +++ b/src/main/java/com/hom/StoreConfiguration.java @@ -0,0 +1,22 @@ +package com.hom; + +import com.hom.services.Andriod; +import com.hom.services.Apple; +import com.hom.services.Mobile; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class StoreConfiguration { + @Bean + public Mobile getAndriod() { + return new Andriod(); + } + + //Error : Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'getApple' available +// Fix : @Bean annotation was missing on getApple , it had only for getAndriod + @Bean + public Mobile getApple() { + return new Apple(); + } +} diff --git a/src/main/java/com/hom/services/Andriod.java b/src/main/java/com/hom/services/Andriod.java new file mode 100644 index 0000000..dce0d45 --- /dev/null +++ b/src/main/java/com/hom/services/Andriod.java @@ -0,0 +1,16 @@ +package com.hom.services; + +import org.springframework.stereotype.Component; + +@Component +public class Andriod implements Mobile { + private final String ONE_PLUS = "onePlus"; + + /** + * @return + */ + @Override + public String getModel() { + return ONE_PLUS; + } +} diff --git a/src/main/java/com/hom/services/Apple.java b/src/main/java/com/hom/services/Apple.java new file mode 100644 index 0000000..85e13ef --- /dev/null +++ b/src/main/java/com/hom/services/Apple.java @@ -0,0 +1,16 @@ +package com.hom.services; + +import org.springframework.stereotype.Component; + +@Component +public class Apple implements Mobile { + private final String IPHONE_PRO_16 = "iPhone16Pro"; + + /** + * @return + */ + @Override + public String getModel() { + return IPHONE_PRO_16; + } +} diff --git a/src/main/java/com/hom/services/Mobile.java b/src/main/java/com/hom/services/Mobile.java new file mode 100644 index 0000000..6a781ab --- /dev/null +++ b/src/main/java/com/hom/services/Mobile.java @@ -0,0 +1,7 @@ +package com.hom.services; + +public interface Mobile { + String getModel(); + + +} diff --git a/src/main/webapp/views/display.jsp b/src/main/webapp/views/display.jsp new file mode 100644 index 0000000..e69de29 diff --git a/src/main/webapp/views/home.jsp b/src/main/webapp/views/home.jsp new file mode 100644 index 0000000..e69de29 diff --git a/src/main/webapp/views/sucess.jsp b/src/main/webapp/views/sucess.jsp new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/example/HpdemoApplicationTests.java b/src/test/java/com/example/ApplicationStartTests.java similarity index 74% rename from src/test/java/com/example/HpdemoApplicationTests.java rename to src/test/java/com/example/ApplicationStartTests.java index b0e4ca5..ad90bbf 100644 --- a/src/test/java/com/example/HpdemoApplicationTests.java +++ b/src/test/java/com/example/ApplicationStartTests.java @@ -7,10 +7,10 @@ @RunWith(SpringRunner.class) @SpringBootTest -public class HpdemoApplicationTests { +public class ApplicationStartTests { - @Test - public void contextLoads() { - } + @Test + public void contextLoads() { + } } From 37b0cf2ee48f13be677b8dae674d49527f4a5d5e Mon Sep 17 00:00:00 2001 From: SSangala Date: Tue, 13 May 2025 18:54:29 -0500 Subject: [PATCH 08/10] Example of Constructor Dependency injection --- .../java/com/example/ApplicationStart.java | 6 +++-- src/main/java/com/hom/StoreConfiguration.java | 22 ------------------- src/main/java/com/hom/services/Andriod.java | 16 -------------- src/main/java/com/hom/services/Apple.java | 16 -------------- src/main/java/com/hom/services/Mobile.java | 7 ------ 5 files changed, 4 insertions(+), 63 deletions(-) delete mode 100644 src/main/java/com/hom/StoreConfiguration.java delete mode 100644 src/main/java/com/hom/services/Andriod.java delete mode 100644 src/main/java/com/hom/services/Apple.java delete mode 100644 src/main/java/com/hom/services/Mobile.java diff --git a/src/main/java/com/example/ApplicationStart.java b/src/main/java/com/example/ApplicationStart.java index 2ba2b62..c1e5557 100644 --- a/src/main/java/com/example/ApplicationStart.java +++ b/src/main/java/com/example/ApplicationStart.java @@ -1,7 +1,7 @@ package com.example; -import com.hom.StoreConfiguration; -import com.hom.services.Mobile; +import com.example.inversionOfControl.Mobile; +import com.example.inversionOfControl.StoreConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -13,6 +13,8 @@ public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(StoreConfiguration.class); Mobile mobile1 = (Mobile) context.getBean("getAndriod"); System.out.println(mobile1.getModel()); + + Mobile mobile11 = (Mobile) context.getBean("getApple"); System.out.println(mobile11.getModel()); diff --git a/src/main/java/com/hom/StoreConfiguration.java b/src/main/java/com/hom/StoreConfiguration.java deleted file mode 100644 index 0e0d33d..0000000 --- a/src/main/java/com/hom/StoreConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.hom; - -import com.hom.services.Andriod; -import com.hom.services.Apple; -import com.hom.services.Mobile; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class StoreConfiguration { - @Bean - public Mobile getAndriod() { - return new Andriod(); - } - - //Error : Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'getApple' available -// Fix : @Bean annotation was missing on getApple , it had only for getAndriod - @Bean - public Mobile getApple() { - return new Apple(); - } -} diff --git a/src/main/java/com/hom/services/Andriod.java b/src/main/java/com/hom/services/Andriod.java deleted file mode 100644 index dce0d45..0000000 --- a/src/main/java/com/hom/services/Andriod.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hom.services; - -import org.springframework.stereotype.Component; - -@Component -public class Andriod implements Mobile { - private final String ONE_PLUS = "onePlus"; - - /** - * @return - */ - @Override - public String getModel() { - return ONE_PLUS; - } -} diff --git a/src/main/java/com/hom/services/Apple.java b/src/main/java/com/hom/services/Apple.java deleted file mode 100644 index 85e13ef..0000000 --- a/src/main/java/com/hom/services/Apple.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hom.services; - -import org.springframework.stereotype.Component; - -@Component -public class Apple implements Mobile { - private final String IPHONE_PRO_16 = "iPhone16Pro"; - - /** - * @return - */ - @Override - public String getModel() { - return IPHONE_PRO_16; - } -} diff --git a/src/main/java/com/hom/services/Mobile.java b/src/main/java/com/hom/services/Mobile.java deleted file mode 100644 index 6a781ab..0000000 --- a/src/main/java/com/hom/services/Mobile.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.hom.services; - -public interface Mobile { - String getModel(); - - -} From 5ad5578ca04d21cea0dada0e683554241bf06106 Mon Sep 17 00:00:00 2001 From: SSangala Date: Tue, 13 May 2025 21:26:58 -0500 Subject: [PATCH 09/10] Example of Constructor Dependency injection --- .../example/dependencyInjection/Colour.java | 12 +++++++++ .../example/inversionOfControl/Andriod.java | 27 +++++++++++++++++++ .../com/example/inversionOfControl/Apple.java | 24 +++++++++++++++++ .../example/inversionOfControl/Mobile.java | 7 +++++ .../StoreConfiguration.java | 26 ++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 src/main/java/com/example/dependencyInjection/Colour.java create mode 100644 src/main/java/com/example/inversionOfControl/Andriod.java create mode 100644 src/main/java/com/example/inversionOfControl/Apple.java create mode 100644 src/main/java/com/example/inversionOfControl/Mobile.java create mode 100644 src/main/java/com/example/inversionOfControl/StoreConfiguration.java diff --git a/src/main/java/com/example/dependencyInjection/Colour.java b/src/main/java/com/example/dependencyInjection/Colour.java new file mode 100644 index 0000000..5b25b65 --- /dev/null +++ b/src/main/java/com/example/dependencyInjection/Colour.java @@ -0,0 +1,12 @@ +package com.example.dependencyInjection; + +public class Colour { + + public void getAndriodColour() { + System.out.println("White"); + } + + public void getAppleColour() { + System.out.println("Black"); + } +} diff --git a/src/main/java/com/example/inversionOfControl/Andriod.java b/src/main/java/com/example/inversionOfControl/Andriod.java new file mode 100644 index 0000000..f0dbaad --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/Andriod.java @@ -0,0 +1,27 @@ +package com.example.inversionOfControl; + +import com.example.dependencyInjection.Colour; +import org.springframework.stereotype.Component; + +@Component +public class Andriod implements Mobile { + Colour color; + + public Andriod() { + System.out.println("Default Andriod Constructor"); + } + + public Andriod(Colour colour) { + this.color = colour; + } + + + @Override + public String getModel() { + color.getAndriodColour(); + String ONE_PLUS = "onePlus"; + return ONE_PLUS; + } + + +} diff --git a/src/main/java/com/example/inversionOfControl/Apple.java b/src/main/java/com/example/inversionOfControl/Apple.java new file mode 100644 index 0000000..e046969 --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/Apple.java @@ -0,0 +1,24 @@ +package com.example.inversionOfControl; + +import com.example.dependencyInjection.Colour; +import org.springframework.stereotype.Component; + +@Component +public class Apple implements Mobile { + Colour color; + + public Apple() { + System.out.println("Default Apple Constructor"); + } + + public Apple(Colour colour) { + this.color = colour; + } + + @Override + public String getModel() { + color.getAppleColour(); + String IPHONE_PRO_16 = "iPhone16Pro"; + return IPHONE_PRO_16; + } +} diff --git a/src/main/java/com/example/inversionOfControl/Mobile.java b/src/main/java/com/example/inversionOfControl/Mobile.java new file mode 100644 index 0000000..040225a --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/Mobile.java @@ -0,0 +1,7 @@ +package com.example.inversionOfControl; + +public interface Mobile { + String getModel(); + + +} diff --git a/src/main/java/com/example/inversionOfControl/StoreConfiguration.java b/src/main/java/com/example/inversionOfControl/StoreConfiguration.java new file mode 100644 index 0000000..1de3c2b --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/StoreConfiguration.java @@ -0,0 +1,26 @@ +package com.example.inversionOfControl; + +import com.example.dependencyInjection.Colour; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class StoreConfiguration { + + @Bean + public Colour getColour() { + return new Colour(); + } + + @Bean + public Mobile getAndriod(Colour getColour) { + return new Andriod(getColour); + } + + //Error : Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'getApple' available +// Fix : @Bean annotation was missing on getApple , it had only for getAndriod + @Bean + public Mobile getApple(Colour getColour) { + return new Apple(getColour); + } +} From cac6c6048dc3970d92e20bcf27857c5af0a8f412 Mon Sep 17 00:00:00 2001 From: SSangala Date: Tue, 13 May 2025 22:39:59 -0500 Subject: [PATCH 10/10] Configure server port in application.properties, custom dispatcher servlet in web.xml --- pom.xml | 11 ++++++++++ src/main/java/AdminApplication.java | 15 +++++++++++++ .../java/com/example/ApplicationStart.java | 2 ++ .../com/home/controllers/HomeController.java | 14 ++++++++++++ src/main/resources/application.properties | 2 ++ .../frontControllerDispatcher-servlet.xml | 22 +++++++++++++++++++ .../webapp/{ => WEB-INF}/views/display.jsp | 0 src/main/webapp/WEB-INF/views/home.jsp | 13 +++++++++++ .../webapp/{ => WEB-INF}/views/sucess.jsp | 0 src/main/webapp/WEB-INF/web.xml | 17 ++++++++++++++ src/main/webapp/views/home.jsp | 0 11 files changed, 96 insertions(+) create mode 100644 src/main/java/AdminApplication.java create mode 100644 src/main/java/com/home/controllers/HomeController.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/webapp/WEB-INF/frontControllerDispatcher-servlet.xml rename src/main/webapp/{ => WEB-INF}/views/display.jsp (100%) create mode 100644 src/main/webapp/WEB-INF/views/home.jsp rename src/main/webapp/{ => WEB-INF}/views/sucess.jsp (100%) create mode 100644 src/main/webapp/WEB-INF/web.xml delete mode 100644 src/main/webapp/views/home.jsp diff --git a/pom.xml b/pom.xml index ffa9bce..6376c5a 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,17 @@ spring-boot-starter-test test + + + + org.apache.tomcat + tomcat-jasper + 8.5.11 + + + javax.servlet + jstl + diff --git a/src/main/java/AdminApplication.java b/src/main/java/AdminApplication.java new file mode 100644 index 0000000..68fe93a --- /dev/null +++ b/src/main/java/AdminApplication.java @@ -0,0 +1,15 @@ +package com; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AdminApplication { + + public static void main(String[] args) { + + SpringApplication.run(AdminApplication.class, args); + } +} + diff --git a/src/main/java/com/example/ApplicationStart.java b/src/main/java/com/example/ApplicationStart.java index c1e5557..9001bdb 100644 --- a/src/main/java/com/example/ApplicationStart.java +++ b/src/main/java/com/example/ApplicationStart.java @@ -1,3 +1,4 @@ +/* package com.example; import com.example.inversionOfControl.Mobile; @@ -21,3 +22,4 @@ public static void main(String[] args) { SpringApplication.run(ApplicationStart.class, args); } } +*/ diff --git a/src/main/java/com/home/controllers/HomeController.java b/src/main/java/com/home/controllers/HomeController.java new file mode 100644 index 0000000..080d7f8 --- /dev/null +++ b/src/main/java/com/home/controllers/HomeController.java @@ -0,0 +1,14 @@ +package com.home.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping(value = "/") + public String getHome() { + // it will be considered as a file ( jsp) not as content + return "/WEB-INF/views/home.jsp"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..054c6e7 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,2 @@ +--=If the port 8080 is already in use then we can configure new port to use as below +server.port=8091 \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/frontControllerDispatcher-servlet.xml b/src/main/webapp/WEB-INF/frontControllerDispatcher-servlet.xml new file mode 100644 index 0000000..9da2f25 --- /dev/null +++ b/src/main/webapp/WEB-INF/frontControllerDispatcher-servlet.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/views/display.jsp b/src/main/webapp/WEB-INF/views/display.jsp similarity index 100% rename from src/main/webapp/views/display.jsp rename to src/main/webapp/WEB-INF/views/display.jsp diff --git a/src/main/webapp/WEB-INF/views/home.jsp b/src/main/webapp/WEB-INF/views/home.jsp new file mode 100644 index 0000000..228a105 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/home.jsp @@ -0,0 +1,13 @@ + + + + HTML Login Form + + + +

Welcome to Spring MVC Application

+ + + + + \ No newline at end of file diff --git a/src/main/webapp/views/sucess.jsp b/src/main/webapp/WEB-INF/views/sucess.jsp similarity index 100% rename from src/main/webapp/views/sucess.jsp rename to src/main/webapp/WEB-INF/views/sucess.jsp diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..25d6d8f --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + + Archetype Created Web Application + + + frontControllerDispatcher + org.springframework.web.servlet.DispatcherServlet + + + + frontControllerDispatcher + / + + \ No newline at end of file diff --git a/src/main/webapp/views/home.jsp b/src/main/webapp/views/home.jsp deleted file mode 100644 index e69de29..0000000