View Javadoc
1   package org.kuali.ole.loaders.describe.service.impl;
2   
3   import com.sun.jersey.api.client.ClientResponse;
4   import com.sun.jersey.api.core.HttpContext;
5   import org.apache.commons.collections.CollectionUtils;
6   import org.apache.commons.lang.StringUtils;
7   import org.apache.log4j.Logger;
8   import org.codehaus.jettison.json.JSONArray;
9   import org.codehaus.jettison.json.JSONException;
10  import org.codehaus.jettison.json.JSONObject;
11  import org.kuali.ole.describe.bo.OleLocation;
12  import org.kuali.ole.describe.bo.OleLocationLevel;
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.OLELoaderRestClient;
17  import org.kuali.ole.loaders.common.service.OLELoaderService;
18  import org.kuali.ole.loaders.common.service.impl.OLELoaderServiceImpl;
19  import org.kuali.ole.loaders.describe.bo.*;
20  import org.kuali.ole.loaders.describe.service.OLELocationLoaderHelperService;
21  import org.kuali.ole.loaders.describe.service.OLELocationLoaderService;
22  import org.kuali.rice.krad.service.BusinessObjectService;
23  import org.kuali.rice.krad.service.KRADServiceLocator;
24  
25  import java.util.*;
26  
27  /**
28   * Created by sheiksalahudeenm on 2/4/15.
29   */
30  public class OLELocationLoaderServiceImpl implements OLELocationLoaderService {
31  
32      private static final Logger LOG = Logger.getLogger(OLELocationLoaderServiceImpl.class);
33  
34      OLELocationLoaderHelperService oleLocationLoaderHelperService = new OLELocationLoaderHelperServiceImpl();
35      private OLELoaderService oleLoaderService;
36      private BusinessObjectService businessObjectService;
37  
38      public BusinessObjectService getBusinessObjectService() {
39          if(businessObjectService == null){
40              businessObjectService = KRADServiceLocator.getBusinessObjectService();
41          }
42          return businessObjectService;
43      }
44  
45      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
46          this.businessObjectService = businessObjectService;
47      }
48      
49      public OLELoaderService getOleLoaderService() {
50          if(oleLoaderService == null ){
51              oleLoaderService = new OLELoaderServiceImpl();
52          }
53          return oleLoaderService;
54      }
55  
56      public void setOleLoaderService(OLELoaderService oleLoaderService) {
57          this.oleLoaderService = oleLoaderService;
58      }
59  
60      public OLELocationLoaderHelperService getOleLocationLoaderHelperService() {
61          return oleLocationLoaderHelperService;
62      }
63  
64      public void setOleLocationLoaderHelperService(OLELocationLoaderHelperService oleLocationLoaderHelperService) {
65          this.oleLocationLoaderHelperService = oleLocationLoaderHelperService;
66      }
67  
68      @Override
69      public Object importLocations(String bodyContent, HttpContext context) {
70          LOG.info("Inside importLocations method.");
71          OLELoaderImportResponseBo oleLoaderImportResponseBo = new OLELoaderImportResponseBo();
72          List<Integer> rejectLocationList = new ArrayList<Integer>();
73          List<JSONObject> createdLocationObject = new ArrayList<JSONObject>();
74          JSONObject requestJsonObject = getOleLoaderService().getJsonObjectFromString(bodyContent);
75          boolean validObject = false;
76          if(requestJsonObject != null) {
77              if (requestJsonObject.has("items")) {
78                  String items = getOleLoaderService().getStringValueFromJsonObject(requestJsonObject, "items");
79                  if (StringUtils.isNotBlank(items)) {
80                      JSONArray locationJsonArray = getOleLoaderService().getJsonArrayFromString(items);
81                      for (int index = 0; index < locationJsonArray.length(); index ++) {
82                          JSONObject jsonObject = null;
83                          OLELocationBo oleLocationBo = new OLELocationBo();
84                          try {
85                              jsonObject = (JSONObject)locationJsonArray.get(index);
86                              if(jsonObject != null){
87                                  if(jsonObject.has("name")){
88                                      String name = getOleLoaderService().getStringValueFromJsonObject(jsonObject,"name");
89                                      if(StringUtils.isNotBlank(name)){
90                                          oleLocationBo.setLocationName(name);
91                                          validObject = true;
92                                      }
93                                  }
94                                  if(jsonObject.has("code")){
95                                      String code = getOleLoaderService().getStringValueFromJsonObject(jsonObject,"code");
96                                      if(StringUtils.isNotBlank(code)){
97                                          oleLocationBo.setLocationCode(code);
98                                          validObject = true;
99                                      }
100                                 }
101                                 if(jsonObject.has("level")){
102                                     JSONObject levelJsonObject = getOleLoaderService().getJsonObjectFromString(getOleLoaderService().getStringValueFromJsonObject(jsonObject,"level"));
103                                     if(levelJsonObject != null){
104                                         String levelUrl = getOleLoaderService().getStringValueFromJsonObject(levelJsonObject, "@id");
105                                         if(StringUtils.isNotBlank(levelUrl)){
106                                             Map<String,Object> restResponseMap = OLELoaderRestClient.jerseryClientGet(levelUrl);
107                                             if((Integer)restResponseMap.get("status")== 200){
108                                                 String levelResponseContent = (String)restResponseMap.get("content");
109                                                 JSONObject levelResponseObject = getOleLoaderService().getJsonObjectFromString(levelResponseContent);
110                                                 if(levelResponseObject != null){
111                                                     String urlId = getOleLoaderService().getStringValueFromJsonObject(levelResponseObject, "@id");
112                                                     if(StringUtils.isNotBlank(urlId)){
113                                                         String levelId = urlId.substring(urlId.indexOf("/api/locationLevel/")+19);
114                                                         oleLocationBo.setLocationLevelId(levelId);
115                                                         validObject = true;
116                                                     }
117                                                 }else{
118                                                     rejectLocationList.add(index+1);
119                                                     continue;
120                                                 }
121                                             }else{
122                                                 rejectLocationList.add(index+1);
123                                                 continue;
124                                             }
125 
126 
127 
128                                         }
129                                     }
130 
131                                 }
132                                 if(jsonObject.has("parent")){
133                                     JSONObject parentJsonObject = getOleLoaderService().getJsonObjectFromString(getOleLoaderService().getStringValueFromJsonObject(jsonObject,"parent"));
134                                     if(parentJsonObject != null){
135                                         String parentUrl = getOleLoaderService().getStringValueFromJsonObject(parentJsonObject,"@id");
136                                         if(StringUtils.isNotBlank(parentUrl)){
137                                             Map<String,Object> restResponseMap = OLELoaderRestClient.jerseryClientGet(parentUrl);
138                                             if((Integer)restResponseMap.get("status")== 200){
139                                                 String parentResponseContent = (String)restResponseMap.get("content");
140                                                 JSONObject parentResponseObject = getOleLoaderService().getJsonObjectFromString(parentResponseContent);
141                                                 if(parentResponseObject != null){
142                                                     String urlId = getOleLoaderService().getStringValueFromJsonObject(parentResponseObject,"@id");
143                                                     if(StringUtils.isNotBlank(urlId)){
144                                                         String parentId = urlId.substring(urlId.indexOf("/api/location/")+14);
145                                                         oleLocationBo.setParentLocationId(parentId);
146                                                         validObject = true;
147                                                     }
148                                                 }else{
149                                                     rejectLocationList.add(index+1);
150                                                     continue;
151                                                 }
152                                             }else{
153                                                 rejectLocationList.add(index+1);
154                                                 continue;
155                                             }
156 
157 
158                                         }
159                                     }
160                                 }
161                             }
162                             if(oleLocationBo != null && validObject){
163                                 if (!oleLocationLoaderHelperService.isLocationExistByCode(oleLocationBo.getLocationCode())) {
164                                     OleLocationLevel oleLocationLevel = oleLocationLoaderHelperService.getLocationLevelById(oleLocationBo.getLocationLevelId());
165                                     if (oleLocationLevel == null) {
166                                         rejectLocationList.add(index+1);
167                                     } else if (oleLocationLoaderHelperService.isParentLocationExist(oleLocationBo.getParentLocationId())) {
168                                         rejectLocationList.add(index + 1);
169                                     } else {
170                                         try {
171                                             OleLocation oleLocation = oleLocationLoaderHelperService.createOleLocation(oleLocationBo);
172                                             createdLocationObject.add((JSONObject)oleLocationLoaderHelperService.formLocationExportResponse(oleLocation, OLELoaderConstants.OLELoaderContext.LOCATION,
173                                                     context.getRequest().getRequestUri().toASCIIString(),false));
174                                         } catch (Exception e) {
175                                             rejectLocationList.add(index+1);
176                                         }
177                                     }
178                                 } else {
179                                     rejectLocationList.add(index+1);
180                                 }
181 
182                             }else{
183                                 return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
184                             }
185                         } catch (JSONException e) {
186                             e.printStackTrace();
187                             rejectLocationList.add(index);
188                         }
189                     }
190                 }else{
191                     return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
192                 }
193 
194             }
195         }else{
196             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
197         }
198         oleLoaderImportResponseBo.setOleRejectedBos(rejectLocationList);
199         oleLoaderImportResponseBo.setOleCreatedBos(createdLocationObject);
200         return oleLoaderImportResponseBo;
201     }
202 
203     @Override
204     public OLELoaderResponseBo updateLocationById(String locationId, String bodyContent,HttpContext context) {
205         LOG.info("Inside updateLocationById method.");
206         OLELocationBo oleLocationBo = new OLELocationBo();
207         JSONObject jsonObject = getOleLoaderService().getJsonObjectFromString(bodyContent);
208         boolean validObject = false;
209         if(jsonObject != null){
210             if(jsonObject.has("name")){
211                 String name = getOleLoaderService().getStringValueFromJsonObject(jsonObject,"name");
212                 if(StringUtils.isNotBlank(name)){
213                     oleLocationBo.setLocationName(name);
214                     validObject = true;
215                 }
216             }
217             if(jsonObject.has("code")){
218                 String code = getOleLoaderService().getStringValueFromJsonObject(jsonObject,"code");
219                 if(StringUtils.isNotBlank(code)){
220                     oleLocationBo.setLocationCode(code);
221                     validObject = true;
222                 }
223             }
224             if(jsonObject.has("level")){
225                 JSONObject levelJsonObject = getOleLoaderService().getJsonObjectFromString(getOleLoaderService().getStringValueFromJsonObject(jsonObject,"level"));
226                 if(levelJsonObject != null){
227                     String levelUrl = getOleLoaderService().getStringValueFromJsonObject(levelJsonObject, "@id");
228                     if(StringUtils.isNotBlank(levelUrl)){
229                         Map<String,Object> restResponseMap = OLELoaderRestClient.jerseryClientGet(levelUrl);
230                         if((Integer)restResponseMap.get("status")== 200){
231                             String levelResponseContent = (String)restResponseMap.get("content");
232                             JSONObject levelResponseObject = getOleLoaderService().getJsonObjectFromString(levelResponseContent);
233                             if(levelResponseObject != null){
234                                 String urlId = getOleLoaderService().getStringValueFromJsonObject(levelResponseObject, "@id");
235                                 if(StringUtils.isNotBlank(urlId)){
236                                     String levelId = urlId.substring(urlId.indexOf("/api/locationLevel/")+19);
237                                     oleLocationBo.setLocationLevelId(levelId);
238                                     validObject = true;
239                                 }
240                             }else{
241                                 return getOleLoaderService().generateResponse(
242                                         OLELoaderConstants.OLEloaderMessage.LOCATION_LEVEL_NOT_EXIST,
243                                         OLELoaderConstants.OLEloaderStatus.LOCATION_LEVEL_NOT_EXIST);
244                             }
245                         }else{
246                             return getOleLoaderService().generateResponse(
247                                     OLELoaderConstants.OLEloaderMessage.LOCATION_LEVEL_NOT_EXIST,
248                                     OLELoaderConstants.OLEloaderStatus.LOCATION_LEVEL_NOT_EXIST);
249                         }
250 
251 
252 
253                     }
254                 }
255 
256             }
257             if(jsonObject.has("parent")){
258                 JSONObject parentJsonObject = getOleLoaderService().getJsonObjectFromString(getOleLoaderService().getStringValueFromJsonObject(jsonObject,"parent"));
259                 if(parentJsonObject != null){
260                     String parentUrl = getOleLoaderService().getStringValueFromJsonObject(parentJsonObject,"@id");
261                     if(StringUtils.isNotBlank(parentUrl)){
262                         Map<String,Object> restResponseMap = OLELoaderRestClient.jerseryClientGet(parentUrl);
263                         if((Integer)restResponseMap.get("status")== 200){
264                             String parentResponseContent = (String)restResponseMap.get("content");
265                             JSONObject parentResponseObject = getOleLoaderService().getJsonObjectFromString(parentResponseContent);
266                             if(parentResponseObject != null){
267                                 String urlId = getOleLoaderService().getStringValueFromJsonObject(parentResponseObject,"@id");
268                                 if(StringUtils.isNotBlank(urlId)){
269                                     String parentId = urlId.substring(urlId.indexOf("/api/location/")+14);
270                                     oleLocationBo.setParentLocationId(parentId);
271                                     validObject = true;
272                                 }
273                             }else{
274                                 return getOleLoaderService().generateResponse(
275                                         OLELoaderConstants.OLEloaderMessage.PARENT_LOCATION_NOT_EXIST,
276                                         OLELoaderConstants.OLEloaderStatus.PARENT_LOCATION_NOT_EXIST);
277                             }
278                         }else{
279                             return getOleLoaderService().generateResponse(
280                                     OLELoaderConstants.OLEloaderMessage.PARENT_LOCATION_NOT_EXIST,
281                                     OLELoaderConstants.OLEloaderStatus.PARENT_LOCATION_NOT_EXIST);
282                         }
283 
284 
285                     }
286                 }
287             }
288         }
289         if(oleLocationBo != null && validObject){
290             if(StringUtils.isNotBlank(oleLocationBo.getLocationLevelId()) && oleLocationLoaderHelperService.isLocationLevelExistById(oleLocationBo.getLocationLevelId()))    {
291                 return getOleLoaderService().generateResponse(
292                         OLELoaderConstants.OLEloaderMessage.LOCATION_LEVEL_NOT_EXIST,
293                         OLELoaderConstants.OLEloaderStatus.LOCATION_LEVEL_NOT_EXIST);
294             }else if(StringUtils.isNotBlank(oleLocationBo.getParentLocationId()) && oleLocationLoaderHelperService.isParentLocationExist(oleLocationBo.getParentLocationId())) {
295                 return getOleLoaderService().generateResponse(
296                         OLELoaderConstants.OLEloaderMessage.PARENT_LOCATION_NOT_EXIST,
297                         OLELoaderConstants.OLEloaderStatus.PARENT_LOCATION_NOT_EXIST);
298             }else{
299                 OleLocation oleLocation = oleLocationLoaderHelperService.getLocationById(locationId);
300                 if(oleLocation != null){
301                     return oleLocationLoaderHelperService.updateOleLocation(oleLocation, oleLocationBo,context);
302                 }else{
303                     return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.LOCATION_NOT_EXIST, OLELoaderConstants.OLEloaderStatus.LOCATION_NOT_EXIST);
304                 }
305             }
306 
307         }else{
308             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
309         }
310     }
311 
312     @Override
313     public Object exportLocationById(String locationId) {
314         LOG.info("Inside exportLocationById method.");
315         OleLocation oleLocation = oleLocationLoaderHelperService.getLocationById(locationId);
316         if(oleLocation != null){
317             return oleLocation;
318         }else{
319             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.LOCATION_NOT_EXIST, OLELoaderConstants.OLEloaderStatus.LOCATION_NOT_EXIST);
320         }
321     }
322 
323     @Override
324     public Object exportLocationByCode(String locationCode) {
325         LOG.info("Inside exportLocationByCode method.");
326         OleLocation oleLocation = oleLocationLoaderHelperService.getLocationByCode(locationCode);
327         if(oleLocation != null){
328             return oleLocation;
329         }else{
330             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.LOCATION_NOT_EXIST, OLELoaderConstants.OLEloaderStatus.LOCATION_NOT_EXIST);
331         }
332     }
333 
334     @Override
335     public List<OleLocation> exportAllLocations(HttpContext context) {
336         LOG.info("Inside exportAllLocation method.");
337         List<OleLocation> oleLocationList = oleLocationLoaderHelperService.getAllLocation();
338         return oleLocationList;
339     }
340 
341     @Override
342     public boolean validateLocationBo(OLELocationBo oleLocationBo) {
343         boolean valid = true;
344         if(StringUtils.isBlank(oleLocationBo.getLocationId()) && StringUtils.isBlank(oleLocationBo.getLocationCode()) &&
345                 StringUtils.isBlank(oleLocationBo.getLocationLevelId()) && StringUtils.isBlank(oleLocationBo.getLocationName()) &&
346                 StringUtils.isBlank(oleLocationBo.getParentLocationId())){
347             valid = false;
348         }
349         return valid;
350     }
351 
352     @Override
353     public Object exportLocationLevelById(String locationLevelId) {
354         LOG.info("Inside exportLocationLevelById method.");
355         OleLocationLevel oleLocationLevel = oleLocationLoaderHelperService.getLocationLevelById(locationLevelId);
356         if(oleLocationLevel != null){
357             return oleLocationLevel;
358         }else{
359             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.LOCATION_LEVEL_NOT_EXIST, OLELoaderConstants.OLEloaderStatus.LOCATION_LEVEL_NOT_EXIST);
360         }
361     }
362 
363     @Override
364     public Object exportLocationLevelByCode(String locationLevelCode) {
365         LOG.info("Inside exportLocationLevelByCdde method.");
366         OleLocationLevel oleLocationLevel = oleLocationLoaderHelperService.getLocationLevelByCode(locationLevelCode);
367         if(oleLocationLevel != null){
368             return oleLocationLevel;
369         }else{
370             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.LOCATION_LEVEL_NOT_EXIST, OLELoaderConstants.OLEloaderStatus.LOCATION_LEVEL_NOT_EXIST);
371         }
372     }
373 
374     @Override
375     public List<OleLocationLevel> exportAllLocationLevels(HttpContext context) {
376         List<OleLocationLevel> oleLocationLevelList = oleLocationLoaderHelperService.getAllLocationLevel();
377         return oleLocationLevelList;
378     }
379 
380     @Override
381     public Object importLocationLevels(String bodyContent, HttpContext context) {
382         LOG.info("Inside importLocations method.");
383         OLELoaderImportResponseBo oleLoaderImportResponseBo = new OLELoaderImportResponseBo();
384         List<Integer> rejectLocationLevelList = new ArrayList<Integer>();
385         List<JSONObject> createdLocationLevelObject = new ArrayList<JSONObject>();
386         JSONObject requestJsonObject = getOleLoaderService().getJsonObjectFromString(bodyContent);
387         boolean validObject = false;
388         if(requestJsonObject != null) {
389             if (requestJsonObject.has("items")) {
390                 String items = getOleLoaderService().getStringValueFromJsonObject(requestJsonObject, "items");
391                 if (StringUtils.isNotBlank(items)) {
392                     JSONArray locationJsonArray = getOleLoaderService().getJsonArrayFromString(items);
393                     for (int index = 0; index < locationJsonArray.length(); index ++) {
394                         JSONObject jsonObject = null;
395                         OleLocationLevel oleLocationLevel = new OleLocationLevel();
396                         try {
397                             jsonObject = (JSONObject)locationJsonArray.get(index);
398                             if(jsonObject != null){
399                                 if(jsonObject.has("name")){
400                                     String name = getOleLoaderService().getStringValueFromJsonObject(jsonObject,"name");
401                                     if(StringUtils.isNotBlank(name)){
402                                         oleLocationLevel.setLevelName(name);
403                                         validObject = true;
404                                     }
405                                 }
406                                 if(jsonObject.has("code")){
407                                     String code = getOleLoaderService().getStringValueFromJsonObject(jsonObject,"code");
408                                     if(StringUtils.isNotBlank(code)){
409                                         oleLocationLevel.setLevelCode(code);
410                                         validObject = true;
411                                     }
412                                 }
413                                 if(jsonObject.has("parent")){
414                                     JSONObject parentJsonObject = getOleLoaderService().getJsonObjectFromString(getOleLoaderService().getStringValueFromJsonObject(jsonObject,"parent"));
415                                     if(parentJsonObject != null){
416                                         String parentUrl = getOleLoaderService().getStringValueFromJsonObject(parentJsonObject,"@id");
417                                         if(StringUtils.isNotBlank(parentUrl)){
418                                             Map<String,Object> restResponseMap = OLELoaderRestClient.jerseryClientGet(parentUrl);
419                                             if((Integer)restResponseMap.get("status")== 200){
420                                                 String parentResponseContent = (String)restResponseMap.get("content");
421                                                 JSONObject parentResponseObject = getOleLoaderService().getJsonObjectFromString(parentResponseContent);
422                                                 if(parentResponseObject != null){
423                                                     String urlId = getOleLoaderService().getStringValueFromJsonObject(parentResponseObject,"@id");
424                                                     if(StringUtils.isNotBlank(urlId)){
425                                                         String parentId = urlId.substring(urlId.indexOf("/api/locationLevel/")+19);
426                                                         oleLocationLevel.setParentLevelId(parentId);
427                                                         validObject = true;
428                                                     }
429                                                 }else{
430                                                     rejectLocationLevelList.add(index+1);
431                                                     continue;
432                                                 }
433                                             }else{
434                                                 rejectLocationLevelList.add(index+1);
435                                                 continue;
436                                             }
437 
438 
439                                         }
440                                     }
441                                 }
442                             }
443                             if(oleLocationLevel != null && validObject){
444                                 if(oleLocationLoaderHelperService.getLocationLevelByCode(oleLocationLevel.getLevelCode()) == null){
445                                     OleLocationLevel parentLocationLevel = oleLocationLoaderHelperService.getLocationLevelById(oleLocationLevel.getParentLevelId());
446                                     if (parentLocationLevel == null) {
447                                         rejectLocationLevelList.add(index+1);
448                                         continue;
449                                     }else {
450                                         try {
451                                             oleLocationLevel.setOleLocationLevel(parentLocationLevel);
452                                             oleLocationLevel = getBusinessObjectService().save(oleLocationLevel);
453                                             createdLocationLevelObject.add((JSONObject)oleLocationLoaderHelperService.formLocationLevelExportResponse(oleLocationLevel, OLELoaderConstants.OLELoaderContext.LOCATION_LEVEL,
454                                                     context.getRequest().getRequestUri().toASCIIString(), false));
455                                         } catch (Exception e) {
456                                             rejectLocationLevelList.add(index+1);
457                                             continue;
458                                         }
459                                     }
460                                 }else{
461                                     rejectLocationLevelList.add(index+1);
462                                     continue;
463                                 }
464 
465 
466                             }else{
467                                 rejectLocationLevelList.add(index+1);
468                                 continue;
469                             }
470                         } catch (JSONException e) {
471                             e.printStackTrace();
472                             rejectLocationLevelList.add(index+1);
473                             continue;
474                         }
475                     }
476                 }else{
477                     return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
478                 }
479 
480             }
481         }else{
482             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
483         }
484         oleLoaderImportResponseBo.setOleRejectedBos(rejectLocationLevelList);
485         oleLoaderImportResponseBo.setOleCreatedBos(createdLocationLevelObject);
486         return oleLoaderImportResponseBo;
487     }
488 
489     @Override
490     public OLELoaderResponseBo updateLocationLevelById(String locationLevelId, String bodyContent, HttpContext context) {
491         LOG.info("Inside updateLocationLevelById method.");
492         OLELocationLevelBo oleLocationLevelBo = new OLELocationLevelBo();
493         JSONObject jsonObject = getOleLoaderService().getJsonObjectFromString(bodyContent);
494         boolean validObject = false;
495         if (jsonObject != null) {
496             if (jsonObject.has("name")) {
497                 String name = getOleLoaderService().getStringValueFromJsonObject(jsonObject, "name");
498                 if (StringUtils.isNotBlank(name)) {
499                     oleLocationLevelBo.setLevelName(name);
500                     validObject = true;
501                 }
502             }
503            /* if (jsonObject.has("code")) {
504                 String code = getOleLoaderService().getStringValueFromJsonObject(jsonObject, "code");
505                 if (StringUtils.isNotBlank(code)) {
506                     oleLocationLevelBo.setLevelCode(code);
507                     validObject = true;
508                 }
509             }*/
510             if (jsonObject.has("parent")) {
511                 JSONObject levelJsonObject = getOleLoaderService().getJsonObjectFromString(getOleLoaderService().getStringValueFromJsonObject(jsonObject, "parent"));
512                 if (levelJsonObject != null) {
513                     String levelUrl = getOleLoaderService().getStringValueFromJsonObject(levelJsonObject, "@id");
514                     if (StringUtils.isNotBlank(levelUrl)) {
515                         Map<String, Object> restResponseMap = OLELoaderRestClient.jerseryClientGet(levelUrl);
516                         if ((Integer) restResponseMap.get("status") == 200) {
517                             String parentLevelResponseContent = (String) restResponseMap.get("content");
518                             JSONObject parentLevelResponseObject = getOleLoaderService().getJsonObjectFromString(parentLevelResponseContent);
519                             if (parentLevelResponseObject != null) {
520                                 String urlId = getOleLoaderService().getStringValueFromJsonObject(parentLevelResponseObject, "@id");
521                                 if (StringUtils.isNotBlank(urlId)) {
522                                     String levelId = urlId.substring(urlId.indexOf("/api/locationLevel/") + 19);
523                                     oleLocationLevelBo.setParentLevelId(levelId);
524                                     validObject = true;
525                                 }
526                             } else {
527                                 return getOleLoaderService().generateResponse(
528                                         OLELoaderConstants.OLEloaderMessage.PARENT_LOCATION_LEVEL_NOT_EXIST,
529                                         OLELoaderConstants.OLEloaderStatus.PARENT_LOCATION_LEVEL_NOT_EXIST);
530                             }
531                         } else {
532                             return getOleLoaderService().generateResponse(
533                                     OLELoaderConstants.OLEloaderMessage.PARENT_LOCATION_LEVEL_NOT_EXIST,
534                                     OLELoaderConstants.OLEloaderStatus.PARENT_LOCATION_LEVEL_NOT_EXIST);
535                         }
536                     }
537                 }
538 
539             }
540 
541             if (oleLocationLevelBo != null && validObject) {
542                 OleLocationLevel oleLocationLevel = oleLocationLoaderHelperService.getLocationLevelById(locationLevelId);
543                 if (oleLocationLevel != null) {
544                     if (StringUtils.isNotBlank(oleLocationLevelBo.getParentLevelId())) {
545                         OleLocationLevel parentLocationLevel = oleLocationLoaderHelperService.getLocationLevelById(oleLocationLevelBo.getParentLevelId());
546                         if (parentLocationLevel != null) {
547                             oleLocationLevel.setOleLocationLevel(parentLocationLevel);
548                             oleLocationLevel.setParentLevelId(oleLocationLevelBo.getParentLevelId());
549                         } else {
550                             return getOleLoaderService().generateResponse(
551                                     OLELoaderConstants.OLEloaderMessage.PARENT_LOCATION_LEVEL_NOT_EXIST,
552                                     OLELoaderConstants.OLEloaderStatus.PARENT_LOCATION_LEVEL_NOT_EXIST);
553                         }
554                     }
555                     return oleLocationLoaderHelperService.updateOleLocationLevel(oleLocationLevel, oleLocationLevelBo, context);
556                 } else {
557                     return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.LOCATION_NOT_EXIST, OLELoaderConstants.OLEloaderStatus.LOCATION_NOT_EXIST);
558                 }
559             } else {
560                 return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
561             }
562         }else {
563             return getOleLoaderService().generateResponse(OLELoaderConstants.OLEloaderMessage.BAD_REQUEST, OLELoaderConstants.OLEloaderStatus.BAD_REQUEST);
564         }
565     }
566 
567 }