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

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


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


                                        Category category = new Category(categoryCode, categoryName);
                                        String data = category.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new DataAccessException("[CategoryDA::writeData]Failed to create filename " + fileName);
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), 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 DataAccessException("[CategoryDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[CategoryDA::readData]Record not found.");
                                        }

                                        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(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[CategoryDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                if (categoryCode.equalsIgnoreCase(code)) {
                                                                        dataObject = new Category();
                                                                        dataObject.setCategoryCode(code);
                                                                        dataObject.setCategoryName(name);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[CategoryDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), 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 DataAccessException("[CategoryDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[CategoryDA::readData]Record not found.");
                                        }

                                        dataObjectSet = new ArrayList<Tuple2<NameValue<String>, NameValue<String>>>();
                                        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 DataAccessException("[CategoryDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                NameValue<String> categoryCode = new NameValue<String>("CategoryCode", fields[0]);
                                                                NameValue<String> categoryName = new NameValue<String>("CategoryName", fields[1]);
                                                                dataObjectSet.add(new Tuple2<NameValue<String>, NameValue<String>>(categoryCode, categoryName));
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[CategoryDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

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

                                        Category category = new Category(categoryCode, categoryName);
                                        String data = category.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new AppException("Failed to create filename " + fileName, "[CategoryDA::writeDataSet]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[CategoryDA::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("Record not found.", "[CategoryDA::readData]", null);
                                } else {

                                        if (lines.length < 1) {
                                                throw new AppException("Record not found.", "[CategoryDA::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) {
                                                        throw new AppException("Unable to read record no " + (String.valueOf(i + 1)), "[CategoryDA::readData]", null);
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String catCode = fields[0];
                                                                String catName = fields[1];
                                                                if (catCode == null) {
                                                                        catCode = "";
                                                                }

                                                                if (catName == null) {
                                                                        catName = "";
                                                                }

                                                                if (categoryCode.equalsIgnoreCase(catCode)) {
                                                                        dataObject = new Category();
                                                                        dataObject.setCategoryCode(catCode);
                                                                        dataObject.setCategoryName(catName);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new AppException("File not found.", "[CategoryDA::readData]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[CategoryDA::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("Record not found.", "[CategoryDA::readDataSet]", null);
                                } else {

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

                                        dataObjectSet = new ArrayList<Tuple2<NameValue<String>, NameValue<String>>>();
                                        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("Unable to read record no " + (String.valueOf(i + 1)), "[CategoryDA::readDataSet]", null);
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {

                                                                //get the value from file and verify it
                                                                String catCode = fields[0];
                                                                String catName = fields[1];
                                                                if (catCode == null) {
                                                                        catCode = "";
                                                                }

                                                                if (catName == null) {
                                                                        catName = "";
                                                                }

                                                                //valid row
                                                                if (!"".equalsIgnoreCase(catCode) && !"".equalsIgnoreCase(catName)) {
                                                                        NameValue<String> categoryCode = new NameValue<String>("CategoryCode", catCode);
                                                                        NameValue<String> categoryName = new NameValue<String>("CategoryName", catName);
                                                                        dataObjectSet.add(new Tuple2<NameValue<String>, NameValue<String>>(categoryCode, categoryName));
                                                                }

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

                                f = new File(dataDir);
                                if (!f.exists()) {
                                        //create data directory
                                        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.");
                                        }

                                }


                                String vendorData = dataDir + File.separator + SystemSetting.getProperty(SystemSetting.VENDOR_TABLE_PROPERTIES) + id.toUpperCase() + "." + SystemSetting.getProperty(SystemSetting.DATABASE_EXTENSION);
                                f = new File(vendorData);
                                if (!f.exists()) {
                                        try {
                                                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 " + vendorData + ".\nPlease manually create it.");
                                        }
                                }
                        }
                } catch (AppException ex) {
                        Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
View Full Code Here

                        Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
                        Category dataObject = categoryDataSet.get(id);
                        if (dataObject != null) {
                                if (dataObject.getProducts().size() > 0) {
                                        //this category still got dependency with product
                                        throw new AppException("Products exist. Cannot delete this Category.\nPlease remove all product first.", "[AppController::removeCategory]", null);
                                }
                        }
                        success = dataObjectManager.deleteCategory(id);
                        if (success) {
                                categoryDataSet.remove(id);

                                //Remove vendors file
                                File f = null;

                                //get application directory
                                String appDir = MyApp.getApplicationDirectory();
                                if (!appDir.endsWith(File.pathSeparator)) {
                                        appDir = appDir + File.separator;
                                }

                                //verify settings for data folder
                                String dataDir = appDir + SystemSetting.getProperty(SystemSetting.DATA_FOLDER_PROPERTIES);
                                f = new File(dataDir);
                                if (!f.exists()) {
                                        //create data directory
                                        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.");
                                        }

                                }


                                String vendorData = dataDir + File.separator + SystemSetting.getProperty(SystemSetting.VENDOR_TABLE_PROPERTIES) + id.toUpperCase() + "." + SystemSetting.getProperty(SystemSetting.DATABASE_EXTENSION);
                                f = new File(vendorData);
                                if (f.exists()) {
                                        success = f.delete();
                                        if (!success) {
                                                Logger.getLogger(MyApp.class.getName()).log(Level.SEVERE, "Failed to delete " + vendorData + ".\nPlease manually create it.");
                                                throw new AppException(null, "[MyApp:main]", "Failed to delete " + vendorData + ".\nPlease manually create it.");
                                        }
                                }
                        }
                } catch (AppException ex) {
                        Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
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.