Skip to content

Commit

Permalink
Ignore subscriptions without products
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed Oct 25, 2023
1 parent 03f1cd9 commit 98f6ad6
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ rule "ignoreNotActiveSubscriptions"
}
end

rule "ignoreServiceSubscriptionsWithoutProducts"
agenda-group "InputValidation"
when
$subscription : Subscription(policy == null)
accumulate(
$product : SubscriptionProduct(subscriptionId == $subscription.id);
$count : count();
$count == 0
)
then
// Create a message if it's not a known service subscription
if (!$subscription.partNumber.startsWith("051-")) {
TreeMap<String, String> msgData = new TreeMap<>();
msgData.put("part_number", $subscription.partNumber.toString());
insert(new Message(Message.Level.INFO, "no_products_associated", msgData));
}
modify($subscription) {
ignored = true;
}
end

rule "ignoreSubscriptionWithoutQuantity"
agenda-group "InputValidation"
when
Expand Down Expand Up @@ -71,7 +92,7 @@ end
rule "logUnknownPartNumber"
agenda-group "InputValidation"
when
$subscription: Subscription(policy == null, partNumber != null)
$subscription: Subscription(policy == null, partNumber != null, ignored == false)
then
TreeMap<String, String> data = new TreeMap<>();
data.put("part_number", $subscription.partNumber);
Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/com/suse/matcher/scenarios/44/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Scenario 44 - Subscriptions without products
============================================

This scenario defines a system with a matching subscription. The user has also
two additional subscriptions:

- a known subscription for a service which is not associated with any product.
This subscription has a part number starting with 051.
- an unknown part number describing a subscription without any associated product

Result
------

The system will get its subscription. The two subscriptions without product will be
both ignored, but for the unknown part number an info message will be reported
165 changes: 165 additions & 0 deletions src/test/resources/com/suse/matcher/scenarios/44/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"timestamp": "2015-05-01T00:00:00.000+0200",
"pinned_matches": [],
"products": [
{
"id": 814,
"name": "SUSE Linux Enterprise Server 11 SP3 x86_64",
"base": true
}
],
"subscriptions": [
{
"id": 1,
"part_number": "051-004678",
"name": "SUSE Premium Silver (30 SRs, valid for 12 Months) - EMEA Zone 2",
"quantity": 1,
"start_date": "2014-07-30T00:00:00Z",
"end_date": "2015-07-31T00:00:00Z",
"scc_username": "UC7",
"product_ids": []
},
{
"end_date": "2015-07-31T00:00:00Z",
"id": 2,
"part_number": "051-003964",
"product_ids": [
669,
670,
673,
674,
677,
679,
681,
683,
684,
686,
687,
688,
690,
691,
694,
695,
696,
697,
698,
700,
703,
704,
706,
707,
708,
709,
712,
713,
717,
718,
719,
721,
723,
724,
725,
726,
727,
729,
730,
733,
735,
737,
742,
746,
748,
751,
752,
753,
756,
757,
759,
761,
765,
766,
767,
768,
769,
772,
773,
774,
775,
776,
777,
778,
779,
782,
783,
785,
786,
790,
791,
792,
793,
794,
796,
801,
802,
803,
806,
808,
809,
810,
811,
812,
813,
814,
815,
817,
818,
819,
822,
824,
827,
828,
832,
954,
955,
956,
957,
1117,
1150,
1153,
1212,
1220,
1298,
1299,
1300,
1305,
1306,
1307
],
"quantity": 2,
"scc_username": "UC7",
"start_date": "2013-08-01T00:00:00Z"
},
{
"id": 3,
"part_number": "UNKNOWN-PART-NUMBER",
"name": "SUSE Premium Fake - Worldwide",
"quantity": 1,
"start_date": "2015-01-31T00:00:00Z",
"end_date": "2015-07-31T00:00:00Z",
"scc_username": "UC7",
"product_ids": []
}
],
"virtualization_groups": [],
"systems": [
{
"cpus": 4,
"id": 1000,
"physical": true,
"product_ids": [
814
],
"virtual_system_ids": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Message,Additional data key,Additional data value
no_products_associated,part_number,UNKNOWN-PART-NUMBER
162 changes: 162 additions & 0 deletions src/test/resources/com/suse/matcher/scenarios/44/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"timestamp": "2015-05-01T00:00:00.000+02",
"matches": [
{
"system_id": 1000,
"subscription_id": 2,
"product_id": 814,
"cents": 100
}
],
"subscription_policies": {
"2": "physical_only"
},
"messages": [
{
"type": "no_products_associated",
"data": {
"part_number": "UNKNOWN-PART-NUMBER"
}
}
],
"subscriptions": [
{
"id": 1,
"part_number": "051-004678",
"name": "SUSE Premium Silver (30 SRs, valid for 12 Months) - EMEA Zone 2",
"quantity": 1,
"start_date": "2014-07-30T00:00:00Z",
"end_date": "2015-07-31T00:00:00Z",
"scc_username": "UC7"
},
{
"id": 2,
"part_number": "051-003964",
"quantity": 2,
"start_date": "2013-08-01T02:00:00.000+02",
"end_date": "2015-07-31T02:00:00.000+02",
"scc_username": "UC7",
"product_ids": [
669,
670,
673,
674,
677,
679,
681,
683,
684,
686,
687,
688,
690,
691,
694,
695,
696,
697,
698,
700,
703,
704,
706,
707,
708,
709,
712,
713,
717,
718,
719,
721,
723,
724,
725,
726,
727,
729,
730,
733,
735,
737,
742,
746,
748,
751,
752,
753,
756,
757,
759,
761,
765,
766,
767,
768,
769,
772,
773,
774,
775,
776,
777,
778,
779,
782,
783,
785,
786,
790,
791,
792,
793,
794,
796,
801,
802,
803,
806,
808,
809,
810,
811,
812,
813,
814,
815,
817,
818,
819,
822,
824,
827,
828,
832,
954,
955,
956,
957,
1117,
1150,
1153,
1212,
1220,
1298,
1299,
1300,
1305,
1306,
1307
]
},
{
"id": 3,
"part_number": "UNKNOWN-PART-NUMBER",
"name": "SUSE Premium Fake - Worldwide",
"quantity": 1,
"start_date": "2015-01-31T00:00:00Z",
"end_date": "2015-07-31T00:00:00Z",
"scc_username": "UC7"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Part Number,Description,Policy,Total Quantity,Matched Quantity,Start Date,End Date
051-003964,,Physical deployment only,2,1,2013-08-01,2015-07-31
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unmatched Product Name,System Name,System ID,CPUs

0 comments on commit 98f6ad6

Please sign in to comment.