Skip to content

Commit

Permalink
MODBULKOPS-334 Added validation
Browse files Browse the repository at this point in the history
  • Loading branch information
obozhko-folio committed Sep 20, 2024
1 parent 5ecb891 commit 5850eb6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.folio.bulkops.domain.dto.BulkOperationRuleCollection;
import org.folio.bulkops.domain.dto.UpdateOptionType;
import org.folio.bulkops.exception.RuleValidationException;
import org.folio.bulkops.service.ConsortiaService;
import org.folio.bulkops.service.ErrorService;
import org.folio.spring.FolioExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -19,6 +21,10 @@
public abstract class AbstractDataProcessor<T extends BulkOperationsEntity> implements DataProcessor<T> {
@Autowired
private ErrorService errorService;
@Autowired
private ConsortiaService consortiaService;
@Autowired
private FolioExecutionContext folioExecutionContext;

@Override
public UpdatedEntityHolder process(String identifier, T entity, BulkOperationRuleCollection rules) {
Expand All @@ -28,7 +34,19 @@ public UpdatedEntityHolder process(String identifier, T entity, BulkOperationRul
for (BulkOperationRule rule : rules.getBulkOperationRules()) {
var details = rule.getRuleDetails();
var option = details.getOption();
var tenantsFromRule = rule.getRuleDetails().getTenants();
if (consortiaService.isCurrentTenantCentralTenant(folioExecutionContext.getTenantId()) && !tenantsFromRule.isEmpty() && !tenantsFromRule.contains(entity.getTenant())) {
errorService.saveError(rule.getBulkOperationId(), identifier,
String.format("%s cannot be updated because the record is associated with %s and %s is not associated with this tenant.",
entity.getIdentifier(org.folio.bulkops.domain.dto.IdentifierType.ID), entity.getTenant(), option.getValue()));
}
for (Action action : details.getActions()) {
var tenantsFromAction = action.getTenants();
if (consortiaService.isCurrentTenantCentralTenant(folioExecutionContext.getTenantId()) && !tenantsFromAction.isEmpty() && !tenantsFromAction.contains(entity.getTenant())) {
errorService.saveError(rule.getBulkOperationId(), identifier,
String.format("%s cannot be updated because the record is associated with %s and %s is not associated with this tenant.",
entity.getIdentifier(org.folio.bulkops.domain.dto.IdentifierType.ID), entity.getTenant(), option.getValue()));
}
try {
updater(option, action).apply(preview);
validator(entity).validate(option, action);
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/swagger.api/schemas/action.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"items": {
"$ref": "action_parameter.json#/Parameter"
}
},
"tenants": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"description": "Option to change",
"$ref": "update_option_type.json#/UpdateOptionType"
},
"tenants": {
"type": "array",
"items": {
"type": "string"
}
},
"actions": {
"type": "array",
"items": {
Expand Down

0 comments on commit 5850eb6

Please sign in to comment.