Example usage for com.itextpdf.text Section setComplete

List of usage examples for com.itextpdf.text Section setComplete

Introduction

In this page you can find the example usage for com.itextpdf.text Section setComplete.

Prototype

public void setComplete(final boolean complete) 

Source Link

Usage

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

/**
 * Das Element wird mit Datentyp, seinen Attributen und Kindelementen
 * geschrieben.//from  ww  w. j  av  a 2s . com
 * 
 * @param currElement
 *            Zu behandelndes Element
 * @param currChapter
 *            Kapitel, zu dem das Element hinzugefgt wird
 * @param chapterEntry
 *            Eintrag des Kapitels fr das Inhaltsverzeichnis
 * @param schemaQueues
 *            Queues mit allen Elementen fr die einzelnen Schemas
 */
private void behandleElement(XSElementDecl currElement, Chapter currChapter, ContPdfEntry chapterEntry,
        Map<String, Queue<XSElementDecl>> schemaQueues) throws DocumentException {
    // Fr jedes Element eine Section; Titel ist der Elementname

    // eine Zeile Abstand
    docPdf.add(getEmptyLineText());

    // Referenz des Elements
    String currReferenzString = getReferenceForElement(currElement);

    // Titel des Elements inkl. Sprungmarke
    Chunk chunkElem = getChunkElement(currElement.getName());
    chunkElem.setLocalDestination(currReferenzString);

    Paragraph currElemPara = new Paragraph(getChunkElement(""));
    currElemPara.add(chunkElem);
    Section currSection = currChapter.addSection(currElemPara);

    // Eintrag fr Inhaltsverzeichnis (Element)
    listEntries.add(new ContPdfEntry(chapterEntry, currSection.getTitle().getContent(), currReferenzString,
            currPageNumber));

    // Sektion dem Dokument (vorlufig) hinzufgen (wichtig fr das
    // Aktualisieren der Seitenzahl)
    currSection.setComplete(false);
    docPdf.add(currSection);

    // Anmerkung zum Element
    XSAnnotation ann = currElement.getAnnotation();
    if (ann != null) {
        // Abstand
        currSection.add(getEmptyLineTextHalf());

        String beschreibung = ann.getAnnotation().toString();
        currSection.add(getParagraphTextItalic(beschreibung));
    }

    // Abstand
    currSection.add(getEmptyLineTextHalf());

    // Datentyp
    Paragraph paraTyp = new Paragraph();
    XSType currType = currElement.getType();
    paraTyp.add(getPhraseTextBold("Datentyp: "));
    String strTyp = getNameWithPrefix(currType);
    if (currType.isLocal()) {
        strTyp = "<lokal definiert>";
    }
    paraTyp.add(getPhraseText(strTyp + "\n"));

    // Basistyp
    if ((currType.getDerivationMethod() == XSType.RESTRICTION)
            || (currType.getDerivationMethod() == XSType.EXTENSION)) {
        paraTyp.add(getPhraseTextBold("basiert auf: "));
        paraTyp.add(getPhraseText(getNameWithPrefix(currType.getBaseType()) + "\n"));
    }
    currSection.add(paraTyp);

    // Attribute (falls vorhanden)
    behandleAttribute(currType, currSection);

    // Kind-Elemente (falls vorhanden)
    if (currType.isComplexType()) {
        // Gruppentyp (sequence oder choice)
        String strCompositor = getCompositorStr(currType.asComplexType());
        if (strCompositor.length() > 0) {
            // Abstand
            currSection.add(getEmptyLineTextHalf());

            currSection.add(getParagraphTextBold(strCompositor + "-Elemente:"));
            behandleKindElemente(currElement, currSection, schemaQueues);
        }
    }

    // Sektion dem Dokument (endgltig) hinzufgen
    currSection.setComplete(true);
    docPdf.add(currSection);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionSocialDiagram(Section section, Document document) {

    Image i = rsp.generateScrenshot(ViewsManager.SOCIAL_VIEW);
    float reductionScale = fitImageInArea(i,
            document.getPageSize().getWidth() - document.rightMargin() - document.leftMargin(), 310, false);
    if (reductionScale <= getMaximumReductionScale()) {
        setAppendixASocialDiagram(true);
    }//  w w  w  . j av  a2s .  com

    StringBuilder sectionIntro = new StringBuilder();
    sectionIntro.append(ftc.getFigure(FigureConstant.SOCIAL_DIAGRAM)
            + " presents the graphical representation of the social view");
    if (needSocialDiagramInAppendixA()) {
        sectionIntro.append(" (a larger picture is shown in appendix A)");
    }
    sectionIntro.append(".");
    section.add(createParagraph(sectionIntro.toString()));

    section.add(decorateImage(i, ftc.getFigure(FigureConstant.SOCIAL_DIAGRAM) + " - Social View for the "
            + getProjectName() + " project"));
    section.setComplete(true);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionStakeholders(Section section) {

    String sectionIntro = "This section describes the stakeholders identified in the " + getProjectName()
            + " project. Stakeholders are represented by roles and agents.";
    section.add(createParagraph(sectionIntro));

    List<Actor> selActor = getStakeholderActors();

    if (selActor.size() != 0) {
        StringBuilder sb = new StringBuilder();

        sb.append("In particular, ");

        List<Role> roles = new ArrayList<Role>();
        for (Actor a : selActor) {
            if (a instanceof Role)
                roles.add((Role) a);
        }/*from  w w w  . j  av a 2  s.co  m*/
        List<String> rolesNames = new ArrayList<String>();
        for (Role r : roles) {
            rolesNames.add("%i" + r.getName() + "%");
        }
        if (roles.size() == 0) {

        } else if (roles.size() == 1) {
            sb.append("identified role is: " + rolesNames.get(0) + socialDiagRef());
        } else {
            sb.append("identified roles are: " + separateListOfString(rolesNames) + socialDiagRef());
        }

        List<Agent> agents = new ArrayList<Agent>();
        for (Actor a : selActor) {
            if (a instanceof Agent)
                agents.add((Agent) a);
        }
        List<String> agentsNames = new ArrayList<String>();
        for (Agent a : agents) {
            agentsNames.add("%i" + a.getName() + "%");
        }
        if (roles.size() > 0 && agents.size() > 0) {
            sb.append(", while ");
        } else if (agents.size() == 0) {
            sb.append(".");
        }

        if (agents.size() == 0) {

        } else if (agents.size() == 1) {
            if (roles.size() > 0)
                sb.append(" ");
            sb.append("identified agent is: " + agentsNames.get(0) + socialDiagRef() + ".");
        } else {
            if (roles.size() > 0)
                sb.append(" ");
            sb.append("identified agents are: " + separateListOfString(agentsNames) + socialDiagRef() + ". ");
        }
        // section.add(createParagraph(sb.toString()));

        // sb = new StringBuilder();
        if (roles.size() > 0) {
            sb.append(" " + ftc.getTable(FigureConstant.ROLE_TABLE));
            if (agents.size() > 0)
                sb.append(" and " + ftc.getTable(FigureConstant.AGENT_TABLE));
        } else {
            sb.append(" " + ftc.getTable(FigureConstant.AGENT_TABLE));
        }
        sb.append(" summarise the stakeholders.");

        section.add(createParagraph(sb.toString()));

        if (roles.size() > 0) {
            List<String[]> headers = new ArrayList<String[]>();
            headers.add(new String[] { "Role" });
            headers.add(new String[] { "Description" });
            headers.add(new String[] { "Mission" });
            headers.add(new String[] { "Purpose" });

            PdfPTable table = createTable(headers);
            for (Role r : roles) {
                table.addCell(getContentCell(r.getName()));
                table.addCell(getContentCell(r.getDescription()));
                table.addCell(getContentCell(r.getMission()));
                table.addCell(getContentCell(r.getPurpose()));
            }
            addTableCaption(table, ftc.getTable(FigureConstant.ROLE_TABLE) + " - Roles in the "
                    + getProjectName() + " project.");
            section.add(table);
            table.setComplete(true);
            section.add(getDefaultParagraph());
        }
        if (agents.size() > 0) {
            List<String[]> headers = new ArrayList<String[]>();
            headers.add(new String[] { "Agent" });
            headers.add(new String[] { "Description" });
            headers.add(new String[] { "Abilities" });
            headers.add(new String[] { "Important", "Features" });
            headers.add(new String[] { "Certifications", "Accreditations" });
            headers.add(new String[] { "Type Of", "Organisation" });

            PdfPTable table = createTable(headers);
            for (Agent a : agents) {
                table.addCell(getContentCell(a.getName()));
                table.addCell(getContentCell(a.getDescription()));
                table.addCell(getContentCell(a.getAbilities()));
                table.addCell(getContentCell(a.getOtherImportantFeatures()));
                table.addCell(getContentCell(a.getPossessedCertificationsAndAccreditations()));
                table.addCell(getContentCell(a.getTypeOfOrganisation()));
            }
            addTableCaption(table, ftc.getTable(FigureConstant.AGENT_TABLE) + " - Agents in the "
                    + getProjectName() + " project");
            section.add(table);
            table.setComplete(true);
            section.add(getDefaultParagraph());
        }

        sb = new StringBuilder();
        List<Play> plays = new ArrayList<Play>();
        for (Actor a : getStakeholderActors()) {
            if (a instanceof Agent) {
                for (Play p : ((Agent) a).getPlayedRoles()) {
                    if (p.getTarget() != null)
                        plays.add(p);
                }
            }
        }
        if (plays.size() > 0) {
            section.add(createParagraph(
                    "Agents and roles are related by means of %i play % relations, as reported on "
                            + ftc.getTable(FigureConstant.PLAY_TABLE)));

            List<String[]> headers = new ArrayList<String[]>();
            headers.add(new String[] { "Agent" });
            headers.add(new String[] { "Role" });

            PdfPTable table = createTable(headers);
            for (Play p : plays) {
                table.addCell(getContentCell(p.getSource().getName()));
                table.addCell(getContentCell(p.getTarget().getName()));
            }
            addTableCaption(table, ftc.getTable(FigureConstant.PLAY_TABLE) + " - Agent/Role relations in the "
                    + getProjectName() + " project");

            section.add(table);
            table.setComplete(true);
        } else {
            section.add(createParagraph("In the " + getProjectName()
                    + " project there are no plays relationships taking place for the given agents/roles."));
        }
    }

    section.setComplete(true);
    section.setTriggerNewPage(true);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionStakeholdersInteractions(Section section) {

    String sectionIntro = "This section describes stakeholders interactions, providing insight on whom they interact with to fulfil their desired objectives, as well as which are the stakeholders that rely on them to fulfil their respective goals. This kind of interaction is carried out by means of%i goal delegations%.";
    section.add(createParagraph(sectionIntro));
    sectionIntro = "To achieve their goals stakeholders might need specific information. If they do not possess this information, they may ask other stakeholders to provide thems documents. %iDocument provision% is used to capture this interaction.";
    section.add(createParagraph(sectionIntro));

    if (generateGoalDelegationsSection()) {
        Section section1 = section.addSection(getSectionTitleParagraph("Goal Delegations"));
        buildSectionGoalDelegations(section1);
        section1.setComplete(true);
    }//from ww w  .jav a 2s . c om

    if (generateDocumentProvisionsSection()) {
        Section section2 = section.addSection(getSectionTitleParagraph("Document Provisions"));
        buildSectionDocumentProvisions(section2);
        section2.setComplete(true);
    }
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionGoalDelegations(Section section) {

    String sectionIntro = "Stakeholders interact with others to achieve some of their goals by means of goal delegations. Goal delegations are graphically represented as a relation that starts from a delegator actor to a delegatee actor (following the direction of the arrow), having a rounded corner rectangle representing the goal being delegated. Security needs are graphically specified as labels that appear below the delegated goal "
            + socialDiagRef() + ".";
    section.add(createParagraph(sectionIntro));

    List<Actor> selActor = getGoalDelegationsActors();
    List<Paragraph> phrases = new ArrayList<Paragraph>();

    for (Actor a : selActor) {

        for (Delegation d : a.getOutgoingDelegations()) {
            Paragraph par = createParagraph("%b" + a.getName() + "% delegates goal %i"
                    + d.getSourceGoal().getName() + "% to %b" + d.getTarget().getName() + "%.");
            List<String> secNeeds = buildDelegationSecNeedList(d);
            if (secNeeds.size() > 0) {
                par.add(new Phrase(" The following security needs apply to this delegation:"));
                par.add(Chunk.NEWLINE);/*from  w  ww  .ja va  2  s .c o m*/
                par.add(new Phrase(separateListOfString(secNeeds) + "."));
            }
            phrases.add(par);
        }

        /*
         * StringBuilder sbInc = new StringBuilder(); sbInc.append("%b" +
         * a.getName() + "% is delegated by ");
         * 
         * int incCount = 0; for (Delegation d : a.getIncomingDelegations())
         * { if (incCount > 0) sbInc.append(", and is delegated by ");
         * sbInc.append("%i" + d.getSource().getName() + "% goal %i" +
         * d.getSourceGoal().getName() + "%"); List<String> secNeed1 =
         * buildSecNeedString(d, false, 'i'); List<String> secNeed2 =
         * buildSecNeedString(d, true, 'i');
         * 
         * if (secNeed2.size() > 0) { switch (secNeed2.size()) { case 1:
         * sbInc.append(" and is required to comply with the " +
         * separateListOfString(secNeed2) + " security need"); break;
         * default: sbInc.append(" and is required to comply with the " +
         * separateListOfString(secNeed2) + " security needs"); break; } }
         * if (secNeed1.size() > 0) { switch (secNeed1.size()) { case 1:
         * sbInc.append(" and requires it to comply with the " +
         * separateListOfString(secNeed1) + " security need"); break;
         * default: sbInc.append(" and requires it to comply with the " +
         * separateListOfString(secNeed1) + " security needs"); break; }
         * 
         * } List<String> parmSecNeed = buildParamterizedSecNeedString(d,
         * 'i'); if (parmSecNeed.size() > 0) {
         * sbInc.append(" and is required for a level of " +
         * separateListOfString(parmSecNeed)); } if (secNeed1.size() == 0 &&
         * secNeed2.size() == 0 && parmSecNeed.size() == 0) {
         * sbInc.append(": no security need is speccified"); } incCount++; }
         * 
         * 
         * StringBuilder sbOut = new StringBuilder(); int outCount = 0; for
         * (Delegation d : a.getOutgoingDelegations()) { if (outCount > 0)
         * sbOut.append(", and delegates to "); sbOut.append("%i" +
         * d.getTarget().getName() + "% goal %i" +
         * d.getSourceGoal().getName() + "%"); List<String> secNeed1 =
         * buildSecNeedString(d, true, 'i'); List<String> secNeed2 =
         * buildSecNeedString(d, false, 'i');
         * 
         * if (secNeed1.size() > 0) { switch (secNeed1.size()) { case 1:
         * sbOut.append(" and requires it to comply with the " +
         * separateListOfString(secNeed1) + " security need"); break;
         * default: sbOut.append(" and requires it to comply with the " +
         * separateListOfString(secNeed1) + " security needs"); break; } }
         * if (secNeed2.size() > 0) { switch (secNeed2.size()) { case 1:
         * sbOut.append(" and is required to comply with the " +
         * separateListOfString(secNeed2) + " security need"); break;
         * default: sbOut.append(" and is required to comply with the " +
         * separateListOfString(secNeed2) + " security needs"); break; } }
         * List<String> parmSecNeed = buildParamterizedSecNeedString(d,
         * 'i'); if (parmSecNeed.size() > 0) {
         * sbOut.append(" and requires a level of " +
         * separateListOfString(parmSecNeed)); } if (secNeed1.size() == 0 &&
         * secNeed2.size() == 0 && parmSecNeed.size() == 0) {
         * sbOut.append(": no security need is speccified"); }
         * 
         * outCount++; }
         * 
         * StringBuilder sb = new StringBuilder(); if (incCount > 0) { if
         * (outCount > 0) { sb.append(sbInc.toString() +
         * " while it delegates to " + sbOut.toString() + "."); } else {
         * sb.append(sbInc.toString() + "."); } } else { if (outCount > 0) {
         * sb.append("%b" + a.getName() + "% delegates to " +
         * sbOut.toString() + "."); } } if (sb.length() > 0) {
         * phrases.add(createParagraph(sb.toString())); }
         */
    }

    if (phrases.size() != 0) {
        sectionIntro = "The following description enlists all the delegations from one role/agent to the others. When applicable, security needs expressed over the delegations are enumerated.";
        section.add(createParagraph(sectionIntro));

        String t = "In the " + getProjectName() + " project" + socialDiagRef()
                + ", we have the following goal delegations:";
        section.add(createParagraph(t));
        section.add(listParagraphs(phrases));

        section.add(createParagraph(ftc.getTable(FigureConstant.DELEGATION_TABLE)
                + " summarises %igoal delegations%, together with the eventual %isecurity needs%, and the possible %ipreconditions% and %ipostconditions%, which determine when the delegation can take place, and the expected outcome of the delegation, respectively."));

        List<String[]> headers = new ArrayList<String[]>();
        headers.add(new String[] { "Delegator" });
        headers.add(new String[] { "Goal" });
        headers.add(new String[] { "Delegatee" });
        headers.add(new String[] { "Security", "Needs" });
        headers.add(new String[] { "Delegation", "Description" });
        headers.add(new String[] { "Pre-", "conditions" });
        headers.add(new String[] { "Post-", "conditions" });

        PdfPTable table = createTable(headers);

        for (Actor a : selActor) {

            if (a.getOutgoingDelegations().size() > 0) {

                PdfPCell cell = getContentCell();
                cell.setPhrase(new Phrase(a.getName(), TABLE_CONTENT));
                cell.setRowspan(a.getOutgoingDelegations().size());
                table.addCell(cell);

                for (Delegation d : a.getOutgoingDelegations()) {
                    table.addCell(getContentCell(d.getSourceGoal().getName()));
                    table.addCell(getContentCell(d.getTarget().getName()));

                    List<String> sn = buildDelegationSecNeedList(d);

                    Phrase p = null;
                    for (int i = 0; i < sn.size(); i++) {
                        if (i == 0)
                            p = new Phrase(sn.get(i), TABLE_CONTENT_SMALL);
                        else {
                            p.add(Chunk.NEWLINE);
                            p.add(new Phrase(sn.get(i), TABLE_CONTENT_SMALL));
                        }
                    }

                    PdfPCell c = getContentCell();
                    c.addElement(p);
                    table.addCell(c);

                    table.addCell(getContentCell(d.getDescription()));
                    table.addCell(getContentCell(d.getPreConditions()));
                    table.addCell(getContentCell(d.getPostConditions()));
                }
            }
        }
        addTableCaption(table,
                ftc.getTable(FigureConstant.DELEGATION_TABLE) + " - Goal Delegations and Security Needs");
        section.add(table);
        table.setComplete(true);

    } else {
        section.add(createParagraph("In the " + getProjectName()
                + " project there are no goal delegations taking place for the given agents/roles."));
    }
    section.setComplete(true);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionDocumentProvisions(Section section) {

    String sectionIntro = "Stakeholders exchange information by means of documents with other stakeholders. The following description enlists all the provisions from one role/agent representing the stakeholder, to other roles/agents. %iDocument provision% is represented as an arrow from the provider to the providee, with a rectangle representing the document. The security needs expressed over the provisions are described, if applicable. Security needs are specified with the help of labels that appear below the document.";
    section.add(createParagraph(sectionIntro));

    List<Actor> selActor = getDocumentProvisionsActors();
    List<Paragraph> phrases = new ArrayList<Paragraph>();

    for (Actor a : selActor) {

        for (Provision p : a.getOutgoingProvisions()) {
            Paragraph par = createParagraph("%b" + a.getName() + "% provides document %i"
                    + p.getSourceResource().getName() + "% to %b" + p.getTarget().getName() + "%.");
            List<String> secNeeds = buildProvisionSecNeedList(p);
            if (secNeeds.size() > 0) {
                par.add(new Phrase(" The following security needs apply to this provision:"));
                par.add(Chunk.NEWLINE);/* w  w w  .ja  v a 2  s  .  c  om*/
                par.add(new Phrase(separateListOfString(secNeeds) + "."));
            }
            phrases.add(par);
        }
    }

    /*
     * for (Actor a : selActor) { StringBuilder sbInc = new StringBuilder();
     * sbInc.append("%b" + a.getName() + "% is provided by "); int incCount
     * = 0; for (Provision p : a.getIncomingProvisions()) { if (incCount >
     * 0) sbInc.append(", and is provided by "); sbInc.append("%i" +
     * p.getSource().getName() + "% document %i" +
     * p.getSourceResource().getName() + "%"); if (p.isIntegrity()) {
     * sbInc.append(" and requires %b" + p.getSource().getName() +
     * "% to ensure %iintegrity of transmission% over the provision of this document"
     * ); }
     * 
     * incCount++; }
     * 
     * StringBuilder sbOut = new StringBuilder(); int outCount = 0; for
     * (Provision p : a.getOutgoingProvisions()) { if (outCount > 0)
     * sbOut.append(", and it provides to "); sbOut.append("%i" +
     * p.getTarget().getName() + "% document %i" +
     * p.getSourceResource().getName() + "%"); if (p.isIntegrity()) {
     * sbInc.append(" and requires %iAvailability% level of " +
     * p.getAvailabilityValue() + "%"); } outCount++; }
     * 
     * StringBuilder sb = new StringBuilder(); if (incCount > 0) { if
     * (outCount > 0) { sb.append(sbInc.toString() +
     * " while it provides to " + sbOut.toString() + "."); } else {
     * sb.append(sbInc.toString() + "."); } } else { if (outCount > 0) {
     * sb.append("%b" + a.getName() + "% provides to " + sbOut.toString() +
     * "."); } }
     * 
     * if (sb.length() > 0) { phrases.add(createParagraph(sb.toString())); }
     * }
     */

    if (phrases.size() != 0) {
        String s = "In the " + getProjectName() + " project " + socialDiagRef()
                + ", we have the following %idocument provisions%:";
        section.add(createParagraph(s));
        section.add(listParagraphs(phrases));

        section.add(createParagraph(ftc.getTable(FigureConstant.PROVISION_TABLE)
                + " summarises the %idocument provisions% for the " + getProjectName() + " project."));

        List<String[]> headers = new ArrayList<String[]>();
        headers.add(new String[] { "Providor" });
        headers.add(new String[] { "Document" });
        headers.add(new String[] { "Providee" });
        headers.add(new String[] { "Security", "Needs" });
        headers.add(new String[] { "Provision", "Descr." });

        PdfPTable table = createTable(headers);

        for (Actor a : selActor) {

            if (a.getOutgoingProvisions().size() > 0) {

                PdfPCell cell = getContentCell();
                cell.setPhrase(new Phrase(a.getName(), TABLE_CONTENT));
                cell.setRowspan(a.getOutgoingProvisions().size());
                table.addCell(cell);

                for (Provision p : a.getOutgoingProvisions()) {
                    table.addCell(getContentCell(p.getSourceResource().getName()));
                    table.addCell(getContentCell(p.getTarget().getName()));

                    List<String> sn = buildProvisionSecNeedList(p);

                    Phrase pr = null;
                    for (int i = 0; i < sn.size(); i++) {
                        if (i == 0)
                            pr = new Phrase(sn.get(i), TABLE_CONTENT_SMALL);
                        else {
                            pr.add(Chunk.NEWLINE);
                            pr.add(new Phrase(sn.get(i), TABLE_CONTENT_SMALL));
                        }
                    }

                    PdfPCell c = getContentCell();
                    c.addElement(pr);
                    table.addCell(c);

                    table.addCell(getContentCell(p.getDescription()));
                }
            }
        }
        addTableCaption(table, ftc.getTable(FigureConstant.PROVISION_TABLE) + " - Document Provisions");
        section.add(table);
        table.setComplete(true);
    } else {
        section.add(createParagraph("In the " + getProjectName()
                + " project there are no document provisions taking place for the given agents/roles."));
    }
    section.setComplete(true);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionGoalAnalysis(Section section) {

    String sectionIntro = "Stakeholders have goals to achieve. Goals are represented within the rationale (round compartment attached to the role/agent"
            + socialDiagRef(", see ", "")
            + ") of the role/agent representing the stakeholder. They achieve their goals by further refining them into finer-grained goals (subgoals) by means of AND/OR-decompositions. AND-decompositions structurally refine a goal into multiple subgoals (all AND subgoals need to be achieved for the goal to be achieved), while OR-decompositions represent alternative ways for achieving a goal (at least one of the subgoals in the OR-decomposition needs to be achieved for the goal to be achieved).";
    section.add(createParagraph(sectionIntro));

    List<Actor> selActor = getGoalAnalysisActors();
    List<Paragraph> phrases = new ArrayList<Paragraph>();

    for (Actor a : selActor) {
        if (a.getGoals().size() != 0) {
            StringBuilder sb = new StringBuilder();

            List<String> goalS = new ArrayList<String>();
            List<Goal> goalDecomposed = new ArrayList<Goal>();
            for (Goal g : a.getGoals()) {
                if (g.getIncomingDecompositions() == null) {
                    goalS.add("goal %i" + g.getName() + "%");
                }//from  ww w.j  a v a 2  s.  c  om
                if (g.getOutgoingDecompositions().size() > 0) {
                    goalDecomposed.add(g);
                }
            }
            if (goalS.size() > 0) {
                sb.append("%b" + a.getName() + "% " + " has to achieve " + separateListOfString(goalS) + ".");
                if (goalDecomposed.size() > 0) {
                    for (Goal g : goalDecomposed) {
                        sb.append(" To achieve %i" + g.getName() + "%, " + g.getActorOwner().getName()
                                + " should achieve ");
                        if (g.getOutgoingDecompositions().get(0) instanceof GoalDecompositionAND) {
                            List<String> list = new ArrayList<String>();
                            for (GoalDecomposition gd : g.getOutgoingDecompositions()) {
                                if (gd.getTarget() != null)
                                    list.add("goal %i" + gd.getTarget().getName() + "%");
                            }
                            sb.append(separateListOfString(list));
                        } else {
                            List<String> list = new ArrayList<String>();
                            for (GoalDecomposition gd : g.getOutgoingDecompositions()) {
                                if (gd.getTarget() != null)
                                    list.add("goal %i" + gd.getTarget().getName() + "%");
                            }
                            sb.append("either " + separateListOfString(list, ", ", " or "));
                        }
                        sb.append(".");
                    }
                }
            }

            if (sb.length() > 0) {
                phrases.add(createParagraph(sb.toString()));
            }
        }
    }
    if (phrases.size() != 0) {
        String s = "In the " + getProjectName() + " project" + socialDiagRef() + " we have:";
        section.add(createParagraph(s));
        section.add(listParagraphs(phrases));

        section.add(createParagraph(
                ftc.getTable(FigureConstant.GOAL_DEC_TABLE) + " summarises the goals of each agent/role in the "
                        + getProjectName() + " project and how they are decomposed, when applicable."));

        List<String[]> headers = new ArrayList<String[]>();
        headers.add(new String[] { "Agent/Role" });
        headers.add(new String[] { "Goal" });
        headers.add(new String[] { "Dec. Type" });
        headers.add(new String[] { "Subgoals" });
        PdfPTable table = createTable(headers);

        for (Actor a : selActor) {

            List<Goal> validGoals = new ArrayList<Goal>();

            for (Goal g : a.getGoals()) {
                if (g.getIncomingDecompositions() == null) {
                    validGoals.add(g);
                } // remove goal of decompostion
            }
            if (validGoals.size() > 0) {
                PdfPCell actorCell = getContentCell(a.getName());

                int rowspan = 0;
                for (Goal g : validGoals) {
                    if (g.getOutgoingDecompositions().size() > 0)
                        rowspan += g.getOutgoingDecompositions().size();
                    else
                        ++rowspan;
                }
                actorCell.setRowspan(rowspan);
                table.addCell(actorCell);

                for (Goal g : validGoals) {

                    PdfPCell goalCell = getContentCell(g.getName());

                    if (g.getOutgoingDecompositions().size() > 0) {
                        String decType = "";
                        if (g.getOutgoingDecompositions().get(0) instanceof GoalDecompositionAND) {
                            decType = "AND";
                        } else {
                            decType = "OR";
                        }
                        PdfPCell decTypeCell = getContentCell(decType);

                        List<String> decomp = new ArrayList<String>();
                        for (GoalDecomposition gd : g.getOutgoingDecompositions()) {
                            if (gd.getTarget() != null)
                                decomp.add(gd.getTarget().getName());
                        }

                        if (decomp.size() > 1) {
                            rowspan = decomp.size();
                            goalCell.setRowspan(rowspan);
                            decTypeCell.setRowspan(rowspan);
                        }
                        table.addCell(goalCell);
                        table.addCell(decTypeCell);
                        for (String stri : decomp) {
                            table.addCell(getContentCell(stri));
                        }
                    } else {
                        table.addCell(goalCell);
                        table.addCell(getContentCell("-"));
                        table.addCell(getContentCell());
                    }
                }
            }
        }
        section.add(table);
        addTableCaption(table, ftc.getTable(FigureConstant.GOAL_DEC_TABLE) + " - Goal Decompositions");
        table.setComplete(true);
    } else {
        section.add(createParagraph("In the " + getProjectName()
                + " project there are no decomposition relations taking place for the given agents/roles."));
    }
    section.setComplete(true);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionGoalContribution(Section section) {

    String sectionIntro = "Goals can contribute one to another. A contribution identifies the impact the fulfilment of one goal has on the fulfilment of another goal. This impact can be either positive or negative, and is rappresented with ++ and -- respectively. Positive contribution means that the achievement of a goal also achieves the other goal. Negative contribution means that the achievement of a goal inhibits the achievement of another goal.";
    section.add(createParagraph(sectionIntro));

    List<Actor> selActor = getGoalContributionActors();
    List<Paragraph> phrases = new ArrayList<Paragraph>();

    for (Actor a : selActor) {

        for (Goal g : a.getGoals()) {
            Map<Actor, List<String>> posContib = new HashMap<Actor, List<String>>();
            Map<Actor, List<String>> negContib = new HashMap<Actor, List<String>>();

            for (GoalContribution c : g.getOutgoingContributions()) {
                Actor act = c.getTarget().getActorOwner();
                String gname = "goal %i" + c.getTarget().getName() + "%";
                if (c instanceof PositiveGoalContribution) {
                    if (!posContib.containsKey(act)) {
                        posContib.put(act, new ArrayList<String>());
                    }/* w  ww  . j ava 2s .  c  om*/
                    posContib.get(act).add(gname);
                } else {
                    if (!negContib.containsKey(act)) {
                        negContib.put(act, new ArrayList<String>());
                    }
                    negContib.get(act).add(gname);
                }
            }

            StringBuilder sb = new StringBuilder();

            if (posContib.size() > 0) {
                sb.append("%ipositive% side effect on ");
                List<String> sl = new ArrayList<String>();
                for (Actor ac : posContib.keySet()) {
                    sl.add(separateListOfString(posContib.get(ac)) + " of " + typeActor(ac) + " %i"
                            + ac.getName() + "%");
                }
                sb.append(separateListOfString(sl));
            }
            if (posContib.size() > 0 && negContib.size() > 0) {
                sb.append(" and has ");
            }
            if (negContib.size() > 0) {
                sb.append("%inegative% side effect on ");
                List<String> sl = new ArrayList<String>();
                for (Actor ac : negContib.keySet()) {
                    sl.add(separateListOfString(negContib.get(ac)) + " of " + typeActor(ac) + " %i"
                            + ac.getName() + "%");
                }
                sb.append(separateListOfString(sl));
            }

            if (sb.length() > 0) {
                phrases.add(createParagraph("The goal %b" + g.getName() + "% of " + typeActor(a) + " %i"
                        + a.getName() + "% has " + sb.toString() + "."));
            }
        }
    }
    if (phrases.size() != 0) {
        String s = "In the " + getProjectName() + " project" + socialDiagRef() + " we have:";
        section.add(createParagraph(s));
        section.add(listParagraphs(phrases));

        section.add(createParagraph(ftc.getTable(FigureConstant.GOAL_CONTRIB_TABLE)
                + " summarises the %igoals contributions% in the " + getProjectName() + " project."));

        List<String[]> headers = new ArrayList<String[]>();
        headers.add(new String[] { "Goal" });
        headers.add(new String[] { "Description" });
        headers.add(new String[] { "Contr. Type" });
        headers.add(new String[] { "Goals" });
        PdfPTable table = createTable(headers);

        for (Actor a : selActor) {
            for (Goal g : a.getGoals()) {
                if (g.getOutgoingContributions().size() > 0) {
                    List<GoalContribution> posContib = new ArrayList<GoalContribution>();
                    List<GoalContribution> negContib = new ArrayList<GoalContribution>();
                    for (GoalContribution c : g.getOutgoingContributions()) {
                        if (c.getTarget() != null) {
                            if (c instanceof PositiveGoalContribution) {
                                posContib.add(c);
                            } else {
                                negContib.add(c);
                            }
                        }
                    }

                    PdfPCell goalCell = getContentCell(new String[] { g.getName(), "(" + a.getName() + ")" });

                    goalCell.setRowspan(g.getOutgoingContributions().size());
                    table.addCell(goalCell);
                    PdfPCell descrCell = getContentCell(g.getDescription());
                    descrCell.setRowspan(g.getOutgoingContributions().size());
                    table.addCell(descrCell);
                    if (posContib.size() > 0) {
                        PdfPCell typeCell = getContentCell("Positive");
                        typeCell.setRowspan(posContib.size());
                        table.addCell(typeCell);
                        for (GoalContribution gc : posContib) {
                            table.addCell(getContentCell(new String[] { gc.getTarget().getName(),
                                    "(" + gc.getTarget().getActorOwner().getName() + ")" }));
                        }
                    }
                    if (negContib.size() > 0) {
                        PdfPCell typeCell = getContentCell("Negative");
                        typeCell.setRowspan(posContib.size());
                        table.addCell(typeCell);
                        for (GoalContribution gc : negContib) {

                            table.addCell(getContentCell(new String[] { gc.getTarget().getName(),
                                    "(" + gc.getTarget().getActorOwner().getName() + ")" }));
                        }
                    }
                }
            }
        }
        section.add(table);
        addTableCaption(table, ftc.getTable(FigureConstant.GOAL_CONTRIB_TABLE) + " - Goal Contributions in the "
                + getProjectName() + " project");
        table.setComplete(true);
    } else {
        section.add(createParagraph("In the " + getProjectName()
                + " project there are no contribution relations taking place for the given agents/roles."));
    }
    section.setComplete(true);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionStakeholdersDocument(Section section) {

    String sectionIntro = "Stakeholders have documents they possess or exchange with others to achieve their goals. Documents are represented within the rationale of the role/agent"
            + socialDiagRef() + ".";
    section.add(createParagraph(sectionIntro));

    List<Actor> selActor = getStakeholdersDocumentActors();
    List<Paragraph> phrases = new ArrayList<Paragraph>();

    for (Actor a : selActor) {
        if (a.getTResources().size() > 0) {
            StringBuilder sb = new StringBuilder();

            List<String> nonProvidedDocs = new ArrayList<String>();
            Map<Set<Actor>, Set<String>> providedDocs = new HashMap<Set<Actor>, Set<String>>();

            for (TResource r : a.getTResources()) {
                if (r.getProvidedFrom().size() == 0) {
                    nonProvidedDocs.add("%i" + r.getName() + "%");
                } else {
                    Set<Actor> s = new HashSet<Actor>();
                    for (Provision p : r.getProvidedFrom()) {
                        s.add(p.getSource());
                    }//from  w  w  w.j  a v a 2 s  . c  o  m
                    if (!providedDocs.containsKey(s)) {
                        providedDocs.put(s, new HashSet<String>());
                    }
                    Set<String> resSet = providedDocs.get(s);
                    resSet.add("%i" + r.getName() + "%");
                    providedDocs.put(s, resSet);
                }
            }
            sb.append("%b" + a.getName() + "% ");

            if (nonProvidedDocs.size() == 1) {
                sb.append("has document " + nonProvidedDocs.get(0) + ".");
            } else if (nonProvidedDocs.size() > 1) {
                sb.append("has documents ");
                sb.append(separateListOfString(nonProvidedDocs) + ".");
            }
            if (providedDocs.size() > 0) {
                if (nonProvidedDocs.size() > 0) {
                    sb.append(" Moreover it has ");
                } else {
                    sb.append("has ");
                }
                List<String> subPart = new ArrayList<String>();

                for (Set<Actor> key : providedDocs.keySet()) {
                    List<String> actors = new ArrayList<String>();
                    List<String> documents = new ArrayList<String>(providedDocs.get(key));
                    for (Actor act : key) {
                        actors.add("%i" + act.getName() + "%");
                    }
                    if (documents.size() == 1) {
                        subPart.add("document " + separateListOfString(documents, ", ", ", ") + " provided by "
                                + separateListOfString(actors, ", ", ", "));
                    } else {
                        subPart.add("documents " + separateListOfString(documents, ", ", ", ") + " provided by "
                                + separateListOfString(actors, ", ", ", "));
                    }
                }
                sb.append(separateListOfString(subPart) + ".");
            }

            /*
             * sb.append("%b" + a.getName() + "% has document");
             * 
             * List<String> documents = new ArrayList<String>();
             * List<String> privdedDocuments = new ArrayList<String>();
             * 
             * for (TResource r : a.getTResources()) { String pr = ""; if
             * (r.getProvidedFrom().size() > 0) { List<String> provider =
             * new ArrayList<String>(); for (Provision p :
             * r.getProvidedFrom()) { provider.add(p.getSource().getName());
             * } if(provider.size()>1){ pr = ", since " +
             * separateListOfString(provider) +
             * " provides it with these documents"; }else{ pr = ", since " +
             * separateListOfString(provider) +
             * " provides it with this document"; }
             * 
             * } String s = "%i" + r.getName() + "%" + pr; if
             * (r.getProvidedFrom().size() == 0) { documents.add(s); } else
             * { privdedDocuments.add(s); } }
             * documents.addAll(privdedDocuments); if (documents.size() > 1)
             * sb.append("s"); sb.append(" " +
             * separateListOfString(documents) + ".");
             */
            phrases.add(createParagraph(sb.toString()));
        }
    }
    if (phrases.size() != 0) {

        String s = "In the " + getProjectName() + " project" + socialDiagRef() + " we have:";
        section.add(createParagraph(s));
        section.add(listParagraphs(phrases));

        section.add(createParagraph(ftc.getTable(FigureConstant.STAKE_DOC_TABLE)
                + " summarises stakeholders %idocuments% for the " + getProjectName() + " project."));
        List<String[]> headers = new ArrayList<String[]>();
        headers.add(new String[] { "Agent/Role" });
        headers.add(new String[] { "Document" });
        headers.add(new String[] { "Description" });
        PdfPTable table = createTable(headers);

        for (Actor a : selActor) {
            if (a.getTResources().size() > 0) {
                PdfPCell actorCell = getContentCell(a.getName());
                actorCell.setRowspan(a.getTResources().size());
                table.addCell(actorCell);
                for (TResource r : a.getTResources()) {
                    table.addCell(getContentCell(r.getName()));
                    table.addCell(getContentCell(r.getDescription()));
                }
            }
        }
        section.add(table);
        addTableCaption(table, ftc.getTable(FigureConstant.STAKE_DOC_TABLE)
                + " - Stakeholders documents in the " + getProjectName() + " project");
        table.setComplete(true);
    } else {
        section.add(createParagraph("In the " + getProjectName()
                + " project there are no document taking place for the given agents/roles."));
    }
    section.setComplete(true);
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

private void buildSectionStakeholdersDocumentAndGoals(Section section) {

    String sectionIntro = "Stakeholders documents are linked to their goals: they need (use) documents to achieve their goals, they modify documents while achieving their goals, and they may produce documents from achieving their goals.";
    section.add(createParagraph(sectionIntro));

    List<Actor> selActor = getStakeholdersDocumentAndGoalsActors();
    List<Paragraph> phrases = new ArrayList<Paragraph>();

    for (Actor a : selActor) {
        List<Goal> validGoal = new ArrayList<Goal>();
        for (Goal g : a.getGoals()) {
            if (g.getResourceNeeded().size() > 0 || g.getResourcesModified().size() > 0
                    || g.getResourcesProduced().size() > 0) {
                validGoal.add(g);/* w  w  w. j  a  va2s.  c  om*/
            }
        }
        if (validGoal.size() > 0) {

            Map<Goal, Map<TResource, String>> goalMap = new HashMap<Goal, Map<TResource, String>>();
            for (Goal g : validGoal) {
                Map<TResource, String> docMap = new HashMap<TResource, String>();
                if (g.getResourceNeeded().size() > 0) {
                    for (Need n : g.getResourceNeeded()) {
                        TResource doc = n.getTarget();
                        if (doc != null)
                            docMap.put(doc, "%ineeds%");
                    }
                }
                if (g.getResourcesModified().size() > 0) {
                    for (Modify m : g.getResourcesModified()) {
                        TResource doc = m.getTarget();
                        if (doc != null) {
                            if (docMap.containsKey(doc)) {
                                docMap.put(doc, docMap.get(doc) + ", %imodify%");
                            } else {
                                docMap.put(doc, "%imodifies%");
                            }
                        }
                    }
                }
                if (g.getResourcesProduced().size() > 0) {
                    for (Produce p : g.getResourcesProduced()) {
                        TResource doc = p.getTarget();
                        if (doc != null) {
                            if (docMap.containsKey(doc)) {
                                docMap.put(doc, docMap.get(doc) + "and %iproduce%");
                            } else {
                                docMap.put(doc, "%iproduces%");
                            }
                        }
                    }
                }
                goalMap.put(g, docMap);
            }

            List<String> l = new ArrayList<String>();

            for (Goal g : goalMap.keySet()) {
                List<String> list = new ArrayList<String>();
                Map<TResource, String> m = goalMap.get(g);
                for (TResource r : m.keySet()) {
                    if (r != null) {
                        list.add(m.get(r) + " document %i" + r.getName() + "%");
                    } else {
                        // System.out.println("NULLLLL");
                    }
                }
                l.add(separateListOfString(list) + " to achieve goal %i" + g.getName() + "%");
            }

            phrases.add(createParagraph("%b" + a.getName() + "% " + separateListOfString(l) + "."));
        }
    }
    if (phrases.size() != 0) {
        String s = "In the " + getProjectName() + " project" + socialDiagRef()
                + " stakeholders documents and goals are related as follows:";
        section.add(createParagraph(s));
        section.add(listParagraphs(phrases));

        section.add(createParagraph(ftc.getTable(FigureConstant.STAKE_DOC_GOAL_TABLE)
                + " summarises goal-document relations for all stakeholders in the " + getProjectName()
                + " project."));
        List<String[]> headers = new ArrayList<String[]>();
        headers.add(new String[] { "Agent/Role" });
        headers.add(new String[] { "Goal" });
        headers.add(new String[] { "Document" });
        headers.add(new String[] { "Relation" });
        PdfPTable table = createTable(headers);

        for (Actor a : selActor) {
            List<Goal> validGoal = new ArrayList<Goal>();
            for (Goal g : a.getGoals()) {
                if (g.getResourceNeeded().size() > 0 || g.getResourcesModified().size() > 0
                        || g.getResourcesProduced().size() > 0) {
                    validGoal.add(g);
                }
            }
            if (validGoal.size() > 0) {
                PdfPCell actorCell = getContentCell(a.getName());
                int rowspan = 0;

                Map<Goal, Map<TResource, String>> goalMap = new HashMap<Goal, Map<TResource, String>>();
                for (Goal g : validGoal) {
                    Map<TResource, String> docMap = new HashMap<TResource, String>();
                    if (g.getResourceNeeded().size() > 0) {
                        for (Need n : g.getResourceNeeded()) {
                            TResource doc = n.getTarget();
                            if (doc != null) {
                                if (docMap.containsKey(doc)) {
                                    docMap.put(doc, docMap.get(doc) + ", Need");
                                } else {
                                    docMap.put(doc, "Need");
                                }
                            }
                        }
                    }
                    if (g.getResourcesModified().size() > 0) {
                        for (Modify m : g.getResourcesModified()) {
                            TResource doc = m.getTarget();
                            if (doc != null) {
                                if (docMap.containsKey(doc)) {
                                    docMap.put(doc, docMap.get(doc) + ", Modify");
                                } else {
                                    docMap.put(doc, "Modify");
                                }
                            }
                        }
                    }
                    if (g.getResourcesProduced().size() > 0) {
                        for (Produce p : g.getResourcesProduced()) {
                            TResource doc = p.getTarget();
                            if (doc != null) {
                                if (docMap.containsKey(doc)) {
                                    docMap.put(doc, docMap.get(doc) + ", Produce");
                                } else {
                                    docMap.put(doc, "Produce");
                                }
                            }
                        }
                    }
                    rowspan += docMap.size();
                    goalMap.put(g, docMap);
                }
                if (rowspan > 1) {
                    actorCell.setRowspan(rowspan);
                }
                table.addCell(actorCell);

                for (Goal g : goalMap.keySet()) {
                    Map<TResource, String> m = goalMap.get(g);
                    PdfPCell goalCell = getContentCell(g.getName());
                    if (m.size() > 1) {
                        goalCell.setRowspan(m.size());
                    }
                    table.addCell(goalCell);

                    for (TResource r : m.keySet()) {
                        table.addCell(getContentCell(r.getName()));
                        table.addCell(getContentCell(m.get(r)));
                    }
                }
            }
        }
        section.add(table);
        addTableCaption(table, ftc.getTable(FigureConstant.STAKE_DOC_GOAL_TABLE)
                + " - Relation of stakeholders documents to their goals");
        table.setComplete(true);
    } else {
        section.add(createParagraph("In the " + getProjectName()
                + " project there are no relationships specified between the goals and documents of the given agents/roles."));
    }
    section.setComplete(true);
}