Search in sources :

Example 11 with Element

use of com.structurizr.model.Element in project java by structurizr.

the class ElementViewTests method test_copyLayoutInformationFrom_CopiesXAndY_WhenANonNullElementViewIsPassed.

@Test
public void test_copyLayoutInformationFrom_CopiesXAndY_WhenANonNullElementViewIsPassed() {
    Element element = model.addSoftwareSystem(Location.External, "SystemA", "");
    ElementView elementView1 = new ElementView(element);
    assertEquals(0, elementView1.getX());
    assertEquals(0, elementView1.getY());
    ElementView elementView2 = new ElementView(element);
    elementView2.setX(123);
    elementView2.setY(456);
    elementView1.copyLayoutInformationFrom(elementView2);
    assertEquals(123, elementView1.getX());
    assertEquals(456, elementView1.getY());
}
Also used : Element(com.structurizr.model.Element) Test(org.junit.Test)

Example 12 with Element

use of com.structurizr.model.Element in project java by structurizr.

the class CustomView method addAnimation.

/**
 * Adds an animation step, with the specified elements.
 *
 * @param elements      the elements that should be shown in the animation step
 */
public void addAnimation(CustomElement... elements) {
    if (elements == null || elements.length == 0) {
        throw new IllegalArgumentException("One or more elements must be specified.");
    }
    Set<String> elementIdsInPreviousAnimationSteps = new HashSet<>();
    for (Animation animationStep : animations) {
        elementIdsInPreviousAnimationSteps.addAll(animationStep.getElements());
    }
    Set<Element> elementsInThisAnimationStep = new HashSet<>();
    Set<Relationship> relationshipsInThisAnimationStep = new HashSet<>();
    for (CustomElement element : elements) {
        if (isElementInView(element)) {
            if (!elementIdsInPreviousAnimationSteps.contains(element.getId())) {
                elementIdsInPreviousAnimationSteps.add(element.getId());
                elementsInThisAnimationStep.add(element);
            }
        }
    }
    if (elementsInThisAnimationStep.size() == 0) {
        throw new IllegalArgumentException("None of the specified elements exist in this view.");
    }
    for (RelationshipView relationshipView : this.getRelationships()) {
        if ((elementsInThisAnimationStep.contains(relationshipView.getRelationship().getSource()) && elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getDestination().getId())) || (elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getSource().getId()) && elementsInThisAnimationStep.contains(relationshipView.getRelationship().getDestination()))) {
            relationshipsInThisAnimationStep.add(relationshipView.getRelationship());
        }
    }
    animations.add(new Animation(animations.size() + 1, elementsInThisAnimationStep, relationshipsInThisAnimationStep));
}
Also used : CustomElement(com.structurizr.model.CustomElement) Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship) CustomElement(com.structurizr.model.CustomElement) HashSet(java.util.HashSet)

Example 13 with Element

use of com.structurizr.model.Element in project java by structurizr.

the class DefaultLayoutMergeStrategy method findRelationshipView.

private RelationshipView findRelationshipView(View viewWithLayoutInformation, Relationship relationshipWithoutLayoutInformation, Map<Element, Element> elementMap) {
    if (!elementMap.containsKey(relationshipWithoutLayoutInformation.getSource()) || !elementMap.containsKey(relationshipWithoutLayoutInformation.getDestination())) {
        return null;
    }
    Element sourceElementWithLayoutInformation = elementMap.get(relationshipWithoutLayoutInformation.getSource());
    Element destinationElementWithLayoutInformation = elementMap.get(relationshipWithoutLayoutInformation.getDestination());
    for (RelationshipView rv : viewWithLayoutInformation.getRelationships()) {
        if (rv.getRelationship().getSource().equals(sourceElementWithLayoutInformation) && rv.getRelationship().getDestination().equals(destinationElementWithLayoutInformation) && rv.getRelationship().getDescription().equals(relationshipWithoutLayoutInformation.getDescription())) {
            return rv;
        }
    }
    return null;
}
Also used : Element(com.structurizr.model.Element)

Example 14 with Element

use of com.structurizr.model.Element in project agile-architecture-documentation-system by Riduidel.

the class ADRExtractor method writeArchitectureDecisionsUsing.

private void writeArchitectureDecisionsUsing(Element element, String project, String label, TicketsHandler handler, OutputBuilder builder) {
    File output = builder.outputFor(AgileArchitectureSection.decision_log, element, this, "adoc");
    if (force) {
        output.delete();
    }
    Collection<Ticket> tickets = handler.getTicketsTagged(project, label);
    // Write each decision
    Map<Ticket, String> ticketsTexts = tickets.stream().sorted(new ByStatusThenDate()).collect(Collectors.toMap(Function.identity(), t -> writeArchitectureDecisionTicket(builder, element, t)));
    try {
        try (FileWriter writer = new FileWriter(output)) {
            decisionList.process(new IndexModel(handler.getIssuesUrl(project), handler.getProjectName(project), label, ticketsTexts), writer);
        }
    } catch (IOException | TemplateException e) {
        throw new UnableToCreateDecisionLog(String.format("Can't write decision log index to file %s", output), e);
    }
// Make sure the decision record uses that index
}
Also used : Date(java.util.Date) TemplateException(freemarker.template.TemplateException) OutputBuilder(org.ndx.agile.architecture.base.OutputBuilder) SimpleDateFormat(java.text.SimpleDateFormat) ModelElementAdapter(org.ndx.agile.architecture.base.enhancers.ModelElementAdapter) Function(java.util.function.Function) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) ModelElementKeys(org.ndx.agile.architecture.base.enhancers.ModelElementKeys) Inject(javax.inject.Inject) Map(java.util.Map) Template(freemarker.template.Template) StaticStructureElement(com.structurizr.model.StaticStructureElement) Instance(javax.enterprise.inject.Instance) TicketStatus(org.ndx.agile.architecture.base.enhancers.tickets.TicketStatus) Ticket(org.ndx.agile.architecture.base.enhancers.tickets.Ticket) Collection(java.util.Collection) FileWriter(java.io.FileWriter) IOException(java.io.IOException) AgileArchitectureSection(org.ndx.agile.architecture.base.AgileArchitectureSection) Enhancer(org.ndx.agile.architecture.base.Enhancer) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) File(java.io.File) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Comparator(java.util.Comparator) TicketsHandler(org.ndx.agile.architecture.base.enhancers.tickets.TicketsHandler) Element(com.structurizr.model.Element) Ticket(org.ndx.agile.architecture.base.enhancers.tickets.Ticket) TemplateException(freemarker.template.TemplateException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 15 with Element

use of com.structurizr.model.Element in project agile-architecture-documentation-system by Riduidel.

the class ADRExtractor method processElement.

@Override
protected void processElement(StaticStructureElement element, OutputBuilder builder) {
    if (element.getProperties().containsKey(AGILE_ARCHITECTURE_TICKETS_PROJECT)) {
        String ticketsProject = element.getProperties().get(AGILE_ARCHITECTURE_TICKETS_PROJECT);
        Optional<TicketsHandler> usableHandler = ticketsHandlers.stream().filter(handler -> handler.canHandle(ticketsProject)).findFirst();
        if (usableHandler.isPresent()) {
            String label = element.getProperties().getOrDefault(AGILE_ARCHITECTURE_TICKETS_ADR_LABEL, "decision");
            TicketsHandler handler = usableHandler.get();
            writeArchitectureDecisionsUsing(element, ticketsProject, label, handler, builder);
        } else {
            logger.warning(String.format("We have this set of handlers\n%s\nin which we couldn't find one for tickets project %s", ticketsHandlers.stream().map(handler -> handler.toString()).collect(Collectors.joining()), ticketsProject));
        }
    }
}
Also used : Date(java.util.Date) TemplateException(freemarker.template.TemplateException) OutputBuilder(org.ndx.agile.architecture.base.OutputBuilder) SimpleDateFormat(java.text.SimpleDateFormat) ModelElementAdapter(org.ndx.agile.architecture.base.enhancers.ModelElementAdapter) Function(java.util.function.Function) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) ModelElementKeys(org.ndx.agile.architecture.base.enhancers.ModelElementKeys) Inject(javax.inject.Inject) Map(java.util.Map) Template(freemarker.template.Template) StaticStructureElement(com.structurizr.model.StaticStructureElement) Instance(javax.enterprise.inject.Instance) TicketStatus(org.ndx.agile.architecture.base.enhancers.tickets.TicketStatus) Ticket(org.ndx.agile.architecture.base.enhancers.tickets.Ticket) Collection(java.util.Collection) FileWriter(java.io.FileWriter) IOException(java.io.IOException) AgileArchitectureSection(org.ndx.agile.architecture.base.AgileArchitectureSection) Enhancer(org.ndx.agile.architecture.base.Enhancer) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) File(java.io.File) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Comparator(java.util.Comparator) TicketsHandler(org.ndx.agile.architecture.base.enhancers.tickets.TicketsHandler) Element(com.structurizr.model.Element) TicketsHandler(org.ndx.agile.architecture.base.enhancers.tickets.TicketsHandler)

Aggregations

Element (com.structurizr.model.Element)27 SoftwareSystem (com.structurizr.model.SoftwareSystem)8 Workspace (com.structurizr.Workspace)7 Relationship (com.structurizr.model.Relationship)7 Collectors (java.util.stream.Collectors)7 Container (com.structurizr.model.Container)6 File (java.io.File)6 IOException (java.io.IOException)6 StaticStructureElement (com.structurizr.model.StaticStructureElement)5 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Map (java.util.Map)5 Inject (javax.inject.Inject)5 OutputBuilder (org.ndx.agile.architecture.base.OutputBuilder)5 Component (com.structurizr.model.Component)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Logger (java.util.logging.Logger)4