Package sg.edu.nus.iss.se07.common.exceptions

Examples of sg.edu.nus.iss.se07.common.exceptions.AppException


                        String data = product.toCSVFormat(format);
                        bw = FileUtil.getBufferedWriter(fileName, append);
                        if (bw != null) {
                                FileUtil.writeContents(bw, data);
                        } else {
                                throw new AppException("[ProductDA::writeData]Failed to create filename " + fileName, "[ProductDA::writeData]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[ProductDA::writeData]", ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here


                                        String data = product.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new AppException("[ProductDA::writeDataSet]Failed to create filename " + fileName, "[ProductDA::writeDataSet]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[ProductDA::writeDataSet]", ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here

                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new AppException("[ProductDA::readData]Record not found.", "[ProductDA::readData]", null);
                                } else {

                                        if (lines.length < 1) {
                                                throw new AppException("[ProductDA::readData]Record not found.", "[ProductDA::readData]", null);
                                        }

                                        for (int i = 0; i < lines.length; i++) {
                                                String record = lines[i];
                                                String[] fields = StringUtil.parse(record, String.valueOf((char) format.getDelimiterChar()));
                                                if (fields == null) {
                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "[ProductDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new AppException("[ProductDA::readData]Unable to read record no " + (String.valueOf(i + 1)), "[ProductDA::readData]", null);
                                                } else {
                                                        if (fields.length != 8) {
                                                                Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                boolean recordValid = true;

                                                                String prodID = fields[0];
                                                                if (prodID == null) {
                                                                        prodID = "-";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductID\n");
                                                                }

                                                                String productName = fields[1];
                                                                if (productName == null) {
                                                                        productName = "-";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductName\n");
                                                                }

                                                                String productDescription = fields[2];
                                                                if (productDescription == null) {
                                                                        productDescription = "-";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductDescription\n");
                                                                }

                                                                int quantityAvailable = 0;
                                                                try {
                                                                        quantityAvailable = Integer.parseInt(fields[3]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        quantityAvailable = 0;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: QuantityAvailable\n" +
                                                                                "Value: " + String.valueOf(quantityAvailable), nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

                                                                float productPrice = -9999.9999f;
                                                                try {
                                                                        productPrice = Float.parseFloat(fields[4]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        productPrice = -9999.9999f;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductPrice\n" +
                                                                                "Value: " + String.valueOf(productPrice), nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

                                                                String barcodeNumber = fields[5];
                                                                if (barcodeNumber == null) {
                                                                        barcodeNumber = "-";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: BarCode Number\n");
                                                                }


                                                                int reorderQuantity = 0;
                                                                try {
                                                                        reorderQuantity = Integer.parseInt(fields[6]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        productPrice = -9999.9999f;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ReOrderQuantity\n" +
                                                                                "Value: " + String.valueOf(reorderQuantity), nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }


                                                                int orderQuantity = Integer.parseInt(fields[7]);
                                                                try {
                                                                        orderQuantity = Integer.parseInt(fields[7]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        productPrice = -9999.9999f;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: OrderQuantity\n" +
                                                                                "Value: " + String.valueOf(orderQuantity), nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

                                                                if (!recordValid) {
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.WARNING, "Some records are found invalid. Default value are assigned.");
                                                                }

                                                                if (productID.equalsIgnoreCase(prodID)) {
                                                                        dataObject = new Product();
                                                                        dataObject.setProductID(prodID);
                                                                        dataObject.setProductName(productName);
                                                                        dataObject.setProductDescription(productDescription);
                                                                        dataObject.setQuantityAvailable(quantityAvailable);
                                                                        dataObject.setProductPrice(productPrice);
                                                                        dataObject.setBarcodeNumber(barcodeNumber);
                                                                        dataObject.setReorderQuantity(reorderQuantity);
                                                                        dataObject.setOrderQuantity(orderQuantity);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new AppException("[ProductDA::readData]File not found.", "[ProductDA::readData]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[ProductDA::readData]", ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new AppException("[ProductDA::readDataSet]Record not found.", "[ProductDA::readDataSet]", null);
                                } else {

                                        if (lines.length < 1) {
                                                throw new AppException("[ProductDA::readDataSet]Record not found.", "[ProductDA::readDataSet]", null);
                                        }

                                        dataObjectSet = new ArrayList<Tuple8<NameValue<String>, NameValue<String>, NameValue<String>, NameValue<Integer>, NameValue<Float>, NameValue<String>, NameValue<Integer>, NameValue<Integer>>>();
                                        for (int i = 0; i < lines.length; i++) {
                                                String record = lines[i];
                                                String[] fields = StringUtil.parse(record, String.valueOf((char) format.getDelimiterChar()));
                                                if (fields == null) {
                                                        throw new AppException("[ProductDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)), "[ProductDA::readDataSet]", null);
                                                } else {
                                                        if (fields.length != 8) {
                                                                Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted. Incomplete fields.");
                                                        } else {

                                                                boolean recordValid = true;

                                                                String prodID = fields[0];
                                                                if (prodID == null) {
                                                                        prodID = "";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductID\n");
                                                                }

                                                                String productName = fields[1];
                                                                if (productName == null) {
                                                                        productName = "";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductName\n");
                                                                }

                                                                String productDescription = fields[2];
                                                                if (productDescription == null) {
                                                                        productDescription = "";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductDescription\n");
                                                                }

                                                                int quantityAvailable = 0;
                                                                try {
                                                                        quantityAvailable = Integer.parseInt(fields[3]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        quantityAvailable = 0;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: QuantityAvailable\n" +
                                                                                "Value: " + String.valueOf(quantityAvailable), nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

                                                                float productPrice = -9999.9999f;
                                                                try {
                                                                        productPrice = Float.parseFloat(fields[4]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        productPrice = -9999.9999f;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ProductPrice\n" +
                                                                                "Value: " + String.valueOf(productPrice), nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

                                                                String barcodeNumber = fields[5];
                                                                if (barcodeNumber == null) {
                                                                        barcodeNumber = "";
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: BarCode Number\n");
                                                                }


                                                                int reorderQuantity = 0;
                                                                try {
                                                                        reorderQuantity = Integer.parseInt(fields[6]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        productPrice = -9999.9999f;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: ReOrderQuantity\n" +
                                                                                "Value: " + String.valueOf(reorderQuantity), nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }


                                                                int orderQuantity = Integer.parseInt(fields[7]);
                                                                try {
                                                                        orderQuantity = Integer.parseInt(fields[7]);
                                                                } catch (NumberFormatException nfx) {
                                                                        recordValid = false;
                                                                        productPrice = -9999.9999f;
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[ProductDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: OrderQuantity\n" +
                                                                                "Value: " + String.valueOf(orderQuantity), nfx);
                                                                        //throw new AppException(nfx.getMessage(), nfx);
                                                                }


                                                                if (!recordValid) {
                                                                        Logger.getLogger(ProductDA.class.getName()).log(Level.WARNING, "Some records are found invalid. Default value are assigned.");
                                                                }

                                                                if (!"".equalsIgnoreCase(prodID) && !"".equalsIgnoreCase(productName) && !"".equalsIgnoreCase(productDescription)) {
                                                                        NameValue<String> nmProductID = new NameValue<String>("ProductID", prodID);
                                                                        NameValue<String> nmProductName = new NameValue<String>("ProductName", productName);
                                                                        NameValue<String> nmProductDescription = new NameValue<String>("ProductDescription", productDescription);
                                                                        NameValue<Integer> nmQuantityAvailable = new NameValue<Integer>("QuantityAvailable", quantityAvailable);
                                                                        NameValue<Float> nmProductPrice = new NameValue<Float>("ProductPrice", productPrice);
                                                                        NameValue<String> nmBarcodeNumber = new NameValue<String>("BarcodeNumber", barcodeNumber);
                                                                        NameValue<Integer> nmReorderQuantity = new NameValue<Integer>("ReorderQuantity", reorderQuantity);
                                                                        NameValue<Integer> nmOrderQuantity = new NameValue<Integer>("OrderQuantity", orderQuantity);

                                                                        dataObjectSet.add(new Tuple8<NameValue<String>, NameValue<String>, NameValue<String>, NameValue<Integer>, NameValue<Float>, NameValue<String>, NameValue<Integer>, NameValue<Integer>>(nmProductID, nmProductName, nmProductDescription, nmQuantityAvailable, nmProductPrice, nmBarcodeNumber, nmReorderQuantity, nmOrderQuantity));
                                                                }

                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new AppException("[ProductDA::readDataSet]File not found.", "[ProductDA::readDataSet]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[ProductDA::readDataSet]", ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

                                                Date finish = null;
                                                try {
                                                        finish = df.parse(eDate);
                                                } catch (ParseException ex) {
                                                        Logger.getLogger(ViewTransactionPanel.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                                                        throw new AppException(null, "[ViewTransactionPanel::search]", ex.getMessage() );
                                                }
                                                try {
                                                        start = df.parse(sDate);
                                                } catch (ParseException ex) {
                                                        Logger.getLogger(ViewTransactionPanel.class.getName()).log(Level.SEVERE, null, ex);
                                                        throw new AppException(null, "[ViewTransactionPanel::search]", ex.getMessage() );
                                                }

                                                appController = AppController.getInstance();
                                                transactions = appController.listTransaction(start, finish);
                                                if (transactions != null) {
View Full Code Here

        }

        public static boolean loadSetting() throws AppException {
                boolean success = SystemSettingControl.cacheSystemSetting();
                if (!success) {
                        throw new AppException("Failed to load Application Configuration Properties file.", "[MyApp::loadSetting]", null);
                }
                return success;
        }
View Full Code Here

                f = new File(dataDir);
                if (!f.exists()) {
                        //create data directory
                        boolean success = f.mkdirs();
                        if (!success) {
                                throw new AppException(null, "[MyApp::main]", "Failed to create data file.\nPlease manually create data folder and update the system setting.");
                        }

                }

                verifyCategoryData(dataDir);
                verifyMemberData(dataDir);
                verifyProductData(dataDir);
                verifyDiscountData(dataDir);
                verifyStorekeeperData(dataDir);
                verifyTransactionData(dataDir);
                verifyVendorData(dataDir);

                f = null;

                //verify settings for report folder
                String reportDir = appDir + SystemSetting.getProperty(SystemSetting.REPORT_FOLDER_PROPERTIES);
                if (!reportDir.endsWith(File.separator)) {
                        reportDir = reportDir + File.separator;
                }
                f = new File(reportDir);
                if (!f.exists()) {
                        //create report directory
                        boolean success = f.mkdirs();
                        if (!success) {
                                throw new AppException(null, "[MyApp:main]", "Failed to create report directory.\nPlease manually create report folder and update the system setting.");
                        }
                }
        }
View Full Code Here

                if (!f.exists()) {
                        try {
                                boolean success = f.createNewFile();
                        } catch (IOException ex) {
                                Logger.getLogger(MyApp.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                                throw new AppException(null, "[MyApp:main]", "Failed to create " + categoryData + ".\nPlease manually create it.");
                        }
                }
        }
View Full Code Here

                if (!f.exists()) {
                        try {
                                boolean success = f.createNewFile();
                        } catch (IOException ex) {
                                Logger.getLogger(MyApp.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                                throw new AppException(null, "[MyApp:main]", "Failed to create " + discountData + ".\nPlease manually create it.");
                        }
                }
        }
View Full Code Here

                if (!f.exists()) {
                        try {
                                boolean success = f.createNewFile();
                        } catch (IOException ex) {
                                Logger.getLogger(MyApp.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                                throw new AppException(null, "[MyApp:main]", "Failed to create " + memberData + ".\nPlease manually create it.");
                        }
                }
        }
View Full Code Here

TOP

Related Classes of sg.edu.nus.iss.se07.common.exceptions.AppException

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.