Package design_patterns.facade

Examples of design_patterns.facade.RestClient


    }
   
    @Override
    public Reservation startReservationManagement(int nextID,Product product, User u) {
        System.out.println("next id: " + nextID);
        RestClient add_reservationto_server = new RestClient();
       
        if (product instanceof Video){
            Reservation reservation = new Reservation(nextID,u,product,new Date(),new Date(),false);
            //System.out.println("json: " + encodeJsonObject(reservation).toJSONString());
            //System.out.println("json: " + encodeJsonObjectProductstats(reservation).toJSONString());           
            add_reservationto_server.apacheHttpClientPost(Login.url+"api/reservation/reservation/", reservation.getUser().getUsername(), reservation.getUser().getPassword(), encodeJsonObject(reservation));
            add_reservationto_server.apacheHttpClientPatch(Login.url+"api/reservation/product/"+reservation.getProduct().getId()+"/", reservation.getUser().getUsername(), reservation.getUser().getPassword(), encodeJsonObjectProductstats(reservation));
            return reservation;
        }
        else if (product instanceof Book ){
            Reservation reservation = new Reservation(nextID,u,product,new Date(),new Date(),false);
            //System.out.println(encodeJsonObject(reservation).toJSONString());
            add_reservationto_server.apacheHttpClientPost(Login.url+"api/reservation/reservation/", reservation.getUser().getUsername(), reservation.getUser().getPassword(), encodeJsonObject(reservation));
            add_reservationto_server.apacheHttpClientPatch(Login.url+"api/reservation/product/"+reservation.getProduct().getId()+"/", reservation.getUser().getUsername(), reservation.getUser().getPassword(), encodeJsonObjectProductstats(reservation));
            return reservation;
        }
        return null;
    }
View Full Code Here


    public boolean fetchdata(Login login, javax.swing.JTextField username,javax.swing.JPasswordField password) {   

            boolean flag=false;
            User u = new User();

            String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/auth/user/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    u.setUsername(username.getText());
                    u.setPassword(password.getPassword());
                    login.setUsers_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        User remoteuser = new User(Integer.parseInt((String)jsonObject.get("id")),(String) jsonObject.get("username"));               
                        login.getUsers_map().put(remoteuser.getUsername(), remoteuser);
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {        
                flag=false;
            }

            User temp = (User) login.getUsers_map().get(u.getUsername());
            if (temp!=null){
                u=temp;
                u.setPassword(password.getPassword());
            }
           
            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/author/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setAuthors(new ArrayList ());
                    login.setAuthors_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        Author author = new Author(Integer.parseInt((String)jsonObject.get("id")),(String) jsonObject.get("name"),(String) jsonObject.get("email"));
                        login.getAuthors().add(author);                  
                        login.getAuthors_map().put(author.getId(), author);
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {        
                flag=false;
            }

            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/product/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setProducts(new ArrayList ());
                    login.setProducts_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("author"));
                        makeMatch.find();
                        String inputInt = makeMatch.group();
                        Author author = (Author) login.getAuthors_map().get(Integer.parseInt(inputInt));
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        Date date=null;
                        try {
                            date = sdf.parse((String) jsonObject.get("pub_date"));
                        } catch (java.text.ParseException ex) {
                            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        Product product = new Product(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                        product.setCount((long) jsonObject.get("count"));
                        if (product!=null){
                            login.getProducts().add(product);                   
                            login.getProducts_map().put(product.getId(), product);
                        }
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {
                flag = false;
            }

            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/video/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setVideos(new ArrayList ());
                    login.setVideos_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        Author author = (Author) login.getAuthors_map().get(Integer.parseInt((String)jsonObject.get("id")));
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        Date date=null;
                        try {
                            date = sdf.parse((String) jsonObject.get("pub_date"));
                        } catch (java.text.ParseException ex) {
                            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        Video video = new Video (Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                        video.setCount((long) jsonObject.get("count"));
                        login.getVideos().add(video);              
                        login.getVideos_map().put(video.getId(), video);
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {
                flag = false;
            }

            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setBooks(new ArrayList ());
                    login.setBooks_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
                        Author author = (Author) login.getAuthors_map().get(Integer.parseInt((String)jsonObject.get("id")));
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        Date date=null;
                        try {
                            date = sdf.parse((String) jsonObject.get("pub_date"));
                        } catch (java.text.ParseException ex) {
                            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        Book book = new Book (Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                        book.setCount((long) jsonObject.get("count"));
                        login.getBooks().add(book);                 
                        login.getBooks_map().put(book.getId(), book);
                    }
                } catch (ParseException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
                flag = true;
            }
            else {
                flag = false;
            }

            data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/reservation/?format=json", username.getText(), password.getPassword());
            if( data!=null) {
                try {
                    login.setReservations(new ArrayList ());
                    login.setReservations_map(new HashMap());
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
View Full Code Here

    private char[] password;
    private ArrayList newproducts;
    public Login login_window;
   
    private ArrayList checkServer(){
        String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/product/?format=json", this.getUsername(), this.getPassword());
        if( data!=null) {
            try {
                this.newproducts = new ArrayList();
                JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                for (Object c : (JSONArray) jsonObject.get("objects")){
View Full Code Here

    }// </editor-fold>//GEN-END:initComponents

    private void loadComboBox(){
        this.jComboBox1.removeAllItems();
        this.reservation=new ArrayList<>();
            String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/reservation_getUser/?format=json", this.menu_window.getUser().getUsername(), this.menu_window.getUser().getPassword());
            if( data!=null) {
                try {
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
View Full Code Here

        for (int i =0; i<this.reservation.size();i++){
            Reservation r = (Reservation)this.reservation.get(i);
            if (r.getProduct().getName().equals(this.product.getName())){
                System.out.println("teste: "+Login.url+"api/reservation/reservation/"+r.getId()+"/?format=json");
                try {
                    new RestClient().doDelete(Login.url+"api/reservation/reservation/"+r.getId()+"/?format=json", this.menu_window.getUser().getUsername(), this.menu_window.getUser().getPassword());
                    System.out.println("Deleted");
                    this.dispose();

                } catch (HttpException ex) {
                    Logger.getLogger(CancelReservationUI.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

   
    public void getVideoStats(User u){
        System.out.println("videostats");
        long total_count = 0;
        ArrayList <Stats> stats_array = new ArrayList <Stats> ();
        String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/video/?format=json", u.getUsername(), u.getPassword());
            if( data!=null) {
                try {
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
View Full Code Here

    public void getBookStats(User u){
        System.out.println("bookstats");
       
        long total_count = 0;
        ArrayList <Stats> stats_array = new ArrayList <Stats> ();
        String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=json", u.getUsername(), u.getPassword());
            if( data!=null) {
                try {
                    JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                    for (Object c : (JSONArray) jsonObject.get("objects")){
                        jsonObject = (JSONObject) c;
View Full Code Here

    public boolean fetchdata(Login login, JTextField username, JPasswordField password) {

        boolean flag=false;
        User u = new User();
        UsersHandler usersHandler=null;
        String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/auth/user/?format=xml", username.getText(), password.getPassword());
        if( data!=null) {
            u.setUsername(username.getText());
            u.setPassword(password.getPassword());
            usersHandler = new UsersHandler(login, data, u);       
            flag = true;
        }
        else {        
            flag=false;
        }

        for (int i=0 ; i<usersHandler.getUsers().size();i++){
            User utemp = (User) usersHandler.getUsers().get(i);
           
            if (utemp.getUsername().equalsIgnoreCase(username.getText())){
                u=utemp;
                u.setPassword(password.getPassword());
                break;
            }
        }

        data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/author/?format=xml", username.getText(), password.getPassword());
        if( data!=null) {
            u.setUsername(username.getText());
            u.setPassword(password.getPassword());
            AuthorsHandler authorsHandler = new AuthorsHandler(login, data, u);
            flag = true;
        }
        else {        
                flag=false;
        }
       
        data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/product/?format=xml", username.getText(), password.getPassword());
        if( data!=null) {
            ProductsHandler productsHandler = new ProductsHandler(login, data, u);
            flag = true;
        }
        else {        
                flag=false;
        }
       
        data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/video/?format=xml", username.getText(), password.getPassword());
        if( data!=null) {
            VideosHandler videosHandler = new VideosHandler(login, data, u);
            flag = true;
        }
        else {        
                flag=false;
        }
       
        data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=xml", username.getText(), password.getPassword());
        if( data!=null) {
            BooksHandler booksHandler = new BooksHandler(login, data, u);
            flag = true;
        }
        else {        
                flag=false;
        }
       
        data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/reservation/?format=xml", username.getText(), password.getPassword());
        if( data!=null) {
            ReservationsHandler reservationsHandler = new ReservationsHandler(login, data, u);
            flag = true;
        }
        else {        
View Full Code Here

  private void listProducts(){
        ProductCreator productcreator = new ProductCreator();
        VideoProductBuilder videobuilder = new VideoProductBuilder();
        BookProductBuilder bookbuilder = new BookProductBuilder();
       
        String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/video/?format=json", this.user.getUsername(), this.user.getPassword());
        if( data!=null) {
            try {
                this.newvideos = new ArrayList();
                JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                for (Object c : (JSONArray) jsonObject.get("objects")){
                    jsonObject = (JSONObject) c;
                    Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("author"));
                    makeMatch.find();
                    String inputInt = makeMatch.group();
                    Author author = (Author) this.login_window.getAuthors_map().get(Integer.parseInt(inputInt));
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                    Date date=null;
                    try {
                        date = sdf.parse((String) jsonObject.get("pub_date"));
                    } catch (java.text.ParseException ex) {
                        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                    }
                
                    productcreator.setProduct(videobuilder);
                    productcreator.constructProduct(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
                    Product product = productcreator.getProduct();
                    this.newvideos.add(product);
                }
            } catch (ParseException ex) {
                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
       
       
        data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=json", this.user.getUsername(), this.user.getPassword());
        if( data!=null) {
            try {
                this.newbooks = new ArrayList();
                JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
                for (Object c : (JSONArray) jsonObject.get("objects")){
View Full Code Here

TOP

Related Classes of design_patterns.facade.RestClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.