Skip to content

Commit

Permalink
Merge branch 'master' into MODBULKOPS-181
Browse files Browse the repository at this point in the history
  • Loading branch information
khandramai authored Jan 15, 2024
2 parents 3499baf + 3bdfec0 commit 9cd3617
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.folio.bulkops.processor;

import static java.lang.Boolean.TRUE;
import static java.lang.Boolean.parseBoolean;
import static java.lang.String.format;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_FALSE_INCLUDING_ITEMS;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_TRUE_INCLUDING_ITEMS;
import static org.folio.bulkops.domain.dto.UpdateOptionType.SUPPRESS_FROM_DISCOVERY;
import static org.folio.bulkops.util.Constants.APPLY_TO_ITEMS;
import static org.folio.bulkops.util.Constants.GET_ITEMS_BY_HOLDING_ID_QUERY;
import static org.folio.bulkops.util.Constants.MSG_NO_CHANGE_REQUIRED;
import static org.folio.bulkops.util.RuleUtils.fetchParameters;
import static org.folio.bulkops.util.RuleUtils.findRuleByOption;

import org.folio.bulkops.client.HoldingsClient;
import org.folio.bulkops.client.ItemClient;
import org.folio.bulkops.domain.bean.HoldingsRecord;
import org.folio.bulkops.domain.bean.Item;
import org.folio.bulkops.domain.dto.Action;
import org.folio.bulkops.domain.dto.BulkOperationRule;
import org.folio.bulkops.domain.entity.BulkOperation;
import org.folio.bulkops.service.ErrorService;
Expand All @@ -24,7 +24,6 @@

import java.util.Collections;
import java.util.List;
import java.util.Set;

@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -55,14 +54,8 @@ public void updateAssociatedRecords(HoldingsRecord holdingsRecord, BulkOperation
}
}

private boolean shouldUpdateDiscoverySuppressForItems(BulkOperationRule rule) {
return rule.getRuleDetails().getActions().stream()
.map(Action::getType)
.anyMatch(actionType -> Set.of(SET_TO_TRUE_INCLUDING_ITEMS, SET_TO_FALSE_INCLUDING_ITEMS).contains(actionType));
}

private boolean suppressItemsIfRequired(HoldingsRecord holdingsRecord, BulkOperationRule rule) {
List<Item> itemsForUpdate = shouldUpdateDiscoverySuppressForItems(rule) ?
List<Item> itemsForUpdate = parseBoolean(fetchParameters(rule).get(APPLY_TO_ITEMS)) ?
itemClient.getByQuery(format(GET_ITEMS_BY_HOLDING_ID_QUERY, holdingsRecord.getId()), Integer.MAX_VALUE)
.getItems().stream()
.filter(item -> !holdingsRecord.getDiscoverySuppress().equals(item.getDiscoverySuppress()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private boolean suppressItemsIfRequired(List<HoldingsRecord> holdingsRecords, bo
.map(id -> itemClient.getByQuery(format(GET_ITEMS_BY_HOLDING_ID_QUERY, id), Integer.MAX_VALUE))
.map(ItemCollection::getItems)
.flatMap(List::stream)
.filter(item -> suppress == item.getDiscoverySuppress())
.filter(item -> suppress != item.getDiscoverySuppress())
.toList() :
Collections.emptyList();
log.info("Found {} items for update", itemsForUpdate.size());
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/swagger.api/schemas/action.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"type": "array",
"items": {
"$ref": "action_parameter.json#/Parameter"
},
"minItems": 1
}
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ void holdings_shouldNotUpdateAssociatedItemsDiscoverySuppress(UpdateActionType a

@ParameterizedTest
@CsvSource(textBlock = """
SET_TO_TRUE_INCLUDING_ITEMS | false
SET_TO_FALSE_INCLUDING_ITEMS | false
SET_TO_TRUE_INCLUDING_ITEMS | true
SET_TO_FALSE_INCLUDING_ITEMS | true
SET_TO_TRUE | false
SET_TO_FALSE | false
SET_TO_TRUE | true
SET_TO_FALSE | true
""", delimiter = '|')
void holdings_shouldUpdateAssociatedItemsDiscoverySuppress(UpdateActionType actionType, boolean notChanged) {
var holdingsId = UUID.randomUUID().toString();
Expand All @@ -148,7 +148,11 @@ void holdings_shouldUpdateAssociatedItemsDiscoverySuppress(UpdateActionType acti

var rule = new BulkOperationRule().ruleDetails(new BulkOperationRuleRuleDetails()
.option(UpdateOptionType.SUPPRESS_FROM_DISCOVERY)
.actions(Collections.singletonList(new Action().type(actionType))));
.actions(Collections.singletonList(new Action()
.type(actionType)
.parameters(Collections.singletonList(new Parameter()
.key(APPLY_TO_ITEMS)
.value("true"))))));
when(ruleService.getRules(operationId)).thenReturn(new BulkOperationRuleCollection()
.bulkOperationRules(Collections.singletonList(rule))
.totalRecords(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.folio.bulkops.domain.dto.EntityType.ITEM;
import static org.folio.bulkops.util.Constants.ADMINISTRATIVE_NOTE;
import static org.folio.bulkops.util.Constants.ADMINISTRATIVE_NOTES;
import static org.folio.bulkops.util.Constants.APPLY_TO_ITEMS;
import static org.folio.bulkops.util.Constants.MSG_NO_CHANGE_REQUIRED;
import static org.folio.bulkops.util.UnifiedTableHeaderBuilder.getHeaders;
import static org.folio.bulkops.domain.dto.BulkOperationStep.COMMIT;
Expand Down Expand Up @@ -43,6 +44,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -77,6 +79,7 @@
import org.folio.bulkops.domain.dto.EntityType;
import org.folio.bulkops.domain.dto.IdentifierType;
import org.folio.bulkops.domain.dto.OperationStatusType;
import org.folio.bulkops.domain.dto.Parameter;
import org.folio.bulkops.domain.dto.Row;
import org.folio.bulkops.domain.dto.UpdateActionType;
import org.folio.bulkops.domain.dto.UpdateOptionType;
Expand Down Expand Up @@ -1021,7 +1024,11 @@ void shouldUpdateItemsWhenCommittingHoldingsRecordDiscoverySuppressed(DiscoveryS
.bulkOperationRules(List.of(new BulkOperationRule()
.ruleDetails(new BulkOperationRuleRuleDetails()
.option(UpdateOptionType.SUPPRESS_FROM_DISCOVERY)
.actions(List.of(new Action().type(testData.actionType)))))));
.actions(List.of(new Action()
.type(testData.actionType)
.parameters(Collections.singletonList(new Parameter()
.key(APPLY_TO_ITEMS)
.value("true")))))))));
when(itemClient.getByQuery(anyString(), anyInt()))
.thenReturn(ItemCollection.builder()
.items(List.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.folio.bulkops.service;

import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_FALSE_INCLUDING_ITEMS;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_TRUE_INCLUDING_ITEMS;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_FALSE;
import static org.folio.bulkops.domain.dto.UpdateActionType.SET_TO_TRUE;
import static org.folio.bulkops.util.Constants.MSG_HOLDING_NO_CHANGE_REQUIRED_SUPPRESSED_ITEMS_UPDATED;
import static org.folio.bulkops.util.Constants.MSG_HOLDING_NO_CHANGE_REQUIRED_UNSUPPRESSED_ITEMS_UPDATED;
import static org.folio.bulkops.util.Constants.MSG_NO_CHANGE_REQUIRED;
Expand All @@ -11,14 +11,14 @@

@RequiredArgsConstructor
public enum DiscoverySuppressTestData {
SET_TRUE_HOLDINGS_SUPPRESSED_ITEMS_SUPPRESSED(SET_TO_TRUE_INCLUDING_ITEMS, true, true, true, true, 0, MSG_NO_CHANGE_REQUIRED),
SET_FALSE_HOLDINGS_SUPPRESSED_ITEMS_SUPPRESSED(SET_TO_FALSE_INCLUDING_ITEMS, true, false, true, true, 2, null),
SET_TRUE_HOLDINGS_UNSUPPRESSED_ITEMS_UNSUPPRESSED(SET_TO_TRUE_INCLUDING_ITEMS, false, true, false, false, 2, null),
SET_FALSE_HOLDINGS_UNSUPPRESSED_ITEMS_UNSUPPRESSED(SET_TO_FALSE_INCLUDING_ITEMS, false, false, false, false, 0, MSG_NO_CHANGE_REQUIRED),
SET_TRUE_HOLDINGS_SUPPRESSED_ONE_ITEM_SUPPRESSED(SET_TO_TRUE_INCLUDING_ITEMS, true, true, true, false, 1, MSG_HOLDING_NO_CHANGE_REQUIRED_UNSUPPRESSED_ITEMS_UPDATED),
SET_FALSE_HOLDINGS_SUPPRESSED_ONE_ITEM_SUPPRESSED(SET_TO_FALSE_INCLUDING_ITEMS, true, false, true, false, 1, null),
SET_TRUE_HOLDINGS_UNSUPPRESSED_ONE_ITEM_UNSUPPRESSED(SET_TO_TRUE_INCLUDING_ITEMS, false, true, true, false, 1, null),
SET_FALSE_HOLDINGS_UNSUPPRESSED_ONE_ITEM_UNSUPPRESSED(SET_TO_FALSE_INCLUDING_ITEMS, false, false, true, false, 1, MSG_HOLDING_NO_CHANGE_REQUIRED_SUPPRESSED_ITEMS_UPDATED);
SET_TRUE_HOLDINGS_SUPPRESSED_ITEMS_SUPPRESSED(SET_TO_TRUE, true, true, true, true, 0, MSG_NO_CHANGE_REQUIRED),
SET_FALSE_HOLDINGS_SUPPRESSED_ITEMS_SUPPRESSED(SET_TO_FALSE, true, false, true, true, 2, null),
SET_TRUE_HOLDINGS_UNSUPPRESSED_ITEMS_UNSUPPRESSED(SET_TO_TRUE, false, true, false, false, 2, null),
SET_FALSE_HOLDINGS_UNSUPPRESSED_ITEMS_UNSUPPRESSED(SET_TO_FALSE, false, false, false, false, 0, MSG_NO_CHANGE_REQUIRED),
SET_TRUE_HOLDINGS_SUPPRESSED_ONE_ITEM_SUPPRESSED(SET_TO_TRUE, true, true, true, false, 1, MSG_HOLDING_NO_CHANGE_REQUIRED_UNSUPPRESSED_ITEMS_UPDATED),
SET_FALSE_HOLDINGS_SUPPRESSED_ONE_ITEM_SUPPRESSED(SET_TO_FALSE, true, false, true, false, 1, null),
SET_TRUE_HOLDINGS_UNSUPPRESSED_ONE_ITEM_UNSUPPRESSED(SET_TO_TRUE, false, true, true, false, 1, null),
SET_FALSE_HOLDINGS_UNSUPPRESSED_ONE_ITEM_UNSUPPRESSED(SET_TO_FALSE, false, false, true, false, 1, MSG_HOLDING_NO_CHANGE_REQUIRED_SUPPRESSED_ITEMS_UPDATED);

final UpdateActionType actionType;
final boolean originalHoldingsDiscoverySuppress;
Expand Down

0 comments on commit 9cd3617

Please sign in to comment.