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