From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../core/validation/ErrorMessageCode.java | 4 +- .../core/validation/api/ValidationManager.java | 17 +-- .../errors/ErrorMessagesFormatBuilder.java | 41 +++--- .../factory/ValidationManagerFactory.java | 12 +- .../validation/types/FileValidationContext.java | 45 +++--- .../validation/types/GlobalValidationContext.java | 155 ++++++++++----------- .../core/validation/types/MessageContainer.java | 13 +- .../core/validation/util/MessageContainerUtil.java | 91 ++++++------ 8 files changed, 167 insertions(+), 211 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/ErrorMessageCode.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/ErrorMessageCode.java index ac31bd4a1e..8fa2494fed 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/ErrorMessageCode.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/ErrorMessageCode.java @@ -22,10 +22,10 @@ package org.openecomp.core.validation; import java.util.Objects; public final class ErrorMessageCode { + private final String messageCode; public ErrorMessageCode(String messageCode) { - this.messageCode = messageCode; } @@ -46,9 +46,7 @@ public final class ErrorMessageCode { if (o == null || getClass() != o.getClass()) { return false; } - ErrorMessageCode that = (ErrorMessageCode) o; - return Objects.equals(this.messageCode, that.messageCode); } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/api/ValidationManager.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/api/ValidationManager.java index 9f75a08051..0408f64447 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/api/ValidationManager.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/api/ValidationManager.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,21 +17,18 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.validation.api; - -import org.openecomp.core.validation.types.GlobalValidationContext; -import org.openecomp.sdc.datatypes.error.ErrorMessage; - import java.util.List; import java.util.Map; +import org.openecomp.core.validation.types.GlobalValidationContext; +import org.openecomp.sdc.datatypes.error.ErrorMessage; public interface ValidationManager { - Map> validate(); + Map> validate(); - void addFile(String fileName, byte[] validationContent); + void addFile(String fileName, byte[] validationContent); - void updateGlobalContext(GlobalValidationContext globalContext); + void updateGlobalContext(GlobalValidationContext globalContext); } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java index e3ed721fdd..4c1ed2173e 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,32 +17,29 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.validation.errors; - import org.openecomp.core.validation.ErrorMessageCode; public class ErrorMessagesFormatBuilder { - private static final String MESSAGE_PATTERN = "[%s]: %s"; - public static String getErrorWithParameters(String error, Object... params) { - return String.format(error, params); - } - /** - * Formatted message with error code. - * - * @param messageCode error code. - * @param errorMessage error message. - * @param params parameters used in formatting message. - * @return formatted message string. - */ - public static String getErrorWithParameters(ErrorMessageCode messageCode, - String errorMessage, String... params) { - String message = getErrorWithParameters(errorMessage, params); + private static final String MESSAGE_PATTERN = "[%s]: %s"; - return ( null != messageCode && null != messageCode.getMessageCode() ) ? - String.format(MESSAGE_PATTERN, messageCode.getMessageCode(), message) : message; - } + public static String getErrorWithParameters(String error, Object... params) { + return String.format(error, params); + } + /** + * Formatted message with error code. + * + * @param messageCode error code. + * @param errorMessage error message. + * @param params parameters used in formatting message. + * @return formatted message string. + */ + public static String getErrorWithParameters(ErrorMessageCode messageCode, String errorMessage, String... params) { + String message = getErrorWithParameters(errorMessage, params); + return (null != messageCode && null != messageCode.getMessageCode()) ? String.format(MESSAGE_PATTERN, messageCode.getMessageCode(), message) + : message; + } } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/factory/ValidationManagerFactory.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/factory/ValidationManagerFactory.java index 36beab10cf..3aac95f733 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/factory/ValidationManagerFactory.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/factory/ValidationManagerFactory.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,17 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.validation.factory; import org.openecomp.core.factory.api.AbstractComponentFactory; import org.openecomp.core.factory.api.AbstractFactory; import org.openecomp.core.validation.api.ValidationManager; - public abstract class ValidationManagerFactory extends AbstractComponentFactory { - public static ValidationManagerFactory getInstance() { - return AbstractFactory.getInstance(ValidationManagerFactory.class); - } + public static ValidationManagerFactory getInstance() { + return AbstractFactory.getInstance(ValidationManagerFactory.class); + } } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/FileValidationContext.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/FileValidationContext.java index 3bc760c805..9b8e53744c 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/FileValidationContext.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/FileValidationContext.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,38 +17,35 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.validation.types; - import java.io.ByteArrayInputStream; import java.io.InputStream; - public class FileValidationContext { - private String fileName; - private MessageContainer messageContainer = new MessageContainer(); - private byte[] content; - public FileValidationContext(String fileName, byte[] fileContent) { - this.fileName = fileName; - this.content = fileContent; - } + private String fileName; + private MessageContainer messageContainer = new MessageContainer(); + private byte[] content; + public FileValidationContext(String fileName, byte[] fileContent) { + this.fileName = fileName; + this.content = fileContent; + } - MessageContainer getMessageContainer() { - return this.messageContainer; - } + MessageContainer getMessageContainer() { + return this.messageContainer; + } - public InputStream getContent() { - return new ByteArrayInputStream(content); - } + public InputStream getContent() { + return new ByteArrayInputStream(content); + } - public String getFileName() { - return this.fileName; - } + public String getFileName() { + return this.fileName; + } - public boolean isEmpty() { - return content == null || content.length == 0; - } + public boolean isEmpty() { + return content == null || content.length == 0; + } } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java index 42ea681b1b..b5ebf11240 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java @@ -13,15 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.validation.types; -import org.apache.commons.collections4.CollectionUtils; -import org.openecomp.core.validation.ErrorMessageCode; -import org.openecomp.sdc.datatypes.error.ErrorLevel; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; - import java.io.InputStream; import java.util.Collection; import java.util.HashMap; @@ -29,95 +22,89 @@ import java.util.Map; import java.util.Optional; import java.util.function.BiPredicate; import java.util.stream.Collectors; +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.validation.ErrorMessageCode; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; public class GlobalValidationContext { - private static final Logger LOGGER = LoggerFactory.getLogger(GlobalValidationContext.class); - private final Map fileContextMap = new HashMap<>(); - private final Map messageContainerMap = new HashMap<>(); - private ErrorMessageCode messageCode; + private static final Logger LOGGER = LoggerFactory.getLogger(GlobalValidationContext.class); + private final Map fileContextMap = new HashMap<>(); + private final Map messageContainerMap = new HashMap<>(); + private ErrorMessageCode messageCode; - public ErrorMessageCode getMessageCode() { - return messageCode; - } - - public void setMessageCode(ErrorMessageCode messageCode) { - this.messageCode = messageCode; - } - - - /** - * Add message. - * - * @param fileName the file name - * @param level the level - * @param message the message - */ - public void addMessage(String fileName, ErrorLevel level, String message) { - - LOGGER.debug("'{}' [{}] in file '{}' ", message, level, fileName); - - if (fileContextMap.containsKey(fileName)) { - fileContextMap.get(fileName).getMessageContainer().getMessageBuilder() - .setMessage(level.toString() + ": " + message).setLevel(level).create(); - } else { - MessageContainer messageContainer; - synchronized (this) { - messageContainer = messageContainerMap.computeIfAbsent(fileName, k -> new MessageContainer()); - } - messageContainer.getMessageBuilder().setMessage(level.toString() + ": " + message) - .setLevel(level).create(); + public ErrorMessageCode getMessageCode() { + return messageCode; } - } - /** - * Gets file content. - * - * @param fileName the file name - * @return the file content - */ - public Optional getFileContent(String fileName) { - FileValidationContext fileContext = fileContextMap.get(fileName); - if (fileContext == null || fileContext.isEmpty()) { - return Optional.empty(); + public void setMessageCode(ErrorMessageCode messageCode) { + this.messageCode = messageCode; } - return Optional.of(fileContext.getContent()); - } - public void addFileContext(String fileName, byte[] fileContent) { - fileContextMap.put(fileName, new FileValidationContext(fileName, fileContent)); - } + /** + * Add message. + * + * @param fileName the file name + * @param level the level + * @param message the message + */ + public void addMessage(String fileName, ErrorLevel level, String message) { + LOGGER.debug("'{}' [{}] in file '{}' ", message, level, fileName); + if (fileContextMap.containsKey(fileName)) { + fileContextMap.get(fileName).getMessageContainer().getMessageBuilder().setMessage(level.toString() + ": " + message).setLevel(level) + .create(); + } else { + MessageContainer messageContainer; + synchronized (this) { + messageContainer = messageContainerMap.computeIfAbsent(fileName, k -> new MessageContainer()); + } + messageContainer.getMessageBuilder().setMessage(level.toString() + ": " + message).setLevel(level).create(); + } + } - /** - * Gets context message containers. - * - * @return the context message containers - */ - public Map getContextMessageContainers() { + /** + * Gets file content. + * + * @param fileName the file name + * @return the file content + */ + public Optional getFileContent(String fileName) { + FileValidationContext fileContext = fileContextMap.get(fileName); + if (fileContext == null || fileContext.isEmpty()) { + return Optional.empty(); + } + return Optional.of(fileContext.getContent()); + } - Map contextMessageContainer = new HashMap<>(); - fileContextMap.entrySet().stream().filter(entry -> CollectionUtils - .isNotEmpty(entry.getValue().getMessageContainer().getErrorMessageList())).forEach( - entry -> contextMessageContainer.put( - entry.getKey(), entry.getValue() - .getMessageContainer())); - messageContainerMap.entrySet().stream() - .filter(entry -> CollectionUtils.isNotEmpty(entry.getValue().getErrorMessageList())) - .forEach(entry -> contextMessageContainer.put(entry.getKey(), entry.getValue())); - return contextMessageContainer; - } + public void addFileContext(String fileName, byte[] fileContent) { + fileContextMap.put(fileName, new FileValidationContext(fileName, fileContent)); + } - public Map getFileContextMap() { - return fileContextMap; - } + /** + * Gets context message containers. + * + * @return the context message containers + */ + public Map getContextMessageContainers() { + Map contextMessageContainer = new HashMap<>(); + fileContextMap.entrySet().stream().filter(entry -> CollectionUtils.isNotEmpty(entry.getValue().getMessageContainer().getErrorMessageList())) + .forEach(entry -> contextMessageContainer.put(entry.getKey(), entry.getValue().getMessageContainer())); + messageContainerMap.entrySet().stream().filter(entry -> CollectionUtils.isNotEmpty(entry.getValue().getErrorMessageList())) + .forEach(entry -> contextMessageContainer.put(entry.getKey(), entry.getValue())); + return contextMessageContainer; + } - public Collection files(BiPredicate func) { - return fileContextMap.keySet().stream().filter(t -> func.test(t, this)) - .collect(Collectors.toList()); - } + public Map getFileContextMap() { + return fileContextMap; + } - public Collection getFiles() { - return this.getFileContextMap().keySet(); - } + public Collection files(BiPredicate func) { + return fileContextMap.keySet().stream().filter(t -> func.test(t, this)).collect(Collectors.toList()); + } + public Collection getFiles() { + return this.getFileContextMap().keySet(); + } } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/MessageContainer.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/MessageContainer.java index eb57672315..bbe6247b76 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/MessageContainer.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/MessageContainer.java @@ -17,15 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.validation.types; -import org.openecomp.sdc.datatypes.error.ErrorLevel; -import org.openecomp.sdc.datatypes.error.ErrorMessage; - import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; public class MessageContainer { @@ -40,16 +38,13 @@ public class MessageContainer { } /** - * Gets error message list by level. - * Only this level, not this level and above + * Gets error message list by level. Only this level, not this level and above * * @param level the level * @return the error message list by level */ public List getErrorMessageListByLevel(ErrorLevel level) { - return errorMessageList.stream() - .filter(message -> message.getLevel().equals(level)) - .collect(Collectors.toList()); + return errorMessageList.stream().filter(message -> message.getLevel().equals(level)).collect(Collectors.toList()); } public class MessageBuilder { diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/util/MessageContainerUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/util/MessageContainerUtil.java index aab83837b8..e5ee3f2e95 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/util/MessageContainerUtil.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/util/MessageContainerUtil.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,69 +17,56 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.validation.util; -import org.openecomp.sdc.datatypes.error.ErrorLevel; -import org.openecomp.sdc.datatypes.error.ErrorMessage; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; public class MessageContainerUtil { - /** - * Gets message by level. - * - * @param level the level - * @param messages the messages - * @return the message by level - */ - public static Map> getMessageByLevel(ErrorLevel level, - Map> - messages) { - if (messages == null) { - return null; - } - Map> filteredMessages = new HashMap<>(); - messages.entrySet().forEach( - entry -> entry.getValue().stream().filter(message -> message.getLevel().equals(level)) - .forEach(message -> addMessage(entry.getKey(), message, filteredMessages - ))); - return filteredMessages; - } - private static void addMessage(String fileName, ErrorMessage message, - Map> messages) { - List messageList = messages.computeIfAbsent(fileName, k -> new ArrayList<>()); - messageList.add(message); - } + /** + * Gets message by level. + * + * @param level the level + * @param messages the messages + * @return the message by level + */ + public static Map> getMessageByLevel(ErrorLevel level, Map> messages) { + if (messages == null) { + return null; + } + Map> filteredMessages = new HashMap<>(); + messages.entrySet().forEach(entry -> entry.getValue().stream().filter(message -> message.getLevel().equals(level)) + .forEach(message -> addMessage(entry.getKey(), message, filteredMessages))); + return filteredMessages; + } - public static String getErrorMessagesListAsString(Map> messages) { - StringBuilder concatErrorMessage = new StringBuilder(); + private static void addMessage(String fileName, ErrorMessage message, Map> messages) { + List messageList = messages.computeIfAbsent(fileName, k -> new ArrayList<>()); + messageList.add(message); + } - for (Map.Entry> errorMessageEntry : messages.entrySet()) { - appendErrorMessageAsString(concatErrorMessage, errorMessageEntry.getKey(), - errorMessageEntry.getValue()); + public static String getErrorMessagesListAsString(Map> messages) { + StringBuilder concatErrorMessage = new StringBuilder(); + for (Map.Entry> errorMessageEntry : messages.entrySet()) { + appendErrorMessageAsString(concatErrorMessage, errorMessageEntry.getKey(), errorMessageEntry.getValue()); + } + return concatErrorMessage.toString(); } - return concatErrorMessage.toString(); - } - private static void appendErrorMessageAsString(StringBuilder concatErrorMessage, - String fileName, - List errorMessageList) { - for (ErrorMessage errorMessage : errorMessageList) { - addErrorMessage(concatErrorMessage, fileName, errorMessage); + private static void appendErrorMessageAsString(StringBuilder concatErrorMessage, String fileName, List errorMessageList) { + for (ErrorMessage errorMessage : errorMessageList) { + addErrorMessage(concatErrorMessage, fileName, errorMessage); + } } - } - private static void addErrorMessage(StringBuilder concatErrorMessage, - String fileName, - ErrorMessage errorMessage) { - concatErrorMessage.append(fileName).append(" : "); - concatErrorMessage.append(errorMessage.getMessage()); - concatErrorMessage.append("\n"); - } + private static void addErrorMessage(StringBuilder concatErrorMessage, String fileName, ErrorMessage errorMessage) { + concatErrorMessage.append(fileName).append(" : "); + concatErrorMessage.append(errorMessage.getMessage()); + concatErrorMessage.append("\n"); + } } -- cgit 1.2.3-korg