View Javadoc
1   package org.kuali.ole.loaders.common.processor;
2   
3   import com.sun.jersey.api.core.HttpContext;
4   import org.apache.commons.collections.CollectionUtils;
5   import org.apache.log4j.Logger;
6   import org.codehaus.jackson.map.ObjectMapper;
7   import org.codehaus.jettison.json.JSONException;
8   import org.codehaus.jettison.json.JSONObject;
9   import org.kuali.ole.deliver.bo.OleBorrowerType;
10  import org.kuali.ole.deliver.bo.OlePatronDocument;
11  import org.kuali.ole.describe.bo.*;
12  import org.kuali.ole.docstore.common.document.content.bib.marc.Collection;
13  import org.kuali.ole.loaders.common.bo.OLELoaderImportResponseBo;
14  import org.kuali.ole.loaders.common.bo.OLELoaderResponseBo;
15  import org.kuali.ole.loaders.common.constants.OLELoaderConstants;
16  import org.kuali.ole.loaders.common.service.OLELoaderService;
17  import org.kuali.ole.loaders.common.service.impl.OLELoaderServiceImpl;
18  import org.kuali.ole.loaders.deliver.service.OLEBorrowerTypeLoaderHelperService;
19  import org.kuali.ole.loaders.deliver.service.OLEBorrowerTypeLoaderService;
20  import org.kuali.ole.loaders.deliver.service.OLEPatronLoaderHelperService;
21  import org.kuali.ole.loaders.deliver.service.OLEPatronLoaderService;
22  import org.kuali.ole.loaders.describe.bo.*;
23  import org.kuali.ole.loaders.describe.service.*;
24  import org.kuali.ole.loaders.describe.service.impl.OLELocationLoaderHelperServiceImpl;
25  import org.kuali.ole.loaders.describe.service.impl.OLELocationLoaderServiceImpl;
26  
27  import javax.ws.rs.*;
28  import javax.ws.rs.core.Context;
29  import javax.ws.rs.core.MediaType;
30  import javax.ws.rs.core.Response;
31  import java.util.Iterator;
32  import java.util.List;
33  
34  /**
35   * Created by sheiksalahudeenm on 2/17/15.
36   */
37  @Path("/")
38  public class OLELoaderApiProcessor {
39  
40      private static final Logger LOG = Logger.getLogger(OLELoaderApiProcessor.class);
41      OLELocationLoaderService oleLocationLoaderService = new OLELocationLoaderServiceImpl();
42      OLELocationLoaderHelperService oleLocationLoaderHelperService = new OLELocationLoaderHelperServiceImpl();
43      OLELoaderService oleLoaderService;
44  
45      public OLELoaderService getOleLoaderService() {
46          if(oleLoaderService == null){
47              oleLoaderService = new OLELoaderServiceImpl();
48          }
49          return oleLoaderService;
50      }
51  
52      public void setOleLoaderService(OLELoaderService oleLoaderService) {
53          this.oleLoaderService = oleLoaderService;
54      }
55  
56      @GET
57      @Path("/location/{pk}")
58      @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
59      public Response exportLocation(@Context HttpContext context, @PathParam("pk") String id){
60          Object object  = null;
61          if(id.matches("^([\\d]*)?$")){
62              object = oleLocationLoaderService.exportLocationById(id);
63          }else{
64              object = oleLocationLoaderService.exportLocationByCode(id);
65          }
66          if(object instanceof OleLocation){
67              object = oleLocationLoaderHelperService.formLocationExportResponse(object,OLELoaderConstants.OLELoaderContext.LOCATION,context.getRequest().getRequestUri().toASCIIString(),true);
68              return  Response.status(200).entity(object).build();
69          }else if(object instanceof  OLELoaderResponseBo){
70              return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
71          }
72          return null;
73      }
74  
75      @GET
76      @Path("/location")
77      @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
78      public Response exportAllLocations(@Context HttpContext context){
79          List<OleLocation> oleLocationList = oleLocationLoaderService.exportAllLocations(context);
80          if(CollectionUtils.isNotEmpty(oleLocationList)){
81              Object object = oleLocationLoaderHelperService.formAllLocationExportResponse(context, oleLocationList, OLELoaderConstants.OLELoaderContext.LOCATION,
82                      context.getRequest().getRequestUri().toASCIIString());
83              return Response.status(200).entity(object).build();
84          }
85          return Response.status(500).entity(null).build();
86      }
87  
88      @POST
89      @Path("/location")
90      @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
91      public Response importLocations(@Context HttpContext context, String bodyContent){
92          LOG.info("Incoming request for Import Locations.");
93          Object object = oleLocationLoaderService.importLocations(bodyContent,context);
94          return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.LOCATION);
95      }
96  
97      @PUT
98      @Path("/location/{locationId}")
99      @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
100     public Response updateLocation(@Context HttpContext context, @PathParam("locationId") String locationId, String body){
101         LOG.info("Incoming request for update Location.");
102         OLELoaderResponseBo object = oleLocationLoaderService.updateLocationById(locationId, body, context);
103         if(object.getStatusCode() == 200){
104             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
105         }else{
106             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
107         }
108 
109     }
110 
111     @GET
112     @Path("/locationLevel/{pk}")
113     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
114     public Response exportLocationLevel(@Context HttpContext context, @PathParam("pk") String id){
115         Object object  = null;
116         if(id.matches("^([\\d]*)?$")){
117             object = oleLocationLoaderService.exportLocationLevelById(id);
118         }else{
119             object = oleLocationLoaderService.exportLocationLevelByCode(id);
120         }
121         if(object instanceof OleLocationLevel){
122             object = oleLocationLoaderHelperService.formLocationLevelExportResponse(object, OLELoaderConstants.OLELoaderContext.LOCATION_LEVEL, context.getRequest().getRequestUri().toASCIIString(),true);
123             return  Response.status(200).entity(object).build();
124         }else if(object instanceof  OLELoaderResponseBo){
125             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
126         }
127         return null;
128     }
129 
130     @GET
131     @Path("/locationLevel")
132     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
133     public Response exportAllLocationLevels(@Context HttpContext context){
134         List<OleLocationLevel> oleLocationLevelList= oleLocationLoaderService.exportAllLocationLevels(context);
135         if(CollectionUtils.isNotEmpty(oleLocationLevelList)){
136             Object object = oleLocationLoaderHelperService.formAllLocationLevelExportResponse(context, oleLocationLevelList, OLELoaderConstants.OLELoaderContext.LOCATION_LEVEL,
137                     context.getRequest().getRequestUri().toASCIIString());
138             return Response.status(200).entity(object).build();
139         }
140         return Response.status(500).entity(null).build();
141     }
142 
143     @POST
144     @Path("/locationLevel")
145     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
146     public Response importLocationLevels(@Context HttpContext context, String bodyContent){
147         LOG.info("Incoming request for Import Locations Level.");
148         Object object = oleLocationLoaderService.importLocationLevels(bodyContent,context);
149         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.LOCATION_LEVEL);
150     }
151 
152     @PUT
153     @Path("/locationLevel/{locationLevelId}")
154     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
155     public Response updateLocationLevel(@Context HttpContext context, @PathParam("locationLevelId") String locationLevelId, String body){
156         LOG.info("Incoming request for update Location Level.");
157         OLELoaderResponseBo object = oleLocationLoaderService.updateLocationLevelById(locationLevelId, body, context);
158         if(object.getStatusCode() == 200){
159             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
160         }else{
161             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
162         }
163 
164     }
165 
166 
167 
168     @GET
169     @Path("/callNumberType/{pk}")
170     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
171     public Response exportShelvingScheme(@Context HttpContext context, @PathParam("pk") String id){
172         LOG.info("Incoming request for exportShelvingScheme.");
173         Object object  = null;
174         OLEShelvingSchemeLoaderService oleShelvingSchemeLoaderService = (OLEShelvingSchemeLoaderService) getOleLoaderService().getLoaderService("shelvingScheme");
175         OLEShelvingSchemeLoaderHelperService oleShelvingSchemeLoaderHelperService = (OLEShelvingSchemeLoaderHelperService) getOleLoaderService().getLoaderHelperService("shelvingScheme");
176         if(id.matches("^([\\d]*)?$")){
177             object = oleShelvingSchemeLoaderService.exportShelvingSchemeById(id);
178         }else{
179             object = oleShelvingSchemeLoaderService.exportShelvingSchemeByCode(id);
180         }
181         if(object instanceof OleShelvingScheme){
182             object = oleShelvingSchemeLoaderHelperService.formOleShelvingSchemeExportResponse(object, OLELoaderConstants.OLELoaderContext.SHELVING_SCHEME, context.getRequest().getRequestUri().toASCIIString(), true);
183             return  Response.status(200).entity(object).build();
184         }else if(object instanceof  OLELoaderResponseBo){
185             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
186         }
187         return null;
188     }
189 
190     @GET
191     @Path("/callNumberType")
192     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
193     public Response exportAllShelvingSchemes(@Context HttpContext context){
194         LOG.info("Incoming request for exportAllShelvingSchemes.");
195         OLEShelvingSchemeLoaderService oleShelvingSchemeLoaderService = (OLEShelvingSchemeLoaderService) getOleLoaderService().getLoaderService("shelvingScheme");
196         OLEShelvingSchemeLoaderHelperService oleShelvingSchemeLoaderHelperService = (OLEShelvingSchemeLoaderHelperService) getOleLoaderService().getLoaderHelperService("shelvingScheme");
197         List<OleShelvingScheme> oleShelvingSchemeList = oleShelvingSchemeLoaderService.exportAllShelvingSchemes();
198         if(CollectionUtils.isNotEmpty(oleShelvingSchemeList)){
199             Object object = oleShelvingSchemeLoaderHelperService.formAllShelvingSchemeExportResponse(context, oleShelvingSchemeList, OLELoaderConstants.OLELoaderContext.SHELVING_SCHEME,
200                     context.getRequest().getRequestUri().toASCIIString());
201             return Response.status(200).entity(object).build();
202         }
203         return Response.status(500).entity(null).build();
204     }
205 
206     @POST
207     @Path("/callNumberType")
208     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
209     public Response importShelvingSchemes(@Context HttpContext context, String bodyContent){
210         LOG.info("Incoming request for importShelvingSchemes.");
211         OLEShelvingSchemeLoaderService oleShelvingSchemeLoaderService = (OLEShelvingSchemeLoaderService) getOleLoaderService().getLoaderService("shelvingScheme");
212         OLEShelvingSchemeLoaderHelperService oleShelvingSchemeLoaderHelperService = (OLEShelvingSchemeLoaderHelperService) getOleLoaderService().getLoaderHelperService("shelvingScheme");
213         Object object = oleShelvingSchemeLoaderService.importShelvingSchemes(bodyContent, context);
214         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.SHELVING_SCHEME);
215     }
216 
217     @PUT
218     @Path("/callNumberType/{shelvingSchemeId}")
219     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
220     public Response updateShelvingScheme(@Context HttpContext context, @PathParam("shelvingSchemeId") String shelvingSchemeId, String body){
221         LOG.info("Incoming request for updateShelvingScheme.");
222         OLEShelvingSchemeLoaderService oleShelvingSchemeLoaderService = (OLEShelvingSchemeLoaderService) getOleLoaderService().getLoaderService("shelvingScheme");
223         OLELoaderResponseBo object = oleShelvingSchemeLoaderService.updateShelvingSchemeById(shelvingSchemeId, body, context);
224         if(object.getStatusCode() == 200){
225             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
226         }else{
227             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
228         }
229     }
230 
231     @GET
232     @Path("/itemType/{pk}")
233     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
234     public Response exportItemType(@Context HttpContext context, @PathParam("pk") String id){
235         LOG.info("Incoming request for exportItemType.");
236         Object object  = null;
237         OLEItemTypeLoaderService oleItemTypeLoaderService = (OLEItemTypeLoaderService) getOleLoaderService().getLoaderService("itemType");
238         OLEItemTypeLoaderHelperService oleItemTypeLoaderHelperService = (OLEItemTypeLoaderHelperService) getOleLoaderService().getLoaderHelperService("itemType");
239         if(id.matches("^([\\d]*)?$")){
240             object = oleItemTypeLoaderService.exportItemTypeById(id);
241         }else{
242             object = oleItemTypeLoaderService.exportItemTypeByCode(id);
243         }
244         if(object instanceof OleInstanceItemType){
245             object = oleItemTypeLoaderHelperService.formOleInstanceItemTypeExportResponse(object, OLELoaderConstants.OLELoaderContext.ITEM_TYPE, context.getRequest().getRequestUri().toASCIIString(), true);
246             return  Response.status(200).entity(object).build();
247         }else if(object instanceof  OLELoaderResponseBo){
248             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
249         }
250         return null;
251     }
252 
253     @GET
254     @Path("/itemType")
255     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
256     public Response exportAllItemTypes(@Context HttpContext context){
257         LOG.info("Incoming request for exportAllItemTypes.");
258         OLEItemTypeLoaderService oleItemTypeLoaderService = (OLEItemTypeLoaderService) getOleLoaderService().getLoaderService("itemType");
259         OLEItemTypeLoaderHelperService oleItemTypeLoaderHelperService = (OLEItemTypeLoaderHelperService) getOleLoaderService().getLoaderHelperService("itemType");
260         List<OleInstanceItemType> oleInstanceItemTypes= oleItemTypeLoaderService.exportAllItemTypes();
261         if(CollectionUtils.isNotEmpty(oleInstanceItemTypes)){
262             Object object = oleItemTypeLoaderHelperService.formAllItemTypeExportResponse(context, oleInstanceItemTypes, OLELoaderConstants.OLELoaderContext.ITEM_TYPE,
263                     context.getRequest().getRequestUri().toASCIIString());
264             return Response.status(200).entity(object).build();
265         }
266         return Response.status(500).entity(null).build();
267     }
268 
269     @POST
270     @Path("/itemType")
271     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
272     public Response importItemType(@Context HttpContext context, String bodyContent){
273         LOG.info("Incoming request for importItemType.");
274         OLEItemTypeLoaderService oleItemTypeLoaderService = (OLEItemTypeLoaderService) getOleLoaderService().getLoaderService("itemType");
275         Object object = oleItemTypeLoaderService.importItemTypes(bodyContent, context);
276         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.ITEM_TYPE);
277     }
278 
279     @PUT
280     @Path("/itemType/{itemTypeId}")
281     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
282     public Response updateItemType(@Context HttpContext context, @PathParam("itemTypeId") String itemTypeId, String body){
283         LOG.info("Incoming request for updateItemType.");
284         OLEItemTypeLoaderService oleItemTypeLoaderService = (OLEItemTypeLoaderService) getOleLoaderService().getLoaderService("itemType");
285         OLELoaderResponseBo object = oleItemTypeLoaderService.updateItemTypeById(itemTypeId, body, context);
286         if(object.getStatusCode() == 200){
287             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
288         }else{
289             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
290         }
291     }
292 
293     @GET
294     @Path("/borrowerType/{pk}")
295     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
296     public Response exportBorrowerType(@Context HttpContext context, @PathParam("pk") String id){
297         LOG.info("Incoming request for exportBorrowerType.");
298         Object object  = null;
299         OLEBorrowerTypeLoaderService oleBorrowerTypeLoaderService = (OLEBorrowerTypeLoaderService) getOleLoaderService().getLoaderService("borrowerType");
300         OLEBorrowerTypeLoaderHelperService oleBorrowerTypeLoaderHelperService = (OLEBorrowerTypeLoaderHelperService) getOleLoaderService().getLoaderHelperService("borrowerType");
301         if(id.matches("^([\\d]*)?$")){
302             object = oleBorrowerTypeLoaderService.exportBorrowerTypeById(id);
303         }else{
304             object = oleBorrowerTypeLoaderService.exportBorrowerTypeByCode(id);
305         }
306         if(object instanceof OleBorrowerType){
307             object = oleBorrowerTypeLoaderHelperService.formOleBorrowerTypeExportResponse(object, OLELoaderConstants.OLELoaderContext.BORROWER_TYPE, context.getRequest().getRequestUri().toASCIIString(), true);
308             return  Response.status(200).entity(object).build();
309         }else if(object instanceof OLELoaderResponseBo){
310             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
311         }
312         return null;
313     }
314 
315     @GET
316     @Path("/borrowerType")
317     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
318     public Response exportAllBorrowerTypes(@Context HttpContext context){
319         LOG.info("Incoming request for exportAllBorrowerTypes.");
320         OLEBorrowerTypeLoaderService oleBorrowerTypeLoaderService = (OLEBorrowerTypeLoaderService) getOleLoaderService().getLoaderService("borrowerType");
321         OLEBorrowerTypeLoaderHelperService oleBorrowerTypeLoaderHelperService = (OLEBorrowerTypeLoaderHelperService) getOleLoaderService().getLoaderHelperService("borrowerType");
322         List<OleBorrowerType> oleInstanceBorrowerTypes= oleBorrowerTypeLoaderService.exportAllBorrowerTypes();
323         if(CollectionUtils.isNotEmpty(oleInstanceBorrowerTypes)){
324             Object object = oleBorrowerTypeLoaderHelperService.formAllBorrowerTypeExportResponse(context, oleInstanceBorrowerTypes, OLELoaderConstants.OLELoaderContext.BORROWER_TYPE,
325                     context.getRequest().getRequestUri().toASCIIString());
326             return Response.status(200).entity(object).build();
327         }
328         return Response.status(500).entity(null).build();
329     }
330 
331     @POST
332     @Path("/borrowerType")
333     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
334     public Response importBorrowerType(@Context HttpContext context, String bodyContent){
335         LOG.info("Incoming request for importBorrowerType.");
336         OLEBorrowerTypeLoaderService oleBorrowerTypeLoaderService = (OLEBorrowerTypeLoaderService) getOleLoaderService().getLoaderService("borrowerType");
337         Object object = oleBorrowerTypeLoaderService.importBorrowerTypes(bodyContent, context);
338         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.BORROWER_TYPE);
339     }
340 
341     @PUT
342     @Path("/borrowerType/{borrowerTypeId}")
343     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
344     public Response updateBorrowerType(@Context HttpContext context, @PathParam("borrowerTypeId") String borrowerTypeId, String body){
345         LOG.info("Incoming request for updateBorrowerType.");
346         OLEBorrowerTypeLoaderService oleBorrowerTypeLoaderService = (OLEBorrowerTypeLoaderService) getOleLoaderService().getLoaderService("borrowerType");
347         OLELoaderResponseBo object = oleBorrowerTypeLoaderService.updateBorrowerTypeById(borrowerTypeId, body, context);
348         if(object.getStatusCode() == 200){
349             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
350         }else{
351             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
352         }
353     }
354 
355     @GET
356     @Path("/itemAvailabilityStatus/{pk}")
357     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
358     public Response exportItemAvailableStatus(@Context HttpContext context, @PathParam("pk") String id){
359         LOG.info("Incoming request for exportItemAvailableStatus.");
360         Object object  = null;
361         OLEItemAvailableStatusLoaderService oleItemAvailableStatusLoaderService = (OLEItemAvailableStatusLoaderService) getOleLoaderService().getLoaderService("itemAvailableStatus");
362         OLEItemAvailableStatusLoaderHelperService oleItemAvailableStatusLoaderHelperService = (OLEItemAvailableStatusLoaderHelperService) getOleLoaderService().getLoaderHelperService("itemAvailableStatus");
363         if(id.matches("^([\\d]*)?$")){
364             object = oleItemAvailableStatusLoaderService.exportItemAvailableStatusById(id);
365         }else{
366             object = oleItemAvailableStatusLoaderService.exportItemAvailableStatusByCode(id);
367         }
368         if(object instanceof OleItemAvailableStatus){
369             object = oleItemAvailableStatusLoaderHelperService.formItemAvailableStatusExportResponse(object, OLELoaderConstants.OLELoaderContext.ITEM_STATUS, context.getRequest().getRequestUri().toASCIIString(), true);
370             return  Response.status(200).entity(object).build();
371         }else if(object instanceof OLELoaderResponseBo){
372             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
373         }
374         return null;
375     }
376 
377     @GET
378     @Path("/itemAvailabilityStatus")
379     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
380     public Response exportAllItemAvailableStatus(@Context HttpContext context){
381         LOG.info("Incoming request for exportAllItemAvailableStatus.");
382         OLEItemAvailableStatusLoaderService oleItemAvailableStatusLoaderService = (OLEItemAvailableStatusLoaderService) getOleLoaderService().getLoaderService("itemAvailableStatus");
383         OLEItemAvailableStatusLoaderHelperService oleItemAvailableStatusLoaderHelperService = (OLEItemAvailableStatusLoaderHelperService) getOleLoaderService().getLoaderHelperService("itemAvailableStatus");
384         List<OleItemAvailableStatus> oleInstanceItemAvailableStatus= oleItemAvailableStatusLoaderService.exportAllItemAvailableStatus();
385         if(CollectionUtils.isNotEmpty(oleInstanceItemAvailableStatus)){
386             Object object = oleItemAvailableStatusLoaderHelperService.formAllItemAvailableStatusExportResponse(context, oleInstanceItemAvailableStatus, OLELoaderConstants.OLELoaderContext.ITEM_STATUS,
387                     context.getRequest().getRequestUri().toASCIIString());
388             return Response.status(200).entity(object).build();
389         }
390         return Response.status(500).entity(null).build();
391     }
392 
393     @POST
394     @Path("/itemAvailabilityStatus")
395     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
396     public Response importItemAvailableStatus(@Context HttpContext context, String bodyContent){
397         LOG.info("Incoming request for importItemAvailableStatus.");
398         OLEItemAvailableStatusLoaderService oleItemAvailableStatusLoaderService = (OLEItemAvailableStatusLoaderService) getOleLoaderService().getLoaderService("itemAvailableStatus");
399         Object object = oleItemAvailableStatusLoaderService.importItemAvailableStatus(bodyContent, context);
400         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.ITEM_STATUS);
401     }
402 
403     @PUT
404     @Path("/itemAvailabilityStatus/{itemAvailableStatusId}")
405     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
406     public Response updateItemAvailableStatus(@Context HttpContext context, @PathParam("itemAvailableStatusId") String itemAvailableStatusId, String body){
407         LOG.info("Incoming request for updateItemAvailableStatus.");
408         OLEItemAvailableStatusLoaderService oleItemAvailableStatusLoaderService = (OLEItemAvailableStatusLoaderService) getOleLoaderService().getLoaderService("itemAvailableStatus");
409         OLELoaderResponseBo object = oleItemAvailableStatusLoaderService.updateItemAvailableStatusById(itemAvailableStatusId, body, context);
410         if(object.getStatusCode() == 200){
411             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
412         }else{
413             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
414         }
415     }
416 
417     @GET
418     @Path("/statSearchCode/{pk}")
419     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
420     public Response exportStatisticalSearchingCode(@Context HttpContext context, @PathParam("pk") String id){
421         LOG.info("Incoming request for exportStatisticalSearchingCode.");
422         Object object  = null;
423         OLEStatisticalSearchingCodeLoaderService oleStatisticalSearchingCodeLoaderService = (OLEStatisticalSearchingCodeLoaderService) getOleLoaderService().getLoaderService("statisticalSearchingCode");
424         OLEStatisticalSearchingCodeLoaderHelperService oleStatisticalSearchingCodeLoaderHelperService = (OLEStatisticalSearchingCodeLoaderHelperService) getOleLoaderService().getLoaderHelperService("statisticalSearchingCode");
425         if(id.matches("^([\\d]*)?$")){
426             object = oleStatisticalSearchingCodeLoaderService.exportStatisticalSearchingCodeById(id);
427         }else{
428             object = oleStatisticalSearchingCodeLoaderService.exportStatisticalSearchingCodeByCode(id);
429         }
430         if(object instanceof OleStatisticalSearchingCodes){
431             object = oleStatisticalSearchingCodeLoaderHelperService.formStatisticalSearchingCodeExportResponse(object, OLELoaderConstants.OLELoaderContext.STAT_SEARCH_CODE, context.getRequest().getRequestUri().toASCIIString(), true);
432             return  Response.status(200).entity(object).build();
433         }else if(object instanceof OLELoaderResponseBo){
434             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
435         }
436         return null;
437     }
438 
439     @GET
440     @Path("/statSearchCode")
441     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
442     public Response exportAllStatisticalSearchingCode(@Context HttpContext context){
443         LOG.info("Incoming request for exportAllStatisticalSearchingCode.");
444         OLEStatisticalSearchingCodeLoaderService oleStatisticalSearchingCodeLoaderService = (OLEStatisticalSearchingCodeLoaderService) getOleLoaderService().getLoaderService("statisticalSearchingCode");
445         OLEStatisticalSearchingCodeLoaderHelperService oleStatisticalSearchingCodeLoaderHelperService = (OLEStatisticalSearchingCodeLoaderHelperService) getOleLoaderService().getLoaderHelperService("statisticalSearchingCode");
446         List<OleStatisticalSearchingCodes> oleInstanceStatisticalSearchingCode= oleStatisticalSearchingCodeLoaderService.exportAllStatisticalSearchingCode();
447         if(CollectionUtils.isNotEmpty(oleInstanceStatisticalSearchingCode)){
448             Object object = oleStatisticalSearchingCodeLoaderHelperService.formAllStatisticalSearchingCodeExportResponse(context, oleInstanceStatisticalSearchingCode, OLELoaderConstants.OLELoaderContext.STAT_SEARCH_CODE,
449                     context.getRequest().getRequestUri().toASCIIString());
450             return Response.status(200).entity(object).build();
451         }
452         return Response.status(500).entity(null).build();
453     }
454 
455     @POST
456     @Path("/statSearchCode")
457     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
458     public Response importStatisticalSearchingCode(@Context HttpContext context, String bodyContent){
459         LOG.info("Incoming request for importStatisticalSearchingCode.");
460         OLEStatisticalSearchingCodeLoaderService oleStatisticalSearchingCodeLoaderService = (OLEStatisticalSearchingCodeLoaderService) getOleLoaderService().getLoaderService("statisticalSearchingCode");
461         Object object = oleStatisticalSearchingCodeLoaderService.importStatisticalSearchingCode(bodyContent, context);
462         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.STAT_SEARCH_CODE);
463     }
464 
465     @PUT
466     @Path("/statSearchCode/{statisticalSearchingCodeId}")
467     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
468     public Response updateStatisticalSearchingCode(@Context HttpContext context, @PathParam("statisticalSearchingCodeId") String statisticalSearchingCodeId, String body){
469         LOG.info("Incoming request for updateStatisticalSearchingCode.");
470         OLEStatisticalSearchingCodeLoaderService oleStatisticalSearchingCodeLoaderService = (OLEStatisticalSearchingCodeLoaderService) getOleLoaderService().getLoaderService("statisticalSearchingCode");
471         OLELoaderResponseBo object = oleStatisticalSearchingCodeLoaderService.updateStatisticalSearchingCodeById(statisticalSearchingCodeId, body, context);
472         if(object.getStatusCode() == 200){
473             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
474         }else{
475             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
476         }
477     }
478 
479     @GET
480     @Path("/bibStatus/{pk}")
481     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
482     public Response exportBibliographicRecordStatus(@Context HttpContext context, @PathParam("pk") String id){
483         Object object  = null;
484         OLEBibliographicRecordStatusLoaderService oleBibliographicRecordStatusLoaderService = (OLEBibliographicRecordStatusLoaderService) getOleLoaderService().getLoaderService("bibliographicRecordStatus");
485         OLEBibliographicRecordStatusLoaderHelperService oleBibliographicRecordStatusLoaderHelperService = (OLEBibliographicRecordStatusLoaderHelperService) getOleLoaderService().getLoaderHelperService("bibliographicRecordStatus");
486         if(id.matches("^([\\d]*)?$")){
487             object = oleBibliographicRecordStatusLoaderService.exportBibliographicRecordStatusById(id);
488         }else{
489             object = oleBibliographicRecordStatusLoaderService.exportBibliographicRecordStatusByCode(id);
490         }
491         if(object instanceof OleBibliographicRecordStatus){
492             object = oleBibliographicRecordStatusLoaderHelperService.formBibliographicRecordStatusExportResponse(object, OLELoaderConstants.OLELoaderContext.BIB_RECORD_STATUS, context.getRequest().getRequestUri().toASCIIString(), true);
493             return  Response.status(200).entity(object).build();
494         }else if(object instanceof OLELoaderResponseBo){
495             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
496         }
497         return null;
498     }
499 
500     @GET
501     @Path("/bibStatus")
502     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
503     public Response exportAllBibliographicRecordStatus(@Context HttpContext context){
504         OLEBibliographicRecordStatusLoaderService oleBibliographicRecordStatusLoaderService = (OLEBibliographicRecordStatusLoaderService) getOleLoaderService().getLoaderService("bibliographicRecordStatus");
505         OLEBibliographicRecordStatusLoaderHelperService oleBibliographicRecordStatusLoaderHelperService = (OLEBibliographicRecordStatusLoaderHelperService) getOleLoaderService().getLoaderHelperService("bibliographicRecordStatus");
506         List<OleBibliographicRecordStatus> oleInstanceBibliographicRecordStatus= oleBibliographicRecordStatusLoaderService.exportAllBibliographicRecordStatus();
507         if(CollectionUtils.isNotEmpty(oleInstanceBibliographicRecordStatus)){
508             Object object = oleBibliographicRecordStatusLoaderHelperService.formAllBibliographicRecordStatusExportResponse(context, oleInstanceBibliographicRecordStatus, OLELoaderConstants.OLELoaderContext.BIB_RECORD_STATUS,
509                     context.getRequest().getRequestUri().toASCIIString());
510             return Response.status(200).entity(object).build();
511         }
512         return Response.status(500).entity(null).build();
513     }
514 
515     @POST
516     @Path("/bibStatus")
517     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
518     public Response importBibliographicRecordStatus(@Context HttpContext context, String bodyContent){
519         LOG.info("Incoming request for Import Locations Level.");
520         OLEBibliographicRecordStatusLoaderService oleBibliographicRecordStatusLoaderService = (OLEBibliographicRecordStatusLoaderService) getOleLoaderService().getLoaderService("bibliographicRecordStatus");
521         Object object = oleBibliographicRecordStatusLoaderService.importBibliographicRecordStatus(bodyContent, context);
522         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.BIB_RECORD_STATUS);
523     }
524 
525     @PUT
526     @Path("/bibStatus/{bibliographicRecordStatusId}")
527     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
528     public Response updateBibliographicRecordStatus(@Context HttpContext context, @PathParam("bibliographicRecordStatusId") String bibliographicRecordStatusId, String body){
529         LOG.info("Incoming request for update Location.");
530         OLEBibliographicRecordStatusLoaderService oleBibliographicRecordStatusLoaderService = (OLEBibliographicRecordStatusLoaderService) getOleLoaderService().getLoaderService("bibliographicRecordStatus");
531         OLELoaderResponseBo object = oleBibliographicRecordStatusLoaderService.updateBibliographicRecordStatusById(bibliographicRecordStatusId, body, context);
532         if(object.getStatusCode() == 200){
533             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
534         }else{
535             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
536         }
537     }
538 
539 
540     @GET
541     @Path("/patron/{pk}")
542     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
543     public Response exportPatron(@Context HttpContext context, @PathParam("pk") String id){
544         Object object  = null;
545         OLEPatronLoaderService olePatronLoaderService = (OLEPatronLoaderService) getOleLoaderService().getLoaderService("patron");
546         OLEPatronLoaderHelperService olePatronLoaderHelperService = (OLEPatronLoaderHelperService) getOleLoaderService().getLoaderHelperService("patron");
547         object = olePatronLoaderService.exportPatronById(id);
548         if(object instanceof OlePatronDocument){
549             object = olePatronLoaderHelperService.formPatronExportResponse(object, OLELoaderConstants.OLELoaderContext.PATRON, context.getRequest().getRequestUri().toASCIIString(), true);
550             return  Response.status(200).entity(object).build();
551         }else if(object instanceof OLELoaderResponseBo){
552             return Response.status(((OLELoaderResponseBo) object).getStatusCode()).entity(((OLELoaderResponseBo) object).getMessage()).type(MediaType.TEXT_PLAIN).build();
553         }
554         return null;
555     }
556 
557     @GET
558     @Path("/patron")
559     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
560     public Response exportAllPatron(@Context HttpContext context){
561         OLEPatronLoaderService olePatronLoaderService = (OLEPatronLoaderService) getOleLoaderService().getLoaderService("patron");
562         OLEPatronLoaderHelperService olePatronLoaderHelperService = (OLEPatronLoaderHelperService) getOleLoaderService().getLoaderHelperService("patron");
563         List<OlePatronDocument> oleInstancePatron= olePatronLoaderService.exportAllPatrons();
564         if(CollectionUtils.isNotEmpty(oleInstancePatron)){
565             Object object = olePatronLoaderHelperService.formAllPatronExportResponse(context, oleInstancePatron, OLELoaderConstants.OLELoaderContext.PATRON,
566                     context.getRequest().getRequestUri().toASCIIString());
567             return Response.status(200).entity(object).build();
568         }
569         return Response.status(500).entity(null).build();
570     }
571 
572     @POST
573     @Path("/patron")
574     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
575     public Response importPatron(@Context HttpContext context, String bodyContent){
576         LOG.info("Incoming request for Import Locations Level.");
577         OLEPatronLoaderService olePatronLoaderService = (OLEPatronLoaderService) getOleLoaderService().getLoaderService("patron");
578         Object object = olePatronLoaderService.importPatrons(bodyContent, context);
579         return getOleLoaderService().formResponseForImport(object,OLELoaderConstants.OLELoaderContext.PATRON);
580     }
581 
582     /*@PUT
583     @Path("/patron/{patronId}")
584     @Produces({"application/ld+json", MediaType.APPLICATION_JSON})
585     public Response updatePatron(@Context HttpContext context, @PathParam("patronId") String patronId, String body){
586         LOG.info("Incoming request for update Location.");
587         OLEPatronLoaderService olePatronLoaderService = (OLEPatronLoaderService) getOleLoaderService().getLoaderService("patron");
588         OLELoaderResponseBo object = olePatronLoaderService.updatePatronById(patronId, body, context);
589         if(object.getStatusCode() == 200){
590             return  Response.status(object.getStatusCode()).entity(object.getDetails()).build();
591         }else{
592             return  Response.status(400).entity(object.getMessage()).type(MediaType.TEXT_PLAIN).build();
593         }
594     }*/
595 
596 
597 }