plopezgit / Sprint3_T3_Developers_Team

0 stars 0 forks source link

[Planning] 6 Days - Inital checklist preparation #1

Closed plopezgit closed 11 months ago

plopezgit commented 12 months ago
  1. REQ:

Debemos crear un programa para gestionar el catálogo de productos de una floristería. En el nivel 1, gestiona la persistencia en un archivo TXT.

Este programa debe cumplir con los siguientes requisitos:

En cuanto a las funcionalidades del Main, como mínimo, debe incluir las siguientes:

  1. BASIC PLAN:
  1. OVERVIEW: MVP PROGRAM FILES STRUCTURES:

  2. Entity

    • Shop (list products, list tickets, getIntance(), getShopStockOfProducts(), getShopTickets())
    • Tickets (list products, getTicketTotal(), getTicketProducts(), addProductToTicket(), toString();)
    • Product (super, abstract)
    • Product_Tree (sub)
    • Product_Flower (sub)
    • Product_Decoration (sub)
  3. App

    • Main (instances Shop Manager and calls init method)
    • ShopManager (Shop shopInstance, Ticket ticket, Bd_File_Write, Bd_File_Read, )
  4. Exception

    • ...
  5. Tools

    • Input_User_Keyboard
    • Bd_File_Write
    • Bd_File_Read
    • Error_Messages
  6. Test

    • ...
  7. file.properties

  8. OVERVIEW: SHOP MANAGER METHODS:

Stock:

Purchase Order Ticket:

Earn:

Backup:

  1. REUSABLE CODE

files on: /Users/pedrolopez/Proyectos/Study

MYSQL CONNECTION CLASS:

import java.sql.Connection;
    import java.sql.DriverManager;

    public class Connection_study_db {

    private Connection dbConnection = null;

    public Connection_study_db () {

    }

    public Connection getConnection () {
        try {
            dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/study", "root", "");
        } catch (Exception ex) {
            System.out.println("There is no connection");
            ex.printStackTrace();
        }
        return dbConnection;
    }

    }

MYSQL ENTITY CRUD:

Insert:

    public void addConcept (String titleConcept, Size effortEstimationConcept) {
        String size= conceptExistOnConceptResultSet(titleConcept);
        if (size == null) {
            Connection conexiondb = conceptDbConnection.getConnection();
            try {
                insertConceptOnConceptDB = conexiondb.prepareStatement("INSERT INTO CONCEPTOS (titleConcept, effortEstimationConcept) VALUES(?,?) ");
                insertConceptOnConceptDB.setString(1, titleConcept);
                insertConceptOnConceptDB.setString(2, effortEstimationConcept.toString());
                insertConceptOnConceptDB.execute();
                System.out.println("The " + titleConcept + " was stored!");
                conexiondb.close();
                incrementItineraryPoints(1);
                putBadgeItinerary();
            } catch (Exception ex) {
                System.out.println("There is no connection");
                ex.printStackTrace();
            }
        } else {
            System.out.println("The concept " + titleConcept + " already exists!"); 

        }
    }
    public void addNewIdea (String titleIdea, String descriptionIdea) {
        Connection conexiondb = conceptDbConnection.getConnection();
        try {
            PreparedStatement insertConceptOnConceptDB = conexiondb.prepareStatement("INSERT INTO IDEAS (titleconcept, titleidea, descriptionidea) VALUES(?,?,?) ");
            insertConceptOnConceptDB.setString(1, titleConcept);
            insertConceptOnConceptDB.setString(2, titleIdea);
            insertConceptOnConceptDB.setString(3, descriptionIdea);
            insertConceptOnConceptDB.execute();
            System.out.println("Your idea was stored!");
            conexiondb.close();
        } catch (Exception ex) {
            System.out.println("There is no connection");
            ex.printStackTrace();
        }
    }

Read:

    public String conceptExistOnConceptResultSet (String titleConcept) {
        String size = null;
        Connection conexiondb = conceptDbConnection.getConnection();
        try {
            getConceptResultSet = conexiondb.createStatement();
            conceptResultSet = getConceptResultSet.executeQuery("SELECT titleConcept, effortEstimationConcept FROM CONCEPTOS");
            while (conceptResultSet.next() && size==null) {

                if (conceptResultSet.getString("titleConcept").equalsIgnoreCase(titleConcept)) {
                    size = conceptResultSet.getString(2);
                } else {
                    size = null;
                }

            }
            conceptResultSet.close();
            conexiondb.close();
        } catch (Exception ex) {
            System.out.println("There is no connection");
            ex.printStackTrace();
    }

Read:

    public String parseConceptResultSet () {
        String result = "";
        Connection conexiondb = conceptDbConnection.getConnection();
        try {
            getConceptResultSet = conexiondb.createStatement();
            conceptResultSet = getConceptResultSet.executeQuery("SELECT * FROM CONCEPTOS");
            while (conceptResultSet.next()) {
                result += conceptResultSet.getString("titleConcept") + " | " 
                        + "Size: " + conceptResultSet.getString("effortEstimationConcept") + " | "
                        + "Notes: " + conceptResultSet.getString("notesConcept") + " | "
                        + "What is it for?: " + conceptResultSet.getString("whatConcept") + " | "
                        + "How is it used?: " + conceptResultSet.getString("howConcept") + " | "
                        + "Why is it used?: " + conceptResultSet.getString("whyConcept") + " | "
                        + "Check in counter: " + conceptResultSet.getString("checkInCounterConcept") + " | "
                        + "\n";
            }
            conceptResultSet.close();
        } catch (Exception ex) {
            System.out.println("There is no connection");
            ex.printStackTrace();
        }
        return result;
    }
    public String parseIdeaResultSet () {
        String result = "";
        Connection conexiondb = conceptDbConnection.getConnection();
        try {
            getConceptResultSet = conexiondb.createStatement();
            conceptResultSet = getConceptResultSet.executeQuery("SELECT * FROM IDEAS");
            while (conceptResultSet.next()) {
                result += conceptResultSet.getString("ididea") + " | " 
                        + "Concept: " + conceptResultSet.getString("titleconcept") + " | "
                        + "Idea: " + conceptResultSet.getString("titleidea") + " | "
                        + "Description: " + conceptResultSet.getString("descriptionidea") + " | "
                        + "\n";
            }
            conceptResultSet.close();
        } catch (Exception ex) {
            System.out.println("There is no connection");
            ex.printStackTrace();
        }
        return result;

    }

Update:

    public void takingNotes () { 
        Toolkit.getDefaultToolkit().beep();
        Connection conexiondb = conceptDbConnection.getConnection();
            try {
                PreparedStatement updateOnConceptDB = conexiondb.prepareStatement("UPDATE CONCEPTOS SET notesConcept= ? WHERE titleConcept= ?");
                updateOnConceptDB.setString(1, notesConcept += Tool.inputString("Ring@~~ Any note so far? ") + " ");
                updateOnConceptDB.setString(2, titleConcept);
                updateOnConceptDB.execute();
                conexiondb.close();
            } catch (Exception ex) {
                System.out.println("There is no connection");
                ex.printStackTrace();
            }   
    }

MONGODB CRUD:

Insert:

        try (MongoClient mongoClient = MongoClients.create()) {

            MongoDatabase opticDb = mongoClient.getDatabase("optic");

            MongoCollection<Document> clientCollection = opticDb.getCollection("client");

            Document client = new Document ("_id", new ObjectId());
            client.append("name", "Tris")
                .append("phone", "534675345")
                .append("email", "tri@kio.com");

            List <Document> clients = new ArrayList<>();

            clients.add(new Document ("_id", new ObjectId()).append("name", "Bull")
                    .append("phone", "35687463")
                    .append("email", "bull@gus.com"));
            clients.add(new Document ("_id", new ObjectId()).append("name", "Marc")
                    .append("phone", "35344352")
                    .append("email", "marc@is.com"));
            clients.add(new Document ("_id", new ObjectId()).append("name", "Kyr")
                    .append("phone", "865345435")
                    .append("email", "kir@wer.com"));

            clientCollection.insertMany(clients, new InsertManyOptions().ordered(false));
        }

Delete:

        try (MongoClient mongoClient = MongoClients.create()) {

            MongoDatabase opticDb = mongoClient.getDatabase("optic");
            MongoCollection<Document> clientCollection = opticDb.getCollection("client");

            Bson filter = eq("phone", "634625424");
            DeleteResult result = clientCollection.deleteOne(filter);

            System.out.println(result);
        }

Read:

        try (MongoClient mongoClient = MongoClients.create()) {

            MongoDatabase opticDb = mongoClient.getDatabase("optic");

            MongoCollection<Document> clientCollection = opticDb.getCollection("client");

            Consumer<Document> printConsumer = document -> System.out.println(document.toJson());
            clientCollection.find(ne("name", "kjhfdjhd")).forEach(printConsumer);

        }

Update:

        JsonWriterSettings prettyPrint = JsonWriterSettings.builder().indent(true).build();

        try (MongoClient mongoClient = MongoClients.create()) {

            MongoDatabase opticDb = mongoClient.getDatabase("optic");
            MongoCollection<Document> clientCollection = opticDb.getCollection("client");

            Bson filter = ne("name", "Ryal");
            Bson updateOperation = set("comment", "Ryal is a very frequent client");

            UpdateResult updateResult = clientCollection.updateOne(filter, updateOperation);

            System.out.println(clientCollection.find(filter).first().toJson(prettyPrint));      
            System.out.println(updateResult);

        }
plopezgit commented 12 months ago

@plopezgit https://drive.google.com/file/d/1HGccPeN8PnWKa4C7asYXcVx9HYpdusQM/view?usp=sharing

Image

plopezgit commented 11 months ago

Latest update 23/11/2023:

Image