Skip to content

orca-scan/orca-validation-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

orca-validation-java

Example of how to validate barcode scans in real-time in using Java and Spring boot framework.

Install

First ensure you have Java and Maven installed.

Then execute the following:

# download this example code
git clone https://github.com/orca-scan/orca-validation-java.git

# go into the new directory
cd orca-validation-java

# install dependecies
mvn package

Run

# start the project
mvn spring-boot:run

Your server will now be running on port 8080.

You can emulate an Orca Scan Validation input using cURL by running the following:

curl --location --request POST 'http://127.0.0.1:8080/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "___orca_sheet_name": "Vehicle Checks",
    "___orca_user_email": "hidden@requires.https",
    "Barcode": "orca-scan-test",
    "Date": "2022-04-19T16:45:02.851Z",
    "Name": "Orca Scan Validation"
}'

Important things to note

  1. Only Orca Scan system fields start with ___
  2. Properties in the JSON payload are an exact match to the field names in your sheet (case and space)

How this example works

This example uses the srping boot framework:

Validation example

@RequestMapping(
    value = "/", 
    method = RequestMethod.POST)
ResponseEntity<String> index(@RequestBody Map<String, Object> data)  throws Exception {

    // debug purpose: show in console raw data received
    System.out.println(data);

    // NOTE:
    // orca system fields start with ___
    // you can access the value of each field using the field name (data.get("Name"), data.get("Barcode"), data.get("Location")
    String name = data.get("Name").toString();

    // validation example
    if (name.length() > 20){
        // return error message
        JSONObject json = new JSONObject();
        json.put("title", "Invalid Name");
        json.put("message", "Name cannot contain more than 20 characters");

        return new ResponseEntity<>(json.toJSONString(), HttpStatus.OK);
    }

    // return HTTP Status 200 with no body
    return new ResponseEntity<>("", HttpStatus.OK);
}

Test server against Orca Cloud

To expose the server securely from localhost and test it easily agaisnt the real Orca Cloud environment you can use Secure Tunnels. Take a look at Ngrok or Cloudflare.

ngrok http 8080

Troubleshooting

If you run into any issues not listed here, please open a ticket.

Examples in other langauges

History

For change-log, check releases.

License

© Orca Scan, the Barcode Scanner app for iOS and Android.

About

How to validate barcode scans using Orca Scan and Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages