1 package org.kuali.ole.ingest;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
5 import org.kuali.ole.pojo.edi.BuyerLineItemReference;
6 import org.kuali.ole.pojo.edi.BuyerReferenceInformation;
7 import org.kuali.ole.pojo.edi.LineItemOrder;
8
9 import java.util.Iterator;
10 import java.util.List;
11
12
13
14
15 public class LineItemOrderMatcherForBib {
16
17
18
19
20
21
22
23 public LineItemOrder getLineItemOrder(List<LineItemOrder> lineItemOrders, BibMarcRecord bibMarcRecord, String vendorProfileCode) {
24 String valuefor035Field = get035FieldValue(bibMarcRecord);
25 for (Iterator<LineItemOrder> iterator = lineItemOrders.iterator(); iterator.hasNext(); ) {
26 LineItemOrder lineItemOrder = iterator.next();
27 BuyerReferenceInformation buyerReferenceInformation = lineItemOrder.getBuyerReferenceInformation().get(0);
28 BuyerLineItemReference buyerLineItemReference = buyerReferenceInformation.getBuyerLineItemReference().get(0);
29 String orderLineNumber = buyerLineItemReference.getOrderLineNumber();
30 String buyersOrderLine = buyerLineItemReference.getBuyersOrderLine();
31 String vendorReferenceNumber = buyersOrderLine.equals("SLI") ? orderLineNumber : "";
32 if (valuefor035Field.equals("(" + vendorProfileCode + ")" + vendorReferenceNumber)) {
33 return lineItemOrder;
34 }
35 }
36 return null;
37
38 }
39
40
41
42
43
44
45 private String get035FieldValue(BibMarcRecord bibMarcRecord) {
46 List<org.kuali.ole.docstore.common.document.content.bib.marc.DataField> datafields = bibMarcRecord.getDataFields();
47 for (Iterator<org.kuali.ole.docstore.common.document.content.bib.marc.DataField> iterator = datafields.iterator(); iterator.hasNext(); ) {
48 org.kuali.ole.docstore.common.document.content.bib.marc.DataField marcDataField = iterator.next();
49 if (marcDataField.getTag().equals("035")) {
50 List<org.kuali.ole.docstore.common.document.content.bib.marc.SubField> subfields = marcDataField.getSubFields();
51 for (Iterator<org.kuali.ole.docstore.common.document.content.bib.marc.SubField> marcSubFieldIterator = subfields.iterator(); marcSubFieldIterator.hasNext(); ) {
52 org.kuali.ole.docstore.common.document.content.bib.marc.SubField marcSubField = marcSubFieldIterator.next();
53 if (marcSubField.getCode().equals("a")) {
54 return marcSubField.getValue();
55 }
56 }
57 }
58 }
59 return null;
60 }
61 }