Skip to content

Commit

Permalink
Add desription in yaml format
Browse files Browse the repository at this point in the history
  • Loading branch information
alucas-nickel authored and mbouchenoire committed May 24, 2021
1 parent 41b1e3a commit b889ae1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 13 deletions.
18 changes: 14 additions & 4 deletions src/main/java/org/lowfer/domain/common/SoftwareComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.lowfer.domain.common;

import org.apache.commons.lang3.StringUtils;
import org.lowfer.repository.AsyncComponentGitRepository;

import javax.annotation.Nullable;
Expand All @@ -33,6 +34,7 @@ public class SoftwareComponent {

private final String name;
private final String label;
private final String description;
private final SoftwareComponentType type;
private final String context;
private final AsyncComponentGitRepository repository;
Expand All @@ -42,6 +44,7 @@ public class SoftwareComponent {
public SoftwareComponent(
String name,
String label,
String description,
SoftwareComponentType type,
@Nullable String context,
@Nullable AsyncComponentGitRepository repository,
Expand All @@ -50,6 +53,7 @@ public SoftwareComponent(

this.name = name;
this.label = label;
this.description = description;
this.type = type;
this.context = context;
this.repository = repository;
Expand All @@ -58,8 +62,10 @@ public SoftwareComponent(
}

static SoftwareComponent agg(Set<SoftwareComponent> components, @Nullable String context) {
final String name = components.stream().map(SoftwareComponent::getName).collect(Collectors.joining(";"));
return new SoftwareComponent(name, "+" + components.size(), AGGREGATE, context, null, emptySet(), emptySet());
final var name = UUID.randomUUID().toString();
final String label = "+" + components.size();
final String description = components.stream().map(SoftwareComponent::getLabel).collect(Collectors.joining(";"));
return new SoftwareComponent(name, label, description, AGGREGATE, context, null, emptySet(), emptySet());
}

public long weight() {
Expand All @@ -75,7 +81,7 @@ SoftwareComponent removeDependencies(Collection<SoftwareComponent> dependencies)
.collect(toList())
.contains(componentDependency.getComponentName()));

return new SoftwareComponent(name, label, type, context, repository, maintainers, updatedDependencies);
return new SoftwareComponent(name, label, description, type, context, repository, maintainers, updatedDependencies);
}

SoftwareComponent addDependency(ComponentDependency dependency) {
Expand All @@ -88,7 +94,7 @@ SoftwareComponent addDependencies(Set<ComponentDependency> dependencies) {

final Set<ComponentDependency> updatedDependencies = new HashSet<>(this.dependencies);
updatedDependencies.addAll(dependencies);
return new SoftwareComponent(name, label, type, context, repository, maintainers, updatedDependencies);
return new SoftwareComponent(name, label, description, type, context, repository, maintainers, updatedDependencies);
}

public String getName() {
Expand All @@ -99,6 +105,10 @@ public String getLabel() {
return label;
}

public String getDescription() {
return description;
}

public SoftwareComponentType getType() {
return type;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/lowfer/graphviz/GraphvizStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.lowfer.graphviz;

import guru.nidi.graphviz.attribute.*;
import org.apache.commons.lang3.StringUtils;
import org.lowfer.config.Color;
import org.lowfer.domain.common.*;

Expand Down Expand Up @@ -116,6 +117,10 @@ private MapAttributes<ForNode> labelAndShape(SoftwareComponent component) {
final var attrs = new MapAttributes<>()
.add("label", component.getLabel());

if (StringUtils.isNoneBlank(component.getDescription())) {
attrs.add("tooltip", component.getDescription());
}

switch (component.getType()) {
case LIBRARY:
return attrs.add("shape", "folder").add("label", padRectangle(component)).add("color", "blue");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/lowfer/serde/ManifestYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ private Try<SoftwareArchitecture> load(SoftwareArchitectureYaml architectureYaml
.map(dependencies -> new SoftwareComponent(
componentYaml.getName(),
componentYaml.getLabel(),
componentYaml.getDescription(),
SoftwareComponentType.fromSerializedName(componentYaml.getType())
.orElseThrow(() -> new IllegalStateException("Failed to find component type: " + componentYaml.getType())),
componentYaml.getContext(),
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/lowfer/serde/SoftwareComponentYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SoftwareComponentYaml {

private String name;
private String label;
private String description;
private String type;
private String context;
private String repository;
Expand All @@ -41,6 +42,7 @@ public class SoftwareComponentYaml {
SoftwareComponentYaml() {
this.name = null;
this.label = null;
this.description = null;
this.type = null;
this.context = null;
this.repository = null;
Expand All @@ -51,6 +53,7 @@ public class SoftwareComponentYaml {
public SoftwareComponentYaml(SoftwareComponent component) {
this.name = component.getName();
this.label = component.getLabel();
this.description = component.getDescription();
this.type = component.getType().getName();
this.context = component.getContext().orElse(null);
this.maintainers = component.getMaintainers().stream()
Expand All @@ -77,6 +80,14 @@ public void setLabel(String label) {
this.label = label;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getType() {
return type;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/features/studio/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const Basic = `name: Basic
components:
- name: Frontend
label: Customer Portal
description: The customer portal frontend
type: frontend
dependencies:
- component: API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ class ComponentNeighborsFilterTest {
@Test
void test() {
final SoftwareComponent bdd1 = new SoftwareComponent(
"bdd1", "bdd1", DATABASE, null, null, emptySet(), emptySet());
"bdd1", "bdd1", null, DATABASE, null, null, emptySet(), emptySet());

final SoftwareComponent back1 = new SoftwareComponent(
"back1", "back1", SERVICE, null, null, emptySet(), Set.of(new ComponentDependency(bdd1)));
"back1", "back1", null, SERVICE, null, null, emptySet(), Set.of(new ComponentDependency(bdd1)));

final SoftwareComponent back2 = new SoftwareComponent(
"back2", "back2", SERVICE, null, null, emptySet(), Set.of(new ComponentDependency(back1, HTTP)));
"back2", "back2", null, SERVICE, null, null, emptySet(), Set.of(new ComponentDependency(back1, HTTP)));

final SoftwareComponent back3 = new SoftwareComponent(
"back3", "back3", SERVICE, null, null, emptySet(), emptySet());
"back3", "back3", null, SERVICE, null, null, emptySet(), emptySet());

final SoftwareComponent front1 = new SoftwareComponent(
"front1", "front1", FRONTEND, null, null, emptySet(), Set.of(new ComponentDependency(back2), new ComponentDependency(back3)));
"front1", "front1", null, FRONTEND, null, null, emptySet(), Set.of(new ComponentDependency(back2), new ComponentDependency(back3)));

final SoftwareArchitecture architecture = new SoftwareArchitecture(UUID.randomUUID().toString(), Set.of(bdd1, back1, back2, back3, front1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public final class SoftwareArchitectureMother {
* @return front -> api2 -> (bdd + api1)
*/
public static SoftwareArchitecture simple() {
final SoftwareComponent bdd = new SoftwareComponent(BDD, "", DATABASE, null, null, emptySet(), emptySet());
final SoftwareComponent apiBack = new SoftwareComponent(API_BACK, "", SERVICE, null, null, emptySet(), emptySet());
final SoftwareComponent apiFront = new SoftwareComponent(API_FRONT, "", SERVICE, null, null, emptySet(), Set.of(new ComponentDependency(bdd), new ComponentDependency(apiBack)));
final SoftwareComponent front = new SoftwareComponent(FRONT, "", FRONTEND, null, null, emptySet(), singleton(new ComponentDependency(apiFront)));
final SoftwareComponent bdd = new SoftwareComponent(BDD, "", null, DATABASE, null, null, emptySet(), emptySet());
final SoftwareComponent apiBack = new SoftwareComponent(API_BACK, "", null, SERVICE, null, null, emptySet(), emptySet());
final SoftwareComponent apiFront = new SoftwareComponent(API_FRONT, "", null, SERVICE, null, null, emptySet(), Set.of(new ComponentDependency(bdd), new ComponentDependency(apiBack)));
final SoftwareComponent front = new SoftwareComponent(FRONT, "", null, FRONTEND, null, null, emptySet(), singleton(new ComponentDependency(apiFront)));
return new SoftwareArchitecture(UUID.randomUUID().toString(), Set.of(bdd, apiBack, apiFront , front));
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/lowfer/domain/SoftwareComponentMother.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static SoftwareComponent single(String name, Set<String> dependencyNames,
return new SoftwareComponent(
name,
name,
null,
type,
null,
null,
Expand All @@ -59,6 +60,7 @@ public static SoftwareComponent single(String name, SoftwareComponentType type,
return new SoftwareComponent(
name,
name,
null,
type,
null,
null,
Expand All @@ -74,6 +76,7 @@ public static SoftwareComponent external(String name, SoftwareComponentType type
return new SoftwareComponent(
name,
name,
null,
type,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Future<List<Commit>> getCommits(String branchName) {
final SoftwareComponent helloWorldComponent = new SoftwareComponent(
"hello-world",
"",
null,
SoftwareComponentType.SERVICE,
null,
repository,
Expand Down Expand Up @@ -86,6 +87,7 @@ public Future<List<Commit>> getCommits(String branchName) {
final SoftwareComponent helloWorldComponent = new SoftwareComponent(
"hello-world",
"",
null,
SoftwareComponentType.SERVICE,
null,
repository,
Expand Down

0 comments on commit b889ae1

Please sign in to comment.