soc.scar.controller.graphView1Controller.java Source code

Java tutorial

Introduction

Here is the source code for soc.scar.controller.graphView1Controller.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package soc.scar.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import soc.scar.domain.ErrorType;
import soc.scar.domain.Group;
import soc.scar.domain.Overview;
import soc.scar.domain.Project;
import soc.scar.domain.Result;
import soc.scar.domain.Review;
import soc.scar.service.ErrorTypeService;
import soc.scar.service.GroupService;
import soc.scar.service.ProjectService;
import soc.scar.service.ReviewService;

@Controller("graphController1")
@Scope("view")
public class graphView1Controller implements Serializable {

    @Resource(name = "reviewService")
    private ReviewService reviewService;
    @Resource(name = "projectService")
    private ProjectService projectService;
    @Resource(name = "groupService")
    private GroupService groupService;
    @Resource(name = "errorTypeService")
    private ErrorTypeService errorTypeService;

    private List<Project> listProjects;
    private List<Review> listReviews;
    private List<Group> listGroups;

    private List<Project> listSelectedProjects;
    private List<Review> listSelectedReviews;
    private List<Group> listSelectedGroup;
    private List<Project> listSelectedProjectsByGroup;

    private List<Overview> listOverviews;

    private List<Group> groupList;
    private List<Review> reviews;
    private List<Review> reviewsList;
    private List<ErrorType> errorType;
    private int totalFalsosPositivos = 0;
    private int totalInformativos = 0;
    private int totalVulnerables = 0;

    @PostConstruct
    public void init() {
        //listProjects = projectService.findAllProjects();
        listGroups = groupService.findAllGroups();
    }

    public void plotGraph() {
        //        System.out.println("");
        //        for (Review r : listSelectedReviews) {
        //            reviewService.getReviewByProject(r.getOverviews());
        //        }

        errorType = errorTypeService.findAllErrorType();
        for (Review rw : listSelectedReviews) {
            for (Overview over : rw.getOverviews()) {
                for (Result rst : over.getResults()) {
                    if (rst.getErrorType().getErrorTypeName().equalsIgnoreCase("Informative")) {
                        totalInformativos += totalInformativos + rst.getResultTotal();
                        System.out.println("Informativos: " + totalInformativos);

                    }
                    if (rst.getErrorType().getErrorTypeName().equalsIgnoreCase("Vulnerable")) {
                        totalVulnerables += totalVulnerables + rst.getResultTotal();
                        System.out.println("Vulnerables: " + totalVulnerables);

                    }
                    if (rst.getErrorType().getErrorTypeName().equalsIgnoreCase("False positive")) {
                        totalFalsosPositivos += totalFalsosPositivos + rst.getResultTotal();
                        System.out.println("False positive: " + totalFalsosPositivos);

                    }
                }
            }
        }
    }

    public void reviewByProject() {
        reviews = new ArrayList<>();

        for (Project project : listSelectedProjects) {
            reviews.addAll(reviewService.findReviewsByProject(project));
        }

        if (listReviews != null && !listReviews.isEmpty()) {
            List<Review> reviewsSelectedToDelete = new ArrayList<>(listReviews);
            reviewsSelectedToDelete.removeAll(listSelectedProjectsByGroup);
            listReviews.removeAll(reviewsSelectedToDelete);
        }

    }

    public void projectByGroup() {
        listSelectedProjectsByGroup = new ArrayList<>();

        for (Group group : listSelectedGroup) {
            listSelectedProjectsByGroup.addAll(projectService.findProjectByGroup(group));
        }

        if (listProjects != null && !listProjects.isEmpty()) {
            List<Project> projectSelectedToDelete = new ArrayList<>(listProjects);
            projectSelectedToDelete.removeAll(listSelectedProjectsByGroup);
            listProjects.removeAll(projectSelectedToDelete);
        }

    }

    public List<Group> getListGroups() {
        return listGroups;
    }

    public void setListGroups(List<Group> listGroups) {
        this.listGroups = listGroups;
    }

    public List<Group> getListSelectedGroup() {
        return listSelectedGroup;
    }

    public void setListSelectedGroup(List<Group> listSelectedGroup) {
        this.listSelectedGroup = listSelectedGroup;
    }

    public List<Project> getListSelectedProjectsByGroup() {
        return listSelectedProjectsByGroup;
    }

    public void setListSelectedProjectsByGroup(List<Project> listSelectedProjectsByGroup) {
        this.listSelectedProjectsByGroup = listSelectedProjectsByGroup;
    }

    public List<Group> getGroupList() {
        return groupList;
    }

    public void setGroupList(List<Group> groupList) {
        this.groupList = groupList;
    }

    public ReviewService getReviewService() {
        return reviewService;
    }

    public void setReviewService(ReviewService reviewService) {
        this.reviewService = reviewService;
    }

    public ProjectService getProjectService() {
        return projectService;
    }

    public void setProjectService(ProjectService projectService) {
        this.projectService = projectService;
    }

    public List<Project> getListProjects() {
        return listProjects;
    }

    public void setListProjects(List<Project> listProjects) {
        this.listProjects = listProjects;
    }

    public List<Review> getListSelectedReviews() {
        return listSelectedReviews;
    }

    public void setListSelectedReviews(List<Review> listSelectedReviews) {
        this.listSelectedReviews = listSelectedReviews;
    }

    public List<Review> getReviews() {
        return reviews;
    }

    public void setReviews(List<Review> reviews) {
        this.reviews = reviews;
    }

    public List<Review> getReviewsList() {
        return reviewsList;
    }

    public void setReviewsList(List<Review> reviewsList) {
        this.reviewsList = reviewsList;
    }

    public List<Review> getListReviews() {
        return listReviews;
    }

    public void setListReviews(List<Review> listReviews) {
        this.listReviews = listReviews;
    }

    public List<Project> getListSelectedProjects() {
        return listSelectedProjects;
    }

    public void setListSelectedProjects(List<Project> listSelectedProjects) {
        this.listSelectedProjects = listSelectedProjects;
    }

}