-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODBULKOPS-389 - Supported actions for bulk editing Instances statist…
…ical codes (#332) * MODBULKOPS-389 Added stat code
- Loading branch information
1 parent
3383a06
commit 84aea6f
Showing
25 changed files
with
532 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/folio/bulkops/domain/converter/InstanceStatisticalCodeListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.folio.bulkops.domain.converter; | ||
|
||
import org.folio.bulkops.domain.format.SpecialCharacterEscaper; | ||
import org.folio.bulkops.service.InstanceReferenceHelper; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.folio.bulkops.util.Constants.ARRAY_DELIMITER; | ||
|
||
public class InstanceStatisticalCodeListConverter extends BaseConverter<List<String>> { | ||
@Override | ||
public List<String> convertToObject(String value) { | ||
return Arrays.stream(value.split(ARRAY_DELIMITER)) | ||
.map(SpecialCharacterEscaper::restore) | ||
.map(name -> InstanceReferenceHelper.service().getStatisticalCodeByName(name).getId()) | ||
.filter(Objects::nonNull) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public String convertToString(List<String> object) { | ||
return object.stream() | ||
.filter(Objects::nonNull) | ||
.map(id -> InstanceReferenceHelper.service().getStatisticalCodeById(id).getName()) | ||
.map(SpecialCharacterEscaper::escape) | ||
.collect(Collectors.joining(ARRAY_DELIMITER)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/org/folio/bulkops/processor/StatisticalCodeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.folio.bulkops.processor; | ||
|
||
import org.folio.bulkops.exception.RuleValidationException; | ||
|
||
@FunctionalInterface | ||
public interface StatisticalCodeValidator<T> { | ||
void validate(T t) throws RuleValidationException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/org/folio/bulkops/processor/folio/StatisticalCodesUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.folio.bulkops.processor.folio; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static java.util.Objects.isNull; | ||
|
||
@Component | ||
public class StatisticalCodesUpdater { | ||
|
||
public List<String> addToStatisticalCodeIds(String statisticalCodeIdsFromAction, List<String> existingStatisticalCodeIds, boolean forPreview) { | ||
var newStatisticalCodeIds = new ArrayList<>(Arrays.asList(statisticalCodeIdsFromAction.split(","))); | ||
if (isNull(existingStatisticalCodeIds)) { | ||
return forPreview ? newStatisticalCodeIds : newStatisticalCodeIds.stream().distinct().toList(); | ||
} | ||
if (forPreview) { | ||
existingStatisticalCodeIds.addAll(newStatisticalCodeIds); | ||
} else { | ||
newStatisticalCodeIds.stream().distinct().filter(newCode -> !existingStatisticalCodeIds.contains(newCode)) | ||
.forEach(existingStatisticalCodeIds::add); | ||
} | ||
return existingStatisticalCodeIds; | ||
} | ||
|
||
public List<String> removeSomeStatisticalCodeIds(String statisticalCodeIdsFromAction, List<String> existingStatisticalCodeIds) { | ||
var statisticalCodeIdsToRemove = new ArrayList<>(Arrays.asList(statisticalCodeIdsFromAction.split(","))); | ||
if (isNull(existingStatisticalCodeIds)) { | ||
return Collections.emptyList(); | ||
} | ||
existingStatisticalCodeIds.removeAll(statisticalCodeIdsToRemove); | ||
return existingStatisticalCodeIds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.