<commit_before>package controllers;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import models.IndexContentDB;
import models.PermeablePavers;
import models.PermeablePaversDB;
import models.PlantDB;
import models.RainBarrel;
import models.RainBarrelDB;
import models.RainGarden;
import models.RainGardenDB;
import models.UserInfoDB;
import models.ResourceDB;
import play.data.Form;
import play.data.validation.ValidationError;
import play.mvc.Controller;
import play.mvc.Security;
import play.mvc.Http.MultipartFormData;
import play.mvc.Http.Request;
import play.mvc.Http.MultipartFormData.FilePart;
import play.mvc.Result;
import views.formdata.CoverTypes;
import views.formdata.DateTypes;
import views.formdata.InstallationTypes;
import views.formdata.MaterialTypes;
import views.formdata.PaverMaterialTypes;
import views.formdata.PermeablePaversFormData;
import views.formdata.RainBarrelFormData;
import views.formdata.RainBarrelTypes;
import views.formdata.WaterUsageTypes;
import views.formdata.YesNoChoiceType;
import views.formdata.PlantTypes;
import views.formdata.PropertyTypes;
import views.formdata.RainGardenFormData;
import views.formdata.SolutionAmountType;
import views.formdata.LoginFormData;
import views.formdata.SignUpFormData;
import views.html.Index;
import views.html.Page1;
import views.html.RegisterRainGarden;
import views.html.Login;
import views.html.ViewGarden;
import views.html.ViewBarrel;
import views.html.SignUp;
import views.html.RegisterMenu;
import views.html.RegisterRainBarrel;
import views.html.LearnMore;
import views.html.RegisterPermeablePavers;
import views.html.ViewPaver;
import views.html.Gallery;

/**
 * Implements the controllers for this application.
 */
public class Application extends Controller {
  private static final long MAX_FILE_SIZE = 2621440;

  /**
   * Returns the home page. 
   * @return The resulting home page. 
   */
  public static Result index() {
    return ok(Index.render(IndexContentDB.getBlocks()));
  }
  
  /**
   * Returns the registration navigation menu.
   * @return The registration navigation menu page.
   */
  public static Result registerMenu() {
    return ok(RegisterMenu.render("Registration - Main"));
  }
  
  /**
   * Returns the created/edited rain garden page.
   * @param id ID of rain garden.
   * @return The resulting rain garden page.
   */
  @Security.Authenticated(Secured.class)
  public static Result registerRainGarden(Long id) {
    RainGardenFormData data = (!(RainGardenDB.hasID(id)))
        ? new RainGardenFormData() : new RainGardenFormData(RainGardenDB.getRainGarden(id));
    Form<RainGardenFormData> formData = Form.form(RainGardenFormData.class).fill(data);
    return ok(RegisterRainGarden.render(formData, YesNoChoiceType.getChoiceList(), 
              PropertyTypes.getTypes(data.propertyType), DateTypes.getMonthTypes(data.month), 
              DateTypes.getDayTypes(data.day), DateTypes.getYearTypes(data.year), 
              PlantTypes.getPlantMap(data.plants), SolutionAmountType.getTypes(data.numberOfRainGardens), 
              Secured.getUserInfo(ctx())));
  }
  
  /**
   * Returns the created/edited rain garden page.
   * @return The resulting rain garden page if information was valid, else the registration form.
   */
  @Security.Authenticated(Secured.class)
  public static Result postRainGardenRegister() {
    Form<RainGardenFormData> formData = Form.form(RainGardenFormData.class).bindFromRequest();
    validateGardenUpload(formData, request().body().asMultipartFormData());
    if (formData.hasErrors()) {
      Map<String, String> dataMap = formData.data();
      List<String> plantList = new ArrayList<String>();
      for (String key : dataMap.keySet()) {
        if (key.contains("plants")) {
          plantList.add(dataMap.get(key));
        }
      }          
      return badRequest(RegisterRainGarden.render(formData, YesNoChoiceType.getChoiceList(), 
                        PropertyTypes.getTypes(dataMap.get("propertyType")), 
                        DateTypes.getMonthTypes(dataMap.get("month")), 
                        DateTypes.getDayTypes(dataMap.get("day")), 
                        DateTypes.getYearTypes(dataMap.get("year")),
                        PlantTypes.getPlantMap(plantList),
                        SolutionAmountType.getTypes(dataMap.get("numberOfRainGardens")),
                        Secured.getUserInfo(ctx())));   
    } 
    else {
      RainGardenFormData data = formData.get();
      RainGarden garden = RainGardenDB.addRainGarden(data, Secured.getUserInfo(ctx()));
      MultipartFormData body = request().body().asMultipartFormData();
      FilePart picture = body.getFile("uploadFile");
      if (picture != null) {
          File source = picture.getFile();
          File destination = new File("public/images/upload/rg" + garden.getID());
          source.renameTo(destination);
      }
      return redirect("/view/rain-garden/" + garden.getID());
     }     
    }
  
  /**
   * Returns the created/edited rain garden page.
   * @param id ID of rain garden.
   * @return The resulting rain garden page.
   */
  @Security.Authenticated(Secured.class)
  public static Result registerRainBarrel(Long id) {
    RainBarrelFormData data = (!(RainBarrelDB.hasID(id)))
        ? new RainBarrelFormData() : new RainBarrelFormData(RainBarrelDB.getRainBarrel(id));
    Form<RainBarrelFormData> formData = Form.form(RainBarrelFormData.class).fill(data);    
    return ok(RegisterRainBarrel.render(formData, YesNoChoiceType.getChoiceList(), 
              PropertyTypes.getTypes(data.propertyType), DateTypes.getMonthTypes(data.month), 
              DateTypes.getDayTypes(data.day), DateTypes.getYearTypes(data.year), 
              RainBarrelTypes.getRainBarrelTypes(data.rainBarrelType), MaterialTypes.getMaterialTypes(data.material),
              WaterUsageTypes.getWaterUsageTypes(data.waterUse), CoverTypes.getCoverTypes(data.cover), 
              InstallationTypes.getInstallationTypes(data.installationType), 
              SolutionAmountType.getTypes(data.numberOfRainBarrels)));
  }
  
  /**
   * Returns the created/edited rain garden page.
   * @return The resulting rain garden page if information was valid, else the registration form.
   */
  @Security.Authenticated(Secured.class)
  public static Result postRainBarrelRegister() {
    Form<RainBarrelFormData> formData = Form.form(RainBarrelFormData.class).bindFromRequest();
    validateBarrelUpload(formData, request().body().asMultipartFormData());
    if (formData.hasErrors()) {
      Map<String, String> dataMap = formData.data();
      return badRequest(RegisterRainBarrel.render(formData, YesNoChoiceType.getChoiceList(), 
                        PropertyTypes.getTypes(dataMap.get("propertyType")), 
                        DateTypes.getMonthTypes(dataMap.get("month")), 
                        DateTypes.getDayTypes(dataMap.get("day")), 
                        DateTypes.getYearTypes(dataMap.get("year")),
                        RainBarrelTypes.getRainBarrelTypes(dataMap.get("rainBarrelType")),
                        MaterialTypes.getMaterialTypes(dataMap.get("material")),
                        WaterUsageTypes.getWaterUsageTypes(dataMap.get("waterUse")),
                        CoverTypes.getCoverTypes(dataMap.get("cover")),
                        InstallationTypes.getInstallationTypes(dataMap.get("installationType")),
                        SolutionAmountType.getTypes(dataMap.get("numberOfRainBarrels"))));   
    } 
    else {
      RainBarrelFormData data = formData.get();
      RainBarrel barrel = RainBarrelDB.addRainBarrel(data, Secured.getUserInfo(ctx()));
      MultipartFormData body = request().body().asMultipartFormData();
      FilePart picture = body.getFile("uploadFile");
      if (picture != null) {
          File source = picture.getFile();
          File destination = new File("public/images/upload/rb" + barrel.getID());
          source.renameTo(destination);
      }
      return redirect("/view/rain-barrel/" + barrel.getID());
     }     
    }
  
  /**
   * Returns the created/edited permeable pavers page.
   * @param id ID of permeable pavers.
   * @return The resulting permeable paver page.
   */
  @Security.Authenticated(Secured.class)
  public static Result registerPermeablePavers(Long id) {
    PermeablePaversFormData data = (!(PermeablePaversDB.hasID(id))) 
        ? new PermeablePaversFormData() : new PermeablePaversFormData(PermeablePaversDB.getPermeablePavers(id));
    Form<PermeablePaversFormData> formData = Form.form(PermeablePaversFormData.class).fill(data); 
      return ok(RegisterPermeablePavers.render(formData, YesNoChoiceType.getChoiceList(), 
                PropertyTypes.getTypes(data.propertyType), DateTypes.getMonthTypes(data.month), 
                DateTypes.getDayTypes(data.day), DateTypes.getYearTypes(data.year), 
                PaverMaterialTypes.getMaterialTypes(data.material), Secured.getUserInfo(ctx())));
  }
  
  /**
   * Returns the created/edited permeable pavers page.
   * @return The resulting permeable pavers page if information was valid, else the registration form.
   */
  @Security.Authenticated(Secured.class)
  public static Result postPermeablePaversRegister() {
    Form<PermeablePaversFormData> formData = Form.form(PermeablePaversFormData.class).bindFromRequest();
    validatePaverUpload(formData, request().body().asMultipartFormData());
    if (formData.hasErrors()) {
      Map<String, String> dataMap = formData.data();<commit_msg>Fixed registration compile issue.<commit_after>package controllers;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import models.IndexContentDB;
import models.PermeablePavers;
import models.PermeablePaversDB;
import models.PlantDB;
import models.RainBarrel;
import models.RainBarrelDB;
import models.RainGarden;
import models.RainGardenDB;
import models.UserInfoDB;
import models.ResourceDB;
import play.data.Form;
import play.data.validation.ValidationError;
import play.mvc.Controller;
import play.mvc.Security;
import play.mvc.Http.MultipartFormData;
import play.mvc.Http.Request;
import play.mvc.Http.MultipartFormData.FilePart;
import play.mvc.Result;
import views.formdata.CoverTypes;
import views.formdata.DateTypes;
import views.formdata.InstallationTypes;
import views.formdata.MaterialTypes;
import views.formdata.PaverMaterialTypes;
import views.formdata.PermeablePaversFormData;
import views.formdata.RainBarrelFormData;
import views.formdata.RainBarrelTypes;
import views.formdata.WaterUsageTypes;
import views.formdata.YesNoChoiceType;
import views.formdata.PlantTypes;
import views.formdata.PropertyTypes;
import views.formdata.RainGardenFormData;
import views.formdata.SolutionAmountType;
import views.formdata.LoginFormData;
import views.formdata.SignUpFormData;
import views.html.Index;
import views.html.Page1;
import views.html.RegisterRainGarden;
import views.html.Login;
import views.html.ViewGarden;
import views.html.ViewBarrel;
import views.html.SignUp;
import views.html.RegisterMenu;
import views.html.RegisterRainBarrel;
import views.html.LearnMore;
import views.html.RegisterPermeablePavers;
import views.html.ViewPaver;
import views.html.Gallery;

/**
 * Implements the controllers for this application.
 */
public class Application extends Controller {
  private static final long MAX_FILE_SIZE = 2621440;

  /**
   * Returns the home page. 
   * @return The resulting home page. 
   */
  public static Result index() {
    return ok(Index.render(IndexContentDB.getBlocks()));
  }
  
  /**
   * Returns the registration navigation menu.
   * @return The registration navigation menu page.
   */
  public static Result registerMenu() {
    return ok(RegisterMenu.render("Registration - Main"));
  }
  
  /**
   * Returns the created/edited rain garden page.
   * @param id ID of rain garden.
   * @return The resulting rain garden page.
   */
  @Security.Authenticated(Secured.class)
  public static Result registerRainGarden(Long id) {
    RainGardenFormData data = (id == 0)
        ? new RainGardenFormData() : new RainGardenFormData(RainGardenDB.getRainGarden(id));
    Form<RainGardenFormData> formData = Form.form(RainGardenFormData.class).fill(data);
    return ok(RegisterRainGarden.render(formData, YesNoChoiceType.getChoiceList(), 
              PropertyTypes.getTypes(data.propertyType), DateTypes.getMonthTypes(data.month), 
              DateTypes.getDayTypes(data.day), DateTypes.getYearTypes(data.year), 
              PlantTypes.getPlantMap(data.plants), SolutionAmountType.getTypes(data.numberOfRainGardens), 
              Secured.getUserInfo(ctx())));
  }
  
  /**
   * Returns the created/edited rain garden page.
   * @return The resulting rain garden page if information was valid, else the registration form.
   */
  @Security.Authenticated(Secured.class)
  public static Result postRainGardenRegister() {
    Form<RainGardenFormData> formData = Form.form(RainGardenFormData.class).bindFromRequest();
    validateGardenUpload(formData, request().body().asMultipartFormData());
    if (formData.hasErrors()) {
      Map<String, String> dataMap = formData.data();
      List<String> plantList = new ArrayList<String>();
      for (String key : dataMap.keySet()) {
        if (key.contains("plants")) {
          plantList.add(dataMap.get(key));
        }
      }          
      return badRequest(RegisterRainGarden.render(formData, YesNoChoiceType.getChoiceList(), 
                        PropertyTypes.getTypes(dataMap.get("propertyType")), 
                        DateTypes.getMonthTypes(dataMap.get("month")), 
                        DateTypes.getDayTypes(dataMap.get("day")), 
                        DateTypes.getYearTypes(dataMap.get("year")),
                        PlantTypes.getPlantMap(plantList),
                        SolutionAmountType.getTypes(dataMap.get("numberOfRainGardens")),
                        Secured.getUserInfo(ctx())));   
    } 
    else {
      RainGardenFormData data = formData.get();
      RainGarden garden = RainGardenDB.addRainGarden(data, Secured.getUserInfo(ctx()));    
      MultipartFormData body = request().body().asMultipartFormData();
      FilePart picture = body.getFile("uploadFile");
      if (picture != null) {
          File source = picture.getFile();
          File destination = new File("public/images/upload/rg" + garden.getID());
          source.renameTo(destination);
      }
      return redirect("/view/rain-garden/" + garden.getID());
     }     
    }
  
  /**
   * Returns the created/edited rain garden page.
   * @param id ID of rain garden.
   * @return The resulting rain garden page.
   */
  @Security.Authenticated(Secured.class)
  public static Result registerRainBarrel(Long id) {
    RainBarrelFormData data = (id == 0)
        ? new RainBarrelFormData() : new RainBarrelFormData(RainBarrelDB.getRainBarrel(id));
    Form<RainBarrelFormData> formData = Form.form(RainBarrelFormData.class).fill(data);    
    return ok(RegisterRainBarrel.render(formData, YesNoChoiceType.getChoiceList(), 
              PropertyTypes.getTypes(data.propertyType), DateTypes.getMonthTypes(data.month), 
              DateTypes.getDayTypes(data.day), DateTypes.getYearTypes(data.year), 
              RainBarrelTypes.getRainBarrelTypes(data.rainBarrelType), MaterialTypes.getMaterialTypes(data.material),
              WaterUsageTypes.getWaterUsageTypes(data.waterUse), CoverTypes.getCoverTypes(data.cover), 
              InstallationTypes.getInstallationTypes(data.installationType), 
              SolutionAmountType.getTypes(data.numberOfRainBarrels)));
  }
  
  /**
   * Returns the created/edited rain garden page.
   * @return The resulting rain garden page if information was valid, else the registration form.
   */
  @Security.Authenticated(Secured.class)
  public static Result postRainBarrelRegister() {
    Form<RainBarrelFormData> formData = Form.form(RainBarrelFormData.class).bindFromRequest();
    validateBarrelUpload(formData, request().body().asMultipartFormData());
    if (formData.hasErrors()) {
      Map<String, String> dataMap = formData.data();
      return badRequest(RegisterRainBarrel.render(formData, YesNoChoiceType.getChoiceList(), 
                        PropertyTypes.getTypes(dataMap.get("propertyType")), 
                        DateTypes.getMonthTypes(dataMap.get("month")), 
                        DateTypes.getDayTypes(dataMap.get("day")), 
                        DateTypes.getYearTypes(dataMap.get("year")),
                        RainBarrelTypes.getRainBarrelTypes(dataMap.get("rainBarrelType")),
                        MaterialTypes.getMaterialTypes(dataMap.get("material")),
                        WaterUsageTypes.getWaterUsageTypes(dataMap.get("waterUse")),
                        CoverTypes.getCoverTypes(dataMap.get("cover")),
                        InstallationTypes.getInstallationTypes(dataMap.get("installationType")),
                        SolutionAmountType.getTypes(dataMap.get("numberOfRainBarrels"))));   
    } 
    else {
      RainBarrelFormData data = formData.get();
      RainBarrel barrel = RainBarrelDB.addRainBarrel(data, Secured.getUserInfo(ctx()));
      MultipartFormData body = request().body().asMultipartFormData();
      FilePart picture = body.getFile("uploadFile");
      if (picture != null) {
          File source = picture.getFile();
          File destination = new File("public/images/upload/rb" + barrel.getID());
          source.renameTo(destination);
      }
      return redirect("/view/rain-barrel/" + barrel.getID());
     }     
    }
  
  /**
   * Returns the created/edited permeable pavers page.
   * @param id ID of permeable pavers.
   * @return The resulting permeable paver page.
   */
  @Security.Authenticated(Secured.class)
  public static Result registerPermeablePavers(Long id) {
    PermeablePaversFormData data = (id == 0) 
        ? new PermeablePaversFormData() : new PermeablePaversFormData(PermeablePaversDB.getPermeablePavers(id));
    Form<PermeablePaversFormData> formData = Form.form(PermeablePaversFormData.class).fill(data); 
      return ok(RegisterPermeablePavers.render(formData, YesNoChoiceType.getChoiceList(), 
                PropertyTypes.getTypes(data.propertyType), DateTypes.getMonthTypes(data.month), 
                DateTypes.getDayTypes(data.day), DateTypes.getYearTypes(data.year), 
                PaverMaterialTypes.getMaterialTypes(data.material), Secured.getUserInfo(ctx())));
  }
  
  /**
   * Returns the created/edited permeable pavers page.
   * @return The resulting permeable pavers page if information was valid, else the registration form.
   */
  @Security.Authenticated(Secured.class)
  public static Result postPermeablePaversRegister() {
    Form<PermeablePaversFormData> formData = Form.form(PermeablePaversFormData.class).bindFromRequest();
    validatePaverUpload(formData, request().body().asMultipartFormData());
    if (formData.hasErrors()) {
      Map<String, String> dataMap = formData.data();
{'fraction_non_alphanumeric': 0.10827958680719417, 'fraction_numerical': 0.0009962770698967018, 'mean_word_length': 3.55396370582617, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533857', 'n_tokens_mistral': 5647, 'n_tokens_neox': 5388, 'n_words': 981}