Search in sources :

Example 11 with PoLine

use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.

the class CreateInvoiceEventHandler method prepareInvoiceLinesToSave.

private List<InvoiceLine> prepareInvoiceLinesToSave(String invoiceId, DataImportEventPayload dataImportEventPayload, Map<Integer, PoLine> associatedPoLines) {
    List<InvoiceLine> invoiceLines = new JsonArray(dataImportEventPayload.getContext().get(INVOICE_LINES_KEY)).stream().map(JsonObject.class::cast).map(json -> json.mapTo(InvoiceLine.class)).map(invoiceLine -> invoiceLine.withInvoiceId(invoiceId).withInvoiceLineStatus(OPEN)).collect(Collectors.toList());
    linkInvoiceLinesToPoLines(invoiceLines, associatedPoLines);
    return invoiceLines;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) ORDER_LINES(org.folio.invoices.utils.ResourcePathResolver.ORDER_LINES) CREATE(org.folio.ActionProfile.Action.CREATE) EventHandler(org.folio.processing.events.services.handler.EventHandler) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PoLine(org.folio.rest.acq.model.orders.PoLine) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) StreamEx.ofSubLists(one.util.streamex.StreamEx.ofSubLists) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) OPEN(org.folio.rest.jaxrs.model.InvoiceLine.InvoiceLineStatus.OPEN) HelperUtils.collectResultsOnSuccess(org.folio.invoices.utils.HelperUtils.collectResultsOnSuccess) MappingProfile(org.folio.MappingProfile) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) DataImportEventPayload(org.folio.DataImportEventPayload) EdifactParsedContent(org.folio.EdifactParsedContent) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Logger(org.apache.logging.log4j.Logger) DI_INVOICE_CREATED(org.folio.DataImportEventTypes.DI_INVOICE_CREATED) Optional(java.util.Optional) ParsedRecord(org.folio.ParsedRecord) Pattern(java.util.regex.Pattern) Invoice(org.folio.rest.jaxrs.model.Invoice) RestClient(org.folio.rest.core.RestClient) FundDistribution(org.folio.rest.acq.model.orders.FundDistribution) Json(io.vertx.core.json.Json) INVOICE(org.folio.ActionProfile.FolioRecord.INVOICE) Record(org.folio.Record) MappingManager(org.folio.processing.mapping.MappingManager) PoLineCollection(org.folio.rest.acq.model.orders.PoLineCollection) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) EDIFACT_INVOICE(org.folio.rest.jaxrs.model.EntityType.EDIFACT_INVOICE) ArrayList(java.util.ArrayList) InvoiceLineHelper(org.folio.rest.impl.InvoiceLineHelper) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) RequestContext(org.folio.rest.core.models.RequestContext) ActionProfile(org.folio.ActionProfile) ResourcePathResolver.resourcesPath(org.folio.invoices.utils.ResourcePathResolver.resourcesPath) MappingContext(org.folio.processing.mapping.mapper.MappingContext) DataImportUtils(org.folio.dataimport.utils.DataImportUtils) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) InvoiceHelper(org.folio.rest.impl.InvoiceHelper) JsonArray(io.vertx.core.json.JsonArray) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) EdifactRecordReader(org.folio.processing.mapping.mapper.reader.record.edifact.EdifactRecordReader) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine)

Example 12 with PoLine

use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.

the class CreateInvoiceEventHandler method getAssociatedPoLinesByPoLineNumber.

private CompletableFuture<Map<Integer, PoLine>> getAssociatedPoLinesByPoLineNumber(Map<Integer, String> invoiceLineNoToPoLineNo, Map<String, String> okapiHeaders) {
    Map<Integer, PoLine> invoiceLineNoToPoLine = new HashMap<>();
    if (invoiceLineNoToPoLineNo.isEmpty()) {
        return completedFuture(invoiceLineNoToPoLine);
    }
    List<CompletableFuture<PoLineCollection>> polineCollectionsFuture = ofSubLists(List.copyOf(invoiceLineNoToPoLineNo.values()), MAX_CHUNK_SIZE).map(this::prepareQueryGetPoLinesByNumber).map(cqlQuery -> new RequestEntry(resourcesPath(ORDER_LINES)).withQuery(cqlQuery).withOffset(0).withLimit(Integer.MAX_VALUE)).map(requestEntry -> restClient.get(requestEntry, new RequestContext(Vertx.currentContext(), okapiHeaders), PoLineCollection.class)).collect(Collectors.toList());
    return collectResultsOnSuccess(polineCollectionsFuture).thenApply(lists -> lists.stream().flatMap(polCollection -> polCollection.getPoLines().stream()).distinct().collect(Collectors.toList())).thenApply(poLines -> poLines.stream().collect(Collectors.toMap(PoLine::getPoLineNumber, poLine -> poLine))).thenAccept(poLineNumberToPoLine -> invoiceLineNoToPoLineNo.forEach((key, value) -> poLineNumberToPoLine.computeIfPresent(value, (polNo, poLine) -> invoiceLineNoToPoLine.put(key, poLine)))).thenApply(v -> invoiceLineNoToPoLine);
}
Also used : ORDER_LINES(org.folio.invoices.utils.ResourcePathResolver.ORDER_LINES) CREATE(org.folio.ActionProfile.Action.CREATE) EventHandler(org.folio.processing.events.services.handler.EventHandler) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PoLine(org.folio.rest.acq.model.orders.PoLine) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) StreamEx.ofSubLists(one.util.streamex.StreamEx.ofSubLists) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) OPEN(org.folio.rest.jaxrs.model.InvoiceLine.InvoiceLineStatus.OPEN) HelperUtils.collectResultsOnSuccess(org.folio.invoices.utils.HelperUtils.collectResultsOnSuccess) MappingProfile(org.folio.MappingProfile) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) DataImportEventPayload(org.folio.DataImportEventPayload) EdifactParsedContent(org.folio.EdifactParsedContent) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Logger(org.apache.logging.log4j.Logger) DI_INVOICE_CREATED(org.folio.DataImportEventTypes.DI_INVOICE_CREATED) Optional(java.util.Optional) ParsedRecord(org.folio.ParsedRecord) Pattern(java.util.regex.Pattern) Invoice(org.folio.rest.jaxrs.model.Invoice) RestClient(org.folio.rest.core.RestClient) FundDistribution(org.folio.rest.acq.model.orders.FundDistribution) Json(io.vertx.core.json.Json) INVOICE(org.folio.ActionProfile.FolioRecord.INVOICE) Record(org.folio.Record) MappingManager(org.folio.processing.mapping.MappingManager) PoLineCollection(org.folio.rest.acq.model.orders.PoLineCollection) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) EDIFACT_INVOICE(org.folio.rest.jaxrs.model.EntityType.EDIFACT_INVOICE) ArrayList(java.util.ArrayList) InvoiceLineHelper(org.folio.rest.impl.InvoiceLineHelper) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) RequestContext(org.folio.rest.core.models.RequestContext) ActionProfile(org.folio.ActionProfile) ResourcePathResolver.resourcesPath(org.folio.invoices.utils.ResourcePathResolver.resourcesPath) MappingContext(org.folio.processing.mapping.mapper.MappingContext) DataImportUtils(org.folio.dataimport.utils.DataImportUtils) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) InvoiceHelper(org.folio.rest.impl.InvoiceHelper) JsonArray(io.vertx.core.json.JsonArray) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) EdifactRecordReader(org.folio.processing.mapping.mapper.reader.record.edifact.EdifactRecordReader) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CompletableFuture(java.util.concurrent.CompletableFuture) HashMap(java.util.HashMap) PoLine(org.folio.rest.acq.model.orders.PoLine) RequestEntry(org.folio.rest.core.models.RequestEntry) RequestContext(org.folio.rest.core.models.RequestContext)

Example 13 with PoLine

use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.

the class CreateInvoiceEventHandler method ensureAdditionalData.

private void ensureAdditionalData(DataImportEventPayload dataImportEventPayload, Map<Integer, PoLine> invoiceLineNoToPoLine) {
    for (Map.Entry<Integer, PoLine> pair : invoiceLineNoToPoLine.entrySet()) {
        PoLine poLine = pair.getValue();
        // put poLine id because invoice line schema expects "poLineId" instead of poLine number
        // https://github.com/folio-org/acq-models/blob/master/mod-invoice-storage/schemas/invoice_line.json
        dataImportEventPayload.getContext().put(format(POL_NUMBER_KEY, pair.getKey() - 1), poLine.getId());
        dataImportEventPayload.getContext().put(format(POL_TITLE_KEY, pair.getKey() - 1), poLine.getTitleOrPackage());
        if (poLine.getFundDistribution() != null) {
            dataImportEventPayload.getContext().put(format(POL_FUND_DISTRIBUTIONS_KEY, pair.getKey() - 1), Json.encode(poLine.getFundDistribution()));
        }
        if (isNotEmpty(poLine.getFundDistribution()) && verifyAllFundsHaveSameExpenseClass(poLine.getFundDistribution())) {
            dataImportEventPayload.getContext().put(format(POL_EXPENSE_CLASS_KEY, pair.getKey() - 1), poLine.getFundDistribution().get(0).getExpenseClassId());
        }
    }
}
Also used : PoLine(org.folio.rest.acq.model.orders.PoLine) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

PoLine (org.folio.rest.acq.model.orders.PoLine)13 PoLineCollection (org.folio.rest.acq.model.orders.PoLineCollection)11 InvoiceLineCollection (org.folio.rest.jaxrs.model.InvoiceLineCollection)11 HashMap (java.util.HashMap)10 Invoice (org.folio.rest.jaxrs.model.Invoice)10 DataImportEventPayload (org.folio.DataImportEventPayload)9 ParsedRecord (org.folio.ParsedRecord)9 Record (org.folio.Record)9 RequestContext (org.folio.rest.core.models.RequestContext)8 Vertx (io.vertx.core.Vertx)6 JsonObject (io.vertx.core.json.JsonObject)6 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)6 ResourcePathResolver.resourcesPath (org.folio.invoices.utils.ResourcePathResolver.resourcesPath)6 RestClient (org.folio.rest.core.RestClient)6 RequestEntry (org.folio.rest.core.models.RequestEntry)6 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)6 JsonArray (io.vertx.core.json.JsonArray)5 ArrayList (java.util.ArrayList)5