@RequestMapping(method = RequestMethod.POST) @ResponseBody public ResponseEntity<?> post(@RequestBody String inputString) { Configuration.logger.info(" EPCIS Masterdata Document Capture Started.... "); if (Configuration.isCaptureVerfificationOn == true) { // JSONParser parser = new JSONParser(); JsonSchemaLoader schemaLoader = new JsonSchemaLoader(); try { JSONObject jsonVocabulary = new JSONObject(inputString); JSONObject jsonVocabularySchema = schemaLoader.getMasterDataSchema(); if (!CaptureUtil.validate(jsonVocabulary, jsonVocabularySchema)) { Configuration.logger.info("Json Document is invalid" + " about master_data_validcheck"); return new ResponseEntity<>( new String("Error: EPCIS Masterdata Document is not validated"), HttpStatus.BAD_REQUEST); } JSONArray jsonVocabularyList = jsonVocabulary .getJSONObject("epcismd") .getJSONObject("EPCISBody") .getJSONArray("VocabularyList"); for (int i = 0; i < jsonVocabularyList.length(); i++) { JSONArray jsonVocabularyElementList = jsonVocabularyList.getJSONObject(i).getJSONArray("Vocabulary"); for (int j = 0; j < jsonVocabularyElementList.length(); j++) { if (Configuration.backend.equals("MongoDB")) { MasterDataWriteConverter mdConverter = new MasterDataWriteConverter(); mdConverter.capture(jsonVocabularyElementList.getJSONObject(j)); Configuration.logger.info(" EPCIS Masterdata Document : Captured "); } } } } catch (JSONException e) { Configuration.logger.info(" Json Document is not valid "); } catch (Exception e) { Configuration.logger.log(Level.ERROR, e.toString()); } } else { JSONObject jsonVocabulary = new JSONObject(inputString); JSONArray jsonVocabularyList = jsonVocabulary .getJSONObject("epcismd") .getJSONObject("EPCISBody") .getJSONArray("VocabularyList"); for (int i = 0; i < jsonVocabularyList.length(); i++) { JSONArray jsonVocabularyElementList = jsonVocabularyList.getJSONObject(i).getJSONArray("Vocabulary"); for (int j = 0; j < jsonVocabularyElementList.length(); j++) { if (Configuration.backend.equals("MongoDB")) { MasterDataWriteConverter mdConverter = new MasterDataWriteConverter(); mdConverter.capture(jsonVocabularyElementList.getJSONObject(i)); Configuration.logger.info(" EPCIS Masterdata Document : Captured "); } } /* startpoint of validation logic for Vocabulary */ } } return new ResponseEntity<>(new String("EPCIS Masterdata Document : Captured"), HttpStatus.OK); }
public BsonDocument asBsonDocument() { CaptureUtil util = new CaptureUtil(); BsonDocument objectEvent = super.asBsonDocument(); // Required Fields objectEvent = util.putAction(objectEvent, action); // Optional Fields if (this.epcList != null && this.epcList.size() != 0) { objectEvent = util.putEPCList(objectEvent, epcList); } if (this.bizStep != null) { objectEvent = util.putBizStep(objectEvent, bizStep); } if (this.disposition != null) { objectEvent = util.putDisposition(objectEvent, disposition); } if (this.readPoint != null) { objectEvent = util.putReadPoint(objectEvent, readPoint); } if (this.bizLocation != null) { objectEvent = util.putBizLocation(objectEvent, bizLocation); } if (this.bizTransactionList != null && this.bizTransactionList.isEmpty() == false) { objectEvent = util.putBizTransactionList(objectEvent, bizTransactionList); } if (this.ilmds != null && this.ilmds.isEmpty() == false) { objectEvent = util.putILMD(objectEvent, namespaces, ilmds); } if (this.extensions != null && this.extensions.isEmpty() == false) { objectEvent = util.putExtensions(objectEvent, namespaces, extensions); } BsonDocument extension = new BsonDocument(); if (this.quantityList != null && this.quantityList.isEmpty() == false) { extension = util.putQuantityList(extension, quantityList); } if (this.sourceList != null && this.sourceList.isEmpty() == false) { extension = util.putSourceList(extension, sourceList); } if (this.destinationList != null && this.destinationList.isEmpty() == false) { extension = util.putDestinationList(extension, destinationList); } if (extension.isEmpty() == false) objectEvent.put("extension", extension); return objectEvent; }