diff --git a/Doc/DiagramadeGantt.pdf b/Doc/DiagramadeGantt.pdf new file mode 100644 index 0000000..b53db27 Binary files /dev/null and b/Doc/DiagramadeGantt.pdf differ diff --git a/Doc/SRSv4.docx b/Doc/SRSv4.docx new file mode 100644 index 0000000..ce72a14 Binary files /dev/null and b/Doc/SRSv4.docx differ diff --git a/Doc/carsapp.jpg b/Doc/carsapp.jpg new file mode 100644 index 0000000..143f9ce Binary files /dev/null and b/Doc/carsapp.jpg differ diff --git a/Doc/salida.pdf b/Doc/salida.pdf new file mode 100644 index 0000000..b53db27 Binary files /dev/null and b/Doc/salida.pdf differ diff --git a/Doc/srsv1.docx b/Doc/srsv1.docx new file mode 100644 index 0000000..b94161d Binary files /dev/null and b/Doc/srsv1.docx differ diff --git a/Doc/srsv2.docx b/Doc/srsv2.docx new file mode 100644 index 0000000..9e919c7 Binary files /dev/null and b/Doc/srsv2.docx differ diff --git a/Doc/srsv3.docx b/Doc/srsv3.docx new file mode 100644 index 0000000..7eedf9e Binary files /dev/null and b/Doc/srsv3.docx differ diff --git a/README.md b/README.md index 9c66bad..6271f3c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Cars web app +HOLA!Cars web app ============ It's a web application used in a course of [Software Engineering] [se-site] in the [UNRC] [unrc] to teach concepts as diff --git a/config/insert.sql b/config/insert.sql new file mode 100644 index 0000000..a017833 --- /dev/null +++ b/config/insert.sql @@ -0,0 +1,4 @@ +insert into carsapp_development.users (first_name,last_name,email,contrasena)values +("juan","perez","juanp@hotmail.com","aaa"), +("pablo","gonzales","pg@hotmail.com","bbb"), +("fulano","asddd","fulanoa@hotmail.com","ccc"); \ No newline at end of file diff --git a/config/schema.sql b/config/schema.sql index 6b5a6b4..14551e7 100644 --- a/config/schema.sql +++ b/config/schema.sql @@ -1,10 +1,137 @@ --- Integrantes: W - X - Y - Z - -DROP TABLE IF EXISTS users; -- Usuarios -CREATE TABLE users( - id INT(11) NOT NULL AUTO_INCREMENT, - email VARCHAR(60) UNIQUE, - first_name VARCHAR(56), - last_name VARCHAR(56), - CONSTRAINT users_pk PRIMARY KEY (id) -); +-- Integrantes: Emiliano Guttlein - Santiago Lapiana - Jorge Avedaño - Nicolas Boccolini +DROP schema if exists carsapp_development; +create schema carsapp_development; + + +DROP TABLE IF EXISTS carsapp_development.users; +CREATE TABLE carsapp_development.users( + id_user INT(11) NOT NULL AUTO_INCREMENT, + email VARCHAR(60) UNIQUE, + first_name VARCHAR(56), + last_name VARCHAR(56), + contrasena VARCHAR(60), + CONSTRAINT pk_users PRIMARY KEY (id_user)); + +DROP TABLE IF EXISTS carsapp_development.addresses; +CREATE TABLE carsapp_development.addresses( + id_address INT(11) NOT NULL AUTO_INCREMENT, + street varchar(56) NOT NULL, + city varchar(56), + province varchar(56), + postal_code varchar(6), + num INT(10), + CONSTRAINT pk_addresses PRIMARY KEY (id_address)); + +DROP TABLE IF EXISTS carsapp_development.users_addresses; +CREATE TABLE carsapp_development.users_addresses( + id_users_address INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + id_address INT(11), + CONSTRAINT pk_users_address PRIMARY KEY (id_users_address)); + -- CONSTRAINT fk_addresses FOREIGN KEY (id_addresss) REFERENCES address (id_addresses) ON DELETE CASCADE ON UPDATE CASCADE); + -- CONSTRAINT fk_users FOREIGN KEY (id_user) REFERENCES users (id_users) ON DELETE CASCADE ON UPDATE CASCADE); + +DROP TABLE IF EXISTS carsapp_development.vehicles; +CREATE TABLE carsapp_development.vehicles( + id_vehicle INT NOT NULL AUTO_INCREMENT, + patent VARCHAR(60), + mark VARCHAR(56), + model VARCHAR(56), + id_user INT(11), + color VARCHAR(20), + tipo VARCHAR(20), + cc INT(20), + isCoupe VARCHAR(10), + capacity INT(20), + CONSTRAINT pk_vehicle PRIMARY KEY (id_vehicle)); + -- CONSTRAINT fk_vehicle_user FOREIGN KEY (id_user) REFERENCES users(id_users)); + +-- DROP TABLE IF EXISTS carsapp_development.cars; +-- CREATE TABLE carsapp_development.cars ( + -- id_cars INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- isCoupe BOOL, + -- CONSTRAINT pk_cars PRIMARY KEY (id_cars)); + -- CONSTRAINT fk_cars_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + +-- DROP TABLE IF EXISTS carsapp_development.motocicles; +-- CREATE TABLE carsapp_development.motocicles ( + -- id_motocicles INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- cc INT, + -- CONSTRAINT pk_motocicles PRIMARY KEY (id_motocicles)); + -- CONSTRAINT fk_motocicles_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + + +-- DROP TABLE IF EXISTS carsapp_development.trucks; +-- CREATE TABLE carsapp_development.trucks ( + -- id_trucks INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- capacity VARCHAR(20), + -- CONSTRAINT pk_trucks PRIMARY KEY (id_trucks)); + -- CONSTRAINT fk_trucks_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + + +-- DROP TABLE IF EXISTS carsapp_development.others; +-- CREATE TABLE carsapp_development.others ( + -- id_others INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- transmission VARCHAR(12), + -- CONSTRAINT pk_others PRIMARY KEY (id_others)); + -- CONSTRAINT fk_others_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + +DROP TABLE IF EXISTS carsapp_development.answers; +CREATE TABLE carsapp_development.answers( + id_answer INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + description VARCHAR(3000), + id_question INT(11), + CONSTRAINT pk_answers PRIMARY KEY (id_answer)); + -- CONSTRAINT fk_answers_questions FOREIGN KEY (id_question) REFERENCES questions(id_question), + -- CONSTRAINT fk_user_answers FOREIGN KEY (id_user) REFERENCES users(id_users)); + +DROP TABLE IF EXISTS carsapp_development.questions; +CREATE TABLE carsapp_development.questions( + id_question INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + id_post INT(11), + description VARCHAR(3000), + CONSTRAINT pk_question PRIMARY KEY (id_question)); + -- CONSTRAINT fk_posts_questions foreign key (id_post) REFERENCES posts(id_post) ON DELETE CASCADE ON UPDATE CASCADE, + -- CONSTRAINT fk_answers_questions FOREIGN KEY (id_answer) REFERENCES answers(id_answers) ON DELETE CASCADE ON UPDATE CASCADE, + -- CONSTRAINT fk_users_questions FOREIGN KEY (id_user) REFERENCES users(id_users) ON DELETE CASCADE ON UPDATE CASCADE); + + +DROP TABLE IF EXISTS carsapp_development.posts; +CREATE TABLE carsapp_development.posts( + id_post INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + id_address INT(11), + patent VARCHAR(60), + description VARCHAR(3000), + CONSTRAINT pk_posts PRIMARY KEY (id_post)); + -- CONSTRAINT fk_user_post FOREIGN KEY (id_user) REFERENCES users (id_users), + -- CONSTRAINT fk_vehicle_post FOREIGN KEY (patent) REFERENCES vehicles (patents)); + +DROP TABLE IF EXISTS carsapp_development.messages; +CREATE TABLE carsapp_development.messages( + id_message INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + description VARCHAR(3000), + CONSTRAINT pk_message PRIMARY KEY (id_message)); + +DROP TABLE IF EXISTS carsapp_development.message_guests; +CREATE TABLE carsapp_development.message_guests( + id_messageGuest INT(11) NOT NULL AUTO_INCREMENT, + description VARCHAR(3000), + CONSTRAINT pk_messageGuest PRIMARY KEY (id_messageGuest)); + +-- DROP TABLE IF EXISTS carsapp_development.qualify; +-- CREATE TABLE carsapp_development.qualify( + -- id_qualify INT(11) NOT NULL AUTO_INCREMENT, + -- id_post INT(11), + -- id_user INT(11), + -- points INT, + -- CONSTRAINT pk_qualify PRIMARY KEY (id_qualify)); + -- CONSTRAINT fk_posts_qualify FOREIGN KEY (id_post) REFERENCES posts(id_posts), + -- CONSTRAINT fk_users_qualify FOREIGN KEY (id_user) REFERENCES users(id_users)); diff --git a/config/schema_test.sql b/config/schema_test.sql new file mode 100644 index 0000000..3a13835 --- /dev/null +++ b/config/schema_test.sql @@ -0,0 +1,130 @@ +-- Integrantes: Emiliano Guttlein - Santiago Lapiana - Jorge Avedaño - Nicolas Boccolini +DROP schema if exists carsapp_test; +create schema carsapp_test; + + +DROP TABLE IF EXISTS carsapp_test.users; +CREATE TABLE carsapp_test.users( + id_user INT(11) NOT NULL AUTO_INCREMENT, + email VARCHAR(60) UNIQUE, + first_name VARCHAR(56), + last_name VARCHAR(56), + contrasena VARCHAR(60), + CONSTRAINT pk_users PRIMARY KEY (id_user)); + +DROP TABLE IF EXISTS carsapp_test.addresses; +CREATE TABLE carsapp_test.addresses( + id_address INT(11) NOT NULL AUTO_INCREMENT, + street varchar(56) NOT NULL, + city varchar(56), + province varchar(56), + postal_code varchar(6), + num INT(10), + CONSTRAINT pk_addresses PRIMARY KEY (id_address)); + +DROP TABLE IF EXISTS carsapp_test.users_addresses; +CREATE TABLE carsapp_test.users_addresses( + id_users_address INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + id_address INT(11), + CONSTRAINT pk_users_address PRIMARY KEY (id_users_address)); + -- CONSTRAINT fk_addresses FOREIGN KEY (id_addresss) REFERENCES address (id_addresses) ON DELETE CASCADE ON UPDATE CASCADE); + -- CONSTRAINT fk_users FOREIGN KEY (id_user) REFERENCES users (id_users) ON DELETE CASCADE ON UPDATE CASCADE); + +DROP TABLE IF EXISTS carsapp_test.vehicles; +CREATE TABLE carsapp_test.vehicles( + id_vehicle INT NOT NULL AUTO_INCREMENT, + patent VARCHAR(60), + mark VARCHAR(56), + model VARCHAR(56), + id_user INT(11), + color VARCHAR(20), + tipo VARCHAR(20), + cc INT(20), + isCoupe VARCHAR(10), + capacity INT(20), + CONSTRAINT pk_vehicle PRIMARY KEY (id_vehicle)); + -- CONSTRAINT fk_vehicle_user FOREIGN KEY (id_user) REFERENCES users(id_users)); + +-- DROP TABLE IF EXISTS carsapp_test.cars; +-- CREATE TABLE carsapp_test.cars ( + -- id_cars INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- isCoupe BOOL, + -- CONSTRAINT pk_cars PRIMARY KEY (id_cars)); + -- CONSTRAINT fk_cars_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + +-- DROP TABLE IF EXISTS carsapp_test.motocicles; +-- CREATE TABLE carsapp_test.motocicles ( + -- id_motocicles INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- cc INT, + -- CONSTRAINT pk_motocicles PRIMARY KEY (id_motocicles)); + -- CONSTRAINT fk_motocicles_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + + +-- DROP TABLE IF EXISTS carsapp_test.trucks; +-- CREATE TABLE carsapp_test.trucks ( + -- id_trucks INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- capacity VARCHAR(20), + -- CONSTRAINT pk_trucks PRIMARY KEY (id_trucks)); + -- CONSTRAINT fk_trucks_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + + +-- DROP TABLE IF EXISTS carsapp_test.others; +-- CREATE TABLE carsapp_test.others ( + -- id_others INT(11) NOT NULL AUTO_INCREMENT, + -- patent VARCHAR(60), + -- transmission VARCHAR(12), + -- CONSTRAINT pk_others PRIMARY KEY (id_others)); + -- CONSTRAINT fk_others_vehicle FOREIGN KEY (patent) REFERENCES vehicles (patents) ON DELETE CASCADE ON UPDATE CASCADE); + +DROP TABLE IF EXISTS carsapp_test.answers; +CREATE TABLE carsapp_test.answers( + id_answer INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + description VARCHAR(3000), + id_question INT(11), + CONSTRAINT pk_answers PRIMARY KEY (id_answer)); + -- CONSTRAINT fk_answers_questions FOREIGN KEY (id_question) REFERENCES questions(id_question), + -- CONSTRAINT fk_user_answers FOREIGN KEY (id_user) REFERENCES users(id_users)); + +DROP TABLE IF EXISTS carsapp_test.questions; +CREATE TABLE carsapp_test.questions( + id_question INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + id_post INT(11), + description VARCHAR(3000), + CONSTRAINT pk_question PRIMARY KEY (id_question)); + -- CONSTRAINT fk_posts_questions foreign key (id_post) REFERENCES posts(id_post) ON DELETE CASCADE ON UPDATE CASCADE, + -- CONSTRAINT fk_answers_questions FOREIGN KEY (id_answer) REFERENCES answers(id_answers) ON DELETE CASCADE ON UPDATE CASCADE, + -- CONSTRAINT fk_users_questions FOREIGN KEY (id_user) REFERENCES users(id_users) ON DELETE CASCADE ON UPDATE CASCADE); + + +DROP TABLE IF EXISTS carsapp_test.posts; +CREATE TABLE carsapp_test.posts( + id_post INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + patent VARCHAR(60), + description VARCHAR(3000), + CONSTRAINT pk_posts PRIMARY KEY (id_post)); + -- CONSTRAINT fk_user_post FOREIGN KEY (id_user) REFERENCES users (id_users), + -- CONSTRAINT fk_vehicle_post FOREIGN KEY (patent) REFERENCES vehicles (patents)); + +DROP TABLE IF EXISTS carsapp_test.messages; +CREATE TABLE carsapp_test.messages( + id_message INT(11) NOT NULL AUTO_INCREMENT, + id_user INT(11), + description VARCHAR(3000), + CONSTRAINT pk_message PRIMARY KEY (id_message)); + +-- DROP TABLE IF EXISTS carsapp_test.qualify; +-- CREATE TABLE carsapp_test.qualify( + -- id_qualify INT(11) NOT NULL AUTO_INCREMENT, + -- id_post INT(11), + -- id_user INT(11), + -- points INT, + -- CONSTRAINT pk_qualify PRIMARY KEY (id_qualify)); + -- CONSTRAINT fk_posts_qualify FOREIGN KEY (id_post) REFERENCES posts(id_posts), + -- CONSTRAINT fk_users_qualify FOREIGN KEY (id_user) REFERENCES users(id_users)); \ No newline at end of file diff --git a/data/carsapp/nodes/0/_state/global-35 b/data/carsapp/nodes/0/_state/global-35 new file mode 100644 index 0000000..d0a8f47 --- /dev/null +++ b/data/carsapp/nodes/0/_state/global-35 @@ -0,0 +1,2 @@ +:) +úˆmeta-dataú†version$†ƒuuidUzS0qa5c4R2q08wkGOoomOgˆtemplatesúûûû \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/users/0/_state/state-70 b/data/carsapp/nodes/0/indices/users/0/_state/state-70 new file mode 100644 index 0000000..070b370 --- /dev/null +++ b/data/carsapp/nodes/0/indices/users/0/_state/state-70 @@ -0,0 +1,4 @@ +{ + "version" : 70, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/users/0/index/_0.cfe b/data/carsapp/nodes/0/indices/users/0/index/_0.cfe new file mode 100644 index 0000000..ad5961f Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/_0.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/_0.cfs b/data/carsapp/nodes/0/indices/users/0/index/_0.cfs new file mode 100644 index 0000000..5055911 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/_0.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/_0.si b/data/carsapp/nodes/0/indices/users/0/index/_0.si new file mode 100644 index 0000000..9567b3e Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/_0.si differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/_1.cfe b/data/carsapp/nodes/0/indices/users/0/index/_1.cfe new file mode 100644 index 0000000..f4cdeca Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/_1.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/_1.cfs b/data/carsapp/nodes/0/indices/users/0/index/_1.cfs new file mode 100644 index 0000000..75f5158 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/_1.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/_1.si b/data/carsapp/nodes/0/indices/users/0/index/_1.si new file mode 100644 index 0000000..98b13e0 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/_1.si differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/_checksums-1403464939629 b/data/carsapp/nodes/0/indices/users/0/index/_checksums-1403464939629 new file mode 100644 index 0000000..972b8ab Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/_checksums-1403464939629 differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/segments.gen b/data/carsapp/nodes/0/indices/users/0/index/segments.gen new file mode 100644 index 0000000..e9fa600 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/segments_3 b/data/carsapp/nodes/0/indices/users/0/index/segments_3 new file mode 100644 index 0000000..9e8de11 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/0/index/segments_3 differ diff --git a/data/carsapp/nodes/0/indices/users/0/index/write.lock b/data/carsapp/nodes/0/indices/users/0/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/0/translog/translog-1403392443002 b/data/carsapp/nodes/0/indices/users/0/translog/translog-1403392443002 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/1/_state/state-70 b/data/carsapp/nodes/0/indices/users/1/_state/state-70 new file mode 100644 index 0000000..070b370 --- /dev/null +++ b/data/carsapp/nodes/0/indices/users/1/_state/state-70 @@ -0,0 +1,4 @@ +{ + "version" : 70, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/users/1/index/_0.cfe b/data/carsapp/nodes/0/indices/users/1/index/_0.cfe new file mode 100644 index 0000000..55d159a Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_0.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_0.cfs b/data/carsapp/nodes/0/indices/users/1/index/_0.cfs new file mode 100644 index 0000000..61f4f4e Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_0.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_0.si b/data/carsapp/nodes/0/indices/users/1/index/_0.si new file mode 100644 index 0000000..b7bceaf Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_0.si differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_1.cfe b/data/carsapp/nodes/0/indices/users/1/index/_1.cfe new file mode 100644 index 0000000..2b39ba5 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_1.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_1.cfs b/data/carsapp/nodes/0/indices/users/1/index/_1.cfs new file mode 100644 index 0000000..2783e8d Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_1.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_1.si b/data/carsapp/nodes/0/indices/users/1/index/_1.si new file mode 100644 index 0000000..43c0b0c Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_1.si differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_2.cfe b/data/carsapp/nodes/0/indices/users/1/index/_2.cfe new file mode 100644 index 0000000..8f7a25d Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_2.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_2.cfs b/data/carsapp/nodes/0/indices/users/1/index/_2.cfs new file mode 100644 index 0000000..092dd57 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_2.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_2.si b/data/carsapp/nodes/0/indices/users/1/index/_2.si new file mode 100644 index 0000000..d859a0e Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_2.si differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/_checksums-1403567697285 b/data/carsapp/nodes/0/indices/users/1/index/_checksums-1403567697285 new file mode 100644 index 0000000..d760856 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/_checksums-1403567697285 differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/segments.gen b/data/carsapp/nodes/0/indices/users/1/index/segments.gen new file mode 100644 index 0000000..f142fa9 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/segments_4 b/data/carsapp/nodes/0/indices/users/1/index/segments_4 new file mode 100644 index 0000000..ac1ccfe Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/1/index/segments_4 differ diff --git a/data/carsapp/nodes/0/indices/users/1/index/write.lock b/data/carsapp/nodes/0/indices/users/1/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/1/translog/translog-1403392443001 b/data/carsapp/nodes/0/indices/users/1/translog/translog-1403392443001 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/2/_state/state-70 b/data/carsapp/nodes/0/indices/users/2/_state/state-70 new file mode 100644 index 0000000..070b370 --- /dev/null +++ b/data/carsapp/nodes/0/indices/users/2/_state/state-70 @@ -0,0 +1,4 @@ +{ + "version" : 70, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/users/2/index/_0.cfe b/data/carsapp/nodes/0/indices/users/2/index/_0.cfe new file mode 100644 index 0000000..943b268 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/_0.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/_0.cfs b/data/carsapp/nodes/0/indices/users/2/index/_0.cfs new file mode 100644 index 0000000..25bb7b2 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/_0.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/_0.si b/data/carsapp/nodes/0/indices/users/2/index/_0.si new file mode 100644 index 0000000..cf0f94f Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/_0.si differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/_1.cfe b/data/carsapp/nodes/0/indices/users/2/index/_1.cfe new file mode 100644 index 0000000..61cc377 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/_1.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/_1.cfs b/data/carsapp/nodes/0/indices/users/2/index/_1.cfs new file mode 100644 index 0000000..b907f46 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/_1.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/_1.si b/data/carsapp/nodes/0/indices/users/2/index/_1.si new file mode 100644 index 0000000..4cfba6b Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/_1.si differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/_checksums-1403396978024 b/data/carsapp/nodes/0/indices/users/2/index/_checksums-1403396978024 new file mode 100644 index 0000000..c5fcf69 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/_checksums-1403396978024 differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/segments.gen b/data/carsapp/nodes/0/indices/users/2/index/segments.gen new file mode 100644 index 0000000..e9fa600 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/segments_3 b/data/carsapp/nodes/0/indices/users/2/index/segments_3 new file mode 100644 index 0000000..2655ea2 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/2/index/segments_3 differ diff --git a/data/carsapp/nodes/0/indices/users/2/index/write.lock b/data/carsapp/nodes/0/indices/users/2/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/2/translog/translog-1403392443004 b/data/carsapp/nodes/0/indices/users/2/translog/translog-1403392443004 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/3/_state/state-70 b/data/carsapp/nodes/0/indices/users/3/_state/state-70 new file mode 100644 index 0000000..070b370 --- /dev/null +++ b/data/carsapp/nodes/0/indices/users/3/_state/state-70 @@ -0,0 +1,4 @@ +{ + "version" : 70, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/users/3/index/_0.cfe b/data/carsapp/nodes/0/indices/users/3/index/_0.cfe new file mode 100644 index 0000000..660e2b2 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_0.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_0.cfs b/data/carsapp/nodes/0/indices/users/3/index/_0.cfs new file mode 100644 index 0000000..d987e56 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_0.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_0.si b/data/carsapp/nodes/0/indices/users/3/index/_0.si new file mode 100644 index 0000000..bea52e5 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_0.si differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_1.cfe b/data/carsapp/nodes/0/indices/users/3/index/_1.cfe new file mode 100644 index 0000000..ac36bc6 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_1.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_1.cfs b/data/carsapp/nodes/0/indices/users/3/index/_1.cfs new file mode 100644 index 0000000..935c19b Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_1.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_1.si b/data/carsapp/nodes/0/indices/users/3/index/_1.si new file mode 100644 index 0000000..6c53991 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_1.si differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_2.cfe b/data/carsapp/nodes/0/indices/users/3/index/_2.cfe new file mode 100644 index 0000000..82ad6ac Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_2.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_2.cfs b/data/carsapp/nodes/0/indices/users/3/index/_2.cfs new file mode 100644 index 0000000..3beb8bf Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_2.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_2.si b/data/carsapp/nodes/0/indices/users/3/index/_2.si new file mode 100644 index 0000000..89b5d61 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_2.si differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/_checksums-1403405548706 b/data/carsapp/nodes/0/indices/users/3/index/_checksums-1403405548706 new file mode 100644 index 0000000..fb36d62 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/_checksums-1403405548706 differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/segments.gen b/data/carsapp/nodes/0/indices/users/3/index/segments.gen new file mode 100644 index 0000000..e9fa600 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/segments_3 b/data/carsapp/nodes/0/indices/users/3/index/segments_3 new file mode 100644 index 0000000..75fdda0 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/index/segments_3 differ diff --git a/data/carsapp/nodes/0/indices/users/3/index/write.lock b/data/carsapp/nodes/0/indices/users/3/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/3/translog/translog-1403392443003 b/data/carsapp/nodes/0/indices/users/3/translog/translog-1403392443003 new file mode 100644 index 0000000..f2c0e11 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/3/translog/translog-1403392443003 differ diff --git a/data/carsapp/nodes/0/indices/users/4/_state/state-70 b/data/carsapp/nodes/0/indices/users/4/_state/state-70 new file mode 100644 index 0000000..070b370 --- /dev/null +++ b/data/carsapp/nodes/0/indices/users/4/_state/state-70 @@ -0,0 +1,4 @@ +{ + "version" : 70, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/users/4/index/_0.cfe b/data/carsapp/nodes/0/indices/users/4/index/_0.cfe new file mode 100644 index 0000000..cfc2a4f Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/4/index/_0.cfe differ diff --git a/data/carsapp/nodes/0/indices/users/4/index/_0.cfs b/data/carsapp/nodes/0/indices/users/4/index/_0.cfs new file mode 100644 index 0000000..7ad21f4 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/4/index/_0.cfs differ diff --git a/data/carsapp/nodes/0/indices/users/4/index/_0.si b/data/carsapp/nodes/0/indices/users/4/index/_0.si new file mode 100644 index 0000000..1a9726d Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/4/index/_0.si differ diff --git a/data/carsapp/nodes/0/indices/users/4/index/_checksums-1403447279812 b/data/carsapp/nodes/0/indices/users/4/index/_checksums-1403447279812 new file mode 100644 index 0000000..419649b Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/4/index/_checksums-1403447279812 differ diff --git a/data/carsapp/nodes/0/indices/users/4/index/segments.gen b/data/carsapp/nodes/0/indices/users/4/index/segments.gen new file mode 100644 index 0000000..225a55b Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/4/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/users/4/index/segments_2 b/data/carsapp/nodes/0/indices/users/4/index/segments_2 new file mode 100644 index 0000000..278e45e Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/4/index/segments_2 differ diff --git a/data/carsapp/nodes/0/indices/users/4/index/write.lock b/data/carsapp/nodes/0/indices/users/4/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/4/translog/translog-1403392443129 b/data/carsapp/nodes/0/indices/users/4/translog/translog-1403392443129 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/users/_state/state-2 b/data/carsapp/nodes/0/indices/users/_state/state-2 new file mode 100644 index 0000000..5c3d346 Binary files /dev/null and b/data/carsapp/nodes/0/indices/users/_state/state-2 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/0/_state/state-58 b/data/carsapp/nodes/0/indices/vehicles/0/_state/state-58 new file mode 100644 index 0000000..c73f63e --- /dev/null +++ b/data/carsapp/nodes/0/indices/vehicles/0/_state/state-58 @@ -0,0 +1,4 @@ +{ + "version" : 58, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/vehicles/0/index/_0.cfe b/data/carsapp/nodes/0/indices/vehicles/0/index/_0.cfe new file mode 100644 index 0000000..dcfd001 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/0/index/_0.cfe differ diff --git a/data/carsapp/nodes/0/indices/vehicles/0/index/_0.cfs b/data/carsapp/nodes/0/indices/vehicles/0/index/_0.cfs new file mode 100644 index 0000000..c4e67f7 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/0/index/_0.cfs differ diff --git a/data/carsapp/nodes/0/indices/vehicles/0/index/_0.si b/data/carsapp/nodes/0/indices/vehicles/0/index/_0.si new file mode 100644 index 0000000..884f92d Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/0/index/_0.si differ diff --git a/data/carsapp/nodes/0/indices/vehicles/0/index/_checksums-1403405625288 b/data/carsapp/nodes/0/indices/vehicles/0/index/_checksums-1403405625288 new file mode 100644 index 0000000..d5c6b6e Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/0/index/_checksums-1403405625288 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/0/index/segments.gen b/data/carsapp/nodes/0/indices/vehicles/0/index/segments.gen new file mode 100644 index 0000000..225a55b Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/0/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/vehicles/0/index/segments_2 b/data/carsapp/nodes/0/indices/vehicles/0/index/segments_2 new file mode 100644 index 0000000..cd7955d Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/0/index/segments_2 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/0/index/write.lock b/data/carsapp/nodes/0/indices/vehicles/0/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/0/translog/translog-1403403818000 b/data/carsapp/nodes/0/indices/vehicles/0/translog/translog-1403403818000 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/1/_state/state-58 b/data/carsapp/nodes/0/indices/vehicles/1/_state/state-58 new file mode 100644 index 0000000..c73f63e --- /dev/null +++ b/data/carsapp/nodes/0/indices/vehicles/1/_state/state-58 @@ -0,0 +1,4 @@ +{ + "version" : 58, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/vehicles/1/index/_checksums-1403403818057 b/data/carsapp/nodes/0/indices/vehicles/1/index/_checksums-1403403818057 new file mode 100644 index 0000000..1b1cb4d Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/1/index/_checksums-1403403818057 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/1/index/segments.gen b/data/carsapp/nodes/0/indices/vehicles/1/index/segments.gen new file mode 100644 index 0000000..63a7ec9 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/1/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/vehicles/1/index/segments_1 b/data/carsapp/nodes/0/indices/vehicles/1/index/segments_1 new file mode 100644 index 0000000..a4706e8 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/1/index/segments_1 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/1/index/write.lock b/data/carsapp/nodes/0/indices/vehicles/1/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/1/translog/translog-1403403818052 b/data/carsapp/nodes/0/indices/vehicles/1/translog/translog-1403403818052 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/2/_state/state-58 b/data/carsapp/nodes/0/indices/vehicles/2/_state/state-58 new file mode 100644 index 0000000..c73f63e --- /dev/null +++ b/data/carsapp/nodes/0/indices/vehicles/2/_state/state-58 @@ -0,0 +1,4 @@ +{ + "version" : 58, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/vehicles/2/index/_checksums-1403403818054 b/data/carsapp/nodes/0/indices/vehicles/2/index/_checksums-1403403818054 new file mode 100644 index 0000000..1b1cb4d Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/2/index/_checksums-1403403818054 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/2/index/segments.gen b/data/carsapp/nodes/0/indices/vehicles/2/index/segments.gen new file mode 100644 index 0000000..63a7ec9 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/2/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/vehicles/2/index/segments_1 b/data/carsapp/nodes/0/indices/vehicles/2/index/segments_1 new file mode 100644 index 0000000..a4706e8 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/2/index/segments_1 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/2/index/write.lock b/data/carsapp/nodes/0/indices/vehicles/2/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/2/translog/translog-1403403818052 b/data/carsapp/nodes/0/indices/vehicles/2/translog/translog-1403403818052 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/3/_state/state-58 b/data/carsapp/nodes/0/indices/vehicles/3/_state/state-58 new file mode 100644 index 0000000..c73f63e --- /dev/null +++ b/data/carsapp/nodes/0/indices/vehicles/3/_state/state-58 @@ -0,0 +1,4 @@ +{ + "version" : 58, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/vehicles/3/index/_0.cfe b/data/carsapp/nodes/0/indices/vehicles/3/index/_0.cfe new file mode 100644 index 0000000..9cf5f1c Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/3/index/_0.cfe differ diff --git a/data/carsapp/nodes/0/indices/vehicles/3/index/_0.cfs b/data/carsapp/nodes/0/indices/vehicles/3/index/_0.cfs new file mode 100644 index 0000000..d0d78d5 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/3/index/_0.cfs differ diff --git a/data/carsapp/nodes/0/indices/vehicles/3/index/_0.si b/data/carsapp/nodes/0/indices/vehicles/3/index/_0.si new file mode 100644 index 0000000..eeb0e2e Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/3/index/_0.si differ diff --git a/data/carsapp/nodes/0/indices/vehicles/3/index/_checksums-1403448433414 b/data/carsapp/nodes/0/indices/vehicles/3/index/_checksums-1403448433414 new file mode 100644 index 0000000..fed423c Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/3/index/_checksums-1403448433414 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/3/index/segments.gen b/data/carsapp/nodes/0/indices/vehicles/3/index/segments.gen new file mode 100644 index 0000000..225a55b Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/3/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/vehicles/3/index/segments_2 b/data/carsapp/nodes/0/indices/vehicles/3/index/segments_2 new file mode 100644 index 0000000..ca688ab Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/3/index/segments_2 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/3/index/write.lock b/data/carsapp/nodes/0/indices/vehicles/3/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/3/translog/translog-1403403818039 b/data/carsapp/nodes/0/indices/vehicles/3/translog/translog-1403403818039 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/4/_state/state-58 b/data/carsapp/nodes/0/indices/vehicles/4/_state/state-58 new file mode 100644 index 0000000..c73f63e --- /dev/null +++ b/data/carsapp/nodes/0/indices/vehicles/4/_state/state-58 @@ -0,0 +1,4 @@ +{ + "version" : 58, + "primary" : true +} \ No newline at end of file diff --git a/data/carsapp/nodes/0/indices/vehicles/4/index/_checksums-1403403818105 b/data/carsapp/nodes/0/indices/vehicles/4/index/_checksums-1403403818105 new file mode 100644 index 0000000..1b1cb4d Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/4/index/_checksums-1403403818105 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/4/index/segments.gen b/data/carsapp/nodes/0/indices/vehicles/4/index/segments.gen new file mode 100644 index 0000000..63a7ec9 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/4/index/segments.gen differ diff --git a/data/carsapp/nodes/0/indices/vehicles/4/index/segments_1 b/data/carsapp/nodes/0/indices/vehicles/4/index/segments_1 new file mode 100644 index 0000000..cd9e2ba Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/4/index/segments_1 differ diff --git a/data/carsapp/nodes/0/indices/vehicles/4/index/write.lock b/data/carsapp/nodes/0/indices/vehicles/4/index/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/4/translog/translog-1403403818102 b/data/carsapp/nodes/0/indices/vehicles/4/translog/translog-1403403818102 new file mode 100644 index 0000000..e69de29 diff --git a/data/carsapp/nodes/0/indices/vehicles/_state/state-2 b/data/carsapp/nodes/0/indices/vehicles/_state/state-2 new file mode 100644 index 0000000..1d74643 Binary files /dev/null and b/data/carsapp/nodes/0/indices/vehicles/_state/state-2 differ diff --git a/data/carsapp/nodes/0/node.lock b/data/carsapp/nodes/0/node.lock new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml index 4b4994d..37a6ae1 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,28 @@ 1.0-SNAPSHOT cars-app http://maven.apache.org + + +Spark repository +https://oss.sonatype.org/content/repositories/snapshots/ + + + + org.elasticsearch + elasticsearch + 1.1.0 + + +com.sparkjava +spark-core +2.0.0 + + +com.sparkjava +spark-template-mustache +1.0.0 + junit junit @@ -48,6 +69,19 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + 1.8 + 1.8 + + diff --git a/src/main/java/com/unrc/app/App.java b/src/main/java/com/unrc/app/App.java index 5b04243..12e3fcc 100644 --- a/src/main/java/com/unrc/app/App.java +++ b/src/main/java/com/unrc/app/App.java @@ -1,29 +1,709 @@ package com.unrc.app; -import org.javalite.activejdbc.Base; +import com.unrc.app.models.*; -import com.unrc.app.models.User; +import com.unrc.app.models.Vehicle; +import static java.lang.Integer.parseInt; +import static java.lang.Integer.parseInt; +import static java.lang.Integer.parseInt; +import static java.lang.Integer.parseInt; +import static java.lang.Integer.parseInt; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.elasticsearch.node.*; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.percolate.TransportShardMultiPercolateAction.Response; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.javalite.activejdbc.Base; +import spark.ModelAndView; +import spark.Spark; +import static spark.Spark.*; +import spark.template.mustache.MustacheTemplateEngine; +import static org.elasticsearch.node.NodeBuilder.*; /** * Hello world! * */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello cruel World!" ); +public class App { + + + public static User currentUser = new User(); + public static Post currentPost = new Post(); + public static boolean connectionAdmin = false; + public static boolean connectionUser = false; + public static boolean connectionGuest = false; + + public static void main(String[] args) { + System.out.println("hi!"); + Html html = new Html(); + + Spark.before((request, response) -> { + Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", "yoush4llnotp4ss"); + }); + Spark.after((request, response) -> { + Base.close(); + }); + +// System.out.println("---------elastic-------------------------"); +// GetResponse response =ElasticSearch.client().prepareGet("vehicles", "vehicle", "2") +// .execute() +// .actionGet(); +// System.out.println("---------------------------consulta---------------------------------------------"); +// +// System.out.println("source.valuess---"+response.getSource()); +// System.out.println("source as string --- "+response.getSourceAsString()); +// ElasticSearch.client().close(); + + +// response =ElasticSearch.client().prepareGet("vehicles", "vehicle", "2") +// .execute() +// .actionGet(); +// System.out.println("---------------------------consulta---------------------------------------------"); +// +// System.out.println("source.valuess---"+response.getSource()); +// System.out.println("source as string --- "+response.getSourceAsString()); +// ElasticSearch.client().close(); +// System.out.println("-----------cierroo-------------------------------------------"); +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~users~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + get("/users", (request, resp) -> { + + Map attributes = new HashMap<>(); + List users = User.findAll(); + attributes.put("users_count", users.size()); + attributes.put("users", users); + return new ModelAndView(attributes, "users.mustache"); + + }, + new MustacheTemplateEngine() + ); + + get("/user", (req, resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + List u = User.findAll(); + String users = ""; + for (int i = 0; i < u.size(); i++) { + users = users + u.get(i).getString("id_user")+ " | " + " " + u.get(i).getString("first_name") + " " + u.get(i).getString("last_name")+ " | "+ " " + u.get(i).getString("email") + ","; + + } + + return html.getAllUsers(users); + } + else + return html.getFailLogin(); + }); + get("/user/:id", (req, resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + System.out.print(req.params(":id")); + User user = User.findFirst("id_user = ?", req.params(":id")); + String vl = user.get("first_name") + "," + user.get("last_name") + "," + user.get("email"); + + return html.getUserBy(vl); + } + else + return html.getFailLogin(); + }); + + get("/insertuser", (req, resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + return html.IngresarUsuario(); + } + else + return html.getFailLogin(); + }); + post("/insertuser", (req, resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + User.createUser(req.queryParams("first_name"),req.queryParams("last_name"),req.queryParams("email"),req.queryParams("contrasena")); + return html.admin(); + } + else + return html.getFailLogin(); + }); + + get("/registeruser", (req, resp) -> { + resp.type("text/html"); + return html.RegistrarUsuario(); + + }); + post("/registeruser", (req, resp) -> { + + resp.type("text/html"); + User.createUser(req.queryParams("first_name"),req.queryParams("last_name"),req.queryParams("email"),req.queryParams("contrasena")); + return html.irlogin(); + }); + + post("/getusers", (req, resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + User tmp = User.findFirst("id_user = ?", req.queryParams("id_user")); + User.deleteUser(tmp.getInteger("id_user")); + return html.admin(); + } + else + return html.getFailLogin(); + }); +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Post~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + get("/post/:id", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + Post post = Post.findFirst("id_post = ?", req.params(":id")); + String own = ""; + User name = User.findFirst("id_user = ?", post.getString("id_user")); + own = own + name.getString("first_name") + "}" + post.getString("patent") + "}" + post.getString("description"); + return html.getPostBy(own); + } + else + return html.getFailLogin(); + }); + get("/question/answers", (req, resp) -> { + + + return null; + }); + get("/ownpost", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + List post = Post.find("id_user = ?", currentUser.get("id_user")); + if (!post.isEmpty()) { + String vh = ""; + for (int i = 0; i < post.size(); i++) { + vh = vh + post.get(i).getString("id_post") + "}" + post.get(i).getString("description") + "}" + currentUser.getString("first_name") + "}" + post.get(i).getString("patent") + ","; + } + if(connectionUser==true){ + return html.getPostUser(vh); + } + else{ + return html.getPostGuest(vh); + } + } else + return html.getMessagePag("No hay post registrados","/webpag"); + } + else + return html.getFailLogin(); + }); + get("/insertpost", (req, resp) -> { + if(connectionUser==true){ + resp.type("text/html"); + List v = Vehicle.find("id_user = ?", currentUser.get("id_user")); + String vh = ""; + + if (!v.isEmpty()) { + for (int i = 0; i < v.size(); i++) { + vh = vh + v.get(i).getString("patent") + ","; + } + } + else return html.getMessagePag("Necesita ingresar vehiculos para crear un post","/webpag"); + + + List a = UsersAddress.find("id_user = ?", currentUser.get("id_user")); + String ad = ""; + if (!a.isEmpty()) { + + + for (int i = 0; i < a.size(); i++) { + Address b = Address.findFirst("id_address = ?", a.get(i).getString("id_address")); + ad = ad + b.getString("id_address")+ "}" +b.getString("province") + " | " + b.getString("city") + " | " + b.getString("postal_code") + " | " + b.getString("street") + " | " +b.getString("num")+ ","; + + } + } + else return html.getMessagePag("Necesita ingresar una direccion para crear un post","/webpag"); + + return html.IngresarPost(currentUser,vh,ad); + + } + else + return html.getFailLogin(); + }); + post("/insertpost", (req, resp) -> { + if(connectionUser==true){ + resp.type("text/html"); + Post.createPost(currentUser, parseInt(req.queryParams("ciudad")), req.queryParams("patente"), req.queryParams("descripcion")); + List v = Vehicle.find("id_user = ?", currentUser.get("id_user")); + String vh = ""; + + if (!v.isEmpty()) { + for (int i = 0; i < v.size(); i++) { + vh = vh + v.get(i).getString("patent") + ","; + } + } + List a = UsersAddress.find("id_user = ?", currentUser.get("id_user")); + String ad = ""; + if (!a.isEmpty()) { + + + for (int i = 0; i < a.size(); i++) { + Address b = Address.findFirst("id_address = ?", a.get(i).getString("id_address")); + ad = ad + b.getString("id_address")+ "}" +b.getString("province") + " | " + b.getString("city") + " | " + b.getString("postal_code") + " | " + b.getString("street") + " | " +b.getString("num")+ ","; + + } + } + return html.IngresarPost(currentUser,vh,ad); + } + else + return html.getFailLogin(); + }); + post("/getpostbysearch", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + if (req.queryParams("coment") == null || req.queryParams("coment").equals("")) { + return html.getMessagePag(" No escribio ningun comentario ","/post"); + } + + Question.createQuestion(currentUser,currentPost.getInteger("id_post"),req.queryParams("coment")); + return html.getMessagePag("Se envio la pregunta","/post"); + } + else + return html.getFailLogin(); + + }); + post("/answerpost", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + + resp.type("text/html"); + Question q = Question.findFirst("id_question = ?", req.queryParams("question")); + if (q.equals(null)||req.queryParams("responder") == null || req.queryParams("responder").equals("")) { + return html.getMessagePag("No se guardo correctamente la respuesta","/post"); + } + System.out.println(req.queryParams("coment")); + Answer.createAnswer(currentUser, q.getInteger("id_question"), req.queryParams("responder")); + return html.getMessagePag("Se guardo la respuesta","/post"); + } + else + return html.getFailLogin(); + + }); + get("/post", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true || connectionGuest==true){ + resp.type("text/html"); + List post = Post.findAll(); + String vh = ""; + for (int i = 0; i < post.size(); i++) { + User name = User.findFirst("id_user = ?", post.get(i).getString("id_user")); + if (name != null) { + vh = vh + post.get(i).getString("id_post") + "}" + post.get(i).getString("description") + "}" + name.getString("first_name") + "}" + post.get(i).getString("patent") + ","; + } + } + if(connectionUser==true || connectionGuest==true){ + if(connectionUser==true) return html.getPostUser(vh); + else return html.getPostGuest(vh); + } + else{ + return html.getAllPost(vh); + } + } + else + return html.getFailLogin(); + }); + + post("/post", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true || connectionGuest==true){ + + if( ( (connectionAdmin==true && !req.queryParams("postEliminar").isEmpty()) )){ + Post tmp = Post.findFirst("id_post = ?", req.queryParams("postEliminar")); + Post.deletePost(tmp.getInteger("id_post")); + return html.getMessagePag("Post Eliminado con exito","/post"); + } + + else{ + resp.type("text/html"); + Post post = Post.findFirst("id_post = ?", req.queryParams("id_post")); + currentPost = post; + + String own = ""; + + String desc = post.getString("description"); + + User name = User.findFirst("id_user = ?", post.getString("id_user")); + own = own + name.getString("first_name")+", " + name.getString("last_name")+"}"; + + Address b = Address.findFirst("id_address = ?", post.getString("id_address")); + own = own + b.getString("province") + "}" + b.getString("city") + "}" + b.getString("postal_code") + "}" + b.getString("street") + "}" +b.getString("num"); - Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", ""); - User user = new User(); - user.set("first_name", "Marilyn"); - user.set("last_name", "Monroe"); - // user.set("dob", "1935-12-06"); - user.saveIt(); + Vehicle tmp = Vehicle.findFirst("patent = ?", post.getString("patent")); + String vl = tmp.getString("patent") + "," + tmp.getString("mark") + "," + tmp.getString("model") + "," + tmp.getString("color") + "," + tmp.getString("tipo") + "," + tmp.getString("isCoupe") + "," + Integer.toString(tmp.getInteger("cc")) + "," + Integer.toString(tmp.getInteger("capacity")); + List ques = Question.find("id_post = ?", req.queryParams("id_post")); + String q = ""; + for (int i = 0; i < ques.size(); i++) { + q+= ques.get(i).get("id_question")+"}"+User.findFirst("id_user = ?", ques.get(i).getInteger("id_user")).getString("first_name") +"}" + ques.get(i).getString("description")+"}"; + Answer ans = Answer.findFirst("id_question = ?", ques.get(i).get("id_question")); + if( ans!=null){ + q+= ans.getString("description")+","; + }else q+="-"+","; - User.createIt("first_name", "Marcelo", "last_name", "Uva"); + } + if (connectionAdmin == true || connectionGuest ==true){ + return html.getPostBySearchAdmin(desc, own, vl,q); + } + else{ + if(post.getInteger("id_user")!=currentUser.getInteger("id_user")) - Base.close(); + return html.getPostBySearch(desc,own, vl,q); + else + + return html.getOwnPostBySearch(desc,own, vl,q); + } + } + } + else + return html.getFailLogin(); + }); + + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Questions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + get("/questions", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + List u = User.findAll(); + String users = ""; + for (int i = 0; i < u.size(); i++) { + users = users + u.get(i).getString("first_name") + " " + u.get(i).getString("last_name") + ","; + } + + return html.getAllUsers(users); + } + else + return html.getFailLogin(); + }); +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vehicles~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + get("/vehicles", (req, resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + List v = Vehicle.findAll(); + String vh = ""; + for (int i = 0; i < v.size(); i++) { + vh = vh + v.get(i).getString("Patent") + "}" + v.get(i).getString("Mark") + "}" + v.get(i).getString("Model") + "}" + v.get(i).getString("Color") + "}" + v.get(i).getString("Tipo") + "}" + v.get(i).getString("id_user") + "}" + v.get(i).getString("isCoupe") + "}" + v.get(i).getString("cc") + "}" + v.get(i).getString("capacity") + ","; + } + + + return html.getAutomoviles(vh); + } + else + return html.getFailLogin(); + }); + get("/vehicle/:patente", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + Vehicle v = Vehicle.findFirst("patent = ?", req.params(":patente")); + String vh = ""; + + vh = vh + v.getString("Patent") + "}" + v.getString("Mark") + "}" + v.getString("Model") + "}" + v.getString("Color") + "}" + v.getString("Tipo") + "}" + v.getString("id_user") + "}" + v.getString("isCoupe") + "}" + v.getString("cc") + "}" + v.getString("capacity"); + + return html.getVehicleBy(vh); + } + else + return html.getFailLogin(); + }); + + get("/insertvehicle", (req, resp) -> { + if(connectionUser==true){ + resp.type("text/html"); + return html.IngresarAutomovil(); + } + else + return html.getFailLogin(); + }); + + post("/insertvehicle", (req, resp) -> { + if(connectionUser==true){ + resp.type("text/html"); + if (req.queryParams("tipo").equals("0")){ + Vehicle.createVehicle(req.queryParams("patente"), req.queryParams("marca"), req.queryParams("modelo"), currentUser.getInteger("id_user"), req.queryParams("color"), "Auto", 0, req.queryParams("isCoupe"), 0); + } + else + if (req.queryParams("tipo").equals("2")) { + Vehicle.createVehicle(req.queryParams("patente"), req.queryParams("marca"), req.queryParams("modelo"), currentUser.getInteger("id_user"), req.queryParams("color"), "Camion", 0,"-", parseInt(req.queryParams("Capacity"))); + } + else + if (req.queryParams("tipo").equals("1")) { + Vehicle.createVehicle(req.queryParams("patente"), req.queryParams("marca"), req.queryParams("modelo"), currentUser.getInteger("id_user"), req.queryParams("color"), "Moto", parseInt(req.queryParams("CC")),"-", 0); + } + + return html.IngresarAutomovil(); + } + else + return html.getFailLogin(); + }); + get("/ownvehicles", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + List v = Vehicle.find("id_user = ?", currentUser.get("id_user")); + if (!v.isEmpty()) { + + String vh = ""; + for (int i = 0; i < v.size(); i++) { + vh = vh + v.get(i).getString("patent") + "}" + v.get(i).getString("mark") + "}" + v.get(i).getString("model") + "}" + v.get(i).getString("color") + "}" + v.get(i).getString("tipo") + "}" + v.get(i).getString("id_user") + "}" + v.get(i).getString("isCoupe") + "}" + v.get(i).getString("cc") + "}" + v.get(i).getString("capacity") + ","; + } + + + return html.getAutomoviles(vh); + } + return html.getMessagePag("No posee vehiculos registrados","/webpag"); + } + else + return html.getFailLogin(); + }); + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Address~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + get("/address", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + List
v = Address.findAll(); + String vh = ""; + for (int i = 0; i < v.size(); i++) { + vh = vh + v.get(i).getString("province") + "}" + v.get(i).getString("city") + "}" + v.get(i).getString("postal_code") + "}" + v.get(i).getString("street") + "}" +v.get(i).getString("num")+ ","; + } + + return html.getCities(vh); + } + else + return html.getFailLogin(); + }); + get("/insertaddress", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + return html.IngresarCiudad(); + } + else + return html.getFailLogin(); + }); + post("/insertaddress", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + Address.createAddress(req.queryParams("direccion"),parseInt(req.queryParams("num")),req.queryParams("ciudad"),req.queryParams("provincia"),parseInt(req.queryParams("codigo_postal"))); + Address a = Address.findByAddress(req.queryParams("direccion"),parseInt(req.queryParams("num")),req.queryParams("ciudad"),req.queryParams("provincia"),parseInt(req.queryParams("codigo_postal"))); + int id_address= parseInt(a.getString("id_address")); + UsersAddress.createUsersAddress(currentUser.getInteger("id_user"), id_address); + return html.IngresarCiudad(); + } + else + return html.getFailLogin(); + }); + + get("/ownaddress", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + List a = UsersAddress.find("id_user = ?", currentUser.get("id_user")); + if (!a.isEmpty()) { + + String vh = ""; + + for (int i = 0; i < a.size(); i++) { + Address b = Address.findFirst("id_address = ?", a.get(i).getString("id_address")); + vh = vh + b.getString("province") + "}" + b.getString("city") + "}" + b.getString("postal_code") + "}" + b.getString("street") + "}" +b.getString("num")+ ","; + + } + + return html.getOwnAddress(vh); + } + return html.getMessagePag("No posee ciudades registradas","/webpag"); + } + else + return html.getFailLogin(); + }); + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Answers~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + get("/answers", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + List v = Answer.findAll(); + String vh = ""; + for (int i = 0; i < v.size(); i++) { + vh = vh + v.get(i).getString("id_post") + " " + v.get(i).getString("id_user") + " " + v.get(i).getString("description") + ","; + } + return html.getAnswers(vh); + } + else + return html.getFailLogin(); + }); + get("/answers/:id", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + + resp.type("text/html"); + Answer v = Answer.findFirst("id_answer", ":id"); + String vh = ""; + vh = vh + v.getString("id_post") + " " + v.getString("id_user") + " " + v.getString("description"); + return html.getAnswersByid(vh); + } + else + return html.getFailLogin(); + }); + + post("/insertanswer", (req, resp) -> { + if(connectionAdmin == true || connectionUser==true){ + resp.type("text/html"); + Answer.createAnswer(currentUser, parseInt(req.queryParams("id_pregunta")), req.queryParams("descripcion")); + return html.IngresarRespuesta(); + } + else + return html.getFailLogin(); + }); + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Contacto Admin~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + get("/admincontactuser", (req, resp) -> { + if(connectionUser==true || connectionGuest==true){ + resp.type("text/html"); + return html.contactAdminUser(); + } + else + return html.getFailLogin(); + }); + + post("/admincontactuser", (req, resp) -> { + if(connectionUser==true || connectionGuest==true){ + resp.type("text/html"); + Message.createMessage(currentUser.getInteger("id_user"), req.queryParams("mensaje")); + return html.contactAdminUser(); + } + else + return html.getFailLogin(); + }); + + get("/admincontactguest", (req, resp) -> { + if(connectionUser==true || connectionGuest==true){ + resp.type("text/html"); + return html.contactAdminGuest(); + } + else + return html.getFailLogin(); + }); + + post("/admincontactguest", (req, resp) -> { + if(connectionUser==true || connectionGuest==true){ + resp.type("text/html"); + MessageGuest.createMessageGuest(req.queryParams("mensaje")); + return html.contactAdminGuest(); + } + else + return html.getFailLogin(); + }); + + + get("/inbox",(req,resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + List m = Message.findAll(); + List mg = MessageGuest.findAll(); + String message = ""; + String messageGuest = ""; + for (int i = 0; i < m.size(); i++) { + User name = User.findFirst("id_user = ?", m.get(i).getString("id_user")); + message = message + m.get(i).getString("id_message")+ "}" + name.getString("first_name") + ","; + } + for (int i = 0; i < mg.size(); i++) { + messageGuest = messageGuest + mg.get(i).getString("id_messageGuest")+ ","; + } + return html.AdminInbox(message,messageGuest); + } + return html.getFailLogin(); + }); + + + post("/inbox",(req,resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + + if(!req.queryParams("idmu").isEmpty()){ + Message messageu = Message.findFirst("id_message = ?", req.queryParams("idmu")); + String mu = messageu.getString("description"); + return html.getMessage(mu); + } + if(!req.queryParams("idmi").isEmpty()){ + MessageGuest messagei = MessageGuest.findFirst("id_messageGuest = ?", req.queryParams("idmi")); + String mi = messagei.getString("description"); + return html.getMessage(mi); + } + if(!req.queryParams("eliminarmu").isEmpty()){ + Message messageu = Message.findFirst("id_message = ?", req.queryParams("eliminarmu")); + messageu.deleteMessage(messageu.getInteger("id_message")); + return html.getMessagePag("Mensaje Eliminado Con Exito","/inbox"); + } + if(!req.queryParams("eliminarmi").isEmpty()){ + MessageGuest messagei = MessageGuest.findFirst("id_messageGuest = ?", req.queryParams("eliminarmi")); + messagei.deleteMessageGuest(messagei.getInteger("id_messageGuest")); + return html.getMessagePag("Mensaje Eliminado Con Exito","/inbox"); + } + + return html.getMessagePag("Error","/inbox"); + + + } + else + return html.getFailLogin(); + + + }); + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Login~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + get("/loginuser", (req, resp) -> { + resp.type("text/html"); + connectionAdmin =false; + connectionUser =false; + connectionGuest =true; + currentUser = null; + currentPost = null; + + return html.loginUsuario(); + }); + post("/loginuser", (req, resp) -> { + + + resp.type("text/html"); + //validar usuario exitente o admin + User tmp = User.findFirst("email = ?", req.queryParams("email")); + + if (req.queryParams("email").equals("admin") && req.queryParams("contrasena").equals("1234")) { + connectionAdmin =true; + connectionUser =false; + connectionGuest =false; + return html.adminControlPane(); + } + else{ + if (tmp != null && tmp.get("contrasena").equals(req.queryParams("contrasena"))) { + connectionAdmin =false; + connectionUser =true; + connectionGuest =false; + currentUser = tmp; + return html.userControlPane(); + } + } + return html.getMessagePag("El usuario o la contrasena son incorrectos","/loginuser"); + }); + + get("/webpag", (req, resp) -> { + if(connectionUser==true){ + resp.type("text/html"); + return html.webpage(); + } + else + return html.getFailLogin(); + }); + + get("/admin", (req, resp) -> { + if(connectionAdmin == true){ + resp.type("text/html"); + return html.admin(); + } + else + return html.getFailLogin(); + }); + + get("/guestcp", (req, resp) -> { + resp.type("text/html"); + return html.guest(); + }); } + + } diff --git a/src/main/java/com/unrc/app/ElasticSearch.java b/src/main/java/com/unrc/app/ElasticSearch.java new file mode 100644 index 0000000..445f10b --- /dev/null +++ b/src/main/java/com/unrc/app/ElasticSearch.java @@ -0,0 +1,18 @@ +package com.unrc.app; + +import org.elasticsearch.client.Client; +import org.elasticsearch.node.Node; + +public class ElasticSearch { + // + public static final Node node = org.elasticsearch.node + .NodeBuilder + .nodeBuilder() + .clusterName("carsapp") + .local(true) + .node(); + public static Client client(){ + return node.client(); + } + // +} \ No newline at end of file diff --git a/src/main/java/com/unrc/app/Html.java b/src/main/java/com/unrc/app/Html.java new file mode 100644 index 0000000..1d45b15 --- /dev/null +++ b/src/main/java/com/unrc/app/Html.java @@ -0,0 +1,627 @@ +package com.unrc.app; + +import com.unrc.app.models.User; + +public class Html { + + public String getAllUsers(String users) { + String s = "

USUARIOS



"; + s = s + "

"; + s+=" "; + s+="

Eliminar usuario (id) :

"; + s = s + "

"; + + return s; + } + + public String getAllPost(String post) { + String s = "

Post



"; + s+= ""; + s = s + ""; + String[] tmp = post.split(","); + + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + s = s + ""; + + } + s+="
IDDESCRIPCIONDUEÑO PATENTE
" + tm[j] + "
"; + s+=" "; + s = s + "

Ver Post:

"; + s+="

Eliminar Post (id) :

"; + s = s + "

"; + + return s; + } + + + public String AdminInbox(String message,String messageGuest) { + String s = "

Mensajes Usuarios

"; + s+= ""; + s = s + ""; + String[] tmp = message.split(","); + + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + s = s + ""; + + } + + s+="
ID MensajeUsuario
" + tm[j] + "
"; + s = s + "

Ver Mensaje de usuario (id):

"; + s+="Eliminar Mensaje de usuario (id) :

"; + + s+= "

Mensajes De Invitados

"; + s+= ""; + s = s + ""; + String[] tmp2 = messageGuest.split(","); + + for (int i = 0; i < tmp2.length; i++) { + s = s + ""; + s = s + ""; + s = s + ""; + s = s + ""; + + } + s+="
ID MensajeUsuario
" + tmp2[i] + "" + "Invitado" + "
"; + s = s + "

Ver Mensaje de invitado (id):

"; + s+="Eliminar Mensaje de invitado (id) :

"; + s+=" "; + + s = s + "
"; + + return s; + } + + public String getFailLogin() { + String s ="
Acceso denegado

"; + return s; + } + + public String getMessagePag(String a,String b) { + String s ="
"+a+"

"; + return s; + } + + public String getUserBy(String user) { + String s = ""; + s = s + "
Usuario

"; + s = s + "
"; + String[] tmp = user.split(","); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + s = s + "

"; + + return s; + } + public String getPostBySearch(String desc,String post,String v,String ans) { + String s = "
POST

"; + s+= "
NombreApellido Email
" + tmp[i] + "
"; + s = s + ""; + s = s + ""; + s+= "
DESCRIPCION
" + desc + "
"; + s = s + ""; + String [] tmp = post.split("}"); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + + s = s+"
DUEÑOPROVINCIACIUDADCODIGO POSTALDIRECCIONNUMERO
" + tmp[i] + "

"; + s = s + "VEHICULO
"; + s = s + ""; + tmp = v.split(","); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + s+="
PatenteMarca Modelo Color Tipo isCoupeCCCapacidad
" + tmp[i] + "


Preguntar


"; + s+="
"; + s = s + "
Preguntas y respuestas
"; + s = s + ""; + tmp = ans.split(","); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + } + s = s + ""; + s = s + "
NumeroUsuario Pregunta Resuesta
" + tm[j] + "
"; + + return s; + } + + public String getMessage(String message){ + String s = "
Mensaje

"; + + s +=""; + s += "

"; + s +=" "; + + return s; + } + + + public String getPostBySearchAdmin(String desc,String post,String v,String ans) { + String s = "
POST

"; + s+= ""; + s = s + ""; + s = s + ""; + s+= "
DESCRIPCION
" + desc + "
"; + s = s + ""; + String [] tmp = post.split("}"); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + + s = s+"
DUEÑOPROVINCIACIUDADCODIGO POSTALDIRECCIONNUMERO
" + tmp[i] + "

"; + s = s + "VEHICULO
"; + s = s + ""; + tmp = v.split(","); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + s+="
PatenteMarca Modelo Color Tipo isCoupeCCCapacidad
" + tmp[i] + "

"; + s = s + "
Preguntas y respuestas
"; + s = s + ""; + tmp = ans.split(","); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + } + + s = s + ""; + s = s + "
NumeroUsuario Pregunta Resuesta
" + tm[j] + "
"; + + return s; + } + public String getOwnPostBySearch(String desc,String post,String v,String ans) { + String s = "
POST

"; + s+= ""; + s = s + ""; + s = s + ""; + s+= "
DESCRIPCION
" + desc + "
"; + s = s + ""; + String [] tmp = post.split("}"); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + + s = s+"
DUEÑOPROVINCIACIUDADCODIGO POSTALDIRECCIONNUMERO
" + tmp[i] + "

"; + s = s + "VEHICULO
"; + s = s + ""; + tmp = v.split(","); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + s+="
PatenteMarca Modelo Color Tipo isCoupeCCCapacidad
" + tmp[i] + "


Responder preguntas

Numero de Pregunta:

"; + s+="
"; + s = s + "
Preguntas y respuestas
"; + s = s + ""; + tmp = ans.split(","); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + } + s = s + ""; + s = s + "
NumeroUsuario Pregunta Resuesta
" + tm[j] + "
"; + + return s; + } + public String getPostBy(String post) { + String s = ""; + s = s + "POST

"; + s = s + ""; + String[] tmp = post.split("}"); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + s = s + "
"; + return s; + } + + public String getVehicleBy(String vehicle) { + String s = "
USUARIOPATENTEDESCRIPCION
" + tmp[i] + "
"; + s = s + "VEHICULO

"; + s = s + ""; + String[] tmp = vehicle.split("}"); + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + + } + s = s + "

"; + + return s; + } + + public String IngresarUsuario() { + String s = "
INGRESAR UN NUEVO USUARIO

"; + s = s + "Nombre:

"; + s = s + "Apellido:

"; + s = s + "Email:

"; + s = s + "Contrasena:

"; + s = s + "


"; + s = s + ""; + s = s + "

"; + + return s; + } + + public String RegistrarUsuario() { + String s = "
Registrarse

"; + s = s + "Nombre:

"; + s = s + "Apellido:

"; + s = s + "Email:

"; + s = s + "Contrasena:

"; + s = s + "


"; + s = s + ""; + + return s; + } + + public String irlogin() { + String s = ""; + return s; + } + + + + public String IngresarCiudad() { + String s = "
INGRESAR UNA CIUDAD


"; + s = s + "Provincia:

"; + s = s + "Ciudad:

"; + s = s + "Cod_Postal:

"; + s = s + "Direccion:

"; + s = s + "Numero:

"; + s = s + "

"; + s = s + ""; + s = s + "

"; + + return s; + } + + public String IngresarPost(User user,String a,String b) { + String s = "
INGRESAR UN NUEVO POST

"; + s = s + "Descripcion:

"; + s = s + "Patente Vehiculo:

"; + + s = s + "Ciudad:

"; + s = s + "

"; + s = s + "

"; + s = s + ""; + + return s; + } + + public String IngresarRespuesta() { + String s = "
INGRESAR UN NUEVA RESPUESTA

"; + s = s + "Descripcion:

"; + s = s + "id usuario:

"; + s = s + "id pregunta:

"; + s = s + "

"; + s = s + ""; + s = s + "

"; + + return s; + } + + public String IngresarPregunta() { + String s = "
INGRESAR UN NUEVA PREGUNTA

"; + s = s + "Id post:

"; + s = s + "Descripcion:

"; + s = s + "id usuario:

"; + s = s + "

"; + s = s + ""; + s = s + "

"; + + return s; + } + + public String IngresarAutomovil() { + String s = "
INGRESAR UN NUEVO VEHICULO


"; + s = s + "Marca:

"; + s = s + "Modelo:

"; + s = s + "Patente:

"; + s = s + "Color:

"; + s = s + "Tipo: Auto Moto Camion "; + s = s + "

Es coupe?(Auto):

"; + s = s + "CC(moto):

"; + s = s +"Capacidad(camion):

"; + s = s + "

"; + s = s + "

"; + s = s + ""; + + return s; + } + + public String getAutomoviles(String autos) { + String[] tmp = autos.split(","); + System.out.println(tmp[0]); + String s = "
PatenteMarca Modelo Color Tipo ID_DueñoEs Coupe?CCCapacidad
" + tmp[i] + "
"; + s = s + "
VEHICULOS REGISTRADOS

"; + s = s + "
"; + for (int i = 0; i < tmp.length ; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + s = s + ""; + + } + s = s + "
PatenteMarca Modelo Color Tipo ID_DueñoEs Coupe?CCCapacidad
" + tm[j] + "
"; + s = "
" + s; + s = s + "

"; + return s; + } + + public String getOwnAddress(String ciudades) { + String[] tmp = ciudades.split(","); + String s = ""; + s = s + "
CIUDADES REGISTRADAS

"; + s = s + "
"; + for (int i = 0; i < tmp.length ; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + s = s + ""; + + } + s = s + "
Provinciaciudad cod_postal Direccion Numero
" + tm[j] + "
"; + s = "
" + s; + s = s + "

"; + return s; + } + + public String getCities(String cities) { + String[] tmp = cities.split(","); + String s = ""; + s = s + "
CIUDADES REGISTRADAS

"; + s = s + "
"; + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j" + tm[j] + ""; + + } + s = s + ""; +// + } + s = s + "

"; + + return s; + } + + public String getAnswers(String answers) { + String[] tmp = answers.split(","); + System.out.println(tmp[0]); + String s = "
Provinciaciudad cod_postal Direccion Numero
"; + s = s + "
RESPUESTAS

"; + s = s + "
"; + for (int i = 0; i < tmp.length - 1; i++) { + s = s + ""; + String[] tm = tmp[i].split(" "); + for (int j = 0; j < 3; j++) { + s = s + ""; + + } + s = s + ""; +// + } + s = s + "

"; + + return s; + } + + public String getAnswersByid(String answers) { + String[] tmp = answers.split(" "); + String s = "
id_postid_user Descripcion
" + tm[j] + "
"; + s = s + "
RESPUESTAS

"; + s = s + "
"; + + s = s + ""; + for (int j = 0; j < 3; j++) { + s = s + ""; + + } + s = s + ""; + s = s + "

"; + + return s; + } + + public String getPostUser(String post) { + String[] tmp = post.split(","); + String s = "
POST

"; + s+= "
id_postid_user Descripcion
" + tmp[j] + "
"; + s = s + ""; + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + s = s + ""; + + } + s+="
IDDESCRIPCIONDUEÑO PATENTE
" + tm[j] + "
"; + s = s + "

Ver Post:

"; + s+=""; + return s; + } + + public String getPostGuest(String post) { + String[] tmp = post.split(","); + String s = "
POST

"; + s+= ""; + s = s + ""; + for (int i = 0; i < tmp.length; i++) { + s = s + ""; + String[] tm = tmp[i].split("}"); + for (int j = 0; j < tm.length; j++) { + s = s + ""; + + } + s = s + ""; + + } + s+="
IDDESCRIPCIONDUEÑO PATENTE
" + tm[j] + "
"; + s = s + "

Ver Post:

"; + s+="
"; + return s; + } + + public String contactAdminUser(){ + String s =""; + s+="
CarsApp "; + s+="

ContactarAdministrador

"; + s+=""; + s+="
"; + s+="Mensaje:
"; + s+=""; + s+="

"; + s = s + ""; + s+="
"; + return s; + } + public String contactAdminGuest(){ + String s =""; + s+="
CarsApp "; + s+="

ContactarAdministrador

"; + s+=""; + s+="
"; + s+="Mensaje:
"; + s+=""; + s+="

"; + s = s + ""; + s+="
"; + return s; + } + + public String loginUsuario() { + String s = "




CARSAPP

"; + s = s + "
Email:

"; + s = s + "Contraseña:

"; + s = s + "

"; + s = s + " "; + s = s + " "; + s = s + ""; + return s; + } + + public String userControlPane() { + String s = ""; + return s; + } + + public String adminControlPane() { + String s = ""; + return s; + } + + public String guestControlPane() { + String s = ""; + return s; + } + + public String webpage() { + String page = "
"; + + page = page + "

CARS APP

"; + + page += " * Crear Post

"; + page += "* Ver mis Posts

"; + page += "* Agregar Vehiculos

"; + page += "* Ver mis Vehiculos

"; + page += "* Agregar Direccion

"; + page += "* Ver mis Direcciones

"; + page += "* Ver Todos Los Posts

"; + page += "* Contactar con Admin "; + page += "

"; + + return page; + } + + public String admin() { + String s ="
"; + + s = s +"

ADMIN CARSAPP

"; + + s = s +"* Ver Usuarios

"; + s = s +"* Ver Post

"; + s = s +"* Crear Usuario

"; + s = s +"* Bloquear Usuario

"; + s = s +"* Borrar pregunta de Usuario

"; + s = s +"* Borrar respuesta de Usuario

"; + s = s +"* Bandeja de Mensajes

"; + s = s +""; + return s; + } + public String guest() { + String s ="
"; + + s = s +"

INVITADO CARSAPP

"; + + s = s + " * Ver todos los Posts

"; + s = s + "* Contactar con Admin "; + s = s +"

"; + return s; + } + +} diff --git a/src/main/java/com/unrc/app/MustacheTemplateEngine.java b/src/main/java/com/unrc/app/MustacheTemplateEngine.java new file mode 100644 index 0000000..e073d33 --- /dev/null +++ b/src/main/java/com/unrc/app/MustacheTemplateEngine.java @@ -0,0 +1,37 @@ +package com.unrc.app; + + +import com.github.mustachejava.DefaultMustacheFactory; +import com.github.mustachejava.Mustache; +import com.github.mustachejava.MustacheFactory; +import java.io.IOException; +import java.io.StringWriter; +import org.eclipse.jetty.io.RuntimeIOException; +import spark.ModelAndView; +import spark.TemplateEngine; + +public class MustacheTemplateEngine extends TemplateEngine { + + private MustacheFactory mustacheFactory; + + /** + * Constructs a mustache template engine + */ + public MustacheTemplateEngine() { + mustacheFactory = new DefaultMustacheFactory("templates"); + } + + @Override + public String render(ModelAndView modelAndView) { + String viewName = modelAndView.getViewName(); + + Mustache mustache = mustacheFactory.compile(viewName); + StringWriter stringWriter = new StringWriter(); + try { + mustache.execute(stringWriter, modelAndView.getModel()).close(); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + return stringWriter.toString(); + } + } diff --git a/src/main/java/com/unrc/app/models/Address.java b/src/main/java/com/unrc/app/models/Address.java new file mode 100644 index 0000000..72b2d5f --- /dev/null +++ b/src/main/java/com/unrc/app/models/Address.java @@ -0,0 +1,48 @@ +package com.unrc.app.models; + +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.javalite.activejdbc.Model; + +public class Address extends Model { + static { + + validatePresenceOf("street","city","province","postal_code","num"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("street", this.get("street")); +// json.put("city", this.get("descrcityiption")); +// json.put("province", this.get("province")); +// json.put("postal_code", this.get("postal_code")); +// json.put("num", this.get("num")); +// ElasticSearch.client().prepareIndex("addresses", "address",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } + + public static Address findByAddress(String direc , int num, String ciudad, String provincia, int codigoPostal){ + return (Address.findFirst("street = ? and num = ? and city = ? and province = ? and postal_code =?", direc , num, ciudad,provincia,codigoPostal)); + } + + public static Address createAddress(String direc , int num, String ciudad, String provincia, int codigoPostal){ + Address address = create("street", direc,"num", num,"city",ciudad,"province",provincia,"postal_code",codigoPostal); + address.saveIt(); + return findByAddress(direc,num,ciudad,provincia,codigoPostal); + } + + public static Boolean direcExistente(String direc, int num,String ciudad,String provincia, int codigoPostal){ + return (Address.first("street = ? and num = ? and city = ? and province = ? and postal_code =?",direc, num, ciudad,provincia,codigoPostal) != null); + } + + public static void deleteAddress(String dir, int num, String ciudad,String provincia, int codigoPostal){ + Address address = Address.findByAddress(dir,num,ciudad,provincia,codigoPostal); + if(direcExistente(dir,num, ciudad,provincia,codigoPostal)) + address.delete(); + } +} \ No newline at end of file diff --git a/src/main/java/com/unrc/app/models/Answer.java b/src/main/java/com/unrc/app/models/Answer.java new file mode 100644 index 0000000..188ce0c --- /dev/null +++ b/src/main/java/com/unrc/app/models/Answer.java @@ -0,0 +1,48 @@ + +package com.unrc.app.models; + +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.javalite.activejdbc.Model; + +public class Answer extends Model{ + static { + validatePresenceOf("id_user","description","id_question"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("id_user", this.get("id_user")); +// json.put("description", this.get("description")); +// json.put("id_question", this.get("id_question")); +// ElasticSearch.client().prepareIndex("questions", "question",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } + public static Answer findByAnswer(int id_user, int id_question){ + return (findFirst("id_question = ? and id_user = ?", id_question, id_user)); + } + + public static Answer createAnswer(User user, int question, String descripcion){ + int user2 = user.getInteger("id_user"); + Answer answer =create("id_user",user2, "description",descripcion,"id_question",question); + answer.saveIt(); + return findByAnswer(user2,question); + } + + public static Boolean existAnswer(int id_question){ + return (Answer.first("id_question = ? ", id_question) != null); + } + + public static void deleteAnswer(int id_question){ + if(existAnswer(id_question)){ + Answer.delete("id_question = ? ", id_question); + } + } + + +} diff --git a/src/main/java/com/unrc/app/models/Message.java b/src/main/java/com/unrc/app/models/Message.java new file mode 100644 index 0000000..b9d2edc --- /dev/null +++ b/src/main/java/com/unrc/app/models/Message.java @@ -0,0 +1,49 @@ +package com.unrc.app.models; + +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.javalite.activejdbc.Model; + + +public class Message extends Model { + static { + validatePresenceOf("id_user","description"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("description", this.get("description")); +// json.put("id_user", this.get("id_user")); +// +// System.out.println(this.getId()+" ----este es el id---"); +// ElasticSearch.client().prepareIndex("messages", "message",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } + + public static Message findByMessage(int id_message ){ + return (Message.findFirst("id_message =?", id_message )); + } + + public static Message createMessage(int id_user, String descripcion){ + Message message = create("id_user", id_user,"description", descripcion); + message.saveIt(); + Message f = Message.findFirst("id_user =? and description=?", id_user,descripcion ); + return findByMessage(f.getInteger("id_message")); + } + + public static Boolean messageExistente(int id_message){ + return (Message.first("id_message =?", id_message)!=null); + } + + public static void deleteMessage(int id_message){ + Message message = Message.findByMessage(id_message); + if(messageExistente(id_message)) + message.delete("id_message = ?", id_message); + } + +} diff --git a/src/main/java/com/unrc/app/models/MessageGuest.java b/src/main/java/com/unrc/app/models/MessageGuest.java new file mode 100644 index 0000000..e84964c --- /dev/null +++ b/src/main/java/com/unrc/app/models/MessageGuest.java @@ -0,0 +1,45 @@ +package com.unrc.app.models; + +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.javalite.activejdbc.Model; + + +public class MessageGuest extends Model { + static { + validatePresenceOf("description"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("description", this.get("description")); +// System.out.println(this.getId()+" ----este es el id---"); +// ElasticSearch.client().prepareIndex("messageguests", "messageguest",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } + + public static MessageGuest findByMessageGuest(int id_messageGuest){ + return (MessageGuest.findFirst("id_messageGuest =?", id_messageGuest )); + } + + public static void createMessageGuest(String descripcion){ + MessageGuest messageGuest = create("description", descripcion); + messageGuest.saveIt(); + } + + public static Boolean messageGuestExistente(int id_messageGuest){ + return (MessageGuest.first("id_messageGuest =?", id_messageGuest)!=null); + } + + public static void deleteMessageGuest(int id_messageGuest){ + MessageGuest messageGuest = MessageGuest.findByMessageGuest(id_messageGuest); + if(messageGuestExistente(id_messageGuest)) + messageGuest.delete("id_messageGuest = ?", id_messageGuest); + } + +} diff --git a/src/main/java/com/unrc/app/models/Post.java b/src/main/java/com/unrc/app/models/Post.java new file mode 100644 index 0000000..6df42b9 --- /dev/null +++ b/src/main/java/com/unrc/app/models/Post.java @@ -0,0 +1,54 @@ +package com.unrc.app.models; +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.javalite.activejdbc.Model; + +public class Post extends Model { + static { + validatePresenceOf("id_user", "id_address","patent","description"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("id_user", this.get("id_user")); +// json.put("id_address", this.get("id_address")); +// json.put("patent", this.get("patent")); +// json.put("description", this.get("description")); +// ElasticSearch.client().prepareIndex("posts", "post",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } + + public static Post findByPost(int id_user, String patente){ + return (findFirst("id_user = ? and patent = ?", id_user, patente)); + } + + public static Post createPost(User user, int id_address,String patente, String descripcion){ + int user2 = user.getInteger("id_user"); + Post post =create("id_user",user2,"id_address",id_address, "description",descripcion,"patent",patente); + post.saveIt(); + return findByPost(user2,patente); + } + + public static Boolean existPost(int id_user,String patente){ + return (Post.first("id_user = ? and patent = ? ", id_user,patente) != null); + } + + public static void deletePost(int id_post){ + List q = Question.find("id_post =?",id_post); + for (int i = 0; i < q.size(); i++) { + Answer.deleteAnswer(q.get(i).getInteger("id_question")); + + } + + Question.delete("id_post = ?", id_post ); + + Post.delete("id_post = ? ",id_post); + } +} + diff --git a/src/main/java/com/unrc/app/models/Question.java b/src/main/java/com/unrc/app/models/Question.java new file mode 100644 index 0000000..e2c2a8b --- /dev/null +++ b/src/main/java/com/unrc/app/models/Question.java @@ -0,0 +1,50 @@ + +package com.unrc.app.models; +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.javalite.activejdbc.Model; + + +public class Question extends Model{ + static { + validatePresenceOf("id_user","id_post","description"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("id_user", this.get("id_user")); +// json.put("id_post", this.get("id_post")); +// json.put("description", this.get("description")); +// ElasticSearch.client().prepareIndex("questions", "question",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } + + public static Question findByQuestion(int id_user, int id_post){ + return (findFirst("id_post = ? and id_user = ?", id_post, id_user)); + } + + public static Question createQuestion(User user, int id_post, String descripcion){ + int user2 = user.getInteger("id_user"); + Question question =create("id_user",user2, "description",descripcion,"id_post",id_post); + question.saveIt(); + return findByQuestion(user2,id_post); + } + + public static Boolean existQuestion(int id_user,int id_post){ + return (Answer.first("id_user = ? and id_post = ? ", id_user,id_post) != null); + } + + public static void deleteQuestion(int id_question,int id_user,int id_post){ + if(existQuestion(id_user,id_post)){ + Answer.delete("id_question = ?", id_question ); + Question.delete("id_user = ? and id_post = ? ",id_user, id_post); + } + } + + +} diff --git a/src/main/java/com/unrc/app/models/User.java b/src/main/java/com/unrc/app/models/User.java index 5441706..afa13be 100644 --- a/src/main/java/com/unrc/app/models/User.java +++ b/src/main/java/com/unrc/app/models/User.java @@ -1,9 +1,64 @@ package com.unrc.app.models; +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.search.SearchResponse; import org.javalite.activejdbc.Model; public class User extends Model { - static { - validatePresenceOf("first_name", "last_name"); - } + static { + validatePresenceOf("first_name", "last_name", "email", "contrasena"); + } + @Override + public void afterCreate(){ + + Map json = new HashMap<>(); + json.put("name", this.get("first_name")); + json.put("email", this.get("email")); + json.put("id", this.getId()); + ElasticSearch.client().prepareIndex("users", "user",String.valueOf(this.getId())) + .setSource(json) + .execute() + .actionGet(); + getUserElasticsearch(); + + } + public void getUserElasticsearch(){ + System.out.println("---------------------------antesconsulta---------------------------------------------"); + + GetResponse response = ElasticSearch.client().prepareGet("users", "user", String.valueOf(this.getId())) + .execute() + .actionGet(); + System.out.println("---------------------------consulta---------------------------------------------"); + + System.out.println("source---"+response.getSource()); + } + + + public static User findByEmail(String email){ + return (findFirst("email = ?", email)); + } + + public static Boolean existUser(int id_user){ + return (User.first("id_user = ? ", id_user) != null); + } + + public static User createUser(String nombre, String apellido, String email, String contrasena){ + User user =create("first_name", nombre, "last_name", apellido, "email", email, "contrasena", contrasena); + user.saveIt(); + return findByEmail(email); + } + + public static void deleteUser(int id_user){ + if(existUser(id_user)){ + User.delete("id_user = ?", id_user); + Vehicle.delete("id_user=?", id_user); + Post.delete("id_user=?", id_user); + Answer.delete("id_user=?", id_user); + Question.delete("id_user=?", id_user); + } + + } } diff --git a/src/main/java/com/unrc/app/models/UsersAddress.java b/src/main/java/com/unrc/app/models/UsersAddress.java new file mode 100644 index 0000000..311ca1e --- /dev/null +++ b/src/main/java/com/unrc/app/models/UsersAddress.java @@ -0,0 +1,47 @@ +package com.unrc.app.models; +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.javalite.activejdbc.Model; +import org.javalite.activejdbc.annotations.Table; + +public class UsersAddress extends Model { + static { + validatePresenceOf("id_user","id_address"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("id_user", this.get("id_user")); +// json.put("id_address", this.get("id_address")); +// ElasticSearch.client().prepareIndex("usersAddress", "useraddress",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } + + public static UsersAddress findByUsersAddress(int id_user, int id_address){ + return (findFirst("id_user = ? and id_address= ?", id_user,id_address)); + } + + public static UsersAddress createUsersAddress(int id_user, int id_address){ + UsersAddress answer =create("id_user",id_user, "id_address",id_address); + answer.saveIt(); + return findByUsersAddress(id_user,id_address); + } + + public static Boolean existUsersAddress(int id_user,int id_address){ + return (UsersAddress.first("id_user = ? and id_address = ? ", id_user,id_address) != null); + } + + public static void deleteUsersAddress(int id_user,int id_address){ + if(existUsersAddress(id_user,id_address)){ + UsersAddress.delete("id_user = ? and id_question = ? ",id_user, id_address); + } + } + + + +} diff --git a/src/main/java/com/unrc/app/models/Vehicle.java b/src/main/java/com/unrc/app/models/Vehicle.java new file mode 100644 index 0000000..4009dfd --- /dev/null +++ b/src/main/java/com/unrc/app/models/Vehicle.java @@ -0,0 +1,68 @@ + +package com.unrc.app.models; +import com.unrc.app.ElasticSearch; +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.get.GetResponse; +import org.javalite.activejdbc.Model; +import org.elasticsearch.client.Client; + +public class Vehicle extends Model{ + static { + validatePresenceOf("mark", "model","patent","id_user", "color","tipo","cc","isCoupe","capacity"); + } +// @Override +// public void afterCreate(){ +// +// Map json = new HashMap<>(); +// json.put("mark", this.get("mark")); +// json.put("model", this.get("model")); +// json.put("patent", this.get("patent")); +// json.put("id_user", this.get("id_user")); +// json.put("color", this.get("color")); +// json.put("tipo", this.get("tipo")); +// json.put("cc", this.get("cc")); +// json.put("isCoupe", this.get("isCoupe")); +// json.put("capacity", this.get("capacity")); +// +// ElasticSearch.client().prepareIndex("vehicles", "vehicle",String.valueOf(this.getId())) +// .setSource(json) +// .execute() +// .actionGet(); +// +// } +// public void getVehicleElasticsearch(){ +// System.out.println("---------------------------antesconsulta---------------------------------------------"); +// ElasticSearch.client().close(); +// GetResponse response = ElasticSearch.client().prepareGet("vehicles", "vehicle", "2") +// .execute() +// .actionGet(); +// System.out.println("---------------------------consulta---------------------------------------------"); +// +// System.out.println("source---"+response.getSource()); +// System.out.println("source as string --- "+response.getSourceAsString()); +// } + + public static Vehicle findByPatent(String patente){ + return (findFirst("patent = ?", patente)); + } + + public static Boolean existVehicle(String patente){ + return (Vehicle.first("patent = ? ", patente ) == null); + } + + public static Vehicle createVehicle(String patente, String marca, String modelo,int usuario,String color,String tipo,int cc,String isCoupe,int capacity){ + Vehicle vehiculo =create("patent", patente, "model", modelo, "mark", marca,"id_user",usuario,"color",color,"tipo",tipo,"cc",cc,"isCoupe",isCoupe,"Capacity",capacity); + + vehiculo.saveIt(); + + return findByPatent(patente); + } + + public static void deleteVehicle(String patente){ + if(existVehicle(patente)){ + Vehicle.delete("patent = ?", patente ); + } + } + +} diff --git a/src/main/java/com/unrc/app/users.mustache b/src/main/java/com/unrc/app/users.mustache new file mode 100644 index 0000000..af4dbc0 --- /dev/null +++ b/src/main/java/com/unrc/app/users.mustache @@ -0,0 +1,12 @@ +

Users

+ +

Users count: {{users_count}}

+ + + {{#users}} + + + + {{/users}} +
{{name}}
+ diff --git a/src/main/resources/users.mustache b/src/main/resources/users.mustache new file mode 100644 index 0000000..af4dbc0 --- /dev/null +++ b/src/main/resources/users.mustache @@ -0,0 +1,12 @@ +

Users

+ +

Users count: {{users_count}}

+ + + {{#users}} + + + + {{/users}} +
{{name}}
+ diff --git a/src/test/java/com/unrc/app/CityTest.java b/src/test/java/com/unrc/app/CityTest.java new file mode 100644 index 0000000..812e783 --- /dev/null +++ b/src/test/java/com/unrc/app/CityTest.java @@ -0,0 +1,48 @@ +package com.unrc.app; + +import com.unrc.app.models.User; +import com.unrc.app.models.Address; + +import org.javalite.activejdbc.Base; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.javalite.test.jspec.JSpec.the; +import static org.junit.Assert.assertEquals; + +public class CityTest{ + @Before + public void before(){ + Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", ""); + System.out.println("UserTest setup"); + Base.openTransaction(); + } + + @After + public void after(){ + System.out.println("UserTest tearDown"); + Base.rollbackTransaction(); + Base.close(); + } + + @Test + public void shouldValidateMandatoryFields(){ + User user = new User(); + Address adress = new Address(); + the(user).shouldNotBe("valid"); + the(adress).shouldNotBe("valid"); + the(adress.errors().get("street")).shouldBeEqual("value is missing"); + the(adress.errors().get("city")).shouldBeEqual("value is missing"); + the(adress.errors().get("province")).shouldBeEqual("value is missing"); + the(adress.errors().get("postal_code")).shouldBeEqual("value is missing"); + the(adress.errors().get("num")).shouldBeEqual("value is missing"); + + user.set("first_name", "John", "last_name", "Doe", "email", "example@email.com","contrasena","asd123"); + adress.set("street","mitre","city","rio cuarto","province","cordoba","postal_code","5800","num","220"); + + // Everything is good: + the(user).shouldBe("valid"); + the(adress).shouldBe("valid"); + } +} diff --git a/src/test/java/com/unrc/app/PostTest.java b/src/test/java/com/unrc/app/PostTest.java new file mode 100644 index 0000000..5000366 --- /dev/null +++ b/src/test/java/com/unrc/app/PostTest.java @@ -0,0 +1,53 @@ +package com.unrc.app; + +import com.unrc.app.models.User; +import com.unrc.app.models.Post; +import com.unrc.app.models.Vehicle; + +import org.javalite.activejdbc.Base; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.javalite.test.jspec.JSpec.the; +import static org.junit.Assert.assertEquals; + +public class PostTest{ + @Before + public void before(){ + Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", ""); + System.out.println("UserTest setup"); + Base.openTransaction(); + } + + @After + public void after(){ + System.out.println("UserTest tearDown"); + Base.rollbackTransaction(); + Base.close(); + } + + @Test + public void shouldValidateMandatoryFields(){ + User user = new User(); + Vehicle vehicle = new Vehicle(); + Post post = new Post(); + the(user).shouldNotBe("valid"); + the(post).shouldNotBe("valid"); + the(vehicle).shouldNotBe("valid"); + the(post.errors().get("id_user")).shouldBeEqual("value is missing"); + the(post.errors().get("id_address")).shouldBeEqual("value is missing"); + the(post.errors().get("patent")).shouldBeEqual("value is missing"); + the(post.errors().get("description")).shouldBeEqual("value is missing"); + + post.set("id_user","1","id_address","1","patent","kff911","description","si es un buen coche"); + user.set("first_name", "John", "last_name", "Doe", "email", "example@email.com","contrasena","asd123"); + vehicle.set("id_vehicle","1","patent","kff911","mark","ferrari","model","enzo","id_user","1","color","rojo","tipo","auto","cc","0","isCoupe","si","capacity","2"); + + + // Everything is good: + the(user).shouldBe("valid"); + the(post).shouldBe("valid"); + the(vehicle).shouldBe("valid"); + } +} diff --git a/src/test/java/com/unrc/app/QuestionTest.java b/src/test/java/com/unrc/app/QuestionTest.java new file mode 100644 index 0000000..55f78e2 --- /dev/null +++ b/src/test/java/com/unrc/app/QuestionTest.java @@ -0,0 +1,61 @@ +package com.unrc.app; + +import com.unrc.app.models.User; +import com.unrc.app.models.Post; +import com.unrc.app.models.Question; +import com.unrc.app.models.Vehicle; + +import org.javalite.activejdbc.Base; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.javalite.test.jspec.JSpec.the; +import static org.junit.Assert.assertEquals; + +public class QuestionTest{ + @Before + public void before(){ + Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", ""); + System.out.println("UserTest setup"); + Base.openTransaction(); + } + + @After + public void after(){ + System.out.println("UserTest tearDown"); + Base.rollbackTransaction(); + Base.close(); + } + + @Test + public void shouldValidateMandatoryFields(){ + User user = new User(); + User user2 = new User(); + Vehicle vehicle = new Vehicle(); + Post post = new Post(); + Question question = new Question(); + the(question).shouldNotBe("valid"); + the(user).shouldNotBe("valid"); + the(post).shouldNotBe("valid"); + the(vehicle).shouldNotBe("valid"); + the(post.errors().get("id_user")).shouldBeEqual("value is missing"); + the(post.errors().get("id_address")).shouldBeEqual("value is missing"); + the(post.errors().get("patent")).shouldBeEqual("value is missing"); + the(post.errors().get("description")).shouldBeEqual("value is missing"); + + post.set("id_user","1","id_address","1","patent","kff911","description","es un gran coche"); + user.set("first_name", "John", "last_name", "Doe", "email", "example@email.com","contrasena","asd123"); + user2.set("first_name", "Juan", "last_name", "hulk", "email", "example2@email.com","contrasena","asd456"); + vehicle.set("id_vehicle","1","patent","kff911","mark","ferrari","model","enzo","id_user","1","color","rojo","tipo","auto","cc","0","isCoupe","si","capacity","2"); + question.set("id_user","2","id_post","1","description","cual es el precio"); + + + + // Everything is good: + the(user).shouldBe("valid"); + the(post).shouldBe("valid"); + the(vehicle).shouldBe("valid"); + the(question).shouldBe("valid"); + } +} diff --git a/src/test/java/com/unrc/app/UserAdressTest.java b/src/test/java/com/unrc/app/UserAdressTest.java new file mode 100644 index 0000000..7052e74 --- /dev/null +++ b/src/test/java/com/unrc/app/UserAdressTest.java @@ -0,0 +1,54 @@ +package com.unrc.app; + +import com.unrc.app.models. *; + + +import org.javalite.activejdbc.Base; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.javalite.test.jspec.JSpec.the; +import static org.junit.Assert.assertEquals; + +public class UserAdressTest{ + @Before + public void before(){ + Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", ""); + System.out.println("UserTest setup"); + Base.openTransaction(); + } + + @After + public void after(){ + System.out.println("UserTest tearDown"); + Base.rollbackTransaction(); + Base.close(); + } + + @Test + public void shouldValidateMandatoryFields(){ + User user = new User(); + Post post = new Post(); + UsersAddress address = new UsersAddress(); + the(user).shouldNotBe("valid"); + the(post).shouldNotBe("valid"); + the(address).shouldNotBe("valid"); + the(address.errors().get("id_user")).shouldBeEqual("value is missing"); + the(address.errors().get("id_address")).shouldBeEqual("value is missing"); + + post.set("id_user","1","id_address","1","patent","kff911","description","es un gran coche"); + user.set("first_name", "John", "last_name", "Doe", "email", "example@email.com","contrasena","asd123"); + address.set("id_user","1","id_address","1"); + + + // Everything is good: + the(user).shouldBe("valid"); + the(post).shouldBe("valid"); + the(address).shouldBe("valid"); + + } + + + +} diff --git a/src/test/java/com/unrc/app/UserTest.java b/src/test/java/com/unrc/app/UserTest.java index be59bd8..fae767c 100644 --- a/src/test/java/com/unrc/app/UserTest.java +++ b/src/test/java/com/unrc/app/UserTest.java @@ -13,7 +13,7 @@ public class UserTest{ @Before public void before(){ - Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_test", "root", ""); + Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", ""); System.out.println("UserTest setup"); Base.openTransaction(); } @@ -32,8 +32,10 @@ public void shouldValidateMandatoryFields(){ the(user).shouldNotBe("valid"); the(user.errors().get("first_name")).shouldBeEqual("value is missing"); the(user.errors().get("last_name")).shouldBeEqual("value is missing"); + the(user.errors().get("email")).shouldBeEqual("value is missing"); + the(user.errors().get("contrasena")).shouldBeEqual("value is missing"); - user.set("first_name", "John", "last_name", "Doe", "email", "example@email.com"); + user.set("first_name", "John", "last_name", "Doe", "email", "example@email.com","contrasena","asd123"); // Everything is good: the(user).shouldBe("valid"); diff --git a/src/test/java/com/unrc/app/VehicleTest.java b/src/test/java/com/unrc/app/VehicleTest.java new file mode 100644 index 0000000..a17b22c --- /dev/null +++ b/src/test/java/com/unrc/app/VehicleTest.java @@ -0,0 +1,52 @@ +package com.unrc.app; + +import com.unrc.app.models.User; +import com.unrc.app.models.Vehicle; +import org.javalite.activejdbc.Base; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.javalite.test.jspec.JSpec.the; +import static org.junit.Assert.assertEquals; + +public class VehicleTest { + + @Before + public void before() { + Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/carsapp_development", "root", ""); + System.out.println("UserTest setup"); + Base.openTransaction(); + } + + @After + public void after() { + System.out.println("UserTest tearDown"); + Base.close(); + } + + @Test + public void shouldValidateMandatoryFields() { + Vehicle vehicle = new Vehicle(); + User user = new User(); + the(user).shouldNotBe("valid"); + the(vehicle).shouldNotBe("valid"); + the(vehicle.errors().get("patent")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("mark")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("model")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("id_user")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("color")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("tipo")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("cc")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("isCoupe")).shouldBeEqual("value is missing"); + the(vehicle.errors().get("capacity")).shouldBeEqual("value is missing"); + + user.set("first_name", "John", "last_name", "Doe", "email", "example@email.com","contrasena","asd123"); + vehicle.set("patent","kff911","mark","ferrari","model","enzo","id_user","1","color","rojo","tipo","auto","cc","0","isCoupe","si","capacity","0"); + + // Everything is good: + + the(user).shouldBe("valid"); + the(vehicle).shouldBe("valid"); + + } +} diff --git a/users.mustache b/users.mustache new file mode 100644 index 0000000..af4dbc0 --- /dev/null +++ b/users.mustache @@ -0,0 +1,12 @@ +

Users

+ +

Users count: {{users_count}}

+ + + {{#users}} + + + + {{/users}} +
{{name}}
+