[RM] Feature [YAML] Please add possibility to copy message structure from Help in yaml format.
MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/HelpBuilder.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/HelpBuilder.java
@@ -677,7 +677,7 @@ public class HelpBuilder {
HelpJsonContainer fieldJsonNode = new FieldJsonContainer(fieldName,
ACTIONS + File.separator + actionName + File.separator + FIELDS + File.separator + fieldName + HTML,
- HelpJsonContainer.FIELD_ICON, HelpEntityType.FIELD, field.getType());
+ HelpJsonContainer.FIELD_ICON, HelpEntityType.FIELD, field.getType(), false);
jsonParent.addChild(fieldJsonNode);
@@ -716,7 +716,7 @@ public class HelpBuilder {
HelpJsonContainer messageJsonNode = new MessageJsonContainer(abstrFM.getName(),
ACTIONS + File.separator + actionName + File.separator + MESSAGES + File.separator + messageName + HTML,
- HelpJsonContainer.MESSAGE_ICON, HelpEntityType.MESSAGE, new ArrayList<HelpJsonContainer>());
+ HelpJsonContainer.MESSAGE_ICON, HelpEntityType.MESSAGE, false, new ArrayList<HelpJsonContainer>());
jsonParent.addChild(messageJsonNode);
@@ -850,7 +850,7 @@ public class HelpBuilder {
HelpJsonContainer messageStructureJsonNode = new MessageJsonContainer(messageName,
DICTIONARIES + File.separator + dictionaryResourceName + File.separator + MESSAGES + File.separator + messageName
- + HTML, HelpJsonContainer.MESSAGE_STRUCTURE_ICON, HelpEntityType.MESSAGE, new ArrayList<HelpJsonContainer>());
+ + HTML, HelpJsonContainer.MESSAGE_STRUCTURE_ICON, HelpEntityType.MESSAGE, false, new ArrayList<HelpJsonContainer>());
jsonParent.addChild(messageStructureJsonNode);
@@ -940,13 +940,13 @@ public class HelpBuilder {
}
}
if (field.isComplex()) {
- fieldJsonNode = new MessageJsonContainer(fieldName, fieldsPathMap.get(equalField), HelpJsonContainer.MESSAGE_ICON, fieldNodeType,
+ fieldJsonNode = new MessageJsonContainer(fieldName, fieldsPathMap.get(equalField), HelpJsonContainer.MESSAGE_ICON, fieldNodeType, field.isCollection(),
new ArrayList<HelpJsonContainer>());
buildMessageFields(field, fieldJsonNode, fieldsPathMap, dictionaryName, fieldsMap);
} else {
fieldJsonNode = new FieldJsonContainer(fieldName, fieldsPathMap.get(equalField), HelpJsonContainer.FIELD_STRUCTURE_ICON, fieldNodeType,
- getJavaTypeLabel(field.getJavaType()));
+ getJavaTypeLabel(field.getJavaType()), field.isCollection());
}
jsonParent.addChild(fieldJsonNode);

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/helpmarshaller/jsoncontainers/FieldJsonContainer.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/helpmarshaller/jsoncontainers/FieldJsonContainer.java
@@ -25,17 +25,20 @@ import java.util.List;
@JsonTypeInfo(use= Id.CLASS, include= As.PROPERTY, property="@class")
public class FieldJsonContainer extends HelpJsonContainer{
private String javaType;
+ private boolean collection;
- public FieldJsonContainer(String name, String htmlPath, String icon, HelpEntityType type, String javaType) {
+ public FieldJsonContainer(String name, String htmlPath, String icon, HelpEntityType type, String javaType, boolean isCollection) {
super(name, htmlPath, icon, type);
this.javaType = javaType;
+ this.collection = isCollection;
}
- public FieldJsonContainer(String name, String htmlPath, String icon, HelpEntityType type, String javaType, List<HelpJsonContainer> childNodes) {
+ public FieldJsonContainer(String name, String htmlPath, String icon, HelpEntityType type, String javaType, boolean isCollection, List<HelpJsonContainer> childNodes) {
super(name, htmlPath, icon, type, childNodes);
this.javaType = javaType;
+ this.collection = isCollection;
}
public FieldJsonContainer() {
@@ -45,5 +48,8 @@ public class FieldJsonContainer extends HelpJsonContainer{
return javaType;
}
+ public boolean isCollection() {
+ return collection;
+ }
}

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/helpmarshaller/jsoncontainers/HelpJsonContainer.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/helpmarshaller/jsoncontainers/HelpJsonContainer.java
@@ -61,32 +61,15 @@ public class HelpJsonContainer {
}
public HelpJsonContainer(HelpEntityName name, String filePath, String icon, HelpEntityType type, List<HelpJsonContainer> childNodes) {
- this.filePath = filePath;
- this.childNodes = childNodes;
- this.name = name.getValue();
- this.icon = icon;
- this.type = type;
-
+ this(name.getValue(), filePath, icon, type, childNodes);
}
public HelpJsonContainer(String name, String filePath, String icon, HelpEntityType type) {
- this.filePath = filePath;
- this.name = name;
- this.icon = icon;
- this.type = type;
-
- this.childNodes = null;
+ this(name, filePath, icon, type, null);
}
-
-
public HelpJsonContainer(String htmlPath, List<HelpJsonContainer> childNodes) {
- this.filePath = htmlPath;
- this.childNodes = childNodes;
-
- this.name = null;
- this.icon = null;
- this.type = null;
+ this((String) null, htmlPath, null, null, childNodes);
}
public HelpJsonContainer() {

MODIFY
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/helpmarshaller/jsoncontainers/MessageJsonContainer.java
BackEnd/Core/sailfish-core/src/main/java/com/exactpro/sf/help/helpmarshaller/jsoncontainers/MessageJsonContainer.java
@@ -21,8 +21,8 @@ import java.util.List;
public class MessageJsonContainer extends FieldJsonContainer {
- public MessageJsonContainer(String name, String htmlPath, String icon, HelpEntityType type, List<HelpJsonContainer> childNodes) {
- super(name, htmlPath, icon, type, null, childNodes);
+ public MessageJsonContainer(String name, String htmlPath, String icon, HelpEntityType type, boolean isCollection, List<HelpJsonContainer> childNodes) {
+ super(name, htmlPath, icon, type, null, isCollection, childNodes);
}
public MessageJsonContainer(){

MODIFY
FrontEnd/SailfishFrontEnd/WebContent/help.xhtml
FrontEnd/SailfishFrontEnd/WebContent/help.xhtml
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Copyright 2009-2019 Exactpro (Exactpro Systems Limited)
+ ~
+ ~ 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.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<p:menuitem id="copyAllStructure" value="All structure" oncomplete="PF('copyDialog').hide()"/>
+ <p:menuitem id="copyAllYamlStructure" value="All structure in YAML (Collapsed)" oncomplete="PF('copyDialog').hide()"/>
+
</p:submenu>
</p:menubar>
<p:tooltip value="Copy an extended header" for="copyAllHeader" />
<p:tooltip value="Copy the structure without a header" for="copyIncompleteStructure" />
<p:tooltip value="Copy the common structure with an extended header" for="copyAllStructure" />
+ <p:tooltip value="Copy the common structure with an extended header in YAML collapsed format" for="copyAllYamlStructure" />
</p:outputPanel>

MODIFY
FrontEnd/SailfishFrontEnd/WebContent/resources/sf/js/help.js
FrontEnd/SailfishFrontEnd/WebContent/resources/sf/js/help.js
@@ -55,11 +55,12 @@ function createHiddenTarget(targetId, toCopy) {
$(exTargetId).val(toCopy);
}
-function copyToClipboard(toCopy1, toCopy2, toCopy3, toCopy4) {
+function copyToClipboard(toCopy1, toCopy2, toCopy3, toCopy4, toCopy5) {
createHiddenTarget("_hiddenCopyText1", toCopy1);
createHiddenTarget("_hiddenCopyText2", toCopy2);
createHiddenTarget("_hiddenCopyText3", toCopy3);
createHiddenTarget("_hiddenCopyText4", toCopy4);
+ createHiddenTarget("_hiddenCopyText5", toCopy5);
}
function copyProcess(targetId) {
@@ -90,6 +91,10 @@ $(document).ready(function() {
copyProcess("#_hiddenCopyText4");
});
+ $('body').on("click", "#copyAllYamlStructure", function (e) {
+ copyProcess("#_hiddenCopyText5");
+ });
+
$('body').on("click", ".eps-guide-panel a:not(.eps-redmine-attachment-link)", function(e){
var link = e.target.getAttribute('href');

MODIFY
FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/help/CopyingFormat.java
FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/help/CopyingFormat.java
@@ -26,6 +26,8 @@ import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.primefaces.model.TreeNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.exactpro.sf.aml.generator.matrix.Column;
import com.exactpro.sf.aml.iomatrix.CSVDelimiter;
@@ -34,14 +36,26 @@ import com.exactpro.sf.common.messages.structures.IFieldStructure;
import com.exactpro.sf.help.helpmarshaller.HelpEntityType;
import com.exactpro.sf.help.helpmarshaller.jsoncontainers.FieldJsonContainer;
import com.exactpro.sf.testwebgui.BeanUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
public class CopyingFormat {
+ private static final Logger logger = LoggerFactory.getLogger(HelpBean.class);
private static final CSVDelimiter DEFAULT_SEPARATOR = CSVDelimiter.TAB;
private static final String LINE_SEPARATOR = "\\n";
private static final String REF_POSTFIX = "_ref";
+ private static final ObjectWriter YAML_WRITER = new ObjectMapper(new YAMLFactory())
+ .writerFor(ObjectNode.class).withDefaultPrettyPrinter();
+
private final Set<String> header = new LinkedHashSet<>();
private final Set<String> newColumns = new LinkedHashSet<>();
private final Map<String, Map<String, String>> groups = new HashMap<>();
@@ -159,6 +173,27 @@ public class CopyingFormat {
return builder.toString();
}
+ public static String copyAllYamlStructure(TreeNode selectedNode) {
+ ObjectNode rootNode = new ObjectNode(JsonNodeFactory.instance);
+
+ createYamlStructure(selectedNode, rootNode);
+ try {
+
+ return YAML_WRITER
+ .writeValueAsString(rootNode)
+ .replace(" ", " ")
+ .replace("\n", "\\n ")
+ .replace("\t", " ")
+ .replace("'", "\\'")
+ .replace("\"", "\\\"")
+ .substring(5);
+ } catch (JsonProcessingException e) {
+ logger.warn("Can`t serialize to YAML", e);
+ }
+
+ return "";
+ }
+
private String createAllHeader() {
StringBuilder builder = new StringBuilder();
@@ -249,4 +284,40 @@ public class CopyingFormat {
public int getNewColumnsCount() {
return newColumns.size();
}
+
+ private static JsonNode getOrCreateNode(JsonNode node, String key, boolean getObjectNode){
+ if (node instanceof ObjectNode) {
+ ObjectNode obj = (ObjectNode) node;
+ return obj.has(key) ? obj.get(key) : getObjectNode ? obj.putObject(key) : obj.putArray(key);
+ } else if (node instanceof ArrayNode) {
+ ArrayNode arrayNode = (ArrayNode) node;
+ return getObjectNode ? arrayNode.addObject() : arrayNode.addArray();
+ }
+
+ return null;
+ }
+
+ private static void createYamlStructure(TreeNode selectedNode, JsonNode parent) {
+ if ("MESSAGE".equals(selectedNode.getType())) {
+ FieldJsonContainer container = (FieldJsonContainer) selectedNode.getData();
+
+ JsonNode message;
+
+ if (container.isCollection()) {
+ message = getOrCreateNode(parent, container.getName(), false);
+ message = getOrCreateNode(message, null, true);
+ } else {
+ message = getOrCreateNode(parent, container.getName(), true);
+ }
+
+ for (TreeNode child : selectedNode.getChildren()) {
+ createYamlStructure(child, message);
+ }
+ } else if ("FIELD".equals(selectedNode.getType())) {
+ FieldJsonContainer container = (FieldJsonContainer) selectedNode.getData();
+ if (parent instanceof ObjectNode) {
+ ((ObjectNode) parent).put(container.getName(), container.getJavaType());
+ }
+ }
+ }
}
\ No newline at end of file

MODIFY
FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/help/HelpBean.java
FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/help/HelpBean.java
@@ -343,12 +343,12 @@ public class HelpBean implements Serializable {
copyingFormat.format(selectedNode);
copyToClipboardJs(copyingFormat.copyNewColumns(), copyingFormat.copyJustHeader(), copyingFormat.copyToClipboard(),
- copyingFormat.copyAllStructure());
+ copyingFormat.copyAllStructure(), CopyingFormat.copyAllYamlStructure(selectedNode));
RequestContext.getCurrentInstance().update("copyDialog");
RequestContext.getCurrentInstance().execute("PF('copyDialog').show()");
}
- private void copyToClipboardJs(String toCopy1, String toCopy2, String toCopy3, String toCopy4) {
+ private void copyToClipboardJs(String toCopy1, String toCopy2, String toCopy3, String toCopy4, String toCopy5) {
StringBuilder builder = new StringBuilder();
@@ -360,6 +360,8 @@ public class HelpBean implements Serializable {
.append(toCopy3)
.append("', '")
.append(toCopy4)
+ .append("', '")
+ .append(toCopy5)
.append("')");
RequestContext.getCurrentInstance().execute(builder.toString());

[RM] Feature #60892. [YAML] Please add possibility to copy message structure from Help in yaml format.

Change-Id: I8c97f0921b2f323bcd2811c391a8ca281116df3a