/app/controllers/Application.java
Java | 2137 lines | 1763 code | 167 blank | 207 comment | 388 complexity | 742548c6cbdc889081855c023b02ae76 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- package controllers;
- import Persistence.MongoBase;
- import com.fasterxml.jackson.databind.JsonNode;
- import com.google.gson.JsonArray;
- import com.google.gson.JsonObject;
- import com.google.gson.JsonParser;
- import com.google.gson.JsonPrimitive;
- import com.mongodb.Mongo;
- import com.typesafe.plugin.MailerAPI;
- import com.typesafe.plugin.MailerPlugin;
- import models.*;
- import models.Notifications.Notification;
- import models.Notifications.Publication;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.bson.types.ObjectId;
- import play.Logger;
- import play.data.Form;
- import play.libs.Akka;
- import play.libs.F;
- import play.libs.WS;
- import play.libs.WS.WSRequestHolder;
- import play.mvc.Controller;
- import play.mvc.Result;
- import play.mvc.Security;
- import views.html.*;
- import javax.mail.*;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import java.io.File;
- import java.io.FileInputStream;
- import java.util.*;
- import java.util.concurrent.Callable;
- import java.util.regex.Pattern;
- import static play.data.Form.form;
- public class Application extends Controller {
- private static final String FB_APP_ID = "583844725030243";
- private static final String FB_APP_SECRET = "fcc5fc20bb48f1a7da3f14ea83ebdec3";
- @Security.Authenticated(Secured.class)
- public static Result index() {
- if(session().get("role").equalsIgnoreCase("venue")){
- return redirect(
- routes.VenuePanel.blank()
- );
- }else if(session().get("role").equalsIgnoreCase("admin")){
- return redirect(
- routes.AdminPanel.blank()
- );
- }
- else{
- return ok(index.render(MongoBase.findListOfDishes(20), MongoBase.findListOfFeeds()));
- }
- }
- public static Result front() {
- return ok(front.render());
- }
- public static Result negocios() {
- return ok(negocios.render(form(ClientContact.class)));
- }
- /**
- * Display the paginated list of computers.
- *
- * @param page Current page number (starts from 0)
- * @param sortBy Column to be sorted
- * @param order Sort order (either asc or desc)
- * @param filter Filter applied on computer names
- */
- @Security.Authenticated(Secured.class)
- public static Result list(int page, String sortBy, String order, String filter) {
- return ok(
- list.render(
- Venues.page(page, 10, sortBy, order, filter),
- sortBy, order, filter
- )
- );
- }
- /**
- * Display the paginated list of computers.
- *
- * @param page Current page number (starts from 0)
- * @param sortBy Column to be sorted
- * @param order Sort order (either asc or desc)
- * @param filter Filter applied on computer names
- */
- @Security.Authenticated(Secured.class)
- public static Result dishesList(int page, String sortBy, String order, String filter) {
- return ok(
- dishList.render(
- Dishes.page(page, 10, sortBy, order, filter),
- sortBy, order, filter
- )
- );
- }
- /**
- * Display the paginated list of computers.
- *
- * @param page Current page number (starts from 0)
- * @param sortBy Column to be sorted
- * @param order Sort order (either asc or desc)
- */
- @Security.Authenticated(Secured.class)
- public static Result venueDishList(int page, String sortBy, String order, String filter) {
- Venue v=MongoBase.findVenueById(session().get("venueId"));
- return ok(
- venuedishes.render(v,
- Dishes.venuePage(page, 10, sortBy, order, session().get("venueId"),filter),
- sortBy, order, session().get("venueId"),filter
- )
- );
- }
- /**
- * Display the paginated list of computers.
- *
- * @param page Current page number (starts from 0)
- * @param sortBy Column to be sorted
- * @param order Sort order (either asc or desc)
- */
- @Security.Authenticated(Secured.class)
- public static Result venuePubList(int page, String sortBy, String order, String filter) {
- // Venue v=MongoBase.findVenueById(session().get("venueId"));
- return ok(
- venuepubs.render(
- Publications.venuePage(page, 10, sortBy, order, session().get("venueId"),filter),
- sortBy, order, session().get("venueId"),filter
- )
- );
- }
- @Security.Authenticated(Secured.class)
- public static Result dishesShowForProvince(String search, String location) {
- List<Dish> dishes = MongoBase.findListOfDishesByProvinceAndType(Dishes.cleanAndSplit(search), location);
- ;
- switch (dishes.size()) {
- case 1:
- return ok(dishShow.render(dishes.get(0), MongoBase.findListOfFeeds()));
- default:
- return ok(dishesShow.render(dishes, search, MongoBase.findListOfFeeds()));
- }
- }
- @Security.Authenticated(Secured.class)
- public static Result dishesShowForCity(String search, String location) {
- List<Dish> dishes = MongoBase.findListOfDishesByCityAndType(Dishes.cleanAndSplit(search), location);
- ;
- switch (dishes.size()) {
- case 1:
- return ok(dishShow.render(dishes.get(0), MongoBase.findListOfFeeds()));
- default:
- return ok(dishesShow.render(dishes, search, MongoBase.findListOfFeeds()));
- }
- }
- @Security.Authenticated(Secured.class)
- public static Result venuesShowForCity(String search, String location) {
- List<Venue> venues = MongoBase.findListOfVenuesForCity(search, location);
- ;
- switch (venues.size()) {
- case 1:
- return ok(venueShow.render(venues.get(0), MongoBase.findListOfDishesByVenueId(venues.get(0).oid.toString()), MongoBase.findListOfFeeds()));
- default:
- return ok(venuesShow.render(venues, search, MongoBase.findListOfFeeds()));
- }
- }
- @Security.Authenticated(Secured.class)
- public static Result venuesShowForProvince(String search, String location) {
- List<Venue> venues = MongoBase.findListOfVenuesForProvince(search, location);
- ;
- switch (venues.size()) {
- case 1:
- return ok(venueShow.render(venues.get(0), MongoBase.findListOfDishesByVenueId(venues.get(0).oid.toString()), MongoBase.findListOfFeeds()));
- default:
- return ok(venuesShow.render(venues, search, MongoBase.findListOfFeeds()));
- }
- }
- public static Result checkValidationCode() {
- JsonNode json = request().body().asJson();
- String code = json.findPath("registerCode").asText();
- if (code == null) {
- return badRequest("Missing parameter [code]. Where is my motherf***ing code!!");
- } else if (!MongoBase.checkValidationCode(code)) {
- return badRequest("No code, no user ");
- }
- return ok("CODIGO CORRECTO!");
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findVenueNameById(String venueId) {
- if (venueId == null) {
- return badRequest("Missing parameter [venueId].");
- }
- String venueName = MongoBase.findVenueNameById(venueId);
- if (venueName == null) {
- return badRequest("Bad Request");
- }
- return ok(venueName);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findVenueById(String venueId) {
- if (venueId == null) {
- return badRequest("Missing parameter [venueId].");
- }
- String venue = MongoBase.findVenueJsonById(venueId);
- if (venue == null) {
- return badRequest("Bad Request");
- }
- return ok(venue);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findVenueByIdPost() {
- JsonNode json = request().body().asJson();
- if(!json.has("venueId")){
- return badRequest("missing parameter [venueId]");
- }
- String venue = MongoBase.findVenueJsonById(json.findPath("venueId").asText());
- if (venue == null) {
- return badRequest("Bad Request");
- }
- return ok(venue);
- }
- public static Result okTio() {
- return ok();
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findReviewsByUserId() {
- JsonNode json = request().body().asJson();
- String userId = json.findPath("userId").textValue();
- if (userId == null) {
- return badRequest("Missing parameter [userId].");
- }
- String user = MongoBase.findReviewsByUserId(new ObjectId(userId));
- Logger.info(user);
- if (user == null) {
- return badRequest("Bad Request");
- }
- return ok(user);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findUserById() {
- JsonNode json = request().body().asJson();
- String userId = json.findPath("userId").asText();
- if (userId == null) {
- return badRequest("Missing parameter [userId].");
- }
- String user = MongoBase.findUserJSONById(userId);
- if (user == null) {
- return badRequest("Bad Request");
- }
- return ok(user);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findUsersByName() {
- JsonNode json = request().body().asJson();
- String name = json.findPath("name").asText();
- if (name == null) {
- return badRequest("Missing parameter [name].");
- }
- String user = MongoBase.findUsersByName(name);
- if (user == null) {
- return badRequest("Bad Request");
- }
- return ok(user);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findUsersFollowed() {
- JsonNode json = request().body().asJson();
- String userId = json.findPath("userId").asText();
- if (userId == null) {
- return badRequest("Missing parameter [useId].");
- }
- String user = MongoBase.findUsersFollowed(userId);
- if (user == null) {
- return badRequest("Bad Request");
- }
- return ok(user);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findUsersByIds() {
- JsonNode json = request().body().asJson();
- Iterator<JsonNode> i = json.findPath("usersIds").elements();
- if (i == null) {
- return badRequest("Missing parameter [usersIds]");
- }
- ArrayList<String> al = new ArrayList<String>();
- while (i.hasNext()) {
- al.add(i.next().asText());
- }
- String users = MongoBase.findUsersById(al);
- if (users == null) {
- return badRequest("Bad Request");
- }
- return ok(users);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result updateUser() {
- Logger.info("UPDATING USER? ");
- JsonNode object = request().body().asJson();
- Logger.info(object.toString());
- User user=new User();
- String oldPassword="";
- if (object.has("user")) {
- user.user = object.get("user").asText();
- }
- if (object.has("mail")) {
- user.mail = object.get("mail").asText();
- }
- if (object.has("_id")) {
- user._id = new ObjectId(object.get("_id").asText());
- }
- if (object.has("fbid")) {
- user.fbid = object.get("fbid").asText();
- }
- if (object.has("location")) {
- user.location = object.get("location").asText();
- }
- if (object.has("date")) {
- user.date = object.get("date").asText();
- }
- if (object.has("birthday")) {
- user.birthday = object.get("birthday").asText();
- }
- if (object.has("gender")) {
- user.gender = object.get("gender").asText();
- }
- if (object.has("phone")) {
- user.phone = object.get("phone").asText();
- }
- if (object.has("photoURL")) {
- user.photoURL=object.get("photoURL").asText();
- }
- if (object.has("password")) {
- user.password = object.get("password").asText();
- }
- if (object.has("oldPassword")) {
- oldPassword=object.get("oldPassword").asText();
- }
- String pass=MongoBase.retrievePassword(user.mail);
- Logger.info("mail: "+object.get("mail").asText());
- if(pass.equalsIgnoreCase(oldPassword)){
- if (MongoBase.updateUser(user)) {
- return ok("Edición de usuario completa");
- } else {
- Logger.info("Error editando.");
- return badRequest("Error editando el usuario");
- }
- }return badRequest("OldPassword incorrecto");
- }
- @Security.Authenticated(VenueSecured.class)
- public static Result updateClient() {
- Logger.info("UPDATING USER? ");
- JsonNode object = request().body().asJson();
- Logger.info(object.toString());
- Client client=new Client();
- String oldPassword="";
- if (object.has("mail")) {
- client.setMail(object.get("mail").asText());
- }
- if (object.has("phone")) {
- client.setPhone(object.get("phone").asText());
- }
- if (object.has("password")) {
- client.setPassword(object.get("password").asText());
- }
- if (object.has("oldPassword")) {
- oldPassword=object.get("oldPassword").asText();
- }
- String pass=MongoBase.retrievePassword(client.getMail());
- Logger.info("mail: "+object.get("mail").asText());
- if(pass.equalsIgnoreCase(oldPassword)){
- if (MongoBase.updateClient(client)) {
- return ok("Edición de cliente completa");
- } else {
- Logger.info("Error editando.");
- return badRequest("Error editando el cliente");
- }
- }return badRequest("OldPassword incorrecto");
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result updateUserWithoutPassword() {
- Logger.info("UPDATING USER? ");
- JsonNode object = request().body().asJson();
- Logger.info(object.toString());
- User user=new User();
- if (object.has("user")) {
- user.user = object.get("user").asText();
- }
- if (object.has("mail")) {
- user.mail = object.get("mail").asText();
- }
- if (object.has("_id")) {
- user._id = new ObjectId(object.get("_id").asText());
- }
- if (object.has("fbid")) {
- user.fbid = object.get("fbid").asText();
- }
- if (object.has("location")) {
- user.location = object.get("location").asText();
- }
- if (object.has("date")) {
- user.date = object.get("date").asText();
- }
- if (object.has("birthday")) {
- user.birthday = object.get("birthday").asText();
- }
- if (object.has("gender")) {
- user.gender = object.get("gender").asText();
- }
- if (object.has("phone")) {
- user.phone = object.get("phone").asText();
- }
- if (object.has("photoURL")) {
- user.photoURL=object.get("photoURL").asText();
- }
- if (MongoBase.updateUser(user)) {
- return ok("Edición de usuario completa");
- } else {
- Logger.info("Error editando.");
- return badRequest("Error editando el usuario");
- }
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result createVenueByName() {
- JsonNode json = request().body().asJson();
- String name = json.findPath("name").asText();
- if (name == null) {
- return badRequest("Missing parameter [name]. Y tal...");
- }
- String result = MongoBase.insertVenueByName(name);
- if (result == null) {
- return badRequest("Error al introducir la venue. Nombre repetido?");
- }
- return ok(result);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result createVenueByProvinceAndName() {
- JsonNode json = request().body().asJson();
- Venue venue=new Venue();
- if(json.has("insertedBy")){
- venue.insertedBy=json.findPath("insertedBy").asText();
- }
- if(json.has("province")){
- venue.address.province=json.findPath("province").asText();
- }
- else{
- return badRequest("Missing parameter [province]. Y tal...");
- }
- if (json.has("name")) {
- venue.name=json.findPath("name").asText();
- }
- else{
- return badRequest("Missing parameter [name]. Y tal...");
- }
- String result=MongoBase.insertVenueByProvinceAndName(venue);
- if ( result==null) {
- return badRequest("Error al introducir la venue.¿¿ Tal vez nombre repetido??");
- }
- return ok(result);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result createVenueOnLocation() {
- JsonNode json = request().body().asJson();
- String atributo = json.findPath("name").asText();
- if (atributo == null) {
- return badRequest("Missing parameter [name]. Y tal...");
- }
- Venue v = new Venue();
- v.name = atributo;
- v.coordinates[0] = (float) json.findPath("coordinates").get(0).doubleValue();
- v.coordinates[1] = (float) json.findPath("coordinates").get(1).doubleValue();
- atributo = json.findPath("street").asText();
- if (atributo != null) {
- v.address.street = atributo;
- }
- atributo = json.findPath("date").asText();
- if (atributo != null) {
- v.date = atributo;
- }
- atributo = json.findPath("insertedBy").asText();
- if (atributo != null) {
- v.insertedBy = atributo;
- }
- //no cojemos el streetNumber, hay lios con int/string
- /*atributo=json.findPath("streetNumber").asText();
- if(atributo!=null){
- v.address.streetNumber=atributo;
- }*/
- atributo = json.findPath("insertedBy").asText();
- if (atributo != null) {
- v.insertedBy = atributo;
- }
- atributo = json.findPath("city").asText();
- if (atributo != null) {
- v.address.city = atributo;
- }
- atributo = json.findPath("province").asText();
- if (atributo != null) {
- v.address.province = atributo;
- }
- atributo = json.findPath("postalCode").asText();
- if (atributo != null) {
- v.address.postalCode = atributo;
- }
- String retorno = MongoBase.insertVenueOnLocation(v);
- if (retorno == null) {
- return badRequest("Error al introducir la venue. Nombre repetido?");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result createDishByNameAndVenueId() {
- Dish d = new Dish();
- JsonNode json = request().body().asJson();
- String name = json.findPath("name").asText();
- String venueId = json.findPath("venueId").asText();
- if (name == null || venueId == null) {
- return badRequest("Missing parameter [name]. Y tal...");
- }
- d.name = name;
- d.venueId = new ObjectId(venueId);
- String atributo = json.findPath("date").asText();
- if (atributo != null) {
- d.date = atributo;
- }
- atributo = json.findPath("insertedBy").asText();
- if (atributo != null) {
- d.insertedBy = atributo;
- }
- d.photoURL = "http://toptasting.s3.amazonaws.com/sinImagenDish.png";
- String dishId = MongoBase.insertDish(d);
- if (dishId == null) {
- return badRequest("Error al introducir el dish.");
- }
- return ok(dishId);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result createDish() {
- Dish d = new Dish();
- JsonNode json = request().body().asJson();
- String name = json.findPath("name").asText();
- String venueId = json.findPath("venueId").asText();
- if (name == null || venueId == null) {
- return badRequest("Missing parameter [name]. Y tal...");
- }
- if(json.hasNonNull("venueName")){
- d.venueName=json.findPath("venueName").asText();
- }
- if(json.hasNonNull("city")){
- d.city=json.findPath("city").asText();
- }
- if(json.hasNonNull("province")){
- d.province=json.findPath("province").asText();
- }
- if(json.hasNonNull("coordinates")){
- double[] coor = new double[2];
- if(json.findPath("coordinates").hasNonNull(0)){
- coor[0] = (float) json.findPath("coordinates").get(0).doubleValue();
- }
- if(json.findPath("coordinates").hasNonNull(1)){
- coor[1] = (float)json.findPath("coordinates").get(1).doubleValue();
- }
- d.coordinates=coor;
- }
- d.name = name;
- d.venueId = new ObjectId(venueId);
- String atributo = json.findPath("date").asText();
- if (atributo != null) {
- d.date = atributo;
- }
- atributo = json.findPath("insertedBy").asText();
- if (atributo != null) {
- d.insertedBy = atributo;
- }
- d.photoURL = "http://toptasting.s3.amazonaws.com/sinImagenDish.png";
- String dishId = MongoBase.insertDish(d);
- if (dishId == null) {
- return badRequest("Error al introducir el dish.");
- }
- return ok(dishId);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishes() {
- JsonNode json = request().body().asJson();
- String searchText = json.findPath("search").asText();
- if (searchText == null) {
- return badRequest("Missing search value");
- }
- String retorno = MongoBase.findDishes(searchText);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishesByType() {
- JsonNode json = request().body().asJson();
- Iterator<JsonNode> i = json.findPath("search").elements();
- if (i == null) {
- return badRequest("Missing search value");
- }
- ArrayList<String> al = new ArrayList<String>();
- while (i.hasNext()) {
- al.add(i.next().asText());
- }
- String retorno = MongoBase.findDishesByType(al);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishesByVenueId() {
- JsonNode json = request().body().asJson();
- String venueId = json.findPath("venueId").asText();
- if (venueId == null) {
- return badRequest("Missing parameter [venueId]");
- }
- String retorno = MongoBase.findDishesByVenueId(venueId);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- Logger.info("Solicitado FindDishesByVenueId");
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findPublicationsByVenueId() {
- JsonNode json = request().body().asJson();
- String venueId = json.findPath("venueId").asText();
- if (venueId == null) {
- return badRequest("Missing parameter [venueId]");
- }
- String retorno = MongoBase.findPublicationsByVenueId(venueId);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- Logger.info("Solicitado FindPublicationsByVenueId");
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDrafts() {
- JsonNode json = request().body().asJson();
- String userId = json.findPath("userId").asText();
- Logger.info("Buscando drafts para el userId "+userId);
- if (userId == null) {
- Logger.info("Se trató de buscar drafts sin user ID");
- return badRequest("Missing parameter [userId].");
- }
- String drafts = MongoBase.findDrafts(new ObjectId(userId));
- if (drafts == null) {
- Logger.info("Ha habido un error buscando drafts");
- return badRequest("Bad Request");
- }
- Logger.info(drafts);
- return ok(drafts);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findFavVenuesByUserId() {
- JsonNode json = request().body().asJson();
- String userId = json.findPath("userId").asText();
- if (userId == null) {
- Logger.info("Se trató de buscar drafts sin user ID");
- return badRequest("Missing parameter [userId].");
- }
- String venues = MongoBase.findFavVenuesByUserId(userId);
- if (venues == null) {
- Logger.info("Ha habido un error buscando venues favoritas");
- return badRequest("Bad Request");
- }
- return ok(venues);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findFavDishesByUserId() {
- JsonNode json = request().body().asJson();
- String userId = json.findPath("userId").asText();
- if (userId == null) {
- Logger.info("Se trató de buscar platos sin user ID");
- return badRequest("Missing parameter [userId].");
- }
- String venues = MongoBase.findFavDishesByUserId(userId);
- if (venues == null) {
- Logger.info("Ha habido un error buscando platos favoritas");
- return badRequest("Bad Request");
- }
- return ok(venues);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findFavPublicationsByUserId() {
- JsonNode json = request().body().asJson();
- String userId = json.findPath("userId").asText();
- if (userId == null) {
- Logger.info("Se trató de buscar publicaciones sin user ID");
- return badRequest("Missing parameter [userId].");
- }
- String venues = MongoBase.findFavPublicationsByUserId(userId);
- if (venues == null) {
- Logger.info("Ha habido un error buscando publicaciones favoritas");
- return badRequest("Bad Request");
- }
- Logger.info("VENUE PUBLICATIONS: "+venues);
- return ok(venues);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishWithId(String dishId) {
- if (dishId == null) {
- return badRequest("Missing parameter [dishId].");
- }
- String dish = MongoBase.findDishJSONById(dishId);
- if (dish == null) {
- return badRequest("Bad Request");
- }
- return ok(dish);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishById() {
- JsonNode json = request().body().asJson();
- String dishId;
- if(json.has("dishId")){
- dishId = json.findPath("dishId").asText();
- }else{
- return badRequest("Faltan parámetros [dishId]");
- }
- String dish = MongoBase.findDishJSONById(dishId);
- if (dish == null) {
- return badRequest("Bad Request");
- }
- return ok(dish);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findNearbyVenues() {
- JsonNode json = request().body().asJson();
- float lat = (float) json.findPath("coordinates").get(0).doubleValue();
- float lon = (float) json.findPath("coordinates").get(1).doubleValue();
- double dis = json.findPath("dis").doubleValue();
- String retorno = MongoBase.findNearbyVenues(lat, lon, dis);
- Logger.info("dis: " + dis + " lat:" + lat + " lon:" + lon);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findNearbyVenuesByName() {
- JsonNode json = request().body().asJson();
- float lat = (float) json.findPath("coordinates").get(0).doubleValue();
- float lon = (float) json.findPath("coordinates").get(1).doubleValue();
- double dis = json.findPath("dis").doubleValue();
- String search = json.findPath("search").asText();
- String retorno = MongoBase.findNearbyVenuesByName(lat, lon, dis, search);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findVenuesByProvince() {
- JsonNode json = request().body().asJson();
- String location = json.findPath("location").asText();
- String retorno = MongoBase.findVenuesByProvince(location);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findVenuesByProvinceAndName() {
- JsonNode json = request().body().asJson();
- String location = json.findPath("location").asText();
- String search = json.findPath("search").asText();
- String retorno = MongoBase.findVenuesByProvinceAndName(location, search);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- public static Result findVenuesByCity() {
- JsonNode json = request().body().asJson();
- System.out.println("buscando venues por ciudad: "+json);
- String location = json.findPath("location").asText();
- String retorno = MongoBase.findVenuesByCity(location);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- public static Result findVenuesByCityAndName() {
- JsonNode json = request().body().asJson();
- String location = json.findPath("location").asText();
- String search = json.findPath("search").asText();
- String retorno = MongoBase.findVenuesByCityAndName(location, search);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findVenuesById() {
- JsonNode json = request().body().asJson();
- List<String> venueIds = json.findValuesAsText("venueIds");
- String retorno = MongoBase.findVenuesById(venueIds);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findNearbyDishesByType() {
- JsonNode json = request().body().asJson();
- float[] coor = new float[2];
- System.out.println("json recibido "+json);
- coor[0] = (float) json.findPath("coordinates").get(0).doubleValue();
- coor[1] = (float) json.findPath("coordinates").get(1).doubleValue();
- double dis = json.findPath("dis").doubleValue();
- Iterator<JsonNode> i = json.findPath("search").elements();
- Logger.info("dis: " + dis + " lat:" + coor[0] + " lon:" + coor[1]);
- if (i == null) {
- return badRequest("Missing search value");
- }
- ArrayList<String> al = new ArrayList<String>();
- while (i.hasNext()) {
- al.add(i.next().asText());
- }
- String retorno = MongoBase.findNearbyDishesByType(coor, dis, al);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishesByCityAndType() {
- JsonNode json = request().body().asJson();
- String location = json.findPath("location").asText();
- Iterator<JsonNode> i = json.findPath("search").elements();
- if (i == null) {
- return badRequest("Missing search value");
- }
- ArrayList<String> al = new ArrayList<String>();
- while (i.hasNext()) {
- al.add(i.next().asText());
- }
- String retorno = MongoBase.findDishesByCityAndType(location, al);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishesByProvinceAndType() {
- JsonNode json = request().body().asJson();
- String location = json.findPath("location").asText();
- Iterator<JsonNode> i = json.findPath("search").elements();
- if (i == null) {
- return badRequest("Missing search value");
- }
- ArrayList<String> al = new ArrayList<String>();
- while (i.hasNext()) {
- al.add(i.next().asText());
- }
- String retorno = MongoBase.findDishesByProvinceAndType(location, al);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- public static Result findNearbyDishes() {
- JsonNode json = request().body().asJson();
- Logger.info(json.toString());
- float[] coor = new float[2];
- coor[0] = (float) json.findPath("coordinates").get(0).doubleValue();
- coor[1] = (float) json.findPath("coordinates").get(1).doubleValue();
- double dis = json.findPath("dis").doubleValue();
- Logger.info("dis: " + dis + " lat:" + coor[0] + "lon:" + coor[1]);
- String retorno = MongoBase.findNearbyDishes(coor, dis);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishesByCity() {
- JsonNode json = request().body().asJson();
- String location = json.findPath("location").asText();
- String retorno = MongoBase.findDishesByCity(location);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findDishesByProvince() {
- JsonNode json = request().body().asJson();
- String location = json.findPath("location").asText();
- String retorno = MongoBase.findDishesByProvince(location);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(AdminSecured.class)
- public static Result consolidate() {
- MongoBase.consolidate();
- flash("success", "Consolidado");
- return redirect(
- routes.AdminPanel.blank()
- );
- }
- public static Result makeSearchNames() {
- MongoBase.makeSearchNames();
- flash("success", "Consolidado");
- return redirect(
- routes.AdminPanel.blank()
- );
- }
- @Security.Authenticated(AdminSecured.class)
- public static Result sendGCMMessage() {
- Publication pub=new Publication();
- pub.setLongDescription(" Lorem ipsum dolor sit amet");
- pub.setInterests(Arrays.asList(new String[]{"jornadas", "gochu"}));
- pub.setVenueId("522ecb6003647294e95cfe46");
- pub.setTitle("Pelazo abre en la pola");
- pub.setVenueLocation("pola de lena");
- MongoBase.createPublication(pub);
- return ok();
- }
- @Security.Authenticated(AdminSecured.class)
- public static Result readXML() {
- /* final int NAME=0;
- final int ADDRESS=1;
- final int CITY=2;
- final int POSTAL_CODE=4;
- final int BAJA=9;
- final int SUB_ACTIVITY=12;
- try
- {
- FileInputStream file = new FileInputStream(new File("/Users/marcosflorezsierra/Downloads/Establecimientos.xls"));
- //Create Workbook instance holding reference to .xlsx file
- HSSFWorkbook workbook = new HSSFWorkbook(file);
- //Get first/desired sheet from the workbook
- HSSFSheet sheet = workbook.getSheetAt(0);
- //Iterate through each rows one by one
- Iterator<Row> rowIterator = sheet.iterator();
- Venue venue;
- while (rowIterator.hasNext())
- {
- Row row = rowIterator.next();
- if(row.getCell(BAJA).getStringCellValue()!=null&&row.getCell(BAJA).getStringCellValue().length()>0){
- venue=new Venue();
- if(row.getCell(CITY).getStringCellValue().length()<1){
- venue.address.city=row.getCell(CITY+1).getStringCellValue();
- }else{
- venue.address.city=row.getCell(CITY).getStringCellValue();
- }
- venue.address.street=row.getCell(ADDRESS).getStringCellValue().toLowerCase();
- venue.address.postalCode=row.getCell(POSTAL_CODE).getStringCellValue();
- venue.address.province="Asturias";
- venue.name=row.getCell(NAME).getStringCellValue();
- if(venue.name.contains(", ")){
- String partes[]=venue.name.split(", ");
- venue.name=partes[1]+" "+partes[0];
- }else if(venue.name.contains(" ,")){
- String partes[]=venue.name.split(" ,");
- venue.name=partes[1]+" "+partes[0];
- }
- venue.name=venue.name.toLowerCase();
- venue.types.add("restaurante");
- String subActivity=row.getCell(SUB_ACTIVITY).getStringCellValue();
- if(subActivity!=null&&subActivity.length()>0){
- venue.types.add(subActivity.toLowerCase());
- }
- System.out.println(venue);
- }
- }
- file.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- */
- MongoBase.insertVenuesXML();
- return ok();
- }
- /*
- public static F.Promise<Result> sendGCMMessage() {
- JsonNode responseJson;
- final JsonNode json = request().body().asJson();
- String mail = json.findPath("mail").asText();
- JsonObject parameters=new JsonObject();
- JsonArray direcciones=new JsonArray();
- JsonObject data=new JsonObject();
- data.add("mensaje",new JsonPrimitive("yes muy malu al DOTA2"));
- direcciones.add(new JsonPrimitive("pepito"));
- parameters.add("registration_ids",direcciones);
- String token = json.findPath("userToken").asText();
- String auth = "AIzaSyD_v66gszhbLwY0iBGCi37Tsb467ruzs0o";
- WSRequestHolder messageRequest = WS.url("https://android.googleapis.com/gcm/send").setAuth("key",auth).setContentType("application/json");
- F.Promise<Result> resultado = messageRequest.post(parameters.getAsString()).map(
- new F.Function<WS.Response, Result>() {
- @Override
- public Result apply(WS.Response response) throws Throwable {
- switch(response.getStatus()){
- case 200: Logger.info("GCM messages correctos");
- flash("success", "Envíado!");
- return redirect(
- routes.AdminPanel.blank()
- );
- case 400:
- flash("error", "Mal JSON");
- return redirect(
- routes.AdminPanel.blank()
- );
- case 401:
- flash("error", "Mala Autenticación!");
- return redirect(
- routes.AdminPanel.blank()
- );
- default: flash("error", "ROMPISTE GOOGLE!!!! BOOOM!");
- return redirect(
- routes.AdminPanel.blank()
- );
- }
- }
- });
- return resultado;
- }
- */
- @Security.Authenticated(AdminSecured.class)
- public static Result corregirTipos() {
- MongoBase.correct();
- flash("success", "Corregidos");
- return redirect(
- routes.AdminPanel.blank()
- );
- }
- @Security.Authenticated(AdminSecured.class)
- public static Result recalculatePoints() {
- MongoBase.recalculatePoints();
- flash("success", "Recalculado");
- return redirect(
- routes.AdminPanel.blank()
- );
- }
- @Security.Authenticated(SecuredWS.class)
- public static Result findVenues() {
- JsonNode json = request().body().asJson();
- String searchText = json.findPath("search").asText();
- if (searchText == null) {
- return badRequest("Missing search value");
- }
- String retorno = MongoBase.findVenues(searchText);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(Secured.class)
- public static Result findMoreVenues() {
- JsonNode json = request().body().asJson();
- String searchText = json.findPath("search").asText();
- String attempt = json.findPath("attempt").asText();
- if (searchText == null) {
- return badRequest("Missing search value");
- }
- String retorno = MongoBase.findVenues(searchText);
- if (retorno == null) {
- return badRequest("Error en la busqueda");
- }
- return ok(retorno);
- }
- @Security.Authenticated(Secured.class)
- public static Result addGcmId() {
- JsonNode json = request().body().asJson();
- String gcmId=null;
- String userId=null;
- if(json.has("gcmId")){
- gcmId = json.findPath("gcmId").asText();
- }else{
- return badRequest("Faltan parámetros [gcmId]");
- }
- if(json.has("userId")){
- userId = json.findPath("userId").asText();
- }else{
- return badRequest("Faltan parámetros [userId]");
- }
- String retorno = MongoBase.addGcmId(userId, gcmId);
- if (retorno != null) {
- return badRequest("Error añadiendo el gcmId");
- }
- return ok();
- }
- @Security.Authenticated(Secured.class)
- public static Result addUserFollower() {
- JsonNode json = request().body().asJson();
- String followerId=null;
- String followedId=null;
- String followerName=null;
- String followedName=null;
- if(json.has("followerId")){
- followerId = json.findPath("followerId").asText();
- }else{
- return badRequest("Faltan parámetros [followerId]");
- }
- if(json.has("followerName")){
- followerName = json.findPath("followerName").asText();
- }else{
- return badRequest("Faltan parámetros [followerName]");
- }
- if(json.has("followedId")){
- followedId = json.findPath("followedId").asText();
- }else{
- return badRequest("Faltan parámetros [followedId]");
- }
- if(json.has("followedName")){
- followedName = json.findPath("followedName").asText();
- }else{
- return badRequest("Faltan parámetros [followedName]");
- }
- String retorno = MongoBase.addUserFollower(followerId, followerName,followedId,followedName);
- if (retorno != null) {
- return badRequest("Error añadiendo follower");
- }
- return ok();
- }
- @Security.Authenticated(Secured.class)
- public static Result removeUserFollower() {
- JsonNode json = request().body().asJson();
- String followerId=null;
- String followedId=null;
- if(json.has("followerId")){
- followerId = json.findPath("followerId").asText();
- }else{
- return badRequest("Faltan parámetros [followerId]");
- }
- if(json.has("followedId")){
- followedId = json.findPath("followedId").asText();
- }else{
- return badRequest("Faltan parámetros [followedId]");
- }
- String retorno = MongoBase.removeUserFollower(followerId, followedId);
- if (retorno != null) {
- return badRequest("Error añadiendo follower");
- }
- return ok();
- }
- @Security.Authenticated(Secured.class)
- public static Result addVenueFollower() {
- JsonNode json = request().body().asJson();
- String followerName=null;
- String venueId=null;
- String venueName=null;
- String followerId=null;
- if(json.has("followerName")){
- followerName = json.findPath("followerName").asText();
- }else{
- return badRequest("Faltan parámetros [followerName]");
- }
- if(json.has("followerId")){
- followerId = json.findPath("followerId").asText();
- }
- else{
- return badRequest("Faltan parámetros [followerId]");
- }
- if(json.has("venueId")){
- venueId = json.findPath("venueId").asText();
- }else{
- return badRequest("Faltan parámetros [venueId]");
- }
- if(json.has("venueName")){
- venueName = json.findPath("venueName").asText();
- }else{
- return badRequest("Faltan parámetros [venueName]");
- }
- String retorno = MongoBase.addVenueFollower(followerId,followerName,venueId, venueName);
- if (retorno != null) {
- return badRequest("Error añadiendo follower");
- }
- return ok();
- }
- @Security.Authenticated(Secured.class)
- public static Result removeVenueFollower() {
- JsonNode json = request().body().asJson();
- String venueId=null;
- String followerId=null;
- if(json.has("followerId")){
- followerId = json.findPath("followerId").asText();
- }
- else{
- return badRequest("Faltan parámetros [followerId]");
- }
- if(json.has("venueId")){
- venueId = json.findPath("venueId").asText();
- }else{
- return badRequest("Faltan parámetros [venueId]");
- }
- String retorno = MongoBase.removeVenueFollower(followerId, venueId);
- if (retorno != null) {
- return badRequest("Error eliminando follower");
- }
- return ok();
- }
- @Security.Authenticated(Secured.class)
- public static Result addInterestFollower() {
- JsonNode json = request().body().asJson();
- String followerId=null;
- String followerName=null;
- String interestName=null;
- if(json.has("followerId")){
- followerId = json.findPath("followerId").asText();
- }else{
- return badRequest("Faltan parámetros [followerId]");
- }
- if(json.has("followerName")){
- followerName = json.findPath("followerName").asText();
- }else{
- return badRequest("Faltan parámetros [followerName]");
- }
- if(json.has("interestName")){
- interestName = json.findPath("interestName").asText();
- }else{
- return badRequest("Faltan parámetros [interestName]");
- }
- String retorno = MongoBase.addInterest(followerId, followerName,interestName);
- if (retorno != null) {
- return badRequest("Error añadiendo follower");
- }
- return ok();
- }
- @Security.Authenticated(Secured.class)
- public static Result removeInterestFollower() {
- JsonNode json = request().body().asJson();
- String followerId=null;
- String followerName=null;
- String interestName=null;
- if(json.has("followerId")){
- followerId = json.findPath("followerId").asText();
- }else{
- return badRequest("Faltan parámetros [followerId]");
- }
- if(json.has("interestName")){
- interestName = json.findPath("interestName").asText();
- }else{
- return badRequest("Faltan parámetros [interestName]");
- }
- String retorno = MongoBase.removeInterest(followerId, interestName);
- if (retorno != null) {
- return badRequest("Error haciendo unfollow");
- }
- return ok();
- }
- @Security.Authenticated(Secured.class)
- public static Result addDishToFavourites() {
- JsonNode json = request().body().asJson();
- String userId=null;
- String userName=null;
- String venueName=null;
- String dishId=null;
- if(json.has("userId")){
- userId = json.findPath("userId").asText();
- Logger.error(userId);
- }else{
- return badRequest("Faltan parámetros [userId]");
- }
- if(json.has("userName")){
- userName = json.findPath("userName").asText();
- }else{
- return badRequest("Faltan parámetros [userName]");
- }
- if(json.has("venueName")){
- venueName = json.findPath("venueName").asText();
- }else{
- …
Large files files are truncated, but you can click here to view the full file