Skip to content

Commit

Permalink
RDCC-5357 Handling 'D' records in pre-processor logic (#158)
Browse files Browse the repository at this point in the history
* RDCC-5357 Handling 'D' records in pre-processor logic

* RDCC-5357 Handling 'D' records in pre-processor logic

* RDCC-5357 Handling 'D' records in pre-processor logic

* RDCC-5357 Handling 'D' records in pre-processor logic

* RDCC-5357 Handling 'D' records in pre-processor logic
  • Loading branch information
nayeemshaik-hmcts authored Sep 8, 2022
1 parent 811ebaf commit 32899cd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static uk.gov.hmcts.reform.data.ingestion.camel.util.MappingConstants.FAILURE;
import static uk.gov.hmcts.reform.data.ingestion.camel.util.MappingConstants.PARTIAL_SUCCESS;
import static uk.gov.hmcts.reform.data.ingestion.camel.util.MappingConstants.ROUTE_DETAILS;
import static uk.gov.hmcts.reform.rd.commondata.camel.util.CommonDataLoadConstants.ACTIVE_Y;

@Component
@Slf4j
Expand Down Expand Up @@ -74,9 +75,9 @@ public void process(Exchange exchange) {

if (!CollectionUtils.isEmpty(invalidCategories)) {
invalidCategories.forEach(categories -> invalidCategoryIds.add(Pair.of(
categories.getKey(),
categories.getRowId()
)));
categories.getKey(),
categories.getRowId()
)));

lovServiceJsrValidatorInitializer.auditJsrExceptions(
invalidCategoryIds,
Expand All @@ -101,12 +102,9 @@ private List<Categories> getValidCategories(Multimap<String, Categories> multima

List<Categories> finalCategories = new ArrayList<>();
multimap.asMap().forEach((key, collection) -> {
List<Categories> categoriesList = collection.stream().toList();
List<Categories> categoriesList = collection.stream().toList();
if (categoriesList.size() > 1) {
Categories activeCategories = categoriesList.stream()
.filter(categories -> categories.getActive().equalsIgnoreCase("Y"))
.findFirst().orElse(null);
finalCategories.addAll(filterInvalidCategories(activeCategories,categoriesList));
finalCategories.addAll(filterInvalidCategories(categoriesList));
} else {
finalCategories.addAll(categoriesList);
}
Expand All @@ -117,7 +115,7 @@ private List<Categories> getValidCategories(Multimap<String, Categories> multima
private Multimap<String, Categories> convertToMultiMap(List<Categories> categoriesList) {
Multimap<String, Categories> multimap = ArrayListMultimap.create();
categoriesList.forEach(categories -> multimap.put(categories.getCategoryKey() + categories.getServiceId()
+ categories.getKey(),categories));
+ categories.getKey(), categories));
return multimap;
}

Expand All @@ -130,23 +128,18 @@ void setFileStatus(Exchange exchange, ApplicationContext applicationContext, Str
);
}

private List<Categories> filterInvalidCategories(Categories activeCategories,List<Categories> categoriesList) {
private List<Categories> filterInvalidCategories(List<Categories> categoriesList) {
List<Categories> validCategories = new ArrayList<>();
int counter = 0;
for (Categories category: categoriesList) {
if (counter == 0 && category.getActive().equalsIgnoreCase("D") && activeCategories != null) {
counter++;
continue;
} else {
if ((category.getActive().equalsIgnoreCase("Y")
&& activeCategories != null) || category.getActive().equalsIgnoreCase("D")) {
validCategories.add(category);
activeCategories = null;
}

boolean activeProcessed = false;

for (Categories category : categoriesList) {
if ((ACTIVE_Y.equalsIgnoreCase(category.getActive())
&& !activeProcessed)) {
validCategories.add(category);
activeProcessed = true;
}
counter++;
}
return validCategories;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ private CommonDataLoadConstants() {
"SELECT categorykey, key, serviceid FROM list_of_values WHERE TRIM(active) = ?";
public static final String DELETE_CATEGORY_BY_STATUS =
"DELETE FROM list_of_values WHERE TRIM(active) = ?";
public static final String ACTIVE_Y = "Y";
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void init() {

@Test
@DisplayName("Test for LOV Duplicate records Case1")
void testListOfValuesCsv_DupRecord_Case1() throws Exception {
void testListOfValuesCsv_DupRecord_Case1() {
var lovServiceList = new ArrayList<Categories>();
lovServiceList.addAll(getLovServicesCase1());

Expand All @@ -101,7 +101,7 @@ void testListOfValuesCsv_DupRecord_Case1() throws Exception {

@Test
@DisplayName("Test for LOV Duplicate records Case2")
void testListOfValuesCsv_DupRecord_Case2() throws Exception {
void testListOfValuesCsv_DupRecord_Case2() {
var lovServiceList = new ArrayList<Categories>();
lovServiceList.addAll(getLovServicesCase2());

Expand All @@ -114,7 +114,23 @@ void testListOfValuesCsv_DupRecord_Case2() throws Exception {

List actualLovServiceList = (List) exchange.getMessage().getBody();
Assertions.assertEquals(1, actualLovServiceList.size());
}

@Test
@DisplayName("Test for LOV 'D' records Case3")
void testListOfValuesCsv_DupRecord_Case3() throws Exception {
var lovServiceList = new ArrayList<Categories>();
lovServiceList.addAll(getLovServicesCase3());

exchange.getIn().setBody(lovServiceList);
when(((ConfigurableApplicationContext)
applicationContext).getBeanFactory()).thenReturn(configurableListableBeanFactory);

processor.process(exchange);
verify(processor, times(1)).process(exchange);

List actualLovServiceList = (List) exchange.getMessage().getBody();
Assertions.assertEquals(1, actualLovServiceList.size());
}

private List<Categories> getLovServicesCase1() {
Expand Down Expand Up @@ -146,7 +162,7 @@ private List<Categories> getLovServicesCase2() {
.categoryKey("caseSubType")
.serviceId("BBA3")
.key("BBA3-001AD")
.valueEN("ADVANCE PAYMENT new")
.valueEN("ADVANCE PAYMENT")
.parentCategory("caseType")
.parentKey("BBA3-001")
.active("D")
Expand All @@ -171,4 +187,27 @@ private List<Categories> getLovServicesCase2() {
.build()
);
}

private List<Categories> getLovServicesCase3() {
return ImmutableList.of(
Categories.builder()
.categoryKey("caseSubType")
.serviceId("BBA3")
.key("BBA3-001AD")
.valueEN("ADVANCE PAYMENT")
.parentCategory("caseType")
.parentKey("BBA3-001")
.active("Y")
.build(),
Categories.builder()
.categoryKey("caseSubType")
.serviceId("BBA3")
.key("BBA3-001AD")
.valueEN("ADVANCE PAYMENT")
.parentCategory("caseType")
.parentKey("BBA3-001")
.active("D")
.build()
);
}
}

0 comments on commit 32899cd

Please sign in to comment.