Dhanut / DroneService

DroneService is responsible to allow communication between clients and drones for medication items.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

There is a major new technology that is destined to be a disruptive force in the field of transportation: the drone. Just as the mobile phone allowed developing countries to leapfrog older technologies for personal communication, the drone has the potential to leapfrog traditional transportation infrastructure.

Useful drone functions include delivery of small items that are (urgently) needed in locations with difficult access.

Task description

We have a fleet of 10 drone. A drone is capable of carrying devices, other than cameras, and capable of delivering small loads. For our use case the load is medications.

A Drone has:

  • serial number (100 characters max);
  • model (Lightweight, Middleweight, Cruiserweight, Heavyweight);
  • weight limit (500gr max);
  • battery capacity (percentage);
  • state (IDLE, LOADING, LOADED, DELIVERING, DELIVERED, RETURNING).

Each Medication has:

  • name (allowed only letters, numbers, ‘-‘, ‘_’);
  • weight;
  • code (allowed only upper-case letters, underscore and numbers);
  • image (picture of the medication case).

Develop a service via REST API that allows clients to communicate with the drones (i.e. dispatch controller). The specific communicaiton with the drone is outside the scope of this task.

The service should allow:

  • registering a drone;
  • loading a drone with medication items;
  • checking loaded medication items for a given drone;
  • checking available drones for loading;
  • check drone battery level for a given drone;

Functional requirements

  • There is no need for UI;
  • Prevent the drone from being loaded with more weight that it can carry;
  • Prevent the drone from being in LOADING state if the battery level is below 25%;
  • Introduce a periodic task to check drones’ battery levels and create history/audit event log for this.

Non-functional requirements

  • Input/output data must be in JSON format;
  • Your project must be buildable and runnable;
  • Your project must have a README file with build/run/test instructions (use DB that can be run locally, e.g. in-memory, via container);
  • Required data must be preloaded in the database.
  • JUnit tests are optional but advisable (if you have time);
  • Advice: Show us how you work through your commit history.

Pre-Requirements Java 8 Database – H2 DB IntelliJ IDE Postman

Main Steps to Build and Run the project

  1. Clone the project through GitHub repo link -> https://github.com/Dhanut/DroneService.git

  2. Go to the file directory where you have cloned and go inside the repo and right click on the pom.xml file and open with IntelliJ.

image

  1. Setup the Java SDK for Java 1.8 and wait for few minutes until all maven dependencies downloaded in IntelliJ.

image

  1. Build the project and run the main Java class and ensure project is working without any error.

Pre-Inserted data to the H2 database

Once we run the application, using the data.sql file it will automatically insert the below data to H2 DB.

image

Testing the End Points via Postman

All the end points in this project are authenticated with the Basic Authentication. Therefore, username and password need to be configured in all the endpoints.

image

Username - admin

Password - admin

  1. Registering a drone

End Point - http://localhost:8888/api/demo/drone/register

Method – POST

Input - { "droneSerialNumber":"AB999000", "droneModel":"LIGHTWEIGHT", "droneWeight":"200", "droneBatteryCapacity":"50", "droneState":"IDLE" }

image

Response: -

image

  1. Load a drone with medications

Assumptions: -

  1. Loading drone should be available in the database.
  2. A Drone can be loaded if and only if it is in IDLE or LOADING state only.
  3. More than one medication can be loaded at the same time.
  4. Total weight of loading medications + drone weight should not be over 500g.
  5. Drone batter capacity should be over 25%.
  6. If the selected drone initially in LOADING state and once after the medications loaded and Total weight of loading medications + drone weight = 500g, then the state of Drone should be updated to LOADED state.
  7. Same medication item can be loaded for the same drone n times, if the above conditional checks pass.
  8. All medications that are going to load should be first available in medication table. And weight of medications always a pre-defined value. This will not change during the load stage even.
  9. During the medication load, the weight of drone in the database will be updated accordingly.

End Point - http://localhost:8888/api/demo/drone/load

Method – POST

Input - { "loadingDroneSerialNumber":"TR222783", "loadingTotalQuantity":2, "loadingDeliveryAddress":" No23, TownHall, Colombo", "loadingMedicationList":[{ "medicationCode" : "001_AT_77", "medicationName": "ZIAGEN", "medicationWeight": 5.00, "medicationImage": "ZIAGEN" }, { "medicationCode" : "002_ZXT_12", "medicationName": "PLENAXIS", "medicationWeight": 1.00, "medicationImage": "PLENAXIS" } ]

}

image

Response: -

image

  1. Checking loaded medications

End Point - http://localhost:8888/api/demo/drone/check/medications/TR222783

Method – GET

Input - Path param – {drone_serial_number}

image

Response: -

image

  1. Checking available drones Assumption: Drone can be available if it is in IDLE or LOADING state only.

End Point - http://localhost:8888/api/demo/drone/check/available

Method – GET

Input - Path param – NA

image

Response: -

image

  1. Checking battery level of drones

End Point - http://localhost:8888/api/demo/drone/check/batteryLevel/AB999000

Method – GET

Input - Path param – Path param – {drone_serial_number}

image

Response: -

image

###logging the battery level of each drone in database using a scheduler

image

###SNAP SHOT of H2 DATABASE

image

###JUNIT coverage of the project

image ##END

About

DroneService is responsible to allow communication between clients and drones for medication items.


Languages

Language:Java 100.0%