1 package org.kuali.ole.service.impl;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
6 import org.kuali.ole.docstore.common.document.*;
7 import org.kuali.ole.docstore.common.document.content.instance.*;
8
9 import org.kuali.ole.docstore.common.document.content.instance.Item;
10 import org.kuali.ole.docstore.common.document.content.instance.Items;
11 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
12 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
13 import org.kuali.ole.docstore.model.enums.DocCategory;
14 import org.kuali.ole.docstore.model.enums.DocFormat;
15 import org.kuali.ole.docstore.model.enums.DocType;
16 import org.kuali.ole.service.OverlayOutputService;
17 import org.kuali.ole.sys.context.SpringContext;
18 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23
24
25
26
27
28
29
30 public class OverlayDocstoreOutputServiceImpl implements OverlayOutputService {
31 private static final Logger LOG = Logger.getLogger(OverlayDocstoreOutputServiceImpl.class);
32
33
34 private DocstoreClientLocator docstoreClientLocator;
35 private HoldingOlemlRecordProcessor holdingOlemlRecordProcessor;
36 private ItemOlemlRecordProcessor itemOlemlRecordProcessor;
37
38 public DocstoreClientLocator getDocstoreClientLocator() {
39 if (docstoreClientLocator == null) {
40 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
41 }
42 return docstoreClientLocator;
43 }
44 @Override
45 public void setOutPutValue(String field, String value,Object object) {
46 if(object instanceof Instance){
47 Instance instance = (Instance)object;
48 OleHoldings oleHoldings = instance.getOleHoldings();
49 Items items = instance.getItems();
50 instance.setOleHoldings(oleHoldings);
51 instance.setItems(items);
52 }else if(object instanceof OleHoldings){
53 OleHoldings oleHoldings = (OleHoldings)object;
54 if(field.equalsIgnoreCase(OLEConstants.OVERLAY_CALLNUMBER)){
55 CallNumber callNumber =oleHoldings.getCallNumber();
56 if(callNumber==null){
57 callNumber = new CallNumber();
58 }
59 String callNumberValue = value;
60 callNumber.setClassificationPart(callNumberValue);
61 oleHoldings.setCallNumber(callNumber);
62 }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_LOCATION)){
63 Location location = oleHoldings.getLocation();
64 if(location == null){
65 location = new Location();
66 }
67 LocationLevel locationLevel = location.getLocationLevel();
68 if(locationLevel == null){
69 locationLevel = new LocationLevel();
70 }
71 locationLevel.setName(value);
72 location.setLocationLevel(locationLevel);
73 oleHoldings.setLocation(location);
74 }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_NOTE)) {
75 Note note = new Note();
76 note.setType(value);
77 List<Note> noteList = new ArrayList<Note>();
78 noteList.add(note);
79 oleHoldings.setNote(noteList);
80 } else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER)) {
81 oleHoldings.setHoldingsIdentifier(value);
82 }
83 }else if(object instanceof Item){
84 Item item = (Item)object;
85 if(field.equalsIgnoreCase(OLEConstants.OVERLAY_CALLNUMBER)){
86 CallNumber callNumber =item.getCallNumber();
87 if(callNumber==null){
88 callNumber = new CallNumber();
89 }
90 String callNumberValue = value;
91 callNumber.setClassificationPart(callNumberValue);
92 item.setCallNumber(callNumber);
93 }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_ITEMTYPE)){
94 ItemType itemType = item.getItemType();
95 if(itemType==null){
96 itemType = new ItemType();
97 }
98 itemType.setFullValue(value);
99 item.setItemType(itemType);
100
101 }
102 else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_BARCODE)){
103 item.setBarcodeARSL(value);
104 }
105 else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_STATISTICALSEARCHINGCODES)){
106 StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
107 statisticalSearchingCode.setFullValue(value);
108 List<StatisticalSearchingCode> statisticalSearchingCodeList = new ArrayList<StatisticalSearchingCode>();
109 statisticalSearchingCodeList.add(statisticalSearchingCode);
110 item.setStatisticalSearchingCode(statisticalSearchingCodeList);
111 }
112 else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_VENDOR_LINEITEM_IDENTIFIER)){
113 item.setVendorLineItemIdentifier(value);
114 }
115 else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_STAFF_ONLY_FLAG)){
116 Boolean staffOnlyFlag = Boolean.parseBoolean(value);
117 item.setStaffOnlyFlag(staffOnlyFlag);
118 }
119 else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_FAST_ADD_FLAG)){
120 Boolean fastAddFlag = Boolean.parseBoolean(value);
121 item.setFastAddFlag(fastAddFlag);
122 }
123 else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_STATUS)){
124 ItemStatus itemStatus = new ItemStatus();
125 itemStatus.setCodeValue(value);
126 itemStatus.setFullValue(value);
127 }
128 else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_LOCATION)){
129 Location location = item.getLocation();
130 if(location == null){
131 location = new Location();
132 }
133 LocationLevel locationLevel = location.getLocationLevel();
134 if(locationLevel == null){
135 locationLevel = new LocationLevel();
136 }
137 locationLevel.setName(value);
138 location.setLocationLevel(locationLevel);
139 item.setLocation(location);
140 }
141 }
142 }
143
144
145 public void persist(Object object) throws Exception {
146
147 if (object instanceof OleHoldings) {
148 Holdings holdings = new PHoldings();
149 holdings.setCategory(DocCategory.WORK.getCode());
150 holdings.setType(DocType.HOLDINGS.getCode());
151 holdings.setFormat(DocFormat.OLEML.getCode());
152 OleHoldings oleHoldings = (OleHoldings) object;
153 holdings.setContentObject(getHoldingOlemlRecordProcessor().toXML(oleHoldings));
154 holdings.setId(oleHoldings.getHoldingsIdentifier());
155 getDocstoreClientLocator().getDocstoreClient().updateHoldings(holdings);
156 } else if (object instanceof Items) {
157 Items items = (Items) object;
158 List<Item> itemList = items.getItem();
159
160 org.kuali.ole.docstore.common.document.Item itemOleml = new ItemOleml();
161 itemOleml.setCategory(DocCategory.WORK.getCode());
162 itemOleml.setType(DocType.ITEM.getCode());
163 itemOleml.setFormat(DocFormat.OLEML.getCode());
164 for (Item item : itemList) {
165 itemOleml.setContent(getItemOlemlRecordProcessor().toXML(item));
166 itemOleml.setId(item.getItemIdentifier());
167 getDocstoreClientLocator().getDocstoreClient().updateItem(itemOleml);
168 }
169 }
170 }
171
172 public HoldingOlemlRecordProcessor getHoldingOlemlRecordProcessor() {
173 if (holdingOlemlRecordProcessor == null) {
174 holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
175 }
176 return holdingOlemlRecordProcessor;
177 }
178
179 public ItemOlemlRecordProcessor getItemOlemlRecordProcessor() {
180 if (itemOlemlRecordProcessor == null) {
181 itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
182 }
183 return itemOlemlRecordProcessor;
184 }
185 }