List of usage examples for com.liferay.portal.kernel.util StringPool AT
String AT
To view the source code for com.liferay.portal.kernel.util StringPool AT.
Click Source Link
From source file:com.liferay.tools.sourceformatter.JavaClass.java
License:Open Source License
protected void checkAnnotationForMethod(JavaTerm javaTerm, String annotation, String requiredMethodNameRegex, int requiredMethodType, String fileName) { String methodContent = javaTerm.getContent(); String methodName = javaTerm.getName(); Pattern pattern = Pattern.compile(requiredMethodNameRegex); Matcher matcher = pattern.matcher(methodName); if (methodContent.contains(_indent + StringPool.AT + annotation + "\n") || methodContent.contains(_indent + StringPool.AT + annotation + StringPool.OPEN_PARENTHESIS)) { if (!matcher.find()) { BaseSourceProcessor.processErrorMessage(fileName, "LPS-36303: Incorrect method name: " + methodName + " " + fileName); } else if (javaTerm.getType() != requiredMethodType) { BaseSourceProcessor.processErrorMessage(fileName, "LPS-36303: Incorrect method type for " + methodName + " " + fileName); }/*from w w w . j a va2 s. co m*/ } else if (matcher.find() && !methodContent.contains(_indent + "@Override")) { BaseSourceProcessor.processErrorMessage(fileName, "Annotation @" + annotation + " required for " + methodName + " " + fileName); } }
From source file:com.liferay.tools.sourceformatter.JavaClass.java
License:Open Source License
protected void checkFinalableFieldType(JavaTerm javaTerm, Set<String> annotationsExclusions, boolean isStatic) throws Exception { String javaTermContent = javaTerm.getContent(); for (String annotation : annotationsExclusions) { if (javaTermContent.contains(_indent + StringPool.AT + annotation)) { return; }/*from ww w .ja v a 2s .co m*/ } StringBundler sb = new StringBundler(4); sb.append("(\\b|\\.)"); sb.append(javaTerm.getName()); sb.append(" (=)|(\\+\\+)|(--)|(\\+=)|(-=)|(\\*=)|(/=)|(%=)"); sb.append("|(\\|=)|(&=)|(^=) "); Pattern pattern = Pattern.compile(sb.toString()); if (!isFinalableField(javaTerm, _name, pattern, true)) { return; } String newJavaTermContent = null; if (isStatic) { newJavaTermContent = StringUtil.replaceFirst(javaTermContent, "private static ", "private static final "); } else { newJavaTermContent = StringUtil.replaceFirst(javaTermContent, "private ", "private final "); } _content = StringUtil.replace(_content, javaTermContent, newJavaTermContent); }
From source file:com.liferay.tools.sourceformatter.JavaClass.java
License:Open Source License
protected boolean hasAnnotationCommentOrJavadoc(String s) { if (s.startsWith(_indent + StringPool.AT) || s.startsWith(_indent + StringPool.SLASH) || s.startsWith(_indent + " *")) { return true; } else {/*from w ww.j a v a2s . c o m*/ return false; } }
From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java
License:Open Source License
protected static String sortAnnotations(String content, String indent) throws IOException { UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(content)); String line = null;/*w w w. ja va 2 s . c om*/ String annotation = StringPool.BLANK; String previousAnnotation = StringPool.BLANK; while ((line = unsyncBufferedReader.readLine()) != null) { if (line.equals(indent + StringPool.CLOSE_CURLY_BRACE)) { return content; } if (StringUtil.count(line, StringPool.TAB) == indent.length()) { if (Validator.isNotNull(previousAnnotation) && (previousAnnotation.compareTo(annotation) > 0)) { content = StringUtil.replaceFirst(content, previousAnnotation, annotation); content = StringUtil.replaceLast(content, annotation, previousAnnotation); return sortAnnotations(content, indent); } if (line.startsWith(indent + StringPool.AT)) { if (Validator.isNotNull(annotation)) { previousAnnotation = annotation; } annotation = line + "\n"; } else { annotation = StringPool.BLANK; previousAnnotation = StringPool.BLANK; } } else { if (Validator.isNull(annotation)) { return content; } annotation += line + "\n"; } } return content; }
From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java
License:Open Source License
protected String formatJava(String fileName, String absolutePath, String content) throws Exception { StringBundler sb = new StringBundler(); try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader( new UnsyncStringReader(content))) { String line = null;/*w ww.j a v a2 s . c om*/ String previousLine = StringPool.BLANK; int lineCount = 0; String ifClause = StringPool.BLANK; String packageName = StringPool.BLANK; String regexPattern = StringPool.BLANK; while ((line = unsyncBufferedReader.readLine()) != null) { lineCount++; line = trimLine(line, false); if (line.startsWith("package ")) { packageName = line.substring(8, line.length() - 1); } if (line.startsWith("import ")) { if (line.endsWith(".*;")) { processErrorMessage(fileName, "import: " + fileName + " " + lineCount); } int pos = line.lastIndexOf(StringPool.PERIOD); if (pos != -1) { String importPackageName = line.substring(7, pos); if (importPackageName.equals(packageName)) { continue; } } } if (line.contains(StringPool.TAB + "for (") && line.contains(":") && !line.contains(" :")) { line = StringUtil.replace(line, ":", " :"); } // LPS-42924 if (line.contains("PortalUtil.getClassNameId(") && fileName.endsWith("ServiceImpl.java")) { processErrorMessage(fileName, "Use classNameLocalService.getClassNameId: " + fileName + " " + lineCount); } // LPS-42599 if (!isExcluded(_hibernateSQLQueryExclusions, absolutePath) && line.contains("= session.createSQLQuery(") && content.contains("com.liferay.portal.kernel.dao.orm.Session")) { line = StringUtil.replace(line, "createSQLQuery", "createSynchronizedSQLQuery"); } line = replacePrimitiveWrapperInstantiation(fileName, line, lineCount); String trimmedLine = StringUtil.trimLeading(line); // LPS-45649 if (trimmedLine.startsWith("throw new IOException(") && line.contains("e.getMessage()")) { line = StringUtil.replace(line, ".getMessage()", StringPool.BLANK); } // LPS-45492 if (trimmedLine.contains("StopWatch stopWatch = null;")) { processErrorMessage(fileName, "Do not set stopwatch to null: " + fileName + " " + lineCount); } checkStringBundler(trimmedLine, fileName, lineCount); checkEmptyCollection(trimmedLine, fileName, lineCount); if (trimmedLine.startsWith("* @deprecated") && _addMissingDeprecationReleaseVersion) { if (!trimmedLine.startsWith("* @deprecated As of ")) { line = StringUtil.replace(line, "* @deprecated", "* @deprecated As of " + getMainReleaseVersion()); } else { String version = trimmedLine.substring(20); version = StringUtil.split(version, StringPool.SPACE)[0]; version = StringUtil.replace(version, StringPool.COMMA, StringPool.BLANK); if (StringUtil.count(version, StringPool.PERIOD) == 1) { line = StringUtil.replaceFirst(line, version, version + ".0"); } } } if (trimmedLine.startsWith("* @see ") && (StringUtil.count(trimmedLine, StringPool.AT) > 1)) { processErrorMessage(fileName, "Do not use @see with another annotation: " + fileName + " " + lineCount); } checkInefficientStringMethods(line, fileName, absolutePath, lineCount); if (trimmedLine.startsWith(StringPool.EQUAL)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (line.contains("ActionForm form")) { processErrorMessage(fileName, "Rename form to actionForm: " + fileName + " " + lineCount); } if (line.contains("ActionMapping mapping")) { processErrorMessage(fileName, "Rename mapping to ActionMapping: " + fileName + " " + lineCount); } if (fileName.contains("/upgrade/") && line.contains("rs.getDate(")) { processErrorMessage(fileName, "Use rs.getTimeStamp: " + fileName + " " + lineCount); } if (!trimmedLine.equals("{") && line.endsWith("{") && !line.endsWith(" {")) { line = StringUtil.replaceLast(line, "{", " {"); } line = sortExceptions(line); if (trimmedLine.startsWith("if (") || trimmedLine.startsWith("else if (") || trimmedLine.startsWith("while (") || Validator.isNotNull(ifClause)) { ifClause = ifClause + line + StringPool.NEW_LINE; if (line.endsWith(") {")) { String newIfClause = checkIfClause(ifClause, fileName, lineCount); if (!ifClause.equals(newIfClause) && content.contains(ifClause)) { return StringUtil.replace(content, ifClause, newIfClause); } ifClause = StringPool.BLANK; } else if (line.endsWith(StringPool.SEMICOLON)) { ifClause = StringPool.BLANK; } } if (trimmedLine.startsWith("Pattern ") || Validator.isNotNull(regexPattern)) { regexPattern = regexPattern + trimmedLine; if (trimmedLine.endsWith(");")) { // LPS-41084 checkRegexPattern(regexPattern, fileName, lineCount); regexPattern = StringPool.BLANK; } } if (!trimmedLine.contains(StringPool.DOUBLE_SLASH) && !trimmedLine.startsWith(StringPool.STAR)) { String strippedQuotesLine = stripQuotes(trimmedLine, CharPool.QUOTE); for (int x = 0;;) { x = strippedQuotesLine.indexOf(StringPool.EQUAL, x + 1); if (x == -1) { break; } char c = strippedQuotesLine.charAt(x - 1); if (Character.isLetterOrDigit(c)) { line = StringUtil.replace(line, c + "=", c + " ="); break; } if (x == (strippedQuotesLine.length() - 1)) { break; } c = strippedQuotesLine.charAt(x + 1); if (Character.isLetterOrDigit(c)) { line = StringUtil.replace(line, "=" + c, "= " + c); break; } } while (trimmedLine.contains(StringPool.TAB)) { line = StringUtil.replaceLast(line, StringPool.TAB, StringPool.SPACE); trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.TAB, StringPool.SPACE); } if (line.contains(StringPool.TAB + StringPool.SPACE) && !previousLine.endsWith("&&") && !previousLine.endsWith("||") && !previousLine.contains(StringPool.TAB + "((") && !previousLine.contains(StringPool.TAB + StringPool.LESS_THAN) && !previousLine.contains(StringPool.TAB + StringPool.SPACE) && !previousLine.contains(StringPool.TAB + "for (") && !previousLine.contains(StringPool.TAB + "implements ") && !previousLine.contains(StringPool.TAB + "throws ")) { line = StringUtil.replace(line, StringPool.TAB + StringPool.SPACE, StringPool.TAB); } while (trimmedLine.contains(StringPool.DOUBLE_SPACE) && !trimmedLine.contains(StringPool.QUOTE + StringPool.DOUBLE_SPACE) && !fileName.contains("Test")) { line = StringUtil.replaceLast(line, StringPool.DOUBLE_SPACE, StringPool.SPACE); trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.DOUBLE_SPACE, StringPool.SPACE); } if (!line.contains(StringPool.QUOTE)) { int pos = line.indexOf(") "); if (pos != -1) { String linePart = line.substring(pos + 2); if (Character.isLetter(linePart.charAt(0)) && !linePart.startsWith("default") && !linePart.startsWith("instanceof") && !linePart.startsWith("throws")) { line = StringUtil.replaceLast(line, StringPool.SPACE + linePart, linePart); } } if ((trimmedLine.startsWith("private ") || trimmedLine.startsWith("protected ") || trimmedLine.startsWith("public ")) && !line.contains(StringPool.EQUAL) && line.contains(" (")) { line = StringUtil.replace(line, " (", "("); } if (line.contains(" [")) { line = StringUtil.replace(line, " [", "["); } for (int x = -1;;) { int posComma = line.indexOf(StringPool.COMMA, x + 1); int posSemicolon = line.indexOf(StringPool.SEMICOLON, x + 1); if ((posComma == -1) && (posSemicolon == -1)) { break; } x = Math.min(posComma, posSemicolon); if (x == -1) { x = Math.max(posComma, posSemicolon); } if (line.length() > (x + 1)) { char nextChar = line.charAt(x + 1); if ((nextChar != CharPool.APOSTROPHE) && (nextChar != CharPool.CLOSE_PARENTHESIS) && (nextChar != CharPool.SPACE) && (nextChar != CharPool.STAR)) { line = StringUtil.insert(line, StringPool.SPACE, x + 1); } } if (x > 0) { char previousChar = line.charAt(x - 1); if (previousChar == CharPool.SPACE) { line = line.substring(0, x - 1).concat(line.substring(x)); } } } } if ((line.contains(" && ") || line.contains(" || ")) && line.endsWith(StringPool.OPEN_PARENTHESIS)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (trimmedLine.endsWith(StringPool.PLUS) && !trimmedLine.startsWith(StringPool.OPEN_PARENTHESIS)) { int closeParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.CLOSE_PARENTHESIS); int openParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.OPEN_PARENTHESIS); if (openParenthesisCount > closeParenthesisCount) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } int x = strippedQuotesLine.indexOf(", "); if (x != -1) { String linePart = strippedQuotesLine.substring(0, x); int closeParenthesisCount = StringUtil.count(linePart, StringPool.CLOSE_PARENTHESIS); int openParenthesisCount = StringUtil.count(linePart, StringPool.OPEN_PARENTHESIS); if (closeParenthesisCount > openParenthesisCount) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } else if (trimmedLine.endsWith(StringPool.COMMA) && !trimmedLine.startsWith("for (")) { int closeParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.CLOSE_PARENTHESIS); int openParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.OPEN_PARENTHESIS); if (closeParenthesisCount < openParenthesisCount) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } if (line.contains(StringPool.COMMA) && !line.contains(StringPool.CLOSE_PARENTHESIS) && !line.contains(StringPool.GREATER_THAN) && !line.contains(StringPool.QUOTE) && line.endsWith(StringPool.OPEN_PARENTHESIS)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (line.endsWith(" +") || line.endsWith(" -") || line.endsWith(" *") || line.endsWith(" /")) { x = line.indexOf(" = "); if (x != -1) { int y = line.indexOf(StringPool.QUOTE); if ((y == -1) || (x < y)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } } if (line.endsWith(" throws") || (previousLine.endsWith(StringPool.OPEN_PARENTHESIS) && line.contains(" throws ") && line.endsWith(StringPool.OPEN_CURLY_BRACE))) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (trimmedLine.startsWith(StringPool.PERIOD) || (line.endsWith(StringPool.PERIOD) && line.contains(StringPool.EQUAL))) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE) && line.endsWith(StringPool.OPEN_CURLY_BRACE)) { Matcher matcher = _lineBreakPattern.matcher(trimmedLine); if (!matcher.find()) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } } if (line.contains(" ") && !line.matches("\\s*\\*.*")) { if (!fileName.endsWith("StringPool.java")) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } } if (line.contains(" {") && !line.matches("\\s*\\*.*")) { processErrorMessage(fileName, "{:" + fileName + " " + lineCount); } int lineLength = getLineLength(line); if (!line.startsWith("import ") && !line.startsWith("package ") && !line.matches("\\s*\\*.*")) { if (fileName.endsWith("Table.java") && line.contains("String TABLE_SQL_CREATE = ")) { } else if (fileName.endsWith("Table.java") && line.contains("String TABLE_SQL_DROP = ")) { } else if (fileName.endsWith("Table.java") && line.contains(" index IX_")) { } else if (lineLength > _MAX_LINE_LENGTH) { if (!isExcluded(_lineLengthExclusions, absolutePath, lineCount) && !isAnnotationParameter(content, trimmedLine)) { String truncateLongLinesContent = getTruncateLongLinesContent(content, line, trimmedLine, lineCount); if (truncateLongLinesContent != null) { return truncateLongLinesContent; } processErrorMessage(fileName, "> 80: " + fileName + " " + lineCount); } } else { int lineLeadingTabCount = getLeadingTabCount(line); int previousLineLeadingTabCount = getLeadingTabCount(previousLine); if (!trimmedLine.startsWith("//")) { if (previousLine.endsWith(StringPool.COMMA) && previousLine.contains(StringPool.OPEN_PARENTHESIS) && !previousLine.contains("for (") && (lineLeadingTabCount > previousLineLeadingTabCount)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if ((lineLeadingTabCount == previousLineLeadingTabCount) && (previousLine.endsWith(StringPool.EQUAL) || previousLine.endsWith(StringPool.OPEN_PARENTHESIS))) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } if (Validator.isNotNull(trimmedLine)) { if (((previousLine.endsWith(StringPool.COLON) && previousLine.contains(StringPool.TAB + "for ")) || (previousLine.endsWith(StringPool.OPEN_PARENTHESIS) && previousLine.contains(StringPool.TAB + "if "))) && ((previousLineLeadingTabCount + 2) != lineLeadingTabCount)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } if (previousLine.endsWith(StringPool.OPEN_CURLY_BRACE) && !trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE) && ((previousLineLeadingTabCount + 1) != lineLeadingTabCount)) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } } if (previousLine.endsWith(StringPool.PERIOD)) { int x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS); if ((x != -1) && ((getLineLength(previousLine) + x) < _MAX_LINE_LENGTH) && (trimmedLine.endsWith(StringPool.OPEN_PARENTHESIS) || (trimmedLine.charAt(x + 1) != CharPool.CLOSE_PARENTHESIS))) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } int diff = lineLeadingTabCount - previousLineLeadingTabCount; if (trimmedLine.startsWith("throws ") && ((diff == 0) || (diff > 1))) { processErrorMessage(fileName, "tab: " + fileName + " " + lineCount); } if ((diff == 2) && (previousLineLeadingTabCount > 0) && line.endsWith(StringPool.SEMICOLON) && !previousLine.contains(StringPool.TAB + "try (")) { line = StringUtil.replaceFirst(line, StringPool.TAB, StringPool.BLANK); } if ((previousLine.contains(" class ") || previousLine.contains(" enum ")) && previousLine.endsWith(StringPool.OPEN_CURLY_BRACE) && Validator.isNotNull(line) && !trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE)) { processErrorMessage(fileName, "line break: " + fileName + " " + lineCount); } } String combinedLinesContent = getCombinedLinesContent(content, fileName, absolutePath, line, trimmedLine, lineLength, lineCount, previousLine, lineLeadingTabCount, previousLineLeadingTabCount); if (combinedLinesContent != null) { return combinedLinesContent; } } } if (lineCount > 1) { sb.append(previousLine); if (Validator.isNotNull(previousLine) && Validator.isNotNull(trimmedLine) && !previousLine.contains("/*") && !previousLine.endsWith("*/")) { String trimmedPreviousLine = StringUtil.trimLeading(previousLine); if ((trimmedPreviousLine.startsWith("// ") && !trimmedLine.startsWith("// ")) || (!trimmedPreviousLine.startsWith("// ") && trimmedLine.startsWith("// "))) { sb.append("\n"); } else if (!trimmedPreviousLine.endsWith(StringPool.OPEN_CURLY_BRACE) && !trimmedPreviousLine.endsWith(StringPool.COLON) && (trimmedLine.startsWith("for (") || trimmedLine.startsWith("if ("))) { sb.append("\n"); } else if (previousLine.endsWith(StringPool.TAB + StringPool.CLOSE_CURLY_BRACE) && !trimmedLine.startsWith(StringPool.CLOSE_CURLY_BRACE) && !trimmedLine.startsWith(StringPool.CLOSE_PARENTHESIS) && !trimmedLine.startsWith(StringPool.DOUBLE_SLASH) && !trimmedLine.equals("*/") && !trimmedLine.startsWith("catch ") && !trimmedLine.startsWith("else ") && !trimmedLine.startsWith("finally ") && !trimmedLine.startsWith("while ")) { sb.append("\n"); } } sb.append("\n"); } previousLine = line; } sb.append(previousLine); } String newContent = sb.toString(); if (newContent.endsWith("\n")) { newContent = newContent.substring(0, newContent.length() - 1); } return newContent; }
From source file:com.liferay.tools.sourceformatter.PropertiesSourceProcessor.java
License:Open Source License
protected void formatSourceFormatterProperties(String fileName, String content) throws Exception { String path = StringPool.BLANK; int pos = fileName.lastIndexOf(StringPool.SLASH); if (pos != -1) { path = fileName.substring(0, pos + 1); }//w ww . jav a 2 s. c o m Properties properties = new Properties(); InputStream inputStream = new FileInputStream(fileName); properties.load(inputStream); Enumeration<String> enu = (Enumeration<String>) properties.propertyNames(); while (enu.hasMoreElements()) { String key = enu.nextElement(); if (!key.endsWith("excludes.files")) { continue; } String value = properties.getProperty(key); if (Validator.isNull(value)) { continue; } List<String> propertyFileNames = ListUtil.fromString(value, StringPool.COMMA); for (String propertyFileName : propertyFileNames) { pos = propertyFileName.indexOf(StringPool.AT); if (pos != -1) { propertyFileName = propertyFileName.substring(0, pos); } if (!fileUtil.exists(path + propertyFileName)) { processErrorMessage(fileName, "Incorrect property value: " + propertyFileName + " " + fileName); } } } }
From source file:com.liferay.util.portlet.PortletRequestUtil.java
License:Open Source License
private static boolean _isValidAttributeValue(Object obj) { if (obj == null) { return false; } else if (obj instanceof Collection<?>) { Collection<?> col = (Collection<?>) obj; if (col.size() == 0) { return false; } else {/*from w w w . j av a2s. com*/ return true; } } else if (obj instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) obj; if (map.size() == 0) { return false; } else { return true; } } else { String objString = String.valueOf(obj); if (Validator.isNull(objString)) { return false; } String hashCode = StringPool.AT.concat(StringUtil.toHexString(obj.hashCode())); if (objString.endsWith(hashCode)) { return false; } return true; } }
From source file:com.marcelmika.lims.jabber.utils.Jid.java
License:Open Source License
/** * Returns Jid from user name in the form of user@host * * @param user name// w w w. ja va 2 s .c o m * @return Lower cased jid */ public static String getJid(String user) { // Check input if (user == null) { return null; } // Add host return user.concat(StringPool.AT).concat(Environment.getJabberServiceName()); }
From source file:com.rivetlogic.quickquestions.action.util.MBUtil.java
License:Open Source License
public static String getReplyToAddress(long categoryId, long messageId, String mx, String defaultMailingListAddress) { if (PropsValues.POP_SERVER_SUBDOMAIN.length() <= 0) { return defaultMailingListAddress; }/*from w w w . j a v a 2 s .c o m*/ StringBundler sb = new StringBundler(8); sb.append(MESSAGE_POP_PORTLET_PREFIX); sb.append(categoryId); sb.append(StringPool.PERIOD); sb.append(messageId); sb.append(StringPool.AT); sb.append(PropsValues.POP_SERVER_SUBDOMAIN); sb.append(StringPool.PERIOD); sb.append(mx); return sb.toString(); }
From source file:com.stoxx.portlet.controller.RegistrationController.java
@ActionMapping(params = "action=addUserRegistrationAction") public void addUserRegistrationAction(ActionRequest actionRequest, ActionResponse actionResponse, Model model, @ModelAttribute(REGISTRATION_BEAN) RegistrationBean registrationBean, BindingResult bindingResult) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); SessionMessages.add(actionRequest,// ww w . j av a2s .c o m PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); String actionResponseParameter = null; try { log.info("***************************the business email address variable is" + businessEmailAddress); log.info("registrationBean.toString() : " + registrationBean.toString()); log.info("***************************On Linked in click" + registrationBean.getLinkedinReg()); log.info("registrationBean.getLinkedinReg() is" + registrationBean.getLinkedinReg()); if (Validator.isNull(registrationBean.getLinkedinReg())) { registrationBean.setLinkedinReg(Boolean.FALSE); } registrationBean.setCompanyId(themeDisplay.getCompanyId()); if (Validator.isNotNull(registrationBean) && registrationBean.getLinkedinReg()) { if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean)) { SessionErrors.add(actionRequest, USER_EXISTS_KEY); actionResponse.setRenderParameter(ACTION, USER_EXISTS); return; } else { registrationBean.setUserType(STOXXConstants.STOXX_GENERAL_USER); registrationBean.setIsExistingUser(Boolean.FALSE); actionResponseParameter = "setupProfileTRANSLATOR"; createActivationLink(actionRequest, registrationBean, themeDisplay); actionResponse.setRenderParameter(ACTION, actionResponseParameter); return; } } if (Validator.isNotNull(registrationBean)) { registrationBean.setCompanyId(themeDisplay.getCompanyId()); log.info("the company id is" + registrationBean.getCompanyId()); log.info("registrationBean.getIsDeletedUser() : " + registrationBean.getIsDeletedUser()); if (Validator.isNotNull(registrationBean.getIsExistingUser()) && registrationBean.getIsExistingUser() && !(Validator.isNotNull(registrationBean.getIsDeletedUser()) && registrationBean.getIsDeletedUser())) { log.info("Return the user back to login page..."); actionResponse.setRenderParameter(ACTION, "existingUserStep2"); return; } } if (Validator.isNotNull(registrationBean) && null != registrationBean.getBusinessEmailAddress()) { log.info("the EXPECTED emailAddress id is" + registrationBean.getBusinessEmailAddress()); RegistrationBean regBean = registrationDelegator.fetchFromStoxxUser(registrationBean); log.info("the status is" + regBean.getStatus()); if (Validator.isNotNull(regBean) && Validator.isNotNull(regBean.getStatus()) && (regBean.getStatus() == 3 || regBean.getStatus() == 4)) { log.info("the user with emailAddress id is" + regBean.getBusinessEmailAddress() + "is an existing user and needs to be migrated"); try { if (regBean.getStatus() == 4 && regBean.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) { String emailDomainName = registrationBean.getBusinessEmailAddress() .substring(registrationBean.getBusinessEmailAddress().lastIndexOf("@")); EmailDomain emailDomain = EmailDomainLocalServiceUtil.getEmailDomain(emailDomainName); regBean.setSalesEntryId(emailDomain.getSalesEntryId()); SalesEntry salesEntry = SalesEntryLocalServiceUtil .getSalesEntry(emailDomain.getSalesEntryId()); int allowedLicenses = salesEntry.getUsersAllowed(); int alreadyUsedLicenses = registrationDelegator .getCustomerCountByGroupId(salesEntry.getSalesEntryId()); log.info("alreadyUsedLicenses from DB for salesentryID: " + salesEntry.getSalesEntryId() + " is: " + alreadyUsedLicenses); log.info("allowedLicenses: " + allowedLicenses + "for salesentry company: " + salesEntry.getCompanyName()); if (allowedLicenses <= alreadyUsedLicenses) { SessionErrors.add(actionRequest, CUST_USER_EXCEEDED); actionResponse.setRenderParameter(ACTION, CUST_USER_EXCEEDED); return; } } } catch (NoSuchEmailDomainException e) { log.info("No domain exist for provided email address."); regBean.setUserType(STOXXConstants.STOXX_GENERAL_USER); } createActivationLink(actionRequest, regBean, themeDisplay); actionResponse.setRenderParameter(ACTION, EXISTING_USER); return; } if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean)) { SessionErrors.add(actionRequest, USER_EXISTS_KEY); actionResponse.setRenderParameter(ACTION, USER_EXISTS); return; } else if (fetchActivationLinkCreateDateDiff(registrationBean.getBusinessEmailAddress())) { SessionErrors.add(actionRequest, RegistrationConstants.REGISTRATION_LINK_EXPIRED); actionResponse.setRenderParameter(ACTION, RegistrationConstants.REGISTRATION_LINK_ALREADY_SENT); return; } else if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean)) { SessionErrors.add(actionRequest, "user-activation-link-already-sent"); actionResponse.setRenderParameter(ACTION, RegistrationConstants.REGISTRATION_LINK_ALREADY_SENT); return; } } else if (null != businessEmailAddress) { log.info("Within else if : businessEmailAddress : " + businessEmailAddress); RegistrationBean regBean = registrationDelegator.fetchFromStoxxUser(registrationBean, businessEmailAddress); if (Validator.isNotNull(regBean) && Validator.isNotNull(regBean.getStatus()) && regBean.getStatus() == 3) { log.info("the user with emailAddress id is" + regBean.getBusinessEmailAddress() + "is an existing user and needs to be migrated"); actionResponse.setRenderParameter(ACTION, EXISTING_USER); return; } if (Validator.isNotNull(regBean) && Validator.isNotNull(regBean.getStatus()) && regBean.getStatus() == 4) { log.info("the user with emailAddress id is" + regBean.getBusinessEmailAddress() + "is an existing user and needs to be migrated"); actionResponse.setRenderParameter(ACTION, DELETED_USER); return; } if (Validator.isNotNull(registrationBean.getIsDeletedUser()) && registrationBean.getIsDeletedUser()) { log.info("User email address is : " + businessEmailAddress + ". User added as customer after delition"); actionResponse.setRenderParameter(ACTION, DELETED_USER); return; } if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean, businessEmailAddress)) { log.info("User exist in liferay DB"); SessionErrors.add(actionRequest, USER_EXISTS_KEY); actionResponse.setRenderParameter(ACTION, USER_EXISTS); return; } else if (fetchActivationLinkCreateDateDiff(businessEmailAddress)) { log.info("The activation link is expired."); SessionErrors.add(actionRequest, LINK_EXPIRED); actionResponse.setRenderParameter(ACTION, RegistrationConstants.REGISTRATION_LINK_ALREADY_SENT); return; } } if (null != registrationBean.getBusinessEmailAddress()) { log.info("Within If " + registrationBean.getBusinessEmailAddress()); if (registrationBean.getBusinessEmailAddress() .substring(registrationBean.getBusinessEmailAddress().indexOf(StringPool.AT) + 1) .equalsIgnoreCase(RegistrationConstants.STAFF_DOMAIN_PATTERN)) { registrationBean.setUserType(STOXXConstants.STOXX_STAFF_USER); createActivationLink(actionRequest, registrationBean, themeDisplay); actionResponseParameter = "setupProfileSTAFF"; } else { try { String emailDomainName = registrationBean.getBusinessEmailAddress() .substring(registrationBean.getBusinessEmailAddress().lastIndexOf("@")); EmailDomain emailDomain = EmailDomainLocalServiceUtil.getEmailDomain(emailDomainName); registrationBean.setSalesEntryId(emailDomain.getSalesEntryId()); SalesEntry salesEntry = SalesEntryLocalServiceUtil .getSalesEntry(emailDomain.getSalesEntryId()); int allowedLicenses = salesEntry.getUsersAllowed(); int alreadyUsedLicenses = registrationDelegator .getCustomerCountByGroupId(salesEntry.getSalesEntryId()); log.info("alreadyUsedLicenses from DB for salesentryID: " + salesEntry.getSalesEntryId() + "is: " + alreadyUsedLicenses); log.info("allowedLicenses: " + allowedLicenses + "for salesentry company: " + salesEntry.getCompanyName()); if (allowedLicenses <= alreadyUsedLicenses) { SessionErrors.add(actionRequest, CUST_USER_EXCEEDED); actionResponse.setRenderParameter(ACTION, CUST_USER_EXCEEDED); return; } registrationBean.setUserType(STOXXConstants.STOXX_REGISTERED_USER); registrationBean.setCompanyName(salesEntry.getCompanyName()); actionResponseParameter = "setupProfileGENERALLICENSED"; } catch (NoSuchEmailDomainException e) { log.info("No domain exist for provided email address."); registrationBean.setUserType(STOXXConstants.STOXX_GENERAL_USER); actionResponseParameter = "setupProfileGENERAL"; } createActivationLink(actionRequest, registrationBean, themeDisplay); } } else { log.info("Within If " + businessEmailAddress); registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean, businessEmailAddress); if (Validator.isNotNull(registrationBean.getActivationLink()) && registrationBean.getActivationLink().indexOf(PropsUtil.get("INTRANET")) != -1 && registrationBean.getActivationLink().contains(StringPool.DOLLAR)) { if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean, businessEmailAddress)) { registrationBean.setBusinessEmailAddress(businessEmailAddress); registrationDelegator.fetchFromStoxxUser(registrationBean); } else { registrationBean.setCompanyName(RegistrationConstants.STAFF_COMPANY); registrationBean.setUserType(STOXXConstants.STOXX_STAFF_USER); } } else if (Validator.isNotNull(registrationBean.getActivationLink()) && registrationBean.getActivationLink().indexOf(PropsUtil.get(INTERNET)) != -1) { if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean, businessEmailAddress)) { registrationBean.setBusinessEmailAddress(businessEmailAddress); registrationDelegator.fetchFromStoxxUser(registrationBean); } else { registrationBean.setUserType(STOXXConstants.STOXX_GENERAL_USER); } } actionResponseParameter = "setupProfileTRANSLATOR"; } log.info("the action parameter is " + actionResponse.getRenderParameterMap()); actionResponse.setRenderParameter(ACTION, actionResponseParameter); } catch (STOXXException e) { log.error("STOXXException in addUserRegistrationAction", e); } catch (Exception e) { log.error("Exception in addUserRegistrationAction ", e); } }