@Entity
@Table(name = "ec_testcase")
public class EcTestcase implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 90)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 2147483647)
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Column(name = "enabled")
    private boolean enabled;
    @Basic(optional = false)
    @NotNull
    @Column(name = "automated")
    private boolean automated;
    @Size(max = 45)
    @Column(name = "added_version")
    private String addedVersion;
    @Size(max = 45)
    @Column(name = "deprecated_version")
    private String deprecatedVersion;
    @Size(max = 45)
    @Column(name = "bug_id")
    private String bugId;
    @Size(max = 45)
    @Column(name = "language")
    private String language;
    @Size(max = 90)
    @Column(name = "test_script_file")
    private String testScriptFile;
    @Size(max = 45)
    @Column(name = "method_name")
    private String methodName;
    @Basic(optional = false)
    @Size(min = 1, max = 10)
    @Column(name = "priority")
    private String priority;
    @Size(max = 45)
    @Column(name = "product")
    private String product;
    @Size(max = 45)
    @Column(name = "feature")
    private String feature;
    @Basic(optional = false)
    @Size(min = 1, max = 45)
    @Column(name = "case_type")
    private String caseType;
    @Column(name = "time_to_run")
    private Integer timeToRun;
    @Size(max = 45)
    @Column(name = "slug")
    private String slug;
    @JoinColumn(name = "folder_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private EcTestfolder folderId;
    @OneToMany(mappedBy = "testcaseId")
    private List<EcTestupload> ecTestuploadList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "testcaseId")
    @OrderBy("stepNumber ASC")
    private SortedSet<EcTeststep> ecTeststepList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "testcaseId")
    private List<EcTestplanTestcaseMapping> ecTestplanTestcaseMappingList;
    @OneToMany(mappedBy = "testcaseId")
    private List<EcTestcaseRequirementMapping> ecTestcaseRequirementMappingLst;

    public EcTestcase() {
    }

    public EcTestcase(Long id) {
        this.id = id;
    }

    public EcTestcase(Long id, String name, String description, boolean enabled, boolean automated) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.enabled = enabled;
        this.automated = automated;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

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

    public boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public boolean getAutomated() {
        return automated;
    }

    public void setAutomated(boolean automated) {
        this.automated = automated;
    }

    public String getAddedVersion() {
        return addedVersion;
    }

    public void setAddedVersion(String addedVersion) {
        this.addedVersion = addedVersion;
    }

    public String getDeprecatedVersion() {
        return deprecatedVersion;
    }

    public void setDeprecatedVersion(String deprecatedVersion) {
        this.deprecatedVersion = deprecatedVersion;
    }

    public String getBugId() {
        return bugId;
    }

    public void setBugId(String bugId) {
        this.bugId = bugId;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getTestScriptFile() {
        return testScriptFile;
    }

    public void setTestScriptFile(String testScriptFile) {
        this.testScriptFile = testScriptFile;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getPriority() {
        return priority;
    }

    public void setPriority(String priority) {
        this.priority = priority;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getFeature() {
        return feature;
    }

    public void setFeature(String feature) {
        this.feature = feature;
    }

    public String getCaseType() {
        return caseType;
    }

    public void setCaseType(String caseType) {
        this.caseType = caseType;
    }

    public Integer getTimeToRun() {
        return timeToRun;
    }

    public void setTimeToRun(Integer timeToRun) {
        this.timeToRun = timeToRun;
    }

    public EcTestfolder getFolderId() {
        return folderId;
    }

    public void setFolderId(EcTestfolder folderId) {
        this.folderId = folderId;
    }

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }

    public List<EcTestupload> getEcTestuploadList() {
        return ecTestuploadList;
    }

    public void setEcTestuploadList(List<EcTestupload> ecTestuploadList) {
        this.ecTestuploadList = ecTestuploadList;
    }

    public SortedSet<EcTeststep> getEcTeststepList() {
        return ecTeststepList;
    }

    public void setEcTeststepList(SortedSet<EcTeststep> ecTeststepList) {
        this.ecTeststepList = ecTeststepList;
    }

    public List<EcTestplanTestcaseMapping> getEcTestplanTestcaseMappingList() {
        return ecTestplanTestcaseMappingList;
    }

    public void setEcTestplanTestcaseMappingList(List<EcTestplanTestcaseMapping> ecTestplanTestcaseMappingList) {
        this.ecTestplanTestcaseMappingList = ecTestplanTestcaseMappingList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EcTestcase)) {
            return false;
        }
        EcTestcase other = (EcTestcase) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.deem.excord.domain.EcTestcase[ id=" + id + " ]";
    }

    public List<EcTestcaseRequirementMapping> getEcTestcaseRequirementMappingLst() {
        return ecTestcaseRequirementMappingLst;
    }

    public void setEcTestcaseRequirementMappingLst(List<EcTestcaseRequirementMapping> ecTestcaseRequirementMappingLst) {
        this.ecTestcaseRequirementMappingLst = ecTestcaseRequirementMappingLst;
    }

} @Entity
@Table(name = "ec_testcase_requirement_mapping")
public class EcTestcaseRequirementMapping implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @JoinColumn(name = "requirement_id", referencedColumnName = "id")
    @ManyToOne
    private EcRequirement requirementId;
    @JoinColumn(name = "testcase_id", referencedColumnName = "id")
    @ManyToOne
    private EcTestcase testcaseId;
    @Column(name = "review")
    private Boolean review;

    public EcTestcaseRequirementMapping() {
    }

    public EcTestcaseRequirementMapping(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public EcRequirement getRequirementId() {
        return requirementId;
    }

    public void setRequirementId(EcRequirement requirementId) {
        this.requirementId = requirementId;
    }

    public EcTestcase getTestcaseId() {
        return testcaseId;
    }

    public void setTestcaseId(EcTestcase testcaseId) {
        this.testcaseId = testcaseId;
    }

    public Boolean getReview() {
        return review;
    }

    public void setReview(Boolean review) {
        this.review = review;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EcTestcaseRequirementMapping)) {
            return false;
        }
        EcTestcaseRequirementMapping other = (EcTestcaseRequirementMapping) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.deem.excord.domain.EcTestcaseRequirementMapping[ id=" + id + " ]";
    }

}
 @Entity
@Table(name = "ec_testfolder")
public class EcTestfolder implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @Size(max = 45)
    @Column(name = "slug")
    private String slug;
    @OneToMany(mappedBy = "parentId")
    private List<EcTestfolder> ecTestfolderList;
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @ManyToOne
    private EcTestfolder parentId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "folderId")
    private List<EcTestcase> ecTestcaseList;

    public EcTestfolder() {
    }

    public EcTestfolder(Long id) {
        this.id = id;
    }

    public EcTestfolder(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }

    public List<EcTestfolder> getEcTestfolderList() {
        return ecTestfolderList;
    }

    public void setEcTestfolderList(List<EcTestfolder> ecTestfolderList) {
        this.ecTestfolderList = ecTestfolderList;
    }

    public EcTestfolder getParentId() {
        return parentId;
    }

    public void setParentId(EcTestfolder parentId) {
        this.parentId = parentId;
    }

    public List<EcTestcase> getEcTestcaseList() {
        return ecTestcaseList;
    }

    public void setEcTestcaseList(List<EcTestcase> ecTestcaseList) {
        this.ecTestcaseList = ecTestcaseList;
    }

    public List<EcTestfolder> getAllParentFolderList() {
        List<EcTestfolder> parentFolderList = new ArrayList<>();
        if (parentId != null) {
            parentFolderList.add(parentId);
            parentFolderList.addAll(parentId.getAllParentFolderList());
        }
        return parentFolderList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EcTestfolder)) {
            return false;
        }
        EcTestfolder other = (EcTestfolder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.deem.excord.domain.EcTestfolder[ id=" + id + " ]";
    }

} @Entity
@Table(name = "ec_testplan")
public class EcTestplan implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "creator")
    private String creator;
    @Basic(optional = false)
    @NotNull
    @Column(name = "enabled")
    private boolean enabled;
    @Size(max = 45)
    @Column(name = "schedule")
    private String schedule;
    @Size(max = 45)
    @Column(name = "release_name")
    private String releaseName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "start_date")
    @Temporal(TemporalType.DATE)
    private Date startDate;
    @Column(name = "end_date")
    @Temporal(TemporalType.DATE)
    private Date endDate;
    @Size(max = 45)
    @Column(name = "leader")
    private String leader;
    @Size(max = 45)
    @Column(name = "slug")
    private String slug;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "testplanId")
    private List<EcTestplanTestcaseMapping> ecTestplanTestcaseMappingList;

    public EcTestplan() {
    }

    public EcTestplan(Long id) {
        this.id = id;
    }

    public EcTestplan(Long id, String name, String creator, boolean enabled, Date startDate) {
        this.id = id;
        this.name = name;
        this.creator = creator;
        this.enabled = enabled;
        this.startDate = startDate;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getSchedule() {
        return schedule;
    }

    public void setSchedule(String schedule) {
        this.schedule = schedule;
    }

    public String getReleaseName() {
        return releaseName;
    }

    public void setReleaseName(String releaseName) {
        this.releaseName = releaseName;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getLeader() {
        return leader;
    }

    public void setLeader(String leader) {
        this.leader = leader;
    }

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }

    public List<EcTestplanTestcaseMapping> getEcTestplanTestcaseMappingList() {
        return ecTestplanTestcaseMappingList;
    }

    public void setEcTestplanTestcaseMappingList(List<EcTestplanTestcaseMapping> ecTestplanTestcaseMappingList) {
        this.ecTestplanTestcaseMappingList = ecTestplanTestcaseMappingList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EcTestplan)) {
            return false;
        }
        EcTestplan other = (EcTestplan) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.deem.excord.domain.EcTestplan[ id=" + id + " ]";
    }

} @Entity
@Table(name = "ec_testplan_testcase_mapping")
public class EcTestplanTestcaseMapping implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Size(max = 45)
    @Column(name = "assigned_to")
    private String assignedTo;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "testplanTestcaseLinkId")
    private List<EcTestresult> ecTestresultList;
    @JoinColumn(name = "testcase_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private EcTestcase testcaseId;
    @JoinColumn(name = "testplan_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private EcTestplan testplanId;

    public EcTestplanTestcaseMapping() {
    }

    public EcTestplanTestcaseMapping(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAssignedTo() {
        return assignedTo;
    }

    public void setAssignedTo(String assignedTo) {
        this.assignedTo = assignedTo;
    }

    public List<EcTestresult> getEcTestresultList() {
        return ecTestresultList;
    }

    public void setEcTestresultList(List<EcTestresult> ecTestresultList) {
        this.ecTestresultList = ecTestresultList;
    }

    public EcTestcase getTestcaseId() {
        return testcaseId;
    }

    public void setTestcaseId(EcTestcase testcaseId) {
        this.testcaseId = testcaseId;
    }

    public EcTestplan getTestplanId() {
        return testplanId;
    }

    public void setTestplanId(EcTestplan testplanId) {
        this.testplanId = testplanId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EcTestplanTestcaseMapping)) {
            return false;
        }
        EcTestplanTestcaseMapping other = (EcTestplanTestcaseMapping) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.deem.excord.domain.EcTestplanTestcaseMapping[ id=" + id + " ]";
    }

} @Entity
@Table(name = "ec_testresult")
public class EcTestresult implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "timestamp")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "status")
    private String status;
    @Size(max = 45)
    @Column(name = "environment")
    private String environment;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "tester")
    private String tester;
    @Lob
    @Size(max = 2147483647)
    @Column(name = "note")
    private String note;
    @Size(max = 45)
    @Column(name = "bug_ticket")
    private String bugTicket;
    @Basic(optional = false)
    @NotNull
    @Column(name = "latest")
    private boolean latest;
    @JoinColumn(name = "testplan_testcase_link_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private EcTestplanTestcaseMapping testplanTestcaseLinkId;

    public EcTestresult() {
    }

    public EcTestresult(Long id) {
        this.id = id;
    }

    public EcTestresult(Long id, Date timestamp, String status, String tester, boolean latest) {
        this.id = id;
        this.timestamp = timestamp;
        this.status = status;
        this.tester = tester;
        this.latest = latest;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getEnvironment() {
        return environment;
    }

    public void setEnvironment(String environment) {
        this.environment = environment;
    }

    public String getTester() {
        return tester;
    }

    public void setTester(String tester) {
        this.tester = tester;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getBugTicket() {
        return bugTicket;
    }

    public void setBugTicket(String bugTicket) {
        this.bugTicket = bugTicket;
    }

    public boolean getLatest() {
        return latest;
    }

    public void setLatest(boolean latest) {
        this.latest = latest;
    }

    public EcTestplanTestcaseMapping getTestplanTestcaseLinkId() {
        return testplanTestcaseLinkId;
    }

    public void setTestplanTestcaseLinkId(EcTestplanTestcaseMapping testplanTestcaseLinkId) {
        this.testplanTestcaseLinkId = testplanTestcaseLinkId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EcTestresult)) {
            return false;
        }
        EcTestresult other = (EcTestresult) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.deem.excord.domain.EcTestresult[ id=" + id + " ]";
    }

} @Entity
@Table(name = "ec_teststep")
public class EcTeststep implements Serializable, Comparable<EcTeststep> {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "step_number")
    private Integer stepNumber;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 2147483647)
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 2147483647)
    @Column(name = "expected")
    private String expected;
    @JoinColumn(name = "testcase_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private EcTestcase testcaseId;

    public EcTeststep() {
    }

    public EcTeststep(Long id) {
        this.id = id;
    }

    public EcTeststep(Long id, Integer stepNumber, String description, String expected) {
        this.id = id;
        this.stepNumber = stepNumber;
        this.description = description;
        this.expected = expected;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getStepNumber() {
        return stepNumber;
    }

    public void setStepNumber(Integer stepNumber) {
        this.stepNumber = stepNumber;
    }

    public String getDescription() {
        return description;
    }

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

    public String getExpected() {
        return expected;
    }

    public void setExpected(String expected) {
        this.expected = expected;
    }

    public EcTestcase getTestcaseId() {
        return testcaseId;
    }

    public void setTestcaseId(EcTestcase testcaseId) {
        this.testcaseId = testcaseId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EcTeststep)) {
            return false;
        }
        EcTeststep other = (EcTeststep) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.deem.excord.domain.EcTeststep[ id=" + id + " ]";
    }

    @Override
    public int compareTo(EcTeststep obj) {
        return this.stepNumber.compareTo(obj.stepNumber);
    }

} public interface TestCaseRepository extends CrudRepository<EcTestcase, Long> {

    public List<EcTestcase> findAllByFolderIdOrderByIdAsc(EcTestfolder folderId);

    @Query(value = "select a.* from ec_testcase a, ec_testplan_testcase_mapping b where a.id = b.testcase_id and b.testplan_id = :testPlanId", nativeQuery = true)
    public List<EcTestcase> findAllTestCasesByTestPlanId(@Param("testPlanId") Long testPlanId);

    public EcTestcase findByIdAndFolderId(Long id, EcTestfolder folder);

    @Query(value = "SELECT count(*) FROM ec_testcase where automated = true", nativeQuery = true)
    public Integer automationCnt();

    @Query(value = "SELECT count(*) FROM ec_testcase where enabled = 1", nativeQuery = true)
    public Integer getCountOfActiveTestcases();

    public List<EcTestcase> findByNameContainingOrDescriptionContainingOrderByIdDesc(String nameKey, String descKey);

    @Query(value = "select a.* from  ec_testcase a  ,ec_testplan_testcase_mapping b where a.id=b.testcase_id and b.testplan_id=:testPlanId and a.folder_id=:folderId", nativeQuery = true)
    public List<EcTestcase> findAllTestCasesByTestPlanIdAndTestFolderId(@Param("testPlanId") Long testPlanId, @Param("folderId") Long folderId);

} public interface TestFolderRepository extends CrudRepository<EcTestfolder, Long> {

    public EcTestfolder findByParentIdIsNull();

    public List<EcTestfolder> findAllByParentIdOrderByNameAsc(EcTestfolder parentId);

    @Query(value = "SELECT case when count(*) > 0 then 'true' else 'false' end FROM ec_testfolder where parent_id = :nodeId", nativeQuery = true)
    public Boolean checkIfHasChildren(@Param("nodeId") Long nodeId);
} public interface TestPlanRepository extends CrudRepository<EcTestplan, Long> {

    //All testplans
    public List<EcTestplan> findAllByOrderByIdDesc();

    //All enabled testplans.
    public List<EcTestplan> findByEnabledOrderByIdDesc(Boolean enabled);

    @Query(value = "select testfolder_id,testcase_folder,test_status ,count(*) from (select c.id testplan_testcase_link_id,a.id testcase_id,a.name testcase_name,b.id testfolder_id,b.name testcase_folder,d.status test_status,d.latest from ec_testcase a,ec_testfolder b,ec_testplan_testcase_mapping c LEFT JOIN ec_testresult d ON d.testplan_testcase_link_id = c.id where a.folder_id = b.id and a.id = c.testcase_id  and c.testplan_id = :testplanId) e where e.latest is null or e.latest = 1 group by testcase_folder,test_status", nativeQuery = true)
    public List<Object[]> findMetricsByTestplanId(@Param("testplanId") Long testplanId);

    @Query(value = "select product,`status`,count(*) from ec_testcase a,ec_testplan_testcase_mapping b LEFT JOIN ec_testresult c ON c.testplan_testcase_link_id = b.id where a.id = b.testcase_id and b.testplan_id = :testplanId and (latest is null or latest = 1 ) group by product,`status`", nativeQuery = true)
    public List<Object[]> findProductMetricsByTestplanId(@Param("testplanId") Long testplanId);

    @Query(value = "select b.testplan_id,a.`status`,count(*) as count from ec_testresult a ,ec_testplan_testcase_mapping b where a.testplan_testcase_link_id = b.id and a.latest =1 and a.`status` = 'NOT_RUN' group by a.`status`,b.testplan_id  UNION ALL select b.testplan_id,a.`status`,count(*) as count from ec_testresult a ,ec_testplan_testcase_mapping b where a.testplan_testcase_link_id = b.id and a.latest =1 and a.`status` = 'PASSED' group by a.`status`,b.testplan_id  UNION ALL select testplan_id,'TOTAL', count(*) count from ec_testplan_testcase_mapping  group by testplan_id UNION ALL  select b.testplan_id,'RUN',count(*) as count from ec_testresult a ,ec_testplan_testcase_mapping b where a.testplan_testcase_link_id = b.id and a.latest =1 and a.status != 'NOT_RUN' group by b.testplan_id", nativeQuery = true)
    public List<Object[]> findMetrics();

    @Query(value = "select status,DATE_FORMAT(`timestamp`,'%m-%Y') as dt,count(*) as cnt from ec_testplan_testcase_mapping b, ec_testresult c where c.testplan_testcase_link_id = b.id and b.testplan_id = :testplanId group by status, dt order by dt asc", nativeQuery = true)
    public List<Object[]> findRunMetricByTestPlanId(@Param("testplanId") Long testplanId);

    @Query(value = "select priority,assigned_to,status,SUM(cnt) from (SELECT b.priority,a.assigned_to,'NOT_RUN' as `status`,count(*) as cnt FROM  ec_testcase b, ec_testplan_testcase_mapping a LEFT JOIN ec_testresult c ON a.id = c.testplan_testcase_link_id where a.testplan_id = :testplanId  and  a.testcase_id = b.id and c.status is null group by a.assigned_to,b.priority UNION ALL SELECT b.priority,a.assigned_to,c.`status`,count(*) as cnt FROM  ec_testcase b, ec_testplan_testcase_mapping a,ec_testresult c where a.id = c.testplan_testcase_link_id and a.testplan_id = :testplanId  and  a.testcase_id = b.id and c.latest = 1 group by a.assigned_to,b.priority,c.status ) as tab1 group by assigned_to,priority,status order by assigned_to,priority,status", nativeQuery = true)
    public List<Object[]> findByPriorityByTester(@Param("testplanId") Long testplanId);

    @Query(value = "SELECT count(*) FROM ec_testplan where enabled = 1", nativeQuery = true)
    public Integer getCountOfActiveTestplan();

    @Modifying
    @Transactional
    @Query(value = "update ec_testplan set enabled = 0 where end_date < now() and enabled = 1", nativeQuery = true)
    public Integer disableExpiredActiveTestPlans();

} public interface TestPlanTestCaseRepository extends CrudRepository<EcTestplanTestcaseMapping, Long> {

    @Query(value = "select b.* from ec_testplan a, ec_testplan_testcase_mapping b,ec_testcase c where a.id = b.testplan_id and b.testcase_id = c.id and a.enabled = true and c.folder_id = :folderId", nativeQuery = true)
    public List<EcTestplanTestcaseMapping> findAllByTestFolderId(@Param("folderId") Long folderId);

    public EcTestplanTestcaseMapping findByTestplanIdAndTestcaseId(EcTestplan tp, EcTestcase tc);

    public List<EcTestplanTestcaseMapping> findByTestplanId(EcTestplan tp);

    public List<EcTestplanTestcaseMapping> findByTestcaseId(EcTestcase tc);

    @Query(value = "SELECT a.* FROM excord.ec_testplan_testcase_mapping a, ec_testcase b where a.testcase_id = b.id and a.testplan_id = :testplanId and b.folder_id = :folderId", nativeQuery = true)
    public List<EcTestplanTestcaseMapping> findByTestplanIdAndFolderId(@Param("testplanId") Long testplanId,@Param("folderId") Long folderId);

} public interface TestResultRepository extends CrudRepository<EcTestresult, Long> {

    @Modifying
    @Transactional
    @Query(value = "update ec_testresult set latest = 0 where testplan_testcase_link_id = :testplantestcaseId", nativeQuery = true)
    public Integer updateAllTestRunsLatestFlag(@Param("testplantestcaseId") Long testplantestcaseId);

    @Query(value = "select b.* from ec_testplan_testcase_mapping a, ec_testresult b where a.testplan_id = :testplanId and a.id = b.testplan_testcase_link_id and b.latest = 1", nativeQuery = true)
    public List<EcTestresult> findLatestTestResultsByTestplanId(@Param("testplanId") Long testplanId);

    @Query(value = "select b.* from ec_testplan_testcase_mapping a, ec_testresult b,ec_testcase c where a.testplan_id = :testplanId and c.id = a.testcase_id and c.folder_id = :folderId and a.id = b.testplan_testcase_link_id and b.latest = 1", nativeQuery = true)
    public List<EcTestresult> findLatestTestResultsByTestplanIdByFolderId(@Param("testplanId") Long testplanId, @Param("folderId") Long folderId);

    @Query(value = "SELECT b.* FROM ec_testplan_testcase_mapping a, ec_testresult b,ec_testcase c where b.testplan_testcase_link_id = a.id and a.testcase_id = c.id and b.latest = 1 and a.testplan_id = :testplanId  and a.testcase_id = :testcaseId", nativeQuery = true)
    public EcTestresult findLatestTestResultsByTestplanIdAndTestcaseId(@Param("testplanId") Long testplanId, @Param("testcaseId") Long testcaseId);

    @Query(value = "SELECT b.* FROM ec_testplan_testcase_mapping a, ec_testresult b,ec_testcase c where b.testplan_testcase_link_id = a.id and a.testcase_id = c.id and a.testplan_id = :testplanId  and a.testcase_id = :testcaseId order by `timestamp` desc", nativeQuery = true)
    public List<EcTestresult> findAllTestResultsByTestplanIdAndTestcaseId(@Param("testplanId") Long testplanId, @Param("testcaseId") Long testcaseId);

    @Query(value = "SELECT a.* FROM ec_testresult a, ec_testplan_testcase_mapping b  where a.testplan_testcase_link_id = b.id and b.testplan_id = :testplanId order by `timestamp` desc", nativeQuery = true)
    public List<EcTestresult> findAllTestResultsByTestplanId(@Param("testplanId") Long testplanId);

    @Query(value = "select tester,environment,count(*) from ec_testresult where DATE_FORMAT(`timestamp`,'%m-%Y') = DATE_FORMAT(NOW(),'%m-%Y') group by tester,environment order by count(*) desc", nativeQuery = true)
    public List<Object[]> findByTopTesterByEnvByMonth();

    @Query(value = "select tester,environment,count(*) from ec_testresult where DATE_FORMAT(`timestamp`,'%Y') = DATE_FORMAT(NOW(),'%Y') group by tester,environment order by count(*) desc", nativeQuery = true)
    public List<Object[]> findByTopTesterByEnvByYear();

    @Query(value = "select c.folder_id,c.`name`,count(*) from ec_testresult a,ec_testplan_testcase_mapping b, ec_testcase c where DATE_FORMAT(a.`timestamp`,'%Y') = DATE_FORMAT(NOW(),'%Y') and a.testplan_testcase_link_id = b.id and b.testcase_id = c.id and c.automated = 0 group by c.id,c.`name` order by count(*) desc limit 50", nativeQuery = true)
    public List<Object[]> mostexecutedManualTests();

    @Query(value = "select DATE_FORMAT(`timestamp`,'%m-%Y'),count(*) from ec_testresult where DATE_FORMAT(`timestamp`,'%Y') = DATE_FORMAT(NOW(),'%Y') group by DATE_FORMAT(`timestamp`,'%m-%Y') order by DATE_FORMAT(`timestamp`,'%m-%Y') asc", nativeQuery = true)
    public List<Object[]> executionByMonth();

    @Query(value = "SELECT count(*) FROM excord.ec_testresult where latest = 1 and YEAR(timestamp) = YEAR(NOW())", nativeQuery = true)
    public Integer getCountOfExecutionByYear();
} public interface TestStepRepository extends CrudRepository<EcTeststep, Long> {

    @Modifying
    @Transactional
    @Query(value = "delete from ec_teststep where testcase_id = :testcaseId", nativeQuery = true)
    public Integer deleteTeststepByTestcaseId(@Param("testcaseId") Long testcaseId);

    public List<EcTeststep> findByTestcaseId(EcTestcase tc);
} public interface TestcaseRequirementRepository extends CrudRepository<EcTestcaseRequirementMapping, Long> {

    public EcTestcaseRequirementMapping findByTestcaseIdAndRequirementId(EcTestcase tc, EcRequirement req);

    @Query(value = "select c.* from ec_testcase a,ec_requirement b,ec_testcase_requirement_mapping c where a.id = c.testcase_id and b.id = c.requirement_id and a.folder_id = :folderId", nativeQuery = true)
    public List<EcTestcaseRequirementMapping> findAllByTestFolderId(@Param("folderId") Long folderId);

    public List<EcTestcaseRequirementMapping> findAllByRequirementId(EcRequirement req);

    public List<EcTestcaseRequirementMapping> findAllByReviewTrue();

    @Query(value = "select case when count(*) > 0 then 'true' else 'false' end from ec_testcase_requirement_mapping where testcase_id = :tcId and review = 1", nativeQuery = true)
    public Boolean checkIfNeedsReview(@Param("tcId") Long tcId);

    @Transactional
    public Integer deleteByTestcaseIdAndRequirementId(EcTestcase tc, EcRequirement req);

    @Modifying
    @Transactional
    @Query(value = "update ec_testcase_requirement_mapping set review = 1 where requirement_id = :reqId", nativeQuery = true)
    public Integer updateAllLinkedTestcaseForReview(@Param("reqId") Long reqId);

    @Modifying
    @Transactional
    @Query(value = "update ec_testcase_requirement_mapping set review = 0 where testcase_id = :testcaseId", nativeQuery = true)
    public Integer updateAllLinkedTestcaseAsReviewed(@Param("testcaseId") Long testcaseId);
}
 public enum BizUtil {

    INSTANCE;
    private static final Logger LOGGER = LoggerFactory.getLogger(BizUtil.class);

    public String getSlug() {
        return UUID.randomUUID().toString();
    }

    public List<TestPlanMetricVo> flattenTestPlanMetricsByFolder(List<Object[]> tmLst) {
        Map<Long, TestPlanMetricVo> tmMap = new HashMap<Long, TestPlanMetricVo>();
        for (Object[] result : tmLst) {
            Long folderId = ((BigInteger) result[0]).longValue();
            String status = (String) result[2];
            if (status == null) {
                status = Constants.STATUS_NOT_RUN;
            }
            TestPlanMetricVo tpm = tmMap.get(folderId);
            if (tpm == null) {
                tpm = new TestPlanMetricVo();
                tpm.setFolderId(folderId);
                tpm.setFolderName((String) result[1]);
                tpm.setPassCount(0);
                tpm.setFailCount(0);
                tpm.setNaCount(0);
                tpm.setBlockedCount(0);
                tpm.setFutureCount(0);
                tpm.setNotcompleteCount(0);
                tpm.setNotrunCount(0);
                tpm.setTotal(0);
            }

            Integer count = 0;
            if (result[3] != null) {
                count = ((BigInteger) result[3]).intValue();
            }
            tpm.setTotal(tpm.getTotal() + count);
            switch (status) {
                case Constants.STATUS_PASSED:
                    tpm.setPassCount(count);
                    break;
                case Constants.STATUS_FAILED:
                    tpm.setFailCount(count);
                    break;
                case Constants.STATUS_BLOCKED:
                    tpm.setBlockedCount(count);
                    break;
                case Constants.STATUS_NOT_COMPLETED:
                    tpm.setNotcompleteCount(count);
                    break;
                default:
                    tpm.setNotrunCount(tpm.getNotrunCount() + count);
                    break;
            }
            tmMap.put(folderId, tpm);

        }

        List<TestPlanMetricVo> finalMetricLst = new ArrayList<TestPlanMetricVo>();
        for (Map.Entry<Long, TestPlanMetricVo> entry : tmMap.entrySet()) {
            TestPlanMetricVo value = entry.getValue();
            value.setPassRate(Math.round((value.getPassCount() * 100.0) / value.getTotal()));
            value.setProgressRate(Math.round(((value.getTotal() - value.getNotrunCount()) * 100.0) / value.getTotal()));
            finalMetricLst.add(value);
        }
        return finalMetricLst;
    }

    public List<TestPlanMetricVo> flattenTestPlanMetricsByProduct(List<Object[]> tmLst) {
        Map<String, TestPlanMetricVo> tmMap = new HashMap<String, TestPlanMetricVo>();
        for (Object[] result : tmLst) {
            String product = (String) result[0];
            String status = (String) result[1];

            if (status == null) {
                status = Constants.STATUS_NOT_RUN;
            }
            TestPlanMetricVo tpm = tmMap.get(product);
            if (tpm == null) {
                tpm = new TestPlanMetricVo();
                tpm.setProduct(product);
                tpm.setPassCount(0);
                tpm.setFailCount(0);
                tpm.setNaCount(0);
                tpm.setBlockedCount(0);
                tpm.setFutureCount(0);
                tpm.setNotcompleteCount(0);
                tpm.setNotrunCount(0);
                tpm.setTotal(0);
            }

            Integer count = 0;
            if (result[2] != null) {
                count = ((BigInteger) result[2]).intValue();
            }
            tpm.setTotal(tpm.getTotal() + count);
            switch (status) {
                case Constants.STATUS_PASSED:
                    tpm.setPassCount(count);
                    break;
                case Constants.STATUS_FAILED:
                    tpm.setFailCount(count);
                    break;
                case Constants.STATUS_BLOCKED:
                    tpm.setBlockedCount(count);
                    break;
                case Constants.STATUS_NOT_COMPLETED:
                    tpm.setNotcompleteCount(count);
                    break;
                default:
                    tpm.setNotrunCount(tpm.getNotrunCount() + count);
                    break;
            }
            tmMap.put(product, tpm);

        }

        List<TestPlanMetricVo> finalMetricLst = new ArrayList<TestPlanMetricVo>();
        for (Map.Entry<String, TestPlanMetricVo> entry : tmMap.entrySet()) {
            TestPlanMetricVo value = entry.getValue();
            value.setPassRate(Math.round((value.getPassCount() * 100.0) / value.getTotal()));
            value.setProgressRate(Math.round(((value.getTotal() - value.getNotrunCount()) * 100.0) / value.getTotal()));
            finalMetricLst.add(value);
        }
        return finalMetricLst;
    }

    public List<TestPlanMetricVo> gererateTestplanMetrics(EcTestplan tp, List<Object[]> metricsLst) {
        List<TestPlanMetricVo> resultLst = new ArrayList<TestPlanMetricVo>();
        TestPlanMetricVo tpm = new TestPlanMetricVo();
        tpm.setTestPlanId(tp.getId());
        tpm.setPassCount(0);
        tpm.setProgressCount(0);
        tpm.setTotal(0);
        for (Object[] result : metricsLst) {
            Long tpId = ((BigInteger) result[0]).longValue();
            String tpStatus = (String) (result[1]);
            Integer tpCount = ((BigInteger) (result[2])).intValue();
            if (tpId.equals(tp.getId())) {
                switch (tpStatus) {
                    case Constants.STATUS_PASSED:
                        tpm.setPassCount(tpCount);
                        break;
                    case "TOTAL":
                        tpm.setTotal(tpCount);
                        break;
                    case "RUN":
                        tpm.setProgressCount(tpCount);
                        break;
                }
            }
        }
        LOGGER.debug("PlanId:{},Pass:{},Total:{},Progress:{}", tp.getId(), tpm.getPassCount(), tpm.getTotal(), tpm.getProgressCount());
        tpm.setPassRate(Math.round((tpm.getPassCount() * 100.0) / tpm.getTotal()));
        tpm.setProgressRate(Math.round((tpm.getProgressCount() * 100.0) / tpm.getTotal()));
        resultLst.add(tpm);
        return resultLst;
    }

    public List<TestPlanMetricVo> gererateAllTestPlanMetrics(List<EcTestplan> testPlanLst, List<Object[]> metricsLst) {
        List<TestPlanMetricVo> resultLst = new ArrayList<TestPlanMetricVo>();
        Map<Long, TestPlanMetricVo> mapObj = new HashMap<Long, TestPlanMetricVo>();
        for (EcTestplan tp : testPlanLst) {
            TestPlanMetricVo tpm = new TestPlanMetricVo();
            tpm.setTestPlanId(tp.getId());
            tpm.setPassCount(0);
            tpm.setProgressCount(0);
            tpm.setTotal(0);
            mapObj.put(tp.getId(), tpm);
        }

        for (Object[] result : metricsLst) {
            Long tpId = ((BigInteger) result[0]).longValue();
            String tpStatus = (String) (result[1]);
            Integer tpCount = ((BigInteger) (result[2])).intValue();
            TestPlanMetricVo tpm = mapObj.get(tpId);
            if (tpm != null) {
                switch (tpStatus) {
                    case Constants.STATUS_PASSED:
                        tpm.setPassCount(tpCount);
                        break;
                    case Constants.STATUS_NOT_RUN:
                        break;
                    case "TOTAL":
                        tpm.setTotal(tpCount);
                        break;
                    case "RUN":
                        tpm.setProgressCount(tpCount);
                        break;
                }
            }
        }
        for (Map.Entry<Long, TestPlanMetricVo> entry : mapObj.entrySet()) {
            TestPlanMetricVo tpm = entry.getValue();
            tpm.setPassRate(Math.round((tpm.getPassCount() * 100.0) / tpm.getTotal()));
            tpm.setProgressRate(Math.round((tpm.getProgressCount() * 100.0) / tpm.getTotal()));
            resultLst.add(tpm);
        }
        return resultLst;
    }

    public Boolean checkStatus(String tstatus) {
        switch (tstatus) {
            case Constants.STATUS_PASSED:
            case Constants.STATUS_BLOCKED:
            case Constants.STATUS_FAILED:
            case Constants.STATUS_NOT_COMPLETED:
            case Constants.STATUS_NOT_RUN:
                return true;
            default:
                return false;
        }

    }

    public Boolean checkReqPriority(String rPriority) {
        switch (rPriority) {
            case Constants.PRIORITY_P1:
            case Constants.PRIORITY_P2:
            case Constants.PRIORITY_P3:
            case Constants.PRIORITY_P4:
                return true;
            default:
                return false;
        }
    }

    public Boolean checkReqStatus(String rStatus) {
        switch (rStatus) {
            case Constants.REQ_STATUS_ACTIVE:
            case Constants.REQ_STATUS_DEPRECATED:
            case Constants.REQ_STATUS_PROPOSED:
                return true;
            default:
                return false;
        }

    }

    public Boolean checkEnv(String tenv) {
        switch (tenv) {

            case Constants.STATUS_PASSED:
            case Constants.STATUS_BLOCKED:
            case Constants.STATUS_FAILED:
            case Constants.STATUS_NOT_COMPLETED:
            case Constants.STATUS_NOT_RUN:
                return true;
            default:
                return false;
        }

    }

    public List<Long> getListOfAllChildReq(EcRequirement currReq) {
        if (currReq.getEcRequirementList().isEmpty()) {
            return null;
        } else {
            List<Long> allReqIdLst = new ArrayList<Long>();
            for (EcRequirement req : currReq.getEcRequirementList()) {
                if (req.getCoverage()) {
                    allReqIdLst.add(req.getId());
                }
                List<Long> nestedChildReqLst = getListOfAllChildReq(req);
                if (nestedChildReqLst != null) {
                    allReqIdLst.addAll(nestedChildReqLst);
                }
            }
            return allReqIdLst;
        }
    }

    public String validateInput(String value, Integer length) {
        if (value == null || value.isEmpty()) {
            return " ";
        }
        if (length > 0 && value.length() > length) {
            value = value.substring(0, length);
        }
        return value;
    }

    public Map<String, String> getFolderHierarchyMap(EcTestplan testPlan) {

        Map<String, String> map = new HashMap<>();
        List<EcTestplanTestcaseMapping> testCaseMappings = testPlan.getEcTestplanTestcaseMappingList();
        for (EcTestplanTestcaseMapping testCaseMapping : testCaseMappings) {
            EcTestfolder folder = testCaseMapping.getTestcaseId().getFolderId();

            StringBuilder pathBuilder = new StringBuilder();
            pathBuilder.append(Constants.PATH_DELIMITER);
            List<EcTestfolder> pFolders = folder.getAllParentFolderList();
            Collections.reverse(pFolders);
            for (EcTestfolder pfolder : pFolders) {
                pathBuilder.append(pfolder.getName());
                pathBuilder.append(Constants.PATH_DELIMITER);
            }
            pathBuilder.append(folder.getName());
            map.put(folder.getId().toString(), pathBuilder.toString());
        }
        return sortByComparator(map);

    }

    private Map<String, String> sortByComparator(Map<String, String> unsortMap) {

        // Convert Map to List
        List<Map.Entry<String, String>> list = new LinkedList<>(unsortMap.entrySet());

        // Sort list with comparator, to compare the Map values
        Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
            @Override
            public int compare(Map.Entry<String, String> o1,
                    Map.Entry<String, String> o2) {
                return (o1.getValue()).compareTo(o2.getValue());
            }
        });

        // Convert sorted map back to a Map
        Map<String, String> sortedMap = new LinkedHashMap<>();
        for (Iterator<Map.Entry<String, String>> it = list.iterator(); it.hasNext();) {
            Map.Entry<String, String> entry = it.next();
            sortedMap.put(entry.getKey(), entry.getValue());
        }
        return sortedMap;
    }
} public interface Constants {

    String STATUS_PASSED = "PASSED";
    String STATUS_FAILED = "FAILED";
    String STATUS_BLOCKED = "BLOCKED";
    String STATUS_NOT_COMPLETED = "NOT_COMPLETED";
    String STATUS_NOT_RUN = "NOT_RUN";
    String STATUS_OTHER = "OTHER";

    String ROLE_USER = "USER";
    String USER_AUTOMATION = "AUTOMATION";
    String USER_SYSTEM = "SYSTEM";

    String PRIORITY_P1 = "P1";
    String PRIORITY_P2 = "P2";
    String PRIORITY_P3 = "P3";
    String PRIORITY_P4 = "P4";

    String REQ_STATUS_ACTIVE = "ACTIVE";
    String REQ_STATUS_DEPRECATED = "DEPRECATED";
    String REQ_STATUS_PROPOSED = "PROPOSED";

    String TYPE_MANUAL = "MANUAL";
    
    Long TRASH_NODE = 2L;
    
    String PATH_DELIMITER = "/";

} public enum FlashMsgUtil {

    INSTANCE;

    public void checkFlashMsg(HttpSession session, Model model) {
        if (session.getAttribute("flashMsg") != null) {
            model.addAttribute("flashMsg", session.getAttribute("flashMsg"));
            session.setAttribute("flashMsg", null);
        }
    }

} @Component
public class HistoryUtil {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(HistoryUtil.class);
    
    @Autowired
    HistoryRepository hDao;
    
    public void addHistory(String logMsg, String slug, HttpServletRequest request, HttpSession session) {
        String user = (String) session.getAttribute("authName");
        LOGGER.info("{} by {} from {}", logMsg, user, getClientIpAddr(request));
        EcHistory history = new EcHistory();
        history.setChangeDate(new Date());
        history.setChangeUser(user);
        history.setChangeSummary(logMsg);
        history.setChangeIp(getClientIpAddr(request));
        history.setSlug(slug);
        hDao.save(history);
        
    }
    
    public String getClientIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("X-Forwarded-For");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
    
}
import com.deem.excord.domain.EcTestcase;
import com.deem.excord.domain.EcTestcaseRequirementMapping;
import com.deem.excord.domain.EcTestfolder;
import com.deem.excord.domain.EcTestplan;
import com.deem.excord.domain.EcTestplanTestcaseMapping;
import com.deem.excord.domain.EcTestresult;
import com.deem.excord.domain.EcTeststep;
import com.deem.excord.repository.TestCaseRepository;
import com.deem.excord.repository.TestFolderRepository;
import com.deem.excord.repository.TestPlanRepository;
import com.deem.excord.repository.TestPlanTestCaseRepository;
import com.deem.excord.repository.TestResultRepository;
import com.deem.excord.repository.TestStepRepository;
import com.deem.excord.repository.TestcaseRequirementRepository;
import com.deem.excord.util.BizUtil;
import com.deem.excord.util.Constants;
import com.deem.excord.util.FlashMsgUtil;
import com.deem.excord.util.HistoryUtil;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
package com.deem.excord.controller;


@Controller
public class TestCaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestCaseController.class);

    @Autowired
    TestFolderRepository tfDao;

    @Autowired
    TestCaseRepository tcDao;

    @Autowired
    TestPlanTestCaseRepository tptcDao;

    @Autowired
    TestPlanRepository tpDao;

    @Autowired
    TestStepRepository tsDao;

    @Autowired
    TestcaseRequirementRepository tcrDao;

    @Autowired
    TestResultRepository trDao;

    @Autowired
    HistoryUtil historyUtil;

    @RequestMapping(value = {"/search"}, method = RequestMethod.GET)
    public String search(HttpSession session, Model model) {
        return "search";
    }

    @RequestMapping(value = {"/search"}, method = RequestMethod.POST)
    public String searchKey(HttpSession session, Model model, @RequestParam(value = "searchKey", required = true) String searchKey) {
        LOGGER.info("Search key: {}", searchKey);
        List<EcTestcase> testCaseLst = tcDao.findByNameContainingOrDescriptionContainingOrderByIdDesc(searchKey, searchKey);
        model.addAttribute("searchKey", searchKey);
        model.addAttribute("testCaseLst", testCaseLst);
        return "search";
    }

    @RequestMapping(value = "/testcase", method = RequestMethod.GET)
    public String testCases(Model model, HttpSession session, @RequestParam(value = "nodeId", required = false, defaultValue = "1") Long nodeId) {

        FlashMsgUtil.INSTANCE.checkFlashMsg(session, model);