Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: DanielFillol/CNJ_Validate
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3.4
Choose a base ref
...
head repository: DanielFillol/CNJ_Validate
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Apr 27, 2022

  1. Create .DS_Store

    DanielFillol committed Apr 27, 2022
    Copy the full SHA
    1ae5cd5 View commit details

Commits on Jul 2, 2022

  1. Update README.md

    DanielFillol authored Jul 2, 2022
    Copy the full SHA
    e107dcd View commit details

Commits on Jul 5, 2022

  1. Test Commit

    DanielFillol committed Jul 5, 2022
    Copy the full SHA
    d3289d0 View commit details
  2. Copy the full SHA
    0585b89 View commit details
  3. Test Commit

    DanielFillol committed Jul 5, 2022
    Copy the full SHA
    d65cc47 View commit details

Commits on Oct 12, 2022

  1. Better error handling

    DanielFillol committed Oct 12, 2022
    Copy the full SHA
    f817bfd View commit details
  2. Bug fix

    DanielFillol committed Oct 12, 2022
    Copy the full SHA
    d6a6357 View commit details

Commits on Mar 28, 2023

  1. Update README.md

    DanielFillol authored Mar 28, 2023
    Copy the full SHA
    220c4d0 View commit details
  2. go mod tidy

    DanielFillol committed Mar 28, 2023
    Copy the full SHA
    db160c0 View commit details
  3. Update README.md

    DanielFillol authored Mar 28, 2023
    Copy the full SHA
    aaa3d00 View commit details

Commits on Apr 3, 2023

  1. Copy the full SHA
    c7e29ac View commit details
  2. Update README.md

    DanielFillol authored Apr 3, 2023
    Copy the full SHA
    47b4163 View commit details

Commits on Aug 9, 2023

  1. Copy the full SHA
    5870d87 View commit details

Commits on Oct 19, 2023

  1. Copy the full SHA
    b0659b3 View commit details
  2. Copy the full SHA
    e45530f View commit details
  3. Copy the full SHA
    0b38dd0 View commit details
  4. Copy the full SHA
    92c47c7 View commit details
  5. feat: update readme file

    DanielFillol committed Oct 19, 2023
    Copy the full SHA
    5f24a81 View commit details
  6. Update README.md

    DanielFillol authored Oct 19, 2023
    Copy the full SHA
    304fb6f View commit details
  7. Copy the full SHA
    7882764 View commit details
  8. Copy the full SHA
    191aab8 View commit details
  9. Copy the full SHA
    768a94d View commit details
  10. Copy the full SHA
    98251d8 View commit details
  11. Copy the full SHA
    78ece0d View commit details

Commits on Oct 20, 2023

  1. Copy the full SHA
    8484a7c View commit details
Showing with 215 additions and 124 deletions.
  1. BIN .DS_Store
  2. +34 −28 CNJ/cnj.go
  3. +112 −30 CNJ/decomposer.go
  4. +20 −18 CNJ/getSegment.go
  5. +3 −3 CNJ/validation.go
  6. +3 −3 CNJCSV/analyzeCSV.go
  7. +2 −2 CNJCSV/write.go
  8. +37 −36 README.md
  9. +2 −2 Test/cnj_test.go
  10. +2 −2 go.mod
  11. 0 go.sum
Binary file added .DS_Store
Binary file not shown.
62 changes: 34 additions & 28 deletions CNJ/cnj.go
Original file line number Diff line number Diff line change
@@ -2,13 +2,14 @@ package CNJ

import "errors"

//AnalysisCNJ returns:
// receivedCNJ
// validCNJ given by ValidateCNJ
// segmentName and segmentShort given by getSegment
// sourceUnitType and SourceUnitNumber given by getSourceUnit
// courtType and courtNumber given by getOriginCourt
// detailed is a struct on it's on given by DecomposeCNJ
// AnalysisCNJ returns:
//
// receivedCNJ
// validCNJ given by ValidateCNJ
// segmentName and segmentShort given by getSegment
// sourceUnitType and SourceUnitNumber given by getSourceUnit
// courtType and courtNumber given by getOriginCourt
// detailed is a struct on it's on given by DecomposeCNJ
type AnalysisCNJ struct {
ReceivedCNJ string `json:"received_cnj,omitempty"`
ValidCNJ bool `json:"valid_cnj,omitempty"`
@@ -21,29 +22,34 @@ type AnalysisCNJ struct {
Detailed DecomposedCNJ `json:"Detailed"`
}

//DecomposedCNJ returns the CNJ in decomposed manner:
// lawsuitNumber: [NNNNNNN]
// verifyingDigit: [DD]
// protocolYear: [AAAA]
// segment: [J]
// court: [CT]
// sourceUnit: [0000]
// argNumber: [NNNNNNNAAAAJCT0000] + "00"
// district: district where the lawsuit was proposed, frequently a city name
// uf: the uf of the correspondent district
// DecomposedCNJ returns the CNJ in decomposed manner:
//
// lawsuitCNJFormat [NNNNNNN]-[DD].[AAAA].[J].[CT].[0000]
// lawsuitNumber: [NNNNNNN]
// verifyingDigit: [DD]
// protocolYear: [AAAA]
// segment: [J]
// court: [CT]
// sourceUnit: [0000]
// argNumber: [NNNNNNNAAAAJCT0000] + "00"
// district: district where the lawsuit was proposed, frequently a city name
// uf: the uf of the correspondent district
// tj: the court shortname [TJ/STJ/TRF..]
type DecomposedCNJ struct {
LawsuitNumber string `json:"lawsuit_number,omitempty"`
VerifyingDigit string `json:"verifying_digit,omitempty"`
ProtocolYear string `json:"protocol_year,omitempty"`
Segment string `json:"segment,omitempty"`
Court string `json:"court,omitempty"`
SourceUnit string `json:"source_unit,omitempty"`
ArgNumber string `json:"arg_number,omitempty"`
District string `json:"district,omitempty"`
UF string `json:"UF,omitempty"`
LawsuitCNJFormat string `json:"lawsuitCNJFormat,omitempty"`
LawsuitNumber string `json:"lawsuit_number,omitempty"`
VerifyingDigit string `json:"verifying_digit,omitempty"`
ProtocolYear string `json:"protocol_year,omitempty"`
Segment string `json:"segment,omitempty"`
Court string `json:"court,omitempty"`
SourceUnit string `json:"source_unit,omitempty"`
ArgNumber string `json:"arg_number,omitempty"`
District string `json:"district,omitempty"`
UF string `json:"UF,omitempty"`
TJ string `json:"TJ,omitempty"`
}

//AnalyzeCNJ returns the complex struct AnalysisCNJ containing all the useful data from this package
// AnalyzeCNJ returns the complex struct AnalysisCNJ containing all the useful data from this package
func AnalyzeCNJ(cnj string) (AnalysisCNJ, error) {
decomposedCNJ, err := DecomposeCNJ(cnj)
if err != nil {
@@ -84,7 +90,7 @@ func AnalyzeCNJ(cnj string) (AnalysisCNJ, error) {

}

//WriteCNJ returns a single string with all organized interpretation of CNJ information
// WriteCNJ returns a single string with all organized interpretation of CNJ information
func WriteCNJ(number AnalysisCNJ) (string, error) {

if number.Detailed.LawsuitNumber == "" {
142 changes: 112 additions & 30 deletions CNJ/decomposer.go
Original file line number Diff line number Diff line change
@@ -2,22 +2,26 @@ package CNJ

import (
"errors"
"github.com/Darklabel91/CNJ_Validate/CNJDatabase"
"github.com/DanielFillol/CNJ_Validate/CNJDatabase"
"strconv"
"strings"
)

const MATH = "00"

// DecomposeCNJ decompose cnj format number into the specifics:
// NNNNNNN-DD.AAAA.J.TR.OOOO
// LawsuitNumber = [NNNNNNN]
// VerifyingDigit = [DD]
// ProtocolYear = [AAAA]
// Segment [J]
// Court [TR]
// SourceUnit [OOOO]
// ArgNumber [LawsuitNumber + ProtocolYear + Segment + Court + SourceUnit + "00"]
// DistrictInfo [Name and UF of the city] it is a reading of J.TR.OOOO combination
//
// lawsuitCNJFormat = [NNNNNNN]-[DD].[AAAA].[J].[CT].[0000]
// LawsuitNumber = [NNNNNNN]
// VerifyingDigit = [DD]
// ProtocolYear = [AAAA]
// Segment = [J]
// Court = [TR]
// SourceUnit [OOOO]
// ArgNumber = [LawsuitNumber + ProtocolYear + Segment + Court + SourceUnit + "00"]
// DistrictInfo = [Name and UF of the city] it is a reading of J.TR.OOOO combination
// UF = [UF]
// TJ = [{COURT}+{UF}]
func DecomposeCNJ(cnj string) (DecomposedCNJ, error) {
if len(cnj) > 25 && len(cnj) < 20 {
return DecomposedCNJ{}, errors.New("CNJ out of format, it must have 25 or 20 char")
@@ -40,20 +44,58 @@ func DecomposeCNJ(cnj string) (DecomposedCNJ, error) {
semiCNJ := segment + "." + court + "." + sourceUnit

dt, err := CNJDatabase.FetchDistrict(semiCNJ)
sg, err := getSegment(segment)
if err != nil {
return DecomposedCNJ{}, err
return DecomposedCNJ{
LawsuitCNJFormat: lawsuitNumber + "-" + verifyingDigit + "." + yearProtocol + "." + segment + "." + court + "." + sourceUnit,
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: err.Error(),
UF: err.Error(),
TJ: err.Error(),
}, err
}

var tj string
if sg.Number == 1 || sg.Number == 2 || sg.Number == 3 || sg.Number == 4 || sg.Number == 7 {
courtNumber, err := strconv.Atoi(court)
if err != nil {
return DecomposedCNJ{
LawsuitCNJFormat: lawsuitNumber + "-" + verifyingDigit + "." + yearProtocol + "." + segment + "." + court + "." + sourceUnit,
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: err.Error(),
UF: err.Error(),
TJ: err.Error(),
}, err
}
tj = sg.Short + strconv.Itoa(courtNumber)
} else {
tj = sg.Short + dt.UF
}

return DecomposedCNJ{
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: dt.SourceUnit,
UF: dt.UF,
LawsuitCNJFormat: lawsuitNumber + "-" + verifyingDigit + "." + yearProtocol + "." + segment + "." + court + "." + sourceUnit,
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: dt.SourceUnit,
UF: dt.UF,
TJ: tj,
}, nil
} else {
lawsuitNumber := cnj[0:7]
@@ -75,20 +117,60 @@ func DecomposeCNJ(cnj string) (DecomposedCNJ, error) {
semiCNJ := segment + "." + court + "." + sourceUnit

dt, err := CNJDatabase.FetchDistrict(semiCNJ)
sg, err := getSegment(segment)
if err != nil {
return DecomposedCNJ{}, err
if err != nil {
return DecomposedCNJ{
LawsuitCNJFormat: lawsuitNumber + "-" + verifyingDigit + "." + yearProtocol + "." + segment + "." + court + "." + sourceUnit,
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: err.Error(),
UF: err.Error(),
TJ: err.Error(),
}, err
}
}

var tj string
if sg.Number == 1 || sg.Number == 2 || sg.Number == 3 || sg.Number == 4 || sg.Number == 7 {
courtNumber, err := strconv.Atoi(court)
if err != nil {
return DecomposedCNJ{
LawsuitCNJFormat: lawsuitNumber + "-" + verifyingDigit + "." + yearProtocol + "." + segment + "." + court + "." + sourceUnit,
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: err.Error(),
UF: err.Error(),
TJ: err.Error(),
}, err
}
tj = sg.Short + strconv.Itoa(courtNumber)
} else {
tj = sg.Short + dt.UF
}

return DecomposedCNJ{
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: dt.District,
UF: dt.UF,
LawsuitCNJFormat: lawsuitNumber + "-" + verifyingDigit + "." + yearProtocol + "." + segment + "." + court + "." + sourceUnit,
LawsuitNumber: lawsuitNumber,
VerifyingDigit: verifyingDigit,
ProtocolYear: yearProtocol,
Segment: segment,
Court: court,
SourceUnit: sourceUnit,
ArgNumber: argNumber,
District: dt.District,
UF: dt.UF,
TJ: tj,
}, nil

}
38 changes: 20 additions & 18 deletions CNJ/getSegment.go
Original file line number Diff line number Diff line change
@@ -6,38 +6,40 @@ import (
)

// Segment returns three basic infos:
//
// number - the segment code
// name - the full name of the segment
// short - the segment nickname
// name - the full name of the segment
// short - the segment nickname
type Segment struct {
Number int
Name string
Short string
}

//courtSegment is a map of every possible segment allowed on CNJ format (goes from 1 to 9)
// courtSegment is a map of every possible segment allowed on CNJ format (goes from 1 to 9)
var courtSegment = map[int]Segment{
1: {Number: 1, Name: "Supremo Tribunal Federal", Short: "STF"},
2: {Number: 2, Name: "Conselho Nacional de Justiça", Short: "CNJ"},
3: {Number: 3, Name: "Superior Tribunal de Justiça", Short: "STJ"},
4: {Number: 4, Name: "Justiça Federal", Short: "JF"},
5: {Number: 5, Name: "Justiça do Trabalho", Short: "JT"},
6: {Number: 6, Name: "Justiça Eleitoral", Short: "JE"},
7: {Number: 7, Name: "Justiça Militar da União", Short: "JMU"},
8: {Number: 8, Name: "Justiça dos Estados e do Distrito Federal e Territórios", Short: "Comum"},
9: {Number: 9, Name: "Justiça Militar Estadual", Short: "JME"},
4: {Number: 4, Name: "Justiça Federal", Short: "TRF"},
5: {Number: 5, Name: "Justiça do Trabalho", Short: "TRT"},
6: {Number: 6, Name: "Justiça Eleitoral", Short: "TRE"},
7: {Number: 7, Name: "Justiça Militar da União", Short: "STM"},
8: {Number: 8, Name: "Justiça dos Estados e do Distrito Federal e Territórios", Short: "TJ"},
9: {Number: 9, Name: "Justiça Militar Estadual", Short: "TJM"},
}

// getSegment returns one of nine possible segments:
// Supremo Tribunal Federal
// Conselho Nacional de Justiça
// Superior Tribunal de Justiça
// Justiça Federal
// Justiça do Trabalho
// Justiça Eleitoral
// Justiça Militar da União
// Justiça dos Estados e do Distrito Federal e Territórios
// Justiça Militar Estadual
//
// Supremo Tribunal Federal
// Conselho Nacional de Justiça
// Superior Tribunal de Justiça
// Justiça Federal
// Justiça do Trabalho
// Justiça Eleitoral
// Justiça Militar da União
// Justiça dos Estados e do Distrito Federal e Territórios
// Justiça Militar Estadual
func getSegment(segment string) (Segment, error) {
segmentCode, err := strconv.Atoi(segment)
if err != nil {
6 changes: 3 additions & 3 deletions CNJ/validation.go
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ func ValidateCNJ(cnj string) (bool, error) {
return false, err
}

vd, err := validVD(decomposedCNJ.ArgNumber)
vd, err := ValidVD(decomposedCNJ.ArgNumber)
if err != nil {
return false, err
}
@@ -29,8 +29,8 @@ func ValidateCNJ(cnj string) (bool, error) {
}
}

// validVD returns the verifyng digit from a given cnj using ArgNumber
func validVD(argNumber string) (string, error) {
// ValidVD returns the verifying digit from a given cnj using ArgNumber
func ValidVD(argNumber string) (string, error) {
cnjInt, bl := new(big.Int).SetString(argNumber, 10)
if bl != true {
return "", errors.New("cant convert ArgNumber into big int")
6 changes: 3 additions & 3 deletions CNJCSV/analyzeCSV.go
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@ package CNJCSV

import (
"fmt"
"github.com/Darklabel91/CNJ_Validate/CNJ"
"github.com/DanielFillol/CNJ_Validate/CNJ"
)

// AnalyzeCNJCSV creates a csv with every single row with AnalyzeCNJ
//from a given raw file and separator rune in a given folder
// from a given raw file and separator rune in a given folder
func AnalyzeCNJCSV(rawFilePath string, separator rune, nameResultFolder string) error {
raw, err := readCsvFile(rawFilePath, separator)
if err != nil {
@@ -22,7 +22,7 @@ func AnalyzeCNJCSV(rawFilePath string, separator rune, nameResultFolder string)
return nil
}

//execute the AnalyzeCNJ from a []string
// execute the AnalyzeCNJ from a []string
func createCSVs(raw []string, nameResultFolder string) error {
var analyzeCNJCSV []CNJ.AnalysisCNJ

4 changes: 2 additions & 2 deletions CNJCSV/write.go
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@ package CNJCSV

import (
"encoding/csv"
"github.com/Darklabel91/CNJ_Validate/CNJ"
"github.com/DanielFillol/CNJ_Validate/CNJ"
"os"
"path/filepath"
"strconv"
)

//writeCSV exports a csv to a given folder, with a given name from a collection of AnalysisCNJ
// writeCSV exports a csv to a given folder, with a given name from a collection of AnalysisCNJ
func writeCSV(fileName string, folderName string, cnjRows []CNJ.AnalysisCNJ) error {
var rows [][]string

Loading