Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package integratedlibraryclient;
- import ejb.BookAuthorManagerBeanRemote;
- import ejb.BookLoanManagerBeanRemote;
- import ejb.LibMemberManagerBeanRemote;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import javax.ejb.EJB;
- import java.util.*;
- public class Main {
- @EJB
- private static LibMemberManagerBeanRemote lmb;
- @EJB
- private static BookAuthorManagerBeanRemote ba;
- @EJB
- private static BookLoanManagerBeanRemote bl;
- public Main(){}
- public static void main(String[] args) {
- Main admin = new Main();
- admin.doILS(args);
- }
- public void doILS(String[] args){
- try{
- String choice = "";
- Scanner sc = new Scanner(System.in);
- while(!choice.equals("0")){
- //main menu
- System.out.println("***************************************");
- System.out.println("Welcome to ILS Admin Portal!");
- System.out.println("***************************************");
- System.out.println("Please enter your choice:");
- System.out.println("1. Add User");
- System.out.println("2. Delete User");
- System.out.println("3. Add Author");
- System.out.println("4. Add Book");
- System.out.println("5. Update Book");
- System.out.println("6. Delete Book");
- System.out.println("7. Checkout Book");
- System.out.println("8. Return Book");
- System.out.println("9. View Reservations");
- System.out.println("10. View Checkouts");
- System.out.println("11. View Fines");
- System.out.println("12. Process Request");
- System.out.println("0: Exit");
- System.out.print("Enter Choice: ");
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- choice = br.readLine();
- if(choice.equals("1")){
- addUser(sc);
- } else if(choice.equals("2")){
- deleteUser(sc);
- } else if(choice.equals("3")){
- addAuthor(sc);
- } else if(choice.equals("4")){
- addBook(sc);
- } else if(choice.equals("5")){
- updateBook(sc);
- } else if(choice.equals("6")){
- deleteBook(sc);
- } else if(choice.equals("7")){
- checkoutBook(sc);
- } else if(choice.equals("8")){
- returnBook(sc);
- } else if(choice.equals("9")){
- viewReservation(sc);
- } else if(choice.equals("10")){
- viewCheckout(sc);
- } else if(choice.equals("11")){
- viewFine(sc);
- } else if(choice.equals("12")){
- processRequest(sc);
- } else if(choice.equals("0")){
- return;
- } else{
- return;
- }
- }
- }catch(Exception ex){
- System.err.println("Caught an unexpected exception!");
- }
- }
- private void addUser(Scanner sc){
- try{
- System.out.println("---ADD USER---");
- System.out.print("Enter User Name: ");
- String inName = sc.nextLine();
- System.out.print("Enter Default Password: ");
- String inPass = sc.nextLine();
- System.out.print("Enter Default Password Again: ");
- String inPass2 = sc.nextLine();
- System.out.print("Enter Contact Number: ");
- String inContact = sc.nextLine();
- System.out.print("Enter E-mail: ");
- String inEmail = sc.nextLine();
- System.out.print("Enter Address: ");
- String inAddress = sc.nextLine();
- String result = lmb.createMember(inName, inPass, inContact, inEmail, inAddress, inPass2);
- System.out.println(result);
- } catch(Exception ex) {
- System.out.println("\nFailed to create member because " + ex.getMessage() + "\n");
- }
- }
- private void deleteUser(Scanner sc){
- try{
- System.out.println("---ADD USER---");
- System.out.print("Enter User Name: ");
- String username = sc.nextLine();
- String result = lmb.deleteMember(username);
- System.out.println(result);
- } catch (Exception ex){
- System.out.println("\n Failed to delete user becase " + ex.getMessage() + "\n");
- }
- }
- private void addAuthor(Scanner sc){
- try{
- System.out.println("---ADD AUTHOR---");
- System.out.print("Enter Author Name: ");
- String inAuthorName = sc.nextLine();
- System.out.print("Enter Author's Description: ");
- String inAuthorDesc = sc.nextLine();
- String authorID = ba.createAuthor(inAuthorName, inAuthorDesc);
- System.out.println("\nAuthor added successfully!\n");
- System.out.println("Author ID: " + authorID);
- } catch (Exception ex){
- System.out.println("\n Failed to create author becase " + ex.getMessage() + "\n");
- }
- }
- private void addBook(Scanner sc){
- try{
- System.out.println("---ADD BOOK---");
- System.out.print("Enter Title: ");
- String inTitle = sc.nextLine();
- System.out.print("Enter Number of Authors: ");
- int numAuthors = sc.nextInt();
- String[] authorArr = new String[numAuthors];
- for(int i=0; i<numAuthors; i++){
- System.out.print("Enter ID of Author: ");
- authorArr[i] = sc.next();
- }
- sc.nextLine();
- System.out.print("Enter Publisher: ");
- String inPub = sc.nextLine();
- System.out.print("Enter Publication Year: ");
- int inPubYear = sc.nextInt();
- sc.nextLine();
- System.out.print("Enter ISBN: ");
- String inISBN = sc.nextLine();
- System.out.print("Enter Copy No: ");
- int inCopyNo = sc.nextInt();
- sc.nextLine();
- String result = ba.createBook(inTitle, inPub, inPubYear, inISBN, inCopyNo, authorArr);
- System.out.println(result);
- } catch(Exception ex) {
- System.out.println("\nFailed to create book because " + ex.getMessage() + "\n");
- }
- }
- private void updateBook(Scanner sc){
- try{
- System.out.println("---UPDATE BOOK---");
- System.out.print("Enter ISBN: ");
- String oldISBN = sc.nextLine();
- System.out.print("Enter Copy Number: ");
- int oldCopyNo = sc.nextInt();
- sc.nextLine();
- System.out.println("---Enter Details of New Book---");
- System.out.print("Enter New Title: ");
- String newTitle = sc.nextLine();
- System.out.print("Enter New Publisher: ");
- String newPub = sc.nextLine();
- System.out.print("Enter New Publication Year: ");
- int newPubYear = sc.nextInt();
- sc.nextLine();
- System.out.print("Enter New ISBN: ");
- String newISBN = sc.nextLine();
- System.out.print("Enter New Copy Number: ");
- int newCopyNo = sc.nextInt();
- System.out.print("Enter New Number of Authors: ");
- int newNumAuthors = sc.nextInt();
- sc.nextLine();
- String[] authorArr = new String[newNumAuthors];
- for(int i=0; i<newNumAuthors; i++){
- System.out.print("Enter ID of Author " + (i+1) + ":");
- authorArr[i] = sc.next();
- }
- sc.nextLine();
- String result = ba.updateBook(oldISBN, oldCopyNo, newTitle, newPub, newPubYear, newISBN, newCopyNo, authorArr);
- System.out.println(result);
- }catch(Exception ex){
- System.out.println("\nFailed to update book because " + ex.getMessage() + "\n");
- }
- }
- public void deleteBook(Scanner sc){
- try {
- System.out.println("---DELETE BOOK---");
- System.out.print("Enter ISBN: ");
- String isbn = sc.nextLine();
- System.out.print("Enter Copy No: ");
- int copyNo = sc.nextInt();
- sc.nextLine();
- String result = ba.deleteBook(isbn, copyNo);
- System.out.println(result);
- } catch (Exception ex) {
- System.out.println("\nFailed to delete book because " + ex.getMessage() + "\n");
- }
- }
- public void checkoutBook(Scanner sc){
- try {
- System.out.println("---CHECKOUT BOOK---");
- System.out.print("Enter Username: ");
- String username = sc.nextLine();
- System.out.print("Enter ISBN: ");
- String isbn = sc.nextLine();
- System.out.print("Enter Copy No: ");
- int copyNo = sc.nextInt();
- sc.nextLine();
- String dueDate = bl.checkoutBook(username, isbn, copyNo);
- if(dueDate.equals("Book currently unavailable")){
- System.out.println(dueDate);
- }
- else {
- System.out.println("Book successfully checkout!");
- System.out.println("Due date: " + dueDate);
- }
- } catch (Exception ex) {
- System.out.println("\nFailed to checkout book because " + ex.getMessage() + "\n");
- }
- }
- public void returnBook(Scanner sc){
- try {
- System.out.println("---RETURN BOOK---");
- System.out.print("Enter ISBN: ");
- String isbn = sc.nextLine();
- System.out.print("Enter Copy No: ");
- int copyNo = sc.nextInt();
- sc.nextLine();
- int days = bl.returnBook(isbn, copyNo);
- if(days > 0)
- System.out.println("Book overdue. Fine successfully created");
- else if(days == -1)
- System.out.println("Error, no checkout for the book");
- System.out.println("Book successfully returned!");
- } catch (Exception ex) {
- System.out.println("\nFailed to checkout book because " + ex.getMessage() + "\n");
- }
- }
- public void viewReservation(Scanner sc){
- try {
- System.out.println("---VIEW RESERVATIONS---");
- System.out.print("Enter ISBN: ");
- String isbn = sc.nextLine();
- System.out.print("Enter Copy No: ");
- int copyNo = sc.nextInt();
- sc.nextLine();
- String returnMsg = (String) bl.viewReservations(isbn, copyNo).get(0);
- ArrayList results = bl.viewReservations(isbn, copyNo);
- int size = bl.viewReservations(isbn, copyNo).size();
- if(returnMsg.equals("Error! Incorrect book details") || returnMsg.equals("No reservations found!")){
- System.out.println(returnMsg);
- } else {
- System.out.println("BookTitle: " + returnMsg);
- for(int i=1; i<size; i++){
- Object o = results.get(i);
- String reservation = (String) o;
- StringTokenizer st = new StringTokenizer(reservation, " # ");
- System.out.println(st.nextToken());
- System.out.println("Username: " + st.nextToken());
- System.out.println("Email: " + st.nextToken());
- System.out.println("Reservation Time: " + st.nextToken() + " " + st.nextToken());
- System.out.println("Note: " + st.nextToken());
- }
- }
- } catch (Exception ex) {
- System.out.println("\nFailed to checkout book because " + ex.getMessage() + "\n");
- }
- }
- public void viewCheckout(Scanner sc){
- try {
- System.out.println("---VIEW CURRENT CHECKOUTS---\n");
- if(bl.viewCheckouts().get(0).equals("No checkout found!")){
- System.out.println("No checkout found!");
- }
- else {
- for(Object o: bl.viewCheckouts()){
- String checkout = (String) o;
- StringTokenizer st = new StringTokenizer(checkout, " # ");
- System.out.println("ISBN: " + st.nextToken());
- System.out.println("Copy No: " + st.nextToken());
- System.out.println("Title: " + st.nextToken());
- System.out.println("Username: " + st.nextToken());
- System.out.println("E-mail Address: " + st.nextToken());
- System.out.println("Loan Date: " + st.nextToken());
- System.out.println("Due Date: " + st.nextToken() + "\n\n");
- }
- }
- } catch (Exception ex) {
- System.out.println("\nFailed to get checkout books because " + ex.getMessage() + "\n");
- }
- }
- public void viewFine(Scanner sc){
- try {
- System.out.println("---VIEW FINES---\n");
- if(bl.viewFines().get(0).equals("No fine found!")){
- System.out.println("No fine found!");
- }
- else {
- for(Object o: bl.viewFines()){
- String fine = (String) o;
- String[] fineS = fine.split("#");
- System.out.println("FineID: " + fineS[0]);
- System.out.println("Fine Date: " + fineS[1]);
- System.out.println("Fine Amount: " + fineS[2]);
- System.out.println("Username: " + fineS[3]);
- System.out.println("E-mail Address: " + fineS[4] + "\n\n");
- }
- }
- } catch (Exception ex) {
- System.out.println("\nFailed to view fine because " + ex.getMessage() + "\n");
- }
- }
- public void processRequest(Scanner sc){
- try {
- System.out.println("---VIEW REQUESTS---\n");
- if(bl.viewRequest().get(0).equals("No request found!")){
- System.out.println("No request found!");
- }
- else {
- for(Object o: bl.viewRequest()){
- String req = (String) o;
- StringTokenizer st = new StringTokenizer(req, " # ");
- System.out.println("Request ID: " + st.nextToken());
- System.out.println("Username: " + st.nextToken());
- System.out.println("Time: " + st.nextToken());
- System.out.println("Message: " + st.nextToken() + "\n");
- }
- System.out.print("Enter the request to be processed: ");
- String requestID = sc.nextLine();
- System.out.print("Change the status to: ");
- String status = sc.nextLine();
- System.out.print("Comment: ");
- String comment = sc.nextLine();
- String result = bl.processRequest(requestID, status, comment);
- System.out.println(result);
- }
- } catch (Exception ex) {
- System.out.println("\nFailed to get request because " + ex.getMessage() + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement