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

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


         *
         * @param memberID
         * @return Member records in form Array List.
         */
        public Member readData(String memberID) throws DataAccessException {
                Member 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("[MemberDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[MemberDA::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(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 3) {
                                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                //get all member value
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }

                                                                //match
                                                                if (memberID.equalsIgnoreCase(code)) {
                                                                        dataObject = new Member();
                                                                        dataObject.setMemberID(code);
                                                                        dataObject.setMemberName(name);
                                                                        dataObject.setMemberPoint(point);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
View Full Code Here


        }

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

                Member dataObject = new Member(id, name);
                MemberManager dataObjectManager = new MemberManager();

                try {
                        success = dataObjectManager.addMember(dataObject);
                        if (success) {
View Full Code Here

        public boolean updateMember(String id, String newName) throws AppException {

                boolean success = true;

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

                if (oldDataObject != null) {
                        Member newDataObject = new Member(id, newName, oldDataObject.getMemberPoint());
                        try {
                                success = dataObjectManager.updateMember(oldDataObject, newDataObject);
                                if (success) {
                                        //update to the cache
                                        Hashtable<String, Member> memberDataSet = DataSet.getMemberDataSet();
View Full Code Here

        public boolean updateMember(String id, int newPoint) throws AppException {
                boolean success = true;

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

                if (oldDataObject != null) {
                        Member newDataObject = new Member(id, oldDataObject.getMemberName(), newPoint);
                        try {
                                success = dataObjectManager.updateMember(oldDataObject, newDataObject);
                                if (success) {
                                        //update to the cache
                                        Hashtable<String, Member> memberDataSet = DataSet.getMemberDataSet();
View Full Code Here

        public int getMemberPoint(String id) throws AppException {
                int point = -99999;

                MemberManager dataObjectManager = new MemberManager();
                Member dataObject = null;
                try {
                        dataObject = dataObjectManager.selectMember(id);
                } catch (AppException ex) {
                        Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                        throw ex;
                }

                if (dataObject != null) {
                        point = dataObject.getMemberPoint();
                } else {
                        return point;
                }

                return point;
View Full Code Here

                return reportfilename;
        }

        public Member selectMember(String id) throws AppException {
                Member dataObject = null;

                MemberManager memberManager = new MemberManager();
                try {
                        dataObject = memberManager.selectMember(id);
                } catch (AppException ex) {
View Full Code Here

                                String header2 = StringUtil.createFixedWidthString("Member ID", 30);
                                String header3 = StringUtil.createFixedWidthString("Points", 7);
                                String outputHeader = String.format(MemberReport.MEMBER_REPORT_FORMAT, header0, header1, header2, header3);
                                lstMember.add(outputHeader);
                                for (int i = 0; i < memberList.size(); i++) {
                                        Member item = memberList.get(i);
                                        int no = i + 1;
                                        String recordNo = StringUtil.createFixedWidthString(String.valueOf(no), 5);
                                        String memberName = StringUtil.createFixedWidthString(item.getMemberName(), 30);
                                        String memberID = StringUtil.createFixedWidthString(item.getMemberID(), 30);
                                        String memberPoint = StringUtil.createFixedWidthString(String.valueOf(item.getMemberPoint()), 6);
                                        String outputCategory = String.format(CategoryReport.CATEGORY_REPORT_FORMAT, recordNo, memberName, memberID, memberPoint);
                                        lstMember.add(outputCategory);
                                }
                        }
                } catch (AppException ex) {
View Full Code Here

                        if (bw != null) {
                                for (int i = 0; i < memberSet.size(); i++) {
                                        String memberName = memberSet.get(i).getItem1().getValue();
                                        String memberID = memberSet.get(i).getItem2().getValue();
                                        int memberPoint = memberSet.get(i).getItem3().getValue();
                                        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);
                        }
View Full Code Here

         * @param memberID
         * @return Member records in form Array List.
         * @throws AppException
         */
        public Member readData(String memberID) throws AppException {
                Member 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("[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;
                                                                }
                                                        }
                                                }
                                        }
View Full Code Here

                                               
                        appController = AppController.getInstance();
                        memberList = appController.listMember();
                        if (memberList != null) {
                                for (int i = 0; i < memberList.size(); i++) {
                                        Member item = memberList.get(i);
                                        int no = i + 1;
                                        String recordNo = StringUtil.createFixedWidthString(String.valueOf(no), 5);
                                        String memberName = StringUtil.createFixedWidthString(item.getMemberName(), 30);
                                        String memberID = StringUtil.createFixedWidthString(item.getMemberID(), 30);
                                        String memberPoint = StringUtil.createFixedWidthString(String.valueOf(item.getMemberPoint()), 6);
                                        String outputCategory = String.format(MemberReport.MEMBER_REPORT_FORMAT, recordNo, memberName, memberID, memberPoint);
                                        lstMember.add(outputCategory);
                                }

                        }
View Full Code Here

TOP

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

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.