Package program

Source Code of program.Repository

package program;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import models.Row_zmarket;
import models.Row_zmb52;
import models.Row_zme2n;
import models.Row_zva05;
import models.Row_zvc2;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


public class Repository {
    ArrayList<Row_zmarket> zmarketList = new ArrayList<Row_zmarket>();
    ArrayList<Row_zmb52> zmb52List = new ArrayList<Row_zmb52>();
    ArrayList<Row_zme2n> zme2nList = new ArrayList<Row_zme2n>();
    ArrayList<Row_zva05> zva05List = new ArrayList<Row_zva05>();
    ArrayList<Row_zvc2> zvc2List = new ArrayList<Row_zvc2>();
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
 
    //=====CONSTRUCTORS=====
    public Repository(String fileZmarket, String fileZmb52, String fileZme2n, String fileZva05, String fileZvc2) {
    //convert incoming strings referencing files into file objects
    File file_zmarket = new File(fileZmarket);
    File file_zmb52 = new File(fileZmb52);
    File file_zme2n = new File(fileZme2n);
    File file_zva05 = new File(fileZva05);
    File file_zvc2 = new File(fileZvc2);
     
    //populate the array lists by calling local parsing subroutines for each file
    populate_zmarket(file_zmarket);
    populate_zmb52(file_zmb52);
    populate_zme2n(file_zme2n);
    populate_zva05(file_zva05);
    populate_zvc2(file_zvc2);
    }
 
    //=====GETTERS=====
    public ArrayList<Row_zmarket> getMatchingRows_zmarket(Date beginDate, Date endDate) {
    ArrayList<Row_zmarket> toReturn = new ArrayList<Row_zmarket>();
   
    Iterator<Row_zmarket> iterator = zmarketList.iterator();
   
    while (iterator.hasNext()) {
      Row_zmarket row = (Row_zmarket) iterator.next();
     
      if ( (row.getVirtualTime().equals(beginDate) ||  row.getVirtualTime().after(beginDate)) && (row.getVirtualTime().equals(endDate) ||  row.getVirtualTime().before(endDate))) {
        toReturn.add(row);
      }
    }
   
    return toReturn;
  }
    public ArrayList<Row_zva05> getMatchingRows_zva05(Date beginDate, Date endDate) {
    ArrayList<Row_zva05> toReturn = new ArrayList<Row_zva05>();
   
    Iterator<Row_zva05> iterator = zva05List.iterator();
   
    while (iterator.hasNext()) {
      Row_zva05 row = (Row_zva05) iterator.next();
     
      if ( (row.getSimulationDate().equals(beginDate) ||  row.getSimulationDate().after(beginDate)) && (row.getSimulationDate().equals(endDate) ||  row.getSimulationDate().before(endDate))) {
        toReturn.add(row);
      }
    }
   
    return toReturn;
  }
    public ArrayList<Row_zvc2> getMatchingRows_zvc2(Date beginDate, Date endDate) {
    ArrayList<Row_zvc2> toReturn = new ArrayList<Row_zvc2>();
   
    Iterator<Row_zvc2> iterator = zvc2List.iterator();
   
    while (iterator.hasNext()) {
      Row_zvc2 row = (Row_zvc2) iterator.next();
     
      if ( (row.getSimulationDate().equals(beginDate) ||  row.getSimulationDate().after(beginDate)) && (row.getSimulationDate().equals(endDate) ||  row.getSimulationDate().before(endDate))) {
        toReturn.add(row);
      }
    }
   
    return toReturn;
  }
    public ArrayList<Row_zmb52> getMatchingRows_zmb52(int locationCode) {
    ArrayList<Row_zmb52> toReturn = new ArrayList<Row_zmb52>();
   
    Iterator<Row_zmb52> iterator = zmb52List.iterator();
   
    while (iterator.hasNext()) {
      Row_zmb52 row = (Row_zmb52) iterator.next();
     
      if (locationCode == row.getStorageLocationCode()) {
        toReturn.add(row);
      }
    }
   
    return toReturn;
  }
   
    //=====POPULATORS=====
    private void populate_zmarket(File file) {
    System.out.print("begin parsing " + file.getName() + "... ");
    int numRows = 0;
     
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(file);
        NodeList rows = doc.getElementsByTagName("alv:ROWS");
        //grab the ROWS element, since ROW elements exist elsewhere too
 
        for (int i=0; i<rows.getLength(); i++) { //iterate through the ROWS element
        Element rowsElement = (Element) rows.item(i);
        NodeList row = rowsElement.getElementsByTagName("ROW");
           
        for (int j=0; j<row.getLength(); j++) { //iterate through the ROW elements
            Element rowElement = (Element) row.item(j);
            NodeList cell = rowElement.getElementsByTagName("CELL");
             
            //default values for attributes needed to create the row object
            Date virtualTime = df.parse("01/01/1900");
            String prodDesc = "";
            String DC = "";
            double orderValue = 0.0;
            double quantity = 0;
            double price = 0.0;
             
            for (int k=0; k<cell.getLength(); k++) { //iterate through the CELL elements
            Element cellElement = (Element) cell.item(k);
            NodeList values = cellElement.getElementsByTagName("VALUE");
            //the value is actually its own element
                 
            if (cellElement.getAttribute("name").equalsIgnoreCase("C001")) { //virtual time
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                String tmpString = value.trim() + "/10";
                virtualTime = df.parse(tmpString);
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C002")) { //product description
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                prodDesc = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C003")) { //distribution channel
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                DC = value.trim();
            }
            if(cellElement.getAttribute("name").equalsIgnoreCase("C004")) { //order value
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                orderValue = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C005")) { //the quantity sold
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                quantity = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C006")) { //market price
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                price = Double.valueOf(value.trim()).doubleValue();
            }
            }
         
            numRows++;
            Row_zmarket entry = new Row_zmarket(virtualTime, prodDesc, DC, orderValue, quantity, price);
            zmarketList.add(entry);
        }
        }
    } catch(Exception e) {
        System.out.println("Couldn't parse zmarket.xml");
        e.printStackTrace();
    }
     
    System.out.println("done. (" + numRows + ") rows parsed.");
    }
    private void populate_zvc2(File file) {
    System.out.print("begin parsing " + file.getName() + "... ");
    int numRows = 0;
   
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(file);
        NodeList rows = doc.getElementsByTagName("alv:ROWS");
        //grab the ROWS element, since ROW elements exist elsewhere too
 
        for (int i=0; i<rows.getLength(); i++) { //iterate through the ROWS element
        Element rowsElement = (Element) rows.item(i);
        NodeList row = rowsElement.getElementsByTagName("ROW");
           
        for (int j=0; j<row.getLength(); j++) { //iterate through the ROW elements
            Element rowElement = (Element) row.item(j);
            NodeList cell = rowElement.getElementsByTagName("CELL");
             
            //default values for attributes needed to create the row object
            Date simulationDate = df.parse("01/01/1900");
            String simQuarter = "";
            String simDay = "";
            String materialDescription = "";
            double orders = 0;
            double orderQuantity = 0;
            double orderValue = 0.0;
             
            for (int k=0; k<cell.getLength(); k++) { //iterate through the CELL elements
            Element cellElement = (Element) cell.item(k);
            NodeList values = cellElement.getElementsByTagName("VALUE");
            //the value is actually its own element
                 
            if (cellElement.getAttribute("name").equalsIgnoreCase("C001")) { //simulation quarter
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                simQuarter = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C002")) { //simulation day
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                simDay = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C003")) { //the material description
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                materialDescription = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C004")) { //orders
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                orders =  Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C005")) { //number of orders
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                orderQuantity = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C006"))  {
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                orderValue =  Double.valueOf(value.trim()).doubleValue();
            }
            }
         
            numRows++;
            simulationDate = df.parse(simQuarter + "/" + simDay + "/10");
            Row_zvc2 entry = new Row_zvc2(simulationDate, materialDescription, orders, orderQuantity, orderValue);
            zvc2List.add(entry);
        }
        }
    } catch(Exception e) {
        System.out.println("Couldn't parse zvc2.xml");
    }
     
    System.out.println("done. (" + numRows + ") rows parsed.");
    }
    private void populate_zva05(File file) {
      System.out.print("begin parsing " + file.getName() + "... ");
    int numRows = 0;
     
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(file);
       
        NodeList rows = doc.getElementsByTagName("alv:ROWS");
        //grab the ROWS element, since ROW elements exist elsewhere too
 
        for (int i=0; i<rows.getLength(); i++) { //iterate through the ROWS element
        Element rowsElement = (Element) rows.item(i);
        NodeList row = rowsElement.getElementsByTagName("ROW");
           
        for (int j=0; j<row.getLength(); j++) { //iterate through the ROW elements
            Element rowElement = (Element) row.item(j);
            NodeList cell = rowElement.getElementsByTagName("CELL");
             
            //default values for attributes needed to create the row object
            Date simulationDate = df.parse("01/01/1900");
            String simQuarter = "";
            String simDay = "";
            String distributionChannel = "";
            String region = "";
            String materialDesc = "";
            int soldToParty = 0;
            double price = 0.0;
            double quantitySold = 0.0;
            double totalSalesValue = 0.0;
            int AR_Qtr = 0;
            int AR_Day = 0;
             
            for (int k=0; k<cell.getLength(); k++) { //iterate through the CELL elements
            Element cellElement = (Element) cell.item(k);
            NodeList values = cellElement.getElementsByTagName("VALUE");
            //the value is actually its own element
                 
            if (cellElement.getAttribute("name").equalsIgnoreCase("C001")) { //the storage location
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                simQuarter = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C002")) { //the material code
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                simDay = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C003")) { //the material description
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                distributionChannel = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C004")) { //the stock level
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                region = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C005")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                materialDesc = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C006")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                soldToParty = Integer.parseInt(value.trim());
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C007")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                price = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C008")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                quantitySold = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C009")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                totalSalesValue = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C010")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                AR_Qtr = Integer.parseInt(value.trim());
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C011")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                AR_Day = Integer.parseInt(value.trim());
            }
            }
           
            numRows++;
            simulationDate = df.parse(simQuarter + "/" + simDay + "/10");
            Row_zva05 entry = new  Row_zva05(simulationDate, distributionChannel, region, materialDesc, soldToParty, price, quantitySold, totalSalesValue, AR_Qtr, AR_Day);
            zva05List.add(entry);
        }
        }
    } catch(Exception e) {
        System.out.println("Couldn't parse zmb52.xml");
    }
     
    System.out.println("done. (" + numRows + ") rows parsed.");
    }
    private void populate_zme2n(File file) {
      System.out.print("begin parsing " + file.getName() + "... ");
    int numRows = 0;
     
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(file);
       
        NodeList rows = doc.getElementsByTagName("alv:ROWS");
        //grab the ROWS element, since ROW elements exist elsewhere too
 
        for (int i=0; i<rows.getLength(); i++) { //iterate through the ROWS element
        Element rowsElement = (Element) rows.item(i);
        NodeList row = rowsElement.getElementsByTagName("ROW");
           
        for (int j=0; j<row.getLength(); j++) { //iterate through the ROW elements
            Element rowElement = (Element) row.item(j);
            NodeList cell = rowElement.getElementsByTagName("CELL");
             
            //default values for attributes needed to create the row object
            String order = "";
            String material = "";
            double quantity = 0;
            double price = 0.0;
            boolean complete = false;
            Date goods = df.parse("01/01/1900");
            Date payment = df.parse("01/01/1900");
             
            for (int k=0; k<cell.getLength(); k++) { //iterate through the CELL elements
            Element cellElement = (Element) cell.item(k);
            NodeList values = cellElement.getElementsByTagName("VALUE");
            //the value is actually its own element
                 
            if (cellElement.getAttribute("name").equalsIgnoreCase("C001")) { //the storage location
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                order = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C002")) { //the material code
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                material = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C003")) { //the material description
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                quantity = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C004")) { //the stock level
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                price = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C005")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                if (valueElement != null) {
                  String value = valueElement.getTextContent().trim();
                  if (value.equalsIgnoreCase("x")) {
                    complete = true;
                  }
                }
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C006")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                value = value.trim() + "/10";
                goods = df.parse(value)
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C007")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                value = value.trim() + "/10";
                payment = df.parse(value);
            }
            }
           
            numRows++;
            Row_zme2n entry = new Row_zme2n (order, material, quantity, price, complete, goods, payment);
            zme2nList.add(entry);
        }
        }
    } catch(Exception e) {
        System.out.println("Couldn't parse zmb52.xml");
        e.printStackTrace();
    }
     
    System.out.println("done. (" + numRows + ") rows parsed.");
    }
    private void populate_zmb52(File file) {
    System.out.print("begin parsing " + file.getName() + "... ");
    int numRows = 0;
     
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(file);
       
        NodeList rows = doc.getElementsByTagName("alv:ROWS");
        //grab the ROWS element, since ROW elements exist elsewhere too
 
        for (int i=0; i<rows.getLength(); i++) { //iterate through the ROWS element
        Element rowsElement = (Element) rows.item(i);
        NodeList row = rowsElement.getElementsByTagName("ROW");
           
        for (int j=0; j<row.getLength(); j++) { //iterate through the ROW elements
            Element rowElement = (Element) row.item(j);
            NodeList cell = rowElement.getElementsByTagName("CELL");
             
            //default values for attributes needed to create the row object
            int storageLocationCode = 0;
            String materialCode = "";
            String materialDescription = "";
            Double stockLevel = 0.0;
            String unitOfMeasure = "";
             
            for (int k=0; k<cell.getLength(); k++) { //iterate through the CELL elements
            Element cellElement = (Element) cell.item(k);
            NodeList values = cellElement.getElementsByTagName("VALUE");
            //the value is actually its own element
                 
            if (cellElement.getAttribute("name").equalsIgnoreCase("C001")) { //the storage location
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                storageLocationCode = Integer.parseInt(value.trim());
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C002")) { //the material code
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                materialCode = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C003")) { //the material description
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                materialDescription = value.trim();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C004")) { //the stock level
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                stockLevel = Double.valueOf(value.trim()).doubleValue();
            }
            if (cellElement.getAttribute("name").equalsIgnoreCase("C005")) { //the unit measure
                Element valueElement = (Element) values.item(0);
                String value = valueElement.getTextContent();
                unitOfMeasure = value.trim();
            }
            }
           
            numRows++;
            Row_zmb52 entry = new Row_zmb52(storageLocationCode, materialCode, materialDescription, stockLevel, unitOfMeasure);
            zmb52List.add(entry);
        }
        }
    } catch(Exception e) {
        System.out.println("Couldn't parse zmb52.xml");
    }
     
    System.out.println("done. (" + numRows + ") rows parsed.");
    }
}
TOP

Related Classes of program.Repository

TOP
Copyright © 2018 www.massapi.com. 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.