-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODEXPW-529] Create CSV file for claims (#609)
* [MODEXPW-529] Rename and restructure converters and mapper * [MODEXPW-529] Rename converters * [MODEXPW-529] Add csv mapper and converter * [MODEXPW-529] Use new mapper together with old one in tasklets * [MODEXPW-529] Simplify existing acq tests to speed up builds * [MODEXPW-529] Simplify edifact mapper test * [MODEXPW-529] Add CsvMapperTest (WIP) * [MODEXPW-529] Fix failing tests * [MODEXPW-529] Move tests to appropriate packages * [MODEXPW-529] Finish CsvMapper test, todo 2 field extractions * [MODEXPW-529] Fix sonar issues * [MODEXPW-529] Add title extraction logic * [MODEXPW-529] Add quantity calculation logic * [MODEXPW-529] Update pointer * [MODEXPW-529] Fix sonar issue * [MODEXPW-529] Improve grouping logic * [MODEXPW-529] Update pointer and rename export config
- Loading branch information
1 parent
ee9b9f1
commit 882cc76
Showing
41 changed files
with
665 additions
and
236 deletions.
There are no files selected for viewing
Submodule folio-export-common
updated
1 files
+128 −0 | schemas/acquisitions/mod-orders-storage/title.json |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/folio/dew/batch/acquisitions/edifact/config/AcquisitionExportConfig.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,44 @@ | ||
package org.folio.dew.batch.acquisitions.edifact.config; | ||
|
||
import org.folio.dew.batch.acquisitions.edifact.mapper.CsvMapper; | ||
import org.folio.dew.batch.acquisitions.edifact.mapper.ExportResourceMapper; | ||
import org.folio.dew.batch.acquisitions.edifact.mapper.converter.CompOrderEdiConverter; | ||
import org.folio.dew.batch.acquisitions.edifact.mapper.converter.CompPoLineEdiConverter; | ||
import org.folio.dew.batch.acquisitions.edifact.mapper.EdifactMapper; | ||
import org.folio.dew.batch.acquisitions.edifact.services.ConfigurationService; | ||
import org.folio.dew.batch.acquisitions.edifact.services.ExpenseClassService; | ||
import org.folio.dew.batch.acquisitions.edifact.services.HoldingService; | ||
import org.folio.dew.batch.acquisitions.edifact.services.IdentifierTypeService; | ||
import org.folio.dew.batch.acquisitions.edifact.services.LocationService; | ||
import org.folio.dew.batch.acquisitions.edifact.services.MaterialTypeService; | ||
import org.folio.dew.batch.acquisitions.edifact.services.OrdersService; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan({ "org.folio.dew.batch.acquisitions.edifact" }) | ||
public class AcquisitionExportConfig { | ||
|
||
@Bean | ||
CompPoLineEdiConverter compositePOLineConverter(IdentifierTypeService identifierTypeService, MaterialTypeService materialTypeService, | ||
ExpenseClassService expenseClassService, LocationService locationService, HoldingService holdingService) { | ||
return new CompPoLineEdiConverter(identifierTypeService, materialTypeService, expenseClassService, locationService, holdingService); | ||
} | ||
|
||
@Bean | ||
CompOrderEdiConverter compositePurchaseOrderConverter(CompPoLineEdiConverter compPoLineEdiConverter, ConfigurationService configurationService) { | ||
return new CompOrderEdiConverter(compPoLineEdiConverter, configurationService); | ||
} | ||
|
||
@Bean | ||
ExportResourceMapper edifactMapper(CompOrderEdiConverter compOrderEdiConverter) { | ||
return new EdifactMapper(compOrderEdiConverter); | ||
} | ||
|
||
@Bean | ||
ExportResourceMapper csvMapper(OrdersService ordersService) { | ||
return new CsvMapper(ordersService); | ||
} | ||
|
||
} |
34 changes: 0 additions & 34 deletions
34
...main/java/org/folio/dew/batch/acquisitions/edifact/config/EdifactPurchaseOrderConfig.java
This file was deleted.
Oops, something went wrong.
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
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
74 changes: 74 additions & 0 deletions
74
src/main/java/org/folio/dew/batch/acquisitions/edifact/mapper/CsvMapper.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,74 @@ | ||
package org.folio.dew.batch.acquisitions.edifact.mapper; | ||
|
||
import static java.util.stream.Collectors.groupingBy; | ||
import static org.folio.dew.utils.Constants.LINE_BREAK; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.folio.dew.batch.acquisitions.edifact.mapper.converter.ClaimCsvConverter; | ||
import org.folio.dew.batch.acquisitions.edifact.services.OrdersService; | ||
import org.folio.dew.domain.dto.CompositePoLine; | ||
import org.folio.dew.domain.dto.CompositePurchaseOrder; | ||
import org.folio.dew.domain.dto.Piece; | ||
import org.folio.dew.domain.dto.VendorEdiOrdersExportConfig; | ||
import org.folio.dew.domain.dto.acquisitions.edifact.ClaimCsvEntry; | ||
|
||
public class CsvMapper implements ExportResourceMapper { | ||
|
||
private final OrdersService ordersService; | ||
|
||
public CsvMapper(OrdersService ordersService) { | ||
this.ordersService = ordersService; | ||
} | ||
|
||
@Override | ||
public String convertForExport(List<CompositePurchaseOrder> compPOs, List<Piece> pieces, VendorEdiOrdersExportConfig ediExportConfig, String jobName) { | ||
var claimCsvConverter = new ClaimCsvConverter(); | ||
var csvResult = new StringBuilder(claimCsvConverter.getCsvHeaders()).append(LINE_BREAK); | ||
getClaimEntries(compPOs, pieces).stream() | ||
.map(claimCsvConverter::convertEntryToCsv) | ||
.map(line -> line.concat(LINE_BREAK)) | ||
.forEachOrdered(csvResult::append); | ||
return csvResult.toString(); | ||
} | ||
|
||
private List<ClaimCsvEntry> getClaimEntries(List<CompositePurchaseOrder> orders, List<Piece> pieces) { | ||
// Map each PoLine ID to its corresponding Pieces | ||
var poLineIdToPieces = pieces.stream().collect(groupingBy(Piece::getPoLineId)); | ||
// Map each PoLine ID to its corresponding PoLine | ||
var poLineIdToPoLine = orders.stream().flatMap(order -> order.getCompositePoLines().stream()) | ||
.collect(Collectors.toMap(CompositePoLine::getId, Function.identity())); | ||
// Map each Piece ID to its corresponding Title | ||
var pieceIdToTitle = poLineIdToPieces.entrySet().stream() | ||
.flatMap(entry -> entry.getValue().stream() | ||
.map(piece -> Pair.of(piece.getId(), getTitleById(poLineIdToPoLine.get(entry.getKey()), piece)))) // Pair of Piece ID and Title | ||
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight)); | ||
|
||
// Key extractor for grouping pieces by: Po Line Number, Display Summary, Chronology, Enumeration, and Title | ||
Function<Piece, ClaimCsvEntry> keyExtractor = piece -> | ||
new ClaimCsvEntry(poLineIdToPoLine.get(piece.getPoLineId()), piece, pieceIdToTitle.get(piece.getId()), 0); | ||
|
||
// Group pieces by the previously defined key (Overridden equals and hashCode methods in ClaimCsvEntry) | ||
// Only a single piece from each group is used, as they share all necessary attributes | ||
Map<ClaimCsvEntry, Long> claimedPieces = pieces.stream() | ||
.collect(Collectors.groupingBy(keyExtractor, Collectors.counting())); | ||
|
||
// Return a list of ClaimCsvEntry objects, each representing a group of claimed pieces | ||
return claimedPieces.entrySet().stream() | ||
.map(entry -> entry.getKey().withQuantity(entry.getValue())) | ||
.sorted(Comparator.comparing(o -> o.compositePoLine().getPoLineNumber())) | ||
.toList(); | ||
} | ||
|
||
private String getTitleById(CompositePoLine poLine, Piece piece) { | ||
return Boolean.TRUE.equals(poLine.getIsPackage()) | ||
? ordersService.getTitleById(piece.getTitleId()).getTitle() | ||
: poLine.getTitleOrPackage(); | ||
} | ||
|
||
} |
Oops, something went wrong.