Skip to content

Commit

Permalink
JBPM-7916 i18n + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagodolphine committed Jan 9, 2019
1 parent 74797ee commit d3c557e
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 39 deletions.
@@ -0,0 +1,32 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
*
* 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.
*/

package org.kie.workbench.common.stunner.core.documentation.model;

public class DocumentationOutput {

public static final DocumentationOutput EMPTY = new DocumentationOutput("");

private String value;

public DocumentationOutput(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
*
* 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.
*/

package org.kie.workbench.common.stunner.core.documentation.model;

public class HTMLDocumentationTemplate {

private String template;

public HTMLDocumentationTemplate(String template) {
this.template = template;
}

public String getTemplate() {
return template;
}
}
Expand Up @@ -17,12 +17,12 @@
package org.kie.workbench.common.stunner.core.documentation.service;

import org.kie.workbench.common.stunner.core.diagram.Diagram;
import org.kie.workbench.common.stunner.core.diagram.Metadata;
import org.kie.workbench.common.stunner.core.documentation.model.DiagramDocumentation;
import org.kie.workbench.common.stunner.core.graph.Graph;
import org.kie.workbench.common.stunner.core.documentation.model.DocumentationOutput;
import org.kie.workbench.common.stunner.core.documentation.model.HTMLDocumentationTemplate;

public interface DiagramDocumentationService<D extends Diagram<Graph, M>, M extends Metadata,
R extends DiagramDocumentation> {
public interface DiagramDocumentationService<D extends Diagram, R extends DiagramDocumentation,
T extends HTMLDocumentationTemplate, P extends DocumentationOutput> {

/**
* Process the diagram generating the documentation output bean.
Expand All @@ -33,16 +33,22 @@ public interface DiagramDocumentationService<D extends Diagram<Graph, M>, M exte

/**
* Returns the template to be used to build the serialized documentation.
* @param diagram
* @return
*/
String getDocumentationTemplate(D diagram);
T getDocumentationTemplate();

/**
* Generates the documentation serialized output
* Generates the documentation serialized output based on the given template.
* @param template
* @param diagramDocumentation
* @return
*/
String buildDocumentation(String template, R diagramDocumentation);
DocumentationOutput buildDocumentation(T template, R diagramDocumentation);

/**
* This is the method that executed the full documentations process.
* @param diagram
* @return the processed documentation output
*/
DocumentationOutput generate(D diagram);
}
Expand Up @@ -399,11 +399,12 @@ protected void initialiseKieEditorForSession(final ProjectDiagram diagram) {
}

private void addDocumentationPage(ProjectDiagram diagram) {
//todo:tiago i18n on label inject the DocumentationPage itself
Optional.ofNullable(documentationView.isEnabled())
.filter(Boolean.TRUE::equals)
.ifPresent(enabled -> addPage(new DocumentationPage(documentationView.initialize(diagram),
"Documentation")));
.ifPresent(enabled -> {
final String label = translationService.getValue(StunnerProjectClientConstants.DOCUMENTATION);
addPage(new DocumentationPage(documentationView.initialize(diagram), label));
});
}

protected void onDiagramLoad() {
Expand Down
Expand Up @@ -30,4 +30,5 @@ public class StunnerProjectClientConstants {

public static final String DIAGRAM_PARSING_ERROR = "org.kie.workbench.common.stunner.project.client.editor.DiagramParsingError";

public static final String DOCUMENTATION = "org.kie.workbench.common.stunner.project.client.editor.Documentation";
}
Expand Up @@ -20,5 +20,6 @@ org.kie.workbench.common.stunner.project.client.editor.OnErrorConfirmUndoLastAct
org.kie.workbench.common.stunner.project.client.editor.DiagramSaveSuccessful=Diagram saved successfully
org.kie.workbench.common.stunner.project.client.editor.DiagramEditorDefaultTitle=Project Diagram Editor
org.kie.workbench.common.stunner.project.client.editor.DiagramParsingError=An error was produced during process diagram parsing. There might be bpm nodes not yet supported by current Process Designer version, or the xml content can contain errors. You can try to open the file with the Legacy Process Designer or repair it manually. {0}
org.kie.workbench.common.stunner.project.client.editor.Documentation=Documentation


Expand Up @@ -17,6 +17,7 @@
package org.kie.workbench.common.stunner.bpmn.definition.property.event.timer;

import java.util.Objects;
import java.util.StringJoiner;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
Expand Down Expand Up @@ -98,4 +99,15 @@ public int hashCode() {
Objects.hashCode(timeCycle),
Objects.hashCode(timeCycleLanguage));
}

@Override
public String toString() {
return new StringJoiner(" ")
.add(Objects.nonNull(timeDate) ? timeDate : "")
.add(Objects.nonNull(timeDuration) ? timeDuration : "")
.add(Objects.nonNull(timeCycle) ? timeCycle : "")
.add(Objects.nonNull(timeCycleLanguage) ? timeCycleLanguage : "")
.toString()
.trim();
}
}
Expand Up @@ -19,11 +19,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
import org.kie.workbench.common.stunner.core.util.HashUtil;
import org.kie.workbench.common.stunner.core.util.StringUtils;

@Portable
@Bindable
Expand Down Expand Up @@ -72,6 +74,9 @@ public int hashCode() {

@Override
public String toString() {
return values.toString();
return values.stream()
.map(String::valueOf)
.filter(StringUtils::nonEmpty)
.collect(Collectors.joining(","));
}
}
Expand Up @@ -22,6 +22,7 @@
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
import org.kie.workbench.common.stunner.core.util.HashUtil;
import org.kie.workbench.common.stunner.core.util.StringUtils;

@Portable
@Bindable
Expand Down Expand Up @@ -75,6 +76,6 @@ public int hashCode() {

@Override
public String toString() {
return this.language + " : " + script;
return StringUtils.nonEmpty(script) ? this.language + " : " + script : "";
}
}
Expand Up @@ -18,11 +18,11 @@

import org.kie.workbench.common.stunner.bpmn.documentation.model.BPMNDocumentation;
import org.kie.workbench.common.stunner.core.diagram.Diagram;
import org.kie.workbench.common.stunner.core.diagram.Metadata;
import org.kie.workbench.common.stunner.core.documentation.model.DocumentationOutput;
import org.kie.workbench.common.stunner.core.documentation.model.HTMLDocumentationTemplate;
import org.kie.workbench.common.stunner.core.documentation.service.DiagramDocumentationService;
import org.kie.workbench.common.stunner.core.graph.Graph;

public interface BPMNDocumentationService extends DiagramDocumentationService<Diagram<Graph, Metadata>, Metadata,
BPMNDocumentation> {
public interface BPMNDocumentationService extends DiagramDocumentationService<Diagram, BPMNDocumentation,
HTMLDocumentationTemplate, DocumentationOutput> {

}
Expand Up @@ -26,9 +26,9 @@
import org.jboss.errai.ui.shared.api.annotations.DataField;
import org.jboss.errai.ui.shared.api.annotations.Templated;
import org.kie.workbench.common.stunner.bpmn.documentation.BPMNDocumentationService;
import org.kie.workbench.common.stunner.bpmn.documentation.model.BPMNDocumentation;
import org.kie.workbench.common.stunner.core.diagram.Diagram;
import org.kie.workbench.common.stunner.core.documentation.DefaultDiagramDocumentationView;
import org.kie.workbench.common.stunner.core.documentation.model.DocumentationOutput;

@Dependent
@Specializes
Expand Down Expand Up @@ -64,15 +64,11 @@ public BPMNDocumentationView initialize(Diagram diagram) {

@Override
public BPMNDocumentationView refresh() {
return getDiagram()
.map(diagram -> {
BPMNDocumentation documentation = documentationService.processDocumentation(diagram);
String documentationTemplate = documentationService.getDocumentationTemplate(diagram);
String html = documentationService.buildDocumentation(documentationTemplate, documentation);
documentationDiv.innerHTML = html;
return this;
})
.orElse(this);
documentationDiv.innerHTML = getDiagram()
.map(documentationService::generate)
.map(DocumentationOutput::getValue)
.orElse("");
return this;
}

@Override
Expand All @@ -95,4 +91,4 @@ public boolean isEnabled() {
// GWT.log("Error on documentation");
// });
// }
}
}
Expand Up @@ -88,7 +88,8 @@
import org.kie.workbench.common.stunner.core.definition.adapter.PropertyAdapter;
import org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils;
import org.kie.workbench.common.stunner.core.diagram.Diagram;
import org.kie.workbench.common.stunner.core.diagram.Metadata;
import org.kie.workbench.common.stunner.core.documentation.model.DocumentationOutput;
import org.kie.workbench.common.stunner.core.documentation.model.HTMLDocumentationTemplate;
import org.kie.workbench.common.stunner.core.graph.Graph;
import org.kie.workbench.common.stunner.core.graph.Node;
import org.kie.workbench.common.stunner.core.graph.content.definition.Definition;
Expand Down Expand Up @@ -140,7 +141,7 @@ public ClientBPMNDocumentationService(final ClientMustacheTemplateRenderer musta
}

@Override
public BPMNDocumentation processDocumentation(Diagram<Graph, Metadata> diagram) {
public BPMNDocumentation processDocumentation(Diagram diagram) {
final Graph<?, Node> graph = diagram.getGraph();

final Optional<BPMNDiagramImpl> diagramModel = StreamSupport.stream(graph.nodes().spliterator(), false)
Expand Down Expand Up @@ -272,19 +273,23 @@ private String getCategoryName(String category) {
}

@Override
public String getDocumentationTemplate(Diagram<Graph, Metadata> diagram) {
public HTMLDocumentationTemplate getDocumentationTemplate() {
final BPMNDocumentationTemplateSource source = GWT.create(BPMNDocumentationTemplateSource.class);
return source.documentationTemplate().getText();
return new HTMLDocumentationTemplate(source.documentationTemplate().getText());
}

@Override
public String buildDocumentation(String template, BPMNDocumentation diagramDocumentation) {
return mustacheTemplateRenderer.render(template, diagramDocumentation);
public DocumentationOutput buildDocumentation(HTMLDocumentationTemplate template, BPMNDocumentation diagramDocumentation) {
final String rendered = mustacheTemplateRenderer.render(template.getTemplate(), diagramDocumentation);
return new DocumentationOutput(rendered);
}

public String buildDocumentation(Diagram<Graph, Metadata> diagram) {
//todo:tiago
return "";
@Override
public DocumentationOutput generate(Diagram diagram) {
return Optional.ofNullable(diagram)
.map(this::processDocumentation)
.map(d -> buildDocumentation(getDocumentationTemplate(), d))
.orElse(DocumentationOutput.EMPTY);
}

private String getCategoryIcon(String category) {
Expand All @@ -300,8 +305,11 @@ private Map<String, String> getElementProperties(Object definition) {
final Set<?> properties = definitionManager.adapters().forDefinition().getProperties(definition);
return properties.stream()
.filter(prop -> !ignoredPropertiesIds.containsKey(propertyAdapter.getId(prop)))
.collect(Collectors.toMap(propertyAdapter::getCaption,
prop -> String.valueOf(propertyAdapter.getValue(prop))));
.collect(Collectors.toMap(propertyAdapter::getCaption, this::getElementValue));
}

private String getElementValue(Object prop) {
return String.valueOf(definitionManager.adapters().forProperty().getValue(prop));
}

private String getDiagramImage(Optional<AbstractCanvasHandler> canvasHandler) {
Expand Down

0 comments on commit d3c557e

Please sign in to comment.