001package org.kuali.ole.service.impl; 002 003import org.apache.log4j.Logger; 004import org.kuali.ole.OLEConstants; 005import org.kuali.ole.docstore.common.client.DocstoreClientLocator; 006import org.kuali.ole.docstore.common.document.*; 007import org.kuali.ole.docstore.common.document.content.instance.*; 008 009import org.kuali.ole.docstore.common.document.content.instance.Item; 010import org.kuali.ole.docstore.common.document.content.instance.Items; 011import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor; 012import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor; 013import org.kuali.ole.docstore.model.enums.DocCategory; 014import org.kuali.ole.docstore.model.enums.DocFormat; 015import org.kuali.ole.docstore.model.enums.DocType; 016import org.kuali.ole.service.OverlayOutputService; 017import org.kuali.ole.sys.context.SpringContext; 018import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 019 020import java.util.ArrayList; 021import java.util.List; 022 023/** 024 * Created by IntelliJ IDEA. 025 * User: premkb 026 * Date: 2/23/13 027 * Time: 2:53 PM 028 * To change this template use File | Settings | File Templates. 029 */ 030public class OverlayDocstoreOutputServiceImpl implements OverlayOutputService { 031 private static final Logger LOG = Logger.getLogger(OverlayDocstoreOutputServiceImpl.class); 032 033 034 private DocstoreClientLocator docstoreClientLocator; 035 private HoldingOlemlRecordProcessor holdingOlemlRecordProcessor; 036 private ItemOlemlRecordProcessor itemOlemlRecordProcessor; 037 038 public DocstoreClientLocator getDocstoreClientLocator() { 039 if (docstoreClientLocator == null) { 040 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class); 041 } 042 return docstoreClientLocator; 043 } 044 @Override 045 public void setOutPutValue(String field, String value,Object object) { 046 if(object instanceof Instance){ 047 Instance instance = (Instance)object; 048 OleHoldings oleHoldings = instance.getOleHoldings(); 049 Items items = instance.getItems(); 050 instance.setOleHoldings(oleHoldings); 051 instance.setItems(items); 052 }else if(object instanceof OleHoldings){ 053 OleHoldings oleHoldings = (OleHoldings)object; 054 if(field.equalsIgnoreCase(OLEConstants.OVERLAY_CALLNUMBER)){ 055 CallNumber callNumber =oleHoldings.getCallNumber(); 056 if(callNumber==null){ 057 callNumber = new CallNumber(); 058 } 059 String callNumberValue = value; 060 callNumber.setClassificationPart(callNumberValue); 061 oleHoldings.setCallNumber(callNumber); 062 }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_LOCATION)){ 063 Location location = oleHoldings.getLocation(); 064 if(location == null){ 065 location = new Location(); 066 } 067 LocationLevel locationLevel = location.getLocationLevel(); 068 if(locationLevel == null){ 069 locationLevel = new LocationLevel(); 070 } 071 locationLevel.setName(value); 072 location.setLocationLevel(locationLevel); 073 oleHoldings.setLocation(location); 074 }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_NOTE)) { 075 Note note = new Note(); 076 note.setType(value); 077 List<Note> noteList = new ArrayList<Note>(); 078 noteList.add(note); 079 oleHoldings.setNote(noteList); 080 } else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER)) { 081 oleHoldings.setHoldingsIdentifier(value); 082 } 083 }else if(object instanceof Item){ 084 Item item = (Item)object; 085 if(field.equalsIgnoreCase(OLEConstants.OVERLAY_CALLNUMBER)){ 086 CallNumber callNumber =item.getCallNumber(); 087 if(callNumber==null){ 088 callNumber = new CallNumber(); 089 } 090 String callNumberValue = value; 091 callNumber.setClassificationPart(callNumberValue); 092 item.setCallNumber(callNumber); 093 }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_ITEMTYPE)){ 094 ItemType itemType = item.getItemType(); 095 if(itemType==null){ 096 itemType = new ItemType(); 097 } 098 itemType.setFullValue(value); 099 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}