Coverage Report - org.paneris.bibliomania.CreateBoard
 
Classes in this File Line Coverage Branch Coverage Complexity
CreateBoard
0%
0/11
0%
0/2
6
CreateBoard$1
0%
0/35
0%
0/10
6
 
 1  
 package org.paneris.bibliomania;
 2  
 
 3  
 import org.melati.Melati;
 4  
 import org.melati.poem.AccessToken;
 5  
 import org.melati.poem.Persistent;
 6  
 import org.melati.poem.PoemTask;
 7  
 import org.melati.poem.PoemThread;
 8  
 import org.melati.poem.UnexpectedExceptionPoemException;
 9  
 import org.paneris.melati.boards.BoardUtils;
 10  
 import org.webmacro.servlet.WebContext;
 11  
 
 12  
 
 13  0
 public class CreateBoard extends BibliomaniaServlet {
 14  
 
 15  
   /**
 16  
    * 
 17  
    */
 18  
   private static final long serialVersionUID = 1L;
 19  
 
 20  
   protected String bibliomaniaHandle(final Melati melati, WebContext context)
 21  
             throws Exception {
 22  
 
 23  0
     final BibliomaniaDatabase db = (BibliomaniaDatabase)PoemThread.database();
 24  0
     Persistent o = melati.getObject();
 25  
     // Bibliomania doesn't have chapter level boards
 26  0
     if (o instanceof Chapter) {
 27  0
                   o = ((Chapter)o).getParentUnit();
 28  
     }
 29  0
     final Persistent object = o;
 30  0
     final Board board = (Board)db.getBoardTable().newPersistent();
 31  0
     PoemThread.withAccessToken(
 32  
         AccessToken.root,
 33  0
         new PoemTask() {
 34  
           public void run() {
 35  
             try {
 36  0
               if (object instanceof Chapter) {
 37  0
                  board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).chapter());
 38  0
               } else if (object instanceof Book) {
 39  0
                  board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).book());
 40  0
               } else if (object instanceof Author) {
 41  0
                  board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).author());
 42  0
               } else if (object instanceof Section) {
 43  0
                  board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).section());
 44  0
               } else if (object instanceof SectionGroup) {
 45  0
                  board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).sectionGroup());
 46  
               } else {
 47  0
                  System.err.println("Unexpected Object in CreateBoard:" + object);
 48  
               }
 49  0
               board.setName(((Unit)object).getBoardName());
 50  0
               board.setDisplayname(((Unit)object).getDisplayName());
 51  0
               board.setPurpose("Discussion of " + ((Unit)object).getDisplayName() + ".");
 52  0
               board.setArchived(false);
 53  0
               board.setOpensubscription(true);
 54  0
               board.setModeratedsubscription(false);
 55  0
               board.setOpenposting(false);
 56  0
               board.setAnonymousposting(false);
 57  0
               board.setModeratedposting(false);
 58  0
               board.setOpenmessageviewing(true);
 59  0
               board.setOpenmemberlist(false);
 60  0
               board.setAttachmentsallowed(false);
 61  0
               board.setAttachmentspath(""); // We are not using attachments, but these fields get filled 
 62  0
               board.setAttachmentsurl("");  // in later anyway
 63  0
               board.makePersistent(((org.paneris.bibliomania.UserTable)db.getUserTable()).boardManager());
 64  
             }
 65  0
             catch (Exception e) {
 66  0
               throw new UnexpectedExceptionPoemException(e);
 67  0
             }
 68  
             try {
 69  0
               ((Unit)object).setMessageboard(board);
 70  
             }
 71  0
             catch (Exception e) {
 72  0
               throw new UnexpectedExceptionPoemException(e);
 73  0
             }
 74  0
           }
 75  
         }
 76  
       );
 77  
 
 78  0
     BoardUtils bu = new BoardUtils("/b/org.paneris.melati.boards.BoardAdmin","bibliomania");
 79  0
     melati.getResponse().sendRedirect(bu.BoardURL(board,"0"));
 80  0
     return null;
 81  
   }
 82  
 
 83  
 }
 84  
 
 85  
 
 86  
 
 87