Example usage for com.itextpdf.text Section add

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

Introduction

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

Prototype

@Override
public boolean add(final Element element) 

Source Link

Document

Adds a Paragraph, List, Table or another Section to this Section.

Usage

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  ww  w.  java 2s .  c o 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 a2s . com
    }

    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);//w w  w. j a  va  2  s.  co  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);/*from ww  w  . j  ava 2s  .com*/
                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() + "%");
                }// www  . java2 s . c  o  m
                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>());
                    }//from   w  ww . j av a 2 s .  co  m
                    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  ww  w.j  a  v  a2s. com*/
                    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);//from  w  w w . jav  a  2  s  . com
            }
        }
        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);
}

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

License:Open Source License

private void buildSectionOrganisationalConstraints(Section section) {

    String sectionIntro = "Apart from the security needs actors specify over their interactions, there are others, which are dictated either by the organisation, business rules and regulations, or law. In this section we enlist these constraints, together with the security requirements derived from them. Currently, the language supports these organisational constraints: %iSeparation of Duties (SoD)% and %iBinding of Duties (BoD)%. Graphically we represent these constraints using a similar notation to that used in workflows, as a circle with the %iunequal% sign within and as a circle with the %iequals% sign within, respectively. The relations are symmetric, and as such they do not have any arrows pointed to the concepts they relate (being these roles or goals).";
    section.add(createParagraph(sectionIntro));

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

    Map<Role, List<IncompatibleDuties>> incompRole = new HashMap<Role, List<IncompatibleDuties>>();
    Map<Goal, List<IncompatibleDuties>> incompGoal = new HashMap<Goal, List<IncompatibleDuties>>();
    Map<Role, List<CompatibleDuties>> compRole = new HashMap<Role, List<CompatibleDuties>>();
    Map<Goal, List<CompatibleDuties>> compGoal = new HashMap<Goal, List<CompatibleDuties>>();

    for (Actor a : selActor) {
        if (a instanceof Role) {
            Role r = (Role) a;
            List<IncompatibleDuties> incDutiesList = new ArrayList<IncompatibleDuties>();
            for (IncompatibleDuties id : r.getIncompatibleDutiesOut()) {
                if (id.getTarget() != null && id.getTarget() instanceof Role)
                    incDutiesList.add(id);
            }//from   ww  w. j a va  2  s.  co m
            for (IncompatibleDuties id : r.getIncompatibleDutiesIn()) {
                if (id.getSource() != null && id.getSource() instanceof Role)
                    incDutiesList.add(id);
            }
            if (incDutiesList.size() > 0) {
                incompRole.put(r, incDutiesList);
            }

            List<CompatibleDuties> compDutiesList = new ArrayList<CompatibleDuties>();
            for (CompatibleDuties bd : r.getCompatibleDutiesOut()) {
                if (bd.getTarget() != null && bd.getTarget() instanceof Role)
                    compDutiesList.add(bd);
            }
            for (CompatibleDuties bd : r.getCompatibleDutiesIn()) {
                if (bd.getSource() != null && bd.getSource() instanceof Role)
                    compDutiesList.add(bd);
            }
            if (compDutiesList.size() > 0) {
                compRole.put(r, compDutiesList);
            }
        }
        for (Goal g : a.getGoals()) {

            List<IncompatibleDuties> incDutiesList = new ArrayList<IncompatibleDuties>();
            for (IncompatibleDuties id : g.getIncompatibleDutiesOut()) {
                if (id.getTarget() != null && id.getTarget() instanceof Goal)
                    incDutiesList.add(id);
            }
            for (IncompatibleDuties id : g.getIncompatibleDutiesIn()) {
                if (id.getSource() != null && id.getSource() instanceof Goal)
                    incDutiesList.add(id);
            }
            if (incDutiesList.size() > 0) {
                incompGoal.put(g, incDutiesList);
            }

            List<CompatibleDuties> compDutiesList = new ArrayList<CompatibleDuties>();
            for (CompatibleDuties bd : g.getCompatibleDutiesOut()) {
                if (bd.getTarget() != null && bd.getTarget() instanceof Goal)
                    compDutiesList.add(bd);
            }
            for (CompatibleDuties bd : g.getCompatibleDutiesIn()) {
                if (bd.getSource() != null && bd.getSource() instanceof Goal)
                    compDutiesList.add(bd);
            }
            if (compDutiesList.size() > 0) {
                compGoal.put(g, compDutiesList);
            }
        }
    }

    /*
     * StringBuilder sb = new StringBuilder(); for (Actor a : selActor) { if
     * (a instanceof Role) { Role r = (Role) a; List<String> incomp = new
     * ArrayList<String>(); for (IncompatibleDuties id :
     * r.getIncompatibleDutiesOut()) { if (id.getTarget() != null &&
     * id.getTarget() instanceof Role) incomp.add("%b" + ((Role)
     * id.getTarget()).getName() + "%"); } for (IncompatibleDuties id :
     * r.getIncompatibleDutiesIn()) { if (id.getSource() != null &&
     * id.getSource() instanceof Role) incomp.add("%b" + ((Role)
     * id.getSource()).getName() + "%"); } if (incomp.size() > 0) { String s
     * = "%b" + r.getName() + "% is incompatible with " +
     * separateListOfString(incomp) +
     * ", since %iSoD% constraints are specified between these roles."; if
     * (sb.length() > 0) sb.append("; "); sb.append("%b" + r.getName() +
     * "% is incompatible with " + separateListOfString(incomp)); } } }
     * 
     * if (sb.length() > 0) {
     * sb.append(", since a %iSoD% constraint is specified between these roles."
     * ); phrases.add(createParagraph(sb.toString())); }
     */

    for (Role incR : incompRole.keySet()) {
        List<String> incomp = new ArrayList<String>();
        for (IncompatibleDuties id : incompRole.get(incR)) {
            SeparationOfDuties r = id.getTarget();
            if (incR == r)
                r = id.getSource();
            if (r != null && r instanceof Role)
                incomp.add("%b" + ((Role) r).getName() + "%");
        }
        if (incomp.size() > 0) {
            String s = "%b" + incR.getName() + "% is incompatible with " + separateListOfString(incomp)
                    + ", since %iSoD% constraints are specified between these roles.";
            phrases.add(createParagraph(s.toString()));
        }
    }

    for (Role compR : compRole.keySet()) {
        List<String> comp = new ArrayList<String>();
        for (CompatibleDuties cd : compRole.get(compR)) {
            BindingOfDuties r = cd.getTarget();
            if (compR == r)
                r = cd.getSource();
            if (r != null && r instanceof Role)
                comp.add("%b" + ((Role) r).getName() + "%");
        }
        if (comp.size() > 0) {
            String s = "%b" + compR.getName() + "% should be combined with " + separateListOfString(comp)
                    + ", since %iBoD% constraints are specified between these roles.";
            phrases.add(createParagraph(s.toString()));
        }
    }

    for (Goal incG : incompGoal.keySet()) {
        List<String> incomp = new ArrayList<String>();
        for (IncompatibleDuties id : incompGoal.get(incG)) {
            SeparationOfDuties g = id.getTarget();
            if (incG == g)
                g = id.getSource();
            if (g != null && g instanceof Goal)
                incomp.add("%b" + ((Goal) g).getName() + "%");
        }
        if (incomp.size() > 0) {
            String s = "%b" + incG.getName() + "% is incompatible with " + separateListOfString(incomp)
                    + ", given that %iSoD% constraint is specified between these goals.";
            phrases.add(createParagraph(s.toString()));
        }
    }

    for (Goal comG : compGoal.keySet()) {
        List<String> comp = new ArrayList<String>();
        for (CompatibleDuties cd : compGoal.get(comG)) {
            BindingOfDuties g = cd.getTarget();
            if (comG == g)
                g = cd.getSource();
            if (g != null && g instanceof Goal)
                comp.add("%b" + ((Goal) g).getName() + "%");
        }
        if (comp.size() > 0) {
            String s = "%b" + comG.getName() + "% should be combined with " + separateListOfString(comp)
                    + ", given that %iBoD% constraint is specified between these goals.";
            phrases.add(createParagraph(s.toString()));
        }
    }

    if (incompRole.size() > 0 || incompGoal.size() > 0 || compGoal.size() > 0 || compRole.size() > 0) {
        String s = "In the " + getProjectName() + " project" + socialDiagRef()
                + " the following organisational constraints have been specified:";
        section.add(createParagraph(s));
        section.add(listParagraphs(phrases));

        section.add(createParagraph(ftc.getTable(FigureConstant.ORG_CONSTR_TABLE)
                + " summarises the organisational constraints for the " + getProjectName() + " project."));
        List<String[]> headers = new ArrayList<String[]>();
        headers.add(new String[] { "Organisational", "Constraint" });
        headers.add(new String[] { "Role/Goal" });
        headers.add(new String[] { "Role/Goal" });
        headers.add(new String[] { "Description" });
        PdfPTable table = createTable(headers);

        if (incompRole.size() > 0) {
            int sodRoleRowspan = 0;
            for (List<IncompatibleDuties> idList : incompRole.values()) {
                sodRoleRowspan += idList.size();
            }
            PdfPCell soDRoleCell = getContentCell(new String[] { "SoD", "(Role - Role)" });
            soDRoleCell.setRowspan(sodRoleRowspan);
            table.addCell(soDRoleCell);

            for (Role r : incompRole.keySet()) {
                List<IncompatibleDuties> idList = incompRole.get(r);
                PdfPCell sRole = getContentCell(r.getName());
                sRole.setRowspan(idList.size());
                table.addCell(sRole);
                for (IncompatibleDuties id : idList) {
                    Role tr = (Role) id.getTarget();
                    if (tr == r)
                        tr = (Role) id.getSource();
                    table.addCell(getContentCell(tr.getName()));
                    String desc = id.getDescription();
                    if (desc == null)
                        desc = "";
                    table.addCell(getContentCell(desc));
                }
            }
        }

        if (compRole.size() > 0) {
            int bodRoleRowspan = 0;
            for (List<CompatibleDuties> lr : compRole.values()) {
                bodRoleRowspan += lr.size();
            }
            PdfPCell boDRoleCell = getContentCell(new String[] { "BoD", "(Role - Role)" });
            boDRoleCell.setRowspan(bodRoleRowspan);
            table.addCell(boDRoleCell);

            for (Role r : compRole.keySet()) {
                List<CompatibleDuties> rl = compRole.get(r);
                PdfPCell sRole = getContentCell(r.getName());
                sRole.setRowspan(rl.size());
                table.addCell(sRole);
                for (CompatibleDuties id : rl) {
                    Role tr = (Role) id.getTarget();
                    if (tr == r)
                        tr = (Role) id.getSource();
                    table.addCell(getContentCell(tr.getName()));
                    String desc = id.getDescription();
                    if (desc == null)
                        desc = "";
                    table.addCell(getContentCell(desc));
                }
            }
        }

        if (incompGoal.size() > 0) {
            int sodGoalRowspan = 0;
            for (List<IncompatibleDuties> idList : incompGoal.values()) {
                sodGoalRowspan += idList.size();
            }
            PdfPCell soDGoalCell = getContentCell(new String[] { "SoD", "(Goal - Goal)" });
            soDGoalCell.setRowspan(sodGoalRowspan);
            table.addCell(soDGoalCell);

            for (Goal g : incompGoal.keySet()) {
                List<IncompatibleDuties> rl = incompGoal.get(g);
                PdfPCell sGoal = getContentCell(g.getName());
                sGoal.setRowspan(rl.size());
                table.addCell(sGoal);
                for (IncompatibleDuties id : rl) {
                    Goal tg = (Goal) id.getTarget();
                    if (tg == g)
                        tg = (Goal) id.getSource();
                    table.addCell(getContentCell(tg.getName()));
                    String desc = id.getDescription();
                    if (desc == null)
                        desc = "";
                    table.addCell(getContentCell(desc));
                }
            }
        }

        if (compGoal.size() > 0) {
            int bodGoalRowspan = 0;
            for (List<CompatibleDuties> lr : compGoal.values()) {
                bodGoalRowspan += lr.size();
            }
            PdfPCell boDGoalCell = getContentCell(new String[] { "BoD", "(Goal - Goal)" });
            boDGoalCell.setRowspan(bodGoalRowspan);
            table.addCell(boDGoalCell);

            for (Goal g : compGoal.keySet()) {
                List<CompatibleDuties> rl = compGoal.get(g);
                PdfPCell sGoal = getContentCell(g.getName());
                sGoal.setRowspan(rl.size());
                table.addCell(sGoal);
                for (CompatibleDuties id : rl) {
                    Goal tg = (Goal) id.getTarget();
                    if (tg == g)
                        tg = (Goal) id.getSource();
                    table.addCell(getContentCell(tg.getName()));
                    String desc = id.getDescription();
                    if (desc == null)
                        desc = "";
                    table.addCell(getContentCell(desc));
                }
            }
        }

        /*
         * PdfPCell soDRoleCell = getContentCell("Sod");
         * soDRoleCell.setRowspan(sodRowspan); table.addCell(soDRoleCell);
         * 
         * for(Role r :sodRole.keySet()){ List<IncompatibleDuties>
         * rl=sodRole.get(r); PdfPCell sRole = getContentCell(r.getName());
         * sRole.setRowspan(rl.size()); table.addCell(sRole);
         * for(IncompatibleDuties id:rl){ Role tr=(Role)id.getTarget();
         * if(tr==r)tr=(Role)id.getSource();
         * table.addCell(getContentCell(tr.getName())); String
         * desc=id.getDescription(); if(desc==null)desc="";
         * table.addCell(getContentCell(desc)); } }
         */

        section.add(table);
        addTableCaption(table, ftc.getTable(FigureConstant.ORG_CONSTR_TABLE) + " - Organisational Constraints");
        table.setComplete(true);
    } else {
        section.add(createParagraph(
                "In the " + getProjectName() + " project there are no organisational constraints specified."));
    }
    section.setComplete(true);

}

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

License:Open Source License

private void buildEventsSection(Section section) {
    Set<Event> events = getDiagram().getAllEvents();

    if (events.size() > 0) {
        String sectionIntro = ftc.getTable(FigureConstant.EVENT_TABLE)
                + " represents all the events modeled in the project " + getProjectName()
                + " together with the set of elements each event threatens. Additionally, for each reported event a textual description is provided, which is extracted from the threat repository.";
        section.add(createParagraph(sectionIntro));

        List<String[]> headers = new ArrayList<String[]>();//
        headers.add(new String[] { "Event name" });
        headers.add(new String[] { "Threatened elements" });
        headers.add(new String[] { "Description" });
        PdfPTable table = createTable(headers);

        //      List<Event> e1l=new ArrayList<Event>();
        //      List<Event> e2l=new ArrayList<Event>();
        //      /*from   w  ww .  ja va  2 s .c o m*/
        //      for(Event e:events){
        //         if(e.getEventID()!=null && e.getEventID().length()>0)
        //            e1l.add(e);
        //         else{
        //            e2l.add(e);
        //         }
        //      }
        //      
        List<Event> ordredevents = new ArrayList(events);
        //      for(Event e:e1l)
        Collections.sort(ordredevents, new Comparator<Event>() {

            @Override
            public int compare(Event e1, Event e2) {

                int i1 = (e1.getEventID() != null && e1.getEventID().length() > 0) ? 0 : 1;
                int i2 = (e1.getEventID() != null && e1.getEventID().length() > 0) ? 0 : -1;
                return i1 + i2;
            }

        });

        for (Event e : ordredevents) {

            table.addCell(getContentCell(e.getName()));

            if (e.getThreatedElements().size() > 0) {
                List<String> threat = new ArrayList<String>();
                for (Threat t : e.getThreatedElements()) {
                    if (t.getTarget() != null && t.getTarget() instanceof StsElement) {
                        threat.add(t.getTarget().eClass().getName() + " : "
                                + ((StsElement) t.getTarget()).getName());
                    }
                }
                String[] phrases = new String[threat.size()];
                for (int i = 0; i < phrases.length; i++) {
                    phrases[i] = threat.get(i);
                }
                table.addCell(getContentCell(phrases));
            } else {
                table.addCell(getContentCell(
                        new String[] { "No elements are depicted", "to be threatened by this event" },
                        TABLE_CONTENT_SMALL));
            }

            //table.addCell(getContentCell(e.getEventID(),TABLE_CONTENT_SMALL));

            String desc = "No concrete threats from the threat repository have been associated to this event";
            if (e.getEventID() != null && e.getEventID().length() > 0) {
                desc = e.getDescription();
            }
            table.addCell(getContentCell(desc, TABLE_CONTENT_SMALL));
        }

        addTableCaption(table, ftc.getTable(FigureConstant.EVENT_TABLE) + " - Events");
        section.add(table);
        table.setComplete(true);
    } else {
        String sectionIntro = "No events have been modeled in the project " + getProjectName();
        section.add(createParagraph(sectionIntro));
    }
    section.setComplete(true);

}