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

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


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

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

                                                                boolean recordValid = true;

                                                                //get all member value
                                                                String name = fields[0];
                                                                String code = fields[1];
                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        //cannot read point --> assume new member, point = -1
                                                                        point = -1;
                                                                        recordValid = false;
                                                                        Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: MemberPoint\n" +
                                                                                "Value: " + String.valueOf(point),
                                                                                nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

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

                                                                //match
                                                                if (memberID.equalsIgnoreCase(code)) {
                                                                        dataObject = new Member();
                                                                        dataObject.setMemberID(code);
                                                                        dataObject.setMemberName(name);
                                                                        dataObject.setMemberPoint(point);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new AppException("[MemberDA::readData]File not found.", "[MemberDA::readData]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[MemberDA::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("[MemberDA::readData]Record not found.", "[MemberDA::readDataSet]", null);
                                } else {

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

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

                                                                boolean recordValid = true;

                                                                //get all member value
                                                                String name = fields[0];
                                                                if (name == null) {
                                                                        name = "";
                                                                }
                                                               
                                                                String code = fields[1];
                                                                if (code == null) {
                                                                        code = "";
                                                                }
                                                               
                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        //cannot read point --> assume new member, point = -1
                                                                        point = -1;
                                                                        recordValid = false;
                                                                        Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: MemberPoint\n" +
                                                                                "Value: " + String.valueOf(point),
                                                                                nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

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

                                                                if (!"".equalsIgnoreCase(code) && !"".equalsIgnoreCase(name)) {
                                                                        NameValue<String> memberName = new NameValue<String>("MemberName", name);
                                                                        NameValue<String> memberID = new NameValue<String>("MemberID", code);
                                                                        NameValue<Integer> memberPoint = new NameValue<Integer>("MemberPoint", point);
                                                                        dataObjectSet.add(new Tuple3<NameValue<String>, NameValue<String>, NameValue<Integer>>( memberName, memberID, memberPoint));
                                                                }

                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new AppException("[MemberDA::readData]File not found.", "[MemberDA::readDataSet]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[MemberDA::readDataSet]", 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

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

                                        Member member = new Member(memberID, memberName, memberPoint);
                                        String data = member.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new AppException("[MemberDA::writeData]Failed to create filename " + fileName, "[MemberDA::writeDataSet]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[MemberDA::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("[MemberDA::readData]Record not found.", "[MemberDA::readData]", null);
                                } else {

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

                                                                boolean recordValid = true;

                                                                //get all member value
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        //cannot read point --> assume new member, point = -1
                                                                        point = -1;
                                                                        recordValid = false;
                                                                        Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: MemberPoint\n" +
                                                                                "Value: " + String.valueOf(point),
                                                                                nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

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

                                                                //match
                                                                if (memberID.equalsIgnoreCase(code)) {
                                                                        dataObject = new Member();
                                                                        dataObject.setMemberID(code);
                                                                        dataObject.setMemberName(name);
                                                                        dataObject.setMemberPoint(point);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new AppException("[MemberDA::readData]File not found.", "[MemberDA::readData]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[MemberDA::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("[MemberDA::readData]Record not found.", "[MemberDA::readDataSet]", null);
                                } else {

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

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

                                                                boolean recordValid = true;

                                                                //get all member value
                                                                String code = fields[0];
                                                                if (code == null) {
                                                                        code = "";
                                                                }
                                                                String name = fields[1];
                                                                if (name == null) {
                                                                        name = "";
                                                                }

                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        //cannot read point --> assume new member, point = -1
                                                                        point = -1;
                                                                        recordValid = false;
                                                                        Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "" +
                                                                                "[MemberDA::readDataSet]Record no " + (String.valueOf(i + 1)) + "is corrupted.\n" +
                                                                                "Field: MemberPoint\n" +
                                                                                "Value: " + String.valueOf(point),
                                                                                nfx);
                                                                //throw new AppException(nfx.getMessage(), nfx);
                                                                }

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

                                                                if (!"".equalsIgnoreCase(code) && !"".equalsIgnoreCase(name)) {
                                                                        NameValue<String> memberID = new NameValue<String>("MemberID", code);
                                                                        NameValue<String> memberName = new NameValue<String>("MemberName", name);
                                                                        NameValue<Integer> memberPoint = new NameValue<Integer>("MemberPoint", point);
                                                                        dataObjectSet.add(new Tuple3<NameValue<String>, NameValue<String>, NameValue<Integer>>(memberID, memberName, memberPoint));
                                                                }

                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new AppException("[MemberDA::readData]File not found.", "[MemberDA::readDataSet]", null);
                        }
                } catch (IOException ex) {
                        throw new AppException(ex.getMessage(), "[MemberDA::readDataSet]", ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException 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.