Package sg.edu.nus.iss.se07.bc

Examples of sg.edu.nus.iss.se07.bc.MemberManager


                        if (bw != null) {
                                for (int i = 0; i < categorySet.size(); i++) {

                                        String categoryCode = categorySet.get(i).getItem1().getValue();
                                        String categoryName = categorySet.get(i).getItem2().getValue();
                                        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);
                        }
View Full Code Here


         *
         * @param categoryCode
         * @return Category records in form Array List.
         */
        public Category readData(String categoryCode) throws DataAccessException {
                Category dataObject = null;
                BufferedReader br = null;

                try {
                        br = FileUtil.getBufferedReader(fileName);
                        if (br != null) {
                                String contents = FileUtil.getContents(br);
                                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;
                                                                }
                                                        }
                                                }
                                        }
View Full Code Here

                        if (bw != null) {
                                for (int i = 0; i < categorySet.size(); i++) {

                                        String categoryCode = categorySet.get(i).getItem1().getValue();
                                        String categoryName = categorySet.get(i).getItem2().getValue();
                                        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);
                        }
View Full Code Here

         * @param categoryCode
         * @return Category records in form Array List.
         * @throws AppException
         */
        public Category readData(String categoryCode) throws AppException {
                Category dataObject = null;
                BufferedReader br = null;

                try {
                        br = FileUtil.getBufferedReader(fileName);
                        if (br != null) {
                                String contents = FileUtil.getContents(br);
                                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;
                                                                }
                                                        }
                                                }
                                        }
View Full Code Here

         * @throws sg.edu.nus.iss.se07.common.exceptions.AppException
         */
        public boolean addCategory(String id, String name) throws AppException {
                boolean success = true;

                Category dataObject = new Category(id, name);
                CategoryManager dataObjectManager = new CategoryManager();

                try {
                        success = dataObjectManager.addCategory(dataObject);
                        if (success) {
                                //update cache
                                Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
                                if (categoryDataSet != null) {

                                        Hashtable<String, Product> productDataSet = DataSet.getProductDataSet();
                                        if (productDataSet != null) {
                                                Enumeration<Product> enumeration = productDataSet.elements();
                                                while (enumeration.hasMoreElements()) {
                                                        Product product = enumeration.nextElement();
                                                        if (product != null) {
                                                                String categorycode = product.getCategoryCode(product.getProductID());
                                                                if (categorycode.equalsIgnoreCase(id)) {
                                                                        dataObject.addProduct(product);
                                                                }
                                                        }

                                                }
                                        }
View Full Code Here

        public boolean updateCategory(String id, String name) throws AppException {
                boolean success = true;

                CategoryManager dataObjectManager = new CategoryManager();

                Category oldDataObject = null;
                try {
                        oldDataObject = dataObjectManager.selectCategory(id);
                } catch (AppException ex) {
                        Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                        throw ex;
                }

                if (oldDataObject != null) {
                        Category newDataObject = new Category(id, name);
                        try {
                                success = dataObjectManager.updateCategory(oldDataObject, newDataObject);
                                if (success) {
                                        //update cache
                                        Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
                                        if (categoryDataSet != null) {
                                                Category old = categoryDataSet.get(id);
                                                if (old!=null) {
                                                        newDataObject.setProducts(old.getProducts());
                                                        newDataObject.setVendors(old.getVendors());                                               
                                                }
                                                categoryDataSet.remove(id);
                                                categoryDataSet.put(id, newDataObject);
                                        }
                                }
View Full Code Here

                CategoryManager dataObjectManager = new CategoryManager();

                try {
                        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);
View Full Code Here

         */
        public boolean addCategory(String id, String name) throws AppException {
                boolean success = true;

                Category dataObject = new Category(id, name);
                CategoryManager dataObjectManager = new CategoryManager();

                try {
                        success = dataObjectManager.addCategory(dataObject);
                        if (success) {
                                //update cache
                                Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
                                if (categoryDataSet != null) {

View Full Code Here

         * @throws sg.edu.nus.iss.se07.common.exceptions.AppException
         */
        public boolean updateCategory(String id, String name) throws AppException {
                boolean success = true;

                CategoryManager dataObjectManager = new CategoryManager();

                Category oldDataObject = null;
                try {
                        oldDataObject = dataObjectManager.selectCategory(id);
                } catch (AppException ex) {
                        Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                        throw ex;
                }

                if (oldDataObject != null) {
                        Category newDataObject = new Category(id, name);
                        try {
                                success = dataObjectManager.updateCategory(oldDataObject, newDataObject);
                                if (success) {
                                        //update cache
                                        Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
                                        if (categoryDataSet != null) {
                                                Category old = categoryDataSet.get(id);
View Full Code Here

         * @throws sg.edu.nus.iss.se07.common.exceptions.AppException
         */
        public boolean removeCategory(String id, String name) throws AppException {
                boolean success = true;

                CategoryManager dataObjectManager = new CategoryManager();

                try {
                        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;
View Full Code Here

TOP

Related Classes of sg.edu.nus.iss.se07.bc.MemberManager

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.