Skip to content

Instantly share code, notes, and snippets.

@fobos531
Created June 11, 2021 15:29
Show Gist options
  • Save fobos531/399e3147107d8b69e2d13a68233fe09b to your computer and use it in GitHub Desktop.
Save fobos531/399e3147107d8b69e2d13a68233fe09b to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.foi.nwtis.jglavina.modul_4_2.zrna;
import jakarta.enterprise.context.SessionScoped;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;
import lombok.Getter;
import lombok.Setter;
import org.foi.nwtis.jglavina.modul_4_2.klijenti.OkHttp;
import org.foi.nwtis.jglavina.modul_4_2.modeli.MeteoPodaci;
import org.foi.nwtis.podaci.Aerodrom;
import org.foi.nwtis.rest.podaci.AvionLeti;
import org.primefaces.util.LangUtils;
/**
*
* @author jakovglavina
*/
@Named(value = "pregledVlastitihAerodroma")
@SessionScoped
public class PregledVlastitihAerodroma implements Serializable {
@Inject
ServletContext context;
@Getter
@Setter
List<Aerodrom> sviAerodromi = dajAerodrome();
@Getter
@Setter
List<Aerodrom> filtriraniAerodromi;
@Getter
@Setter
Aerodrom odabraniAerodrom;
@Getter
@Setter
LocalDate datum;
@Getter
@Setter
LocalDateTime datumVrijeme;
@Getter
@Setter
List<AvionLeti> letoviAerodroma;
@Getter
@Setter
List<AvionLeti> filtriraniLetovi;
@Getter
@Setter
List<MeteoPodaci> meteoPodaciNaDan;
@Getter
@Setter
MeteoPodaci meteoPodaciNaVrijeme;
/**
* Konstruktor
*/
public PregledVlastitihAerodroma() throws IOException {
}
public boolean globalnaFilterFunkcija(Object value, Object filter, Locale locale) {
String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (LangUtils.isValueBlank(filterText)) {
return true;
}
Aerodrom aerodrom = (Aerodrom) value;
return aerodrom.getIcao().toLowerCase().contains(filterText)
|| aerodrom.getNaziv().toLowerCase().contains(filterText);
}
public boolean globalnaFilterFunkcijaLetovi(Object value, Object filter, Locale locale) {
String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (LangUtils.isValueBlank(filterText)) {
return true;
}
AvionLeti let = (AvionLeti) value;
return let.getIcao24().toLowerCase().contains(filterText)
|| let.getEstDepartureAirport().toLowerCase().contains(filterText)
|| let.getEstArrivalAirport().toLowerCase().contains(filterText)
|| let.getCallsign().toLowerCase().contains(filterText);
}
public List<Aerodrom> dajAerodrome() throws IOException {
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession sesija = req.getSession(false);
OkHttp client = new OkHttp();
String kor = String.valueOf(sesija.getAttribute("korisnik"));
String loz = String.valueOf(sesija.getAttribute("lozinka"));
return client.getCollectionAerodromi(kor, loz);
}
public void dajLetoveAviona() throws IOException {
System.out.println("DATUM HMMM " + datum);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String datumFormatiran = datum.format(formatter);
System.out.println("ODABRANI DATUM JE " + datumFormatiran);
System.out.println("ODABRANI ICAO JE " + odabraniAerodrom.getIcao());
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession sesija = req.getSession(false);
OkHttp client = new OkHttp();
String kor = String.valueOf(sesija.getAttribute("korisnik"));
String loz = String.valueOf(sesija.getAttribute("lozinka"));
letoviAerodroma = client.getCollectionLetovi(odabraniAerodrom.getIcao(), datumFormatiran, kor, loz);
System.out.println("LETOVI " + letoviAerodroma.toString());
}
public void dajMeteoPodatkeNaDan() throws IOException {
System.out.println(" tu sam unutra");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String datumFormatiran = datum.format(formatter);
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession sesija = req.getSession(false);
OkHttp client = new OkHttp();
String kor = String.valueOf(sesija.getAttribute("korisnik"));
String loz = String.valueOf(sesija.getAttribute("lozinka"));
meteoPodaciNaDan = client.getMeteoPodaciDan(odabraniAerodrom.getIcao(), datumFormatiran, kor, loz);
System.out.println("Meteo pdoaci na dan " + meteoPodaciNaDan.toString());
}
public void dajMeteoPodatkeNaVrijeme() throws IOException {
long seconds = datumVrijeme.atZone(ZoneOffset.UTC).toEpochSecond();
HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession sesija = req.getSession(false);
OkHttp client = new OkHttp();
String kor = String.valueOf(sesija.getAttribute("korisnik"));
String loz = String.valueOf(sesija.getAttribute("lozinka"));
meteoPodaciNaVrijeme = client.getMeteoPodaciVrijeme(odabraniAerodrom.getIcao(), String.valueOf(seconds), kor, loz);
System.out.println("METEO PODACI " + meteoPodaciNaVrijeme.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment