@@ -45,8 +45,22 @@ const (
4545 // Dependency directions.
4646 DirectionSuccessor = "successor"
4747 DirectionPredecessor = "predecessor"
48+
49+ // Covenant stocknumbers.
50+ RegularCovenantSuffix = "/COV"
51+ AlternativeCovenantSuffix = `/CV\d+$`
52+
53+ // OBT stocknumbers.
54+ RegularOBTSuffix = "/LPF"
55+ AlternativeOBTSuffix = "/LFP"
56+
57+ // Creative Commons copyright.
58+ CreativeCommonsCopyright = " CC BY"
59+ AlternativeCreativeCommonsCopyright = " CC0"
4860)
4961
62+ var CovenantRegex = regexp .MustCompile (AlternativeCovenantSuffix )
63+
5064type Package struct {
5165 Products []string `form:"productList"`
5266}
@@ -76,6 +90,7 @@ type dependentCopyright struct {
7690 LicenseGroupCopyright string `json:"licenseGroupCopyright"`
7791 ProposedCopyright string `json:"proposedCopyright"`
7892 IsCombinedCopyright bool `json:"isCombinedCopyright"`
93+ CanBeCombined bool `json:"canBeCombined"`
7994 DependentCopyrights []dependentCopyright `json:"dependentCopyrights,omitempty"`
8095}
8196
@@ -84,6 +99,7 @@ type Dependency struct {
8499 RawCopyright string `json:"rawCopyright"`
85100 CurrentCopyright string `json:"currentCopyright"`
86101 IsCombinedCopyright bool `json:"isCombinedCopyright"`
102+ CanBeCombined bool `json:"canBeCombined"`
87103 DependentCopyrights []dependentCopyright `json:"dependentCopyrights"`
88104}
89105
@@ -865,11 +881,18 @@ func (m *Manager) GetCopyrightDependency(
865881 rawCopyright = copyrightRows [0 ].Copyright .String
866882 }
867883
884+ canBeCombined := copyrightCanBeCombined (
885+ copyrightRows [0 ].ModeID ,
886+ copyrightRows [0 ].Stocknumber .String ,
887+ dependents ,
888+ )
889+
868890 out := Dependency {
869891 LicenseGroupName : copyrightRows [0 ].Name ,
870892 RawCopyright : rawCopyright ,
871893 CurrentCopyright : copyrightRows [0 ].Copyright .String ,
872894 IsCombinedCopyright : isCombinedCopyright ,
895+ CanBeCombined : canBeCombined ,
873896 DependentCopyrights : dependents ,
874897 }
875898
@@ -1047,11 +1070,18 @@ func (m *Manager) processDependentCopyright(
10471070 return nil , err
10481071 }
10491072
1073+ canBeCombined := copyrightCanBeCombined (
1074+ copyrightRows [0 ].ModeID ,
1075+ copyrightRows [0 ].Stocknumber .String ,
1076+ nestedDependents ,
1077+ )
1078+
10501079 return & dependentCopyright {
10511080 LicenseGroupID : int (row .LicenseGroupID ),
10521081 LicenseGroupName : row .LicenseGroupName ,
10531082 LicenseGroupCopyright : row .Copyright .String ,
10541083 IsCombinedCopyright : isCombinedCopyright ,
1084+ CanBeCombined : canBeCombined ,
10551085 ProposedCopyright : proposedCopyright ,
10561086 DependentCopyrights : nestedDependents ,
10571087 }, nil
@@ -1308,3 +1338,53 @@ func removeDependentDuplicates(
13081338
13091339 return noDuplicates
13101340}
1341+
1342+ // copyrightCanBeCombined determines if the copyright can be combined
1343+ // based on mode, stocknumber, and dependents.
1344+ func copyrightCanBeCombined (
1345+ modeID uint8 ,
1346+ stocknumber string ,
1347+ dependents []dependentCopyright ,
1348+ ) bool {
1349+ // Only Video filesets may not be combined
1350+ if modeID != ModeVideoID {
1351+ return true
1352+ }
1353+
1354+ // COV and OBT filesets cannot be combined
1355+ if stocknumberIsCovenant (stocknumber ) || stocknumberIsOBT (stocknumber ) {
1356+ return false
1357+ }
1358+
1359+ // Standalone filesets cannot be combined
1360+ if len (dependents ) == 0 {
1361+ return false
1362+ }
1363+
1364+ // If any dependent has Creative Commons copyright, it cannot be combined
1365+ for _ , dependent := range dependents {
1366+ if copyrightHasCCLicense (dependent .LicenseGroupCopyright ) {
1367+ return false
1368+ }
1369+ }
1370+
1371+ return true
1372+ }
1373+
1374+ // stocknumberIsCovenant checks if the stocknumber indicates a Covenant fileset.
1375+ func stocknumberIsCovenant (stocknumber string ) bool {
1376+ return strings .HasSuffix (stocknumber , RegularCovenantSuffix ) ||
1377+ CovenantRegex .MatchString (stocknumber )
1378+ }
1379+
1380+ // stocknumberIsOBT checks if the stocknumber indicates an OBT fileset.
1381+ func stocknumberIsOBT (stocknumber string ) bool {
1382+ return strings .HasSuffix (stocknumber , RegularOBTSuffix ) ||
1383+ strings .HasSuffix (stocknumber , AlternativeOBTSuffix )
1384+ }
1385+
1386+ // copyrightHasCCLicense checks if the copyright contains a Creative Commons license.
1387+ func copyrightHasCCLicense (copyright string ) bool {
1388+ return strings .Contains (copyright , CreativeCommonsCopyright ) ||
1389+ strings .Contains (copyright , AlternativeCreativeCommonsCopyright )
1390+ }
0 commit comments