Skip to content

ProgrammerJaid/Java-Sync-Service

Repository files navigation

puzzle-4-xxl

Java Sync Service.

An API that reads CSV File and updates data into databse if new rows are found in CSV File.Key features:

  • Automatic Data gets uploaded on the database.

How to use?

This API uses your localhost:8080. To run the sync service use this url: http://localhost:8080/java-sync-service/api/startsync

The code accepts JSON object as to populate the CSV file the link to add new rows in CSV is: http://localhost:8080/java-sync-service/api/populate The JSON object can be provided in the following way:

{
    "time": "2018-08-23 04:25:29",
    "family": "ECOM_200",
    "product": "Clothes",
    "country": "Canada",
    "deviceType": "Mobile",
    "os": "iOS",
    "checkOutFailure": 2008.1457,
    "paymentAPIFailure": 2183.7807,
    "purchaseCount": 14984.9599,
    "revenue": 11564.4751
}

Its a lot of name-value pairs to write.So I have provided a link to ease the job just for testing purpose. We can use the following http://localhost:8080/java-sync-service/api/random to get random row to be uploaded just for checking purposes.

Once the data in provided Assignment sheet.csv is fully loaded the new data added can be seen database and we can retrieve it with using http://localhost:8080/java-sync-service/api/lastrecord.

The following are the screenshot of successful testing of endpoints in postman

To start the service. Screenshot (109)

To retrieve data and populate it, please note,use http://localhost:8080/java-sync-service/api/lastrecord.This can be used to checklast data in database. Screenshot (107)

We can use http://localhost:8080/java-sync-service/api/random to get random data, that can be used to populated just for testing. Screenshot (112)

Send the data to populate through POST method body in JSON format http://localhost:8080/java-sync-service/api/populate. Screenshot (108)


Once it starts syncing and all the data has been updated from csv file to database.When we try to populate with new data please wait 1 or half a minute to check lastRecord as the it will sync again in 2 minutes.The default batch value is set to 650 as it takes 100seconds to transfer from file to database. Screenshot (104)

MySQL script for creating database table is given below, helpful sql commands.

CREATE USER 'root'@'localhost' IDENTIFIED BY 'passingword';

GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'passingword';
create database csv_data;
use csv_data;

create table csv_table(id INT NOT NULL AUTO_INCREMENT,
givenTime VARCHAR(19) ,product_id INT,country INT,
check_failure Decimal(11,4),APIFailure Decimal(11,4),
purchase_count Decimal(11,4),revenue Decimal(11,4),
primary key(id));

select * from csv_table order by id desc limit 1;
drop table csv_table;

Please import this as a maven project. Any error in web.xml would be due difference in xmlns:xsi in project web.xml and in tomcat server web.xml just copy tomcat xmlns:xsi host name.Please place MySql Connector jar in your tomcat lib, details given in class heading in Application.java in package co.greendeck.businesslogic.

Thank you.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages