View Javadoc

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.model.xmlpojo.work.instance.oleml.*;
6   import org.kuali.ole.describe.service.DocstoreHelperService;
7   import org.kuali.ole.service.OverlayOutputService;
8   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
9   
10  import java.util.ArrayList;
11  import java.util.List;
12  
13  /**
14   * Created by IntelliJ IDEA.
15   * User: premkb
16   * Date: 2/23/13
17   * Time: 2:53 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  public class OverlayDocstoreOutputServiceImpl implements OverlayOutputService {
21      private static final Logger LOG = Logger.getLogger(OverlayDocstoreOutputServiceImpl.class);
22  
23      private DocstoreHelperService docstoreHelperService;
24  
25      @Override
26      public void setOutPutValue(String field, String value,Object object) {
27          if(object instanceof Instance){
28              Instance instance = (Instance)object;
29              OleHoldings oleHoldings = instance.getOleHoldings();
30              Items items = instance.getItems();
31              instance.setOleHoldings(oleHoldings);
32              instance.setItems(items);
33          }else if(object instanceof OleHoldings){
34              OleHoldings oleHoldings = (OleHoldings)object;
35              if(field.equalsIgnoreCase(OLEConstants.OVERLAY_CALLNUMBER)){
36                  CallNumber callNumber =oleHoldings.getCallNumber();
37                  if(callNumber==null){
38                      callNumber = new CallNumber();
39                  }
40                  String callNumberValue = value;
41                  callNumber.setClassificationPart(callNumberValue);
42                  oleHoldings.setCallNumber(callNumber);
43              }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_LOCATION)){
44                  Location location = oleHoldings.getLocation();
45                  if(location == null){
46                      location = new Location();
47                  }
48                  LocationLevel locationLevel = location.getLocationLevel();
49                  if(locationLevel == null){
50                      locationLevel = new LocationLevel();
51                  }
52                  locationLevel.setName(value);
53                  location.setLocationLevel(locationLevel);
54                  oleHoldings.setLocation(location);
55              }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_NOTE)) {
56                  Note  note = new Note();
57                  note.setType(value);
58                  List<Note> noteList = new ArrayList<Note>();
59                  noteList.add(note);
60                  oleHoldings.setNote(noteList);
61              }  else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_HOLDINGS_IDENTIFIER)) {
62                  oleHoldings.setHoldingsIdentifier(value);
63              }
64          }else if(object instanceof Item){
65              Item item = (Item)object;
66              if(field.equalsIgnoreCase(OLEConstants.OVERLAY_CALLNUMBER)){
67                  CallNumber callNumber =item.getCallNumber();
68                  if(callNumber==null){
69                      callNumber = new CallNumber();
70                  }
71                  String callNumberValue = value;
72                  callNumber.setClassificationPart(callNumberValue);
73                  item.setCallNumber(callNumber);
74              }else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_ITEMTYPE)){
75                  ItemType itemType = item.getItemType();
76                  if(itemType==null){
77                      itemType = new ItemType();
78                  }
79                  itemType.setFullValue(value);
80                  item.setItemType(itemType);
81  
82              }
83              else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_BARCODE)){
84                  item.setBarcodeARSL(value);
85              }
86              else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_STATISTICALSEARCHINGCODES)){
87                  StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
88                  statisticalSearchingCode.setFullValue(value);
89                  List<StatisticalSearchingCode> statisticalSearchingCodeList = new ArrayList<StatisticalSearchingCode>();
90                  statisticalSearchingCodeList.add(statisticalSearchingCode);
91                  item.setStatisticalSearchingCode(statisticalSearchingCodeList);
92              }
93              else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_VENDOR_LINEITEM_IDENTIFIER)){
94                  item.setVendorLineItemIdentifier(value);
95              }
96              else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_STAFF_ONLY_FLAG)){
97                  Boolean staffOnlyFlag = Boolean.parseBoolean(value);
98                  item.setStaffOnlyFlag(staffOnlyFlag);
99              }
100             else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_FAST_ADD_FLAG)){
101                 Boolean fastAddFlag = Boolean.parseBoolean(value);
102                 item.setFastAddFlag(fastAddFlag);
103             }
104             else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_STATUS)){
105                 ItemStatus itemStatus = new ItemStatus();
106                 itemStatus.setCodeValue(value);
107                 itemStatus.setFullValue(value);
108             }
109             else if(field.equalsIgnoreCase(OLEConstants.OVERLAY_ITEM_LOCATION)){
110                 Location location = item.getLocation();
111                 if(location == null){
112                     location = new Location();
113                 }
114                 LocationLevel locationLevel = location.getLocationLevel();
115                 if(locationLevel == null){
116                     locationLevel = new LocationLevel();
117                 }
118                 locationLevel.setName(value);
119                 location.setLocationLevel(locationLevel);
120                 item.setLocation(location);
121             }
122         }
123     }
124 
125 
126 
127     public void persist(Object object)throws Exception{
128         if(object instanceof InstanceCollection){
129             InstanceCollection instanceCollection = (InstanceCollection)object;
130             getDocstoreHelperService().updateInstanceToDocstore(instanceCollection);
131         }else if(object instanceof OleHoldings){
132             OleHoldings oleHoldings = (OleHoldings)object;
133             getDocstoreHelperService().updateOleHoldingToDocstore(oleHoldings);
134         }else if(object instanceof Items){
135             Items items = (Items)object;
136             List<Item> itemList = items.getItem();
137             for(Item item : itemList){
138                 getDocstoreHelperService().updateOleItemToDocstore(item);
139             }
140         }
141     }
142 
143     private DocstoreHelperService getDocstoreHelperService(){
144         if (docstoreHelperService == null) {
145             docstoreHelperService = GlobalResourceLoader.getService(OLEConstants.DOCSTORE_HELPER_SERVICE);
146         }
147         return docstoreHelperService;
148     }
149 
150     public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
151         this.docstoreHelperService = docstoreHelperService;
152     }
153 }