BluePrints/.classpath
BluePrints/.gitignore
/target/ /logs/
BluePrints/.project
BluePrints org.eclipse.wst.common.project.facet.core.builder org.eclipse.jdt.core.javabuilder org.springframework.ide.eclipse.core.springbuilder org.springframework.ide.eclipse.boot.validation.springbootbuilder net.sf.eclipsecs.core.CheckstyleBuilder org.eclipse.wst.validation.validationbuilder org.eclipse.m2e.core.maven2Builder org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature org.eclipse.wst.common.project.facet.core.nature org.eclipse.wst.common.modulecore.ModuleCoreNature
BluePrints/.settings/.jsdtscope
BluePrints/.settings/org.eclipse.core.resources.prefs
eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 encoding//src/test/java=UTF-8 encoding/=UTF-8
BluePrints/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8
BluePrints/.settings/org.eclipse.wst.common.component
BluePrints/.settings/org.eclipse.wst.common.project.facet.core.xml
BluePrints/.settings/org.eclipse.wst.jsdt.ui.superType.container
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
BluePrints/.settings/org.eclipse.wst.jsdt.ui.superType.name
Window
BluePrints/.settings/org.eclipse.wst.validation.prefs
disabled=06target eclipse.preferences.version=1
BluePrints/GitProj/Kings/BluePrints/target/m2e-wtp/web-resources/.gitignore
/META-INF/
BluePrints/pom.xml
4.0.0 edu.kings.cs480 BluePrints war BluePrints http://maven.apache.org edu.kings.cs480.BluePrints.BluePrintsMain UTF-8 1.8 org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE org.springframework.boot spring-boot-starter-tomcat provided org.springframework.boot spring-boot-starter-data-jpa org.apache.tomcat.embed tomcat-embed-jasper provided com.unboundid unboundid-ldapsdk org.springframework.boot spring-boot-starter-freemarker org.webjars bootstrap 4.0.0-beta.3 org.webjars.bower popper.js 1.12.9 org.json json org.postgresql postgresql org.webjars datatables 1.10.16 runtime org.springframework.boot spring-boot-starter-log4j2 org.apache.logging.log4j log4j-slf4j-impl com.h2database h2 runtime javax.xml.bind jaxb-api runtime 2.3.0 org.webjars jquery 3.0.0 runtime org.springframework.boot spring-boot-maven-plugin 1.0
BluePrints/ReadMe.md
Source Code Citations: Author(s): Martin Konicek and Maarten Bodewes Date: 4/18/18 Title: Password Version: 06-14-2012 Type: Source Code Web Site: https://stackoverflow.com/questions/2860943/how-can-i-hash-a-password-in-java?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
BluePrints/src/main/java/edu/kings/cs480/BluePrints/ActiveDirectory/AuthenticatedUser.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/ActiveDirectory/AuthenticatedUser.java
/**
 * 
 */
package  edu . kings . cs480 . BluePrints . ActiveDirectory ;
import  javax . naming . NamingException ;
import  javax . naming . directory . Attributes ;
/**
 * This class represents a user from the Active Directory.
 */
public   class   AuthenticatedUser   {
     /** Keeps track of the user's king's id. */
     private   String  kingsid ;
     /** Keeps track of the user's first name. */
     private   String  firstName ;
     /** Keeps track of the user's last name. */
     private   String  lastName ;
     /** Keeps track of the user's email address. */
     private   String  email ;
     /**
     * Creates a user with the provided information.
     * 
     *  @param  attr
     *            - the set of attributes which contains information about this
     *            user.
     *
     */
     protected   AuthenticatedUser ( Attributes  attr )   throws   NamingException   {
        firstName  =   ( String )  attr . get ( "givenName" ). get ( 0 );
        lastName  =   ( String )  attr . get ( "sn" ). get ( 0 );
        kingsid  =   ( String )  attr . get ( "KingsID" ). get ( 0 );
        email  =   ( String )  attr . get ( "mail" ). get ( 0 );
     }
     /**
     * Returns the user's first name.
     * 
     *  @return  the user's first name.
     */
     public   String  getFirstName ()   {
         return  firstName ;
     }
     /**
     * Returns the user's last name.
     * 
     *  @return  the user's last name.
     */
     public   String  getLastName ()   {
         return  lastName ;
     }
     /**
     * Returns the user's email.
     * 
     *  @return  the user's email.
     */
     public   String  getEmail ()   {
         return  email ;
     }
     /**
     * Returns the user's king's id.
     * 
     *  @return  the user's king's id.
     */
     public   String  getKingsId ()   {
         return  kingsid ;
     }
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/ActiveDirectory/AuthenticationService.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/ActiveDirectory/AuthenticationService.java
package  edu . kings . cs480 . BluePrints . ActiveDirectory ;
import  java . util . Hashtable ;
import  javax . naming . Context ;
import  javax . naming . NamingEnumeration ;
import  javax . naming . NamingException ;
import  javax . naming . directory . Attribute ;
import  javax . naming . directory . Attributes ;
import  javax . naming . directory . SearchResult ;
import  javax . naming . directory . SearchControls ;
import  javax . naming . ldap . InitialLdapContext ;
import  javax . naming . ldap . LdapContext ;
/**
 * AuthenticationService
 *
 * Provides an interface to authenticate against the King's Active Directory server.
 *
 */
public   class   AuthenticationService   {
     // the domain name to authenticate against.
     private   static   String  domain  =   "kings.edu" ;
     /**
     * AuthenticationService()
     */
     private   AuthenticationService ()   {
     }
     /**
     * authenticate
     *
     * Try to authenticate against active directory via ldap and return the status of the authentication.
     *
     *  @param  email The email to authenticate against.
     *  @param  password The password associated with the email
     *  @return  true if authentication was successful, otherwise false.
     *  @throws  NamingException When communication or authentication fails against the domain controller.
     */
     public   static   LdapContext  authenticate ( String  email ,   String  password )   throws   NamingException   {
         // Define our properties of LDAP.
         Hashtable < String ,   String >  adProps  =   new   Hashtable < String ,   String > ();
        adProps . put ( Context . SECURITY_PRINCIPAL ,  email );
        adProps . put ( Context . SECURITY_CREDENTIALS ,  password );
        adProps . put ( Context . INITIAL_CONTEXT_FACTORY ,   "com.sun.jndi.ldap.LdapCtxFactory" );
        adProps . put ( Context . PROVIDER_URL ,   "ldap://"   +  domain );
         // Try created a connection based on the above properties that we defined.
         try   {
             return   new   InitialLdapContext ( adProps ,   null );
         }
         catch ( javax . naming . CommunicationException  e )   {
            e . printStackTrace ();
             throw   new   NamingException ( "Failed to connect to "   +  domain );
         }
         catch ( NamingException  e )   {
             throw   new   NamingException ( "Failed to authenticate against "   +  domain );
         }
     }
     /**
     * getUser
     *
     * Returns the user object based on the user from AD, otherwise return null.
     *
     *  @param  email The email to retrieve.
     *  @param  context The context connection to the AD directory.
     *  @return  A user if the user exists, otherwise return null.
     */
     public   static   AuthenticatedUser  getUser ( String  email ,   LdapContext  context )   {
        
        
         try   {
            
             String []  requestedAttrs  =   new   String []   {   "sn" ,   "givenName" ,   "KingsID" ,   "mail" ,   "userPrincipalName" };
            
             // Setup a search control.
             SearchControls  controls  =   new   SearchControls ();
             // Limit our search, otherwise we will time out traversing the whole directory.
            controls . setSearchScope ( javax . naming . directory . SearchControls . SUBTREE_SCOPE );
             // Limit our attributes, AD has 100+ fields, we don't need all of them.
            controls . setReturningAttributes ( requestedAttrs );
             // Define our connection string, this format is required for LDAP.
             // TODO: Refactor this.
             NamingEnumeration < SearchResult >  result  =  context . search ( "OU=User_New,DC=kings,DC=edu" ,   "(& (userPrincipalName=" + email + ")(objectClass=user))" ,  controls );
             // Search our attributes until we come across one that matches the email we specified.
             if   ( result . hasMore ())   {
                 Attributes  attr  =  result . next (). getAttributes ();
                 Attribute  user  =  attr . get ( "userPrincipalName" );
                 if   ( user != null )   return   new   AuthenticatedUser ( attr );
             }
         }
         catch ( NamingException  e )   {
             // TODO: Handle this gracefully.
             //System.out.println(e.toString());
            e . printStackTrace ();
         }
         return   null ;
     }
    
    
    
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/BuildingAdapter.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/BuildingAdapter.java
/**
 * 
 */
package  edu . kings . cs480 . BluePrints . Adapters ;
import  java . util . List ;
import  java . util . UUID ;
import  org . springframework . beans . factory . annotation . Autowired ;
import  org . springframework . stereotype . Service ;
import  edu . kings . cs480 . BluePrints . Database . AppUser ;
import  edu . kings . cs480 . BluePrints . Database . AppUserRepository ;
import  edu . kings . cs480 . BluePrints . Database . Building ;
import  edu . kings . cs480 . BluePrints . Database . BuildingCoordinate ;
import  edu . kings . cs480 . BluePrints . Database . BuildingRepository ;
import  edu . kings . cs480 . BluePrints . Database . CoordinateRepository ;
/**
 * This class is responsible for handling method used in the Map Manager Page.
 * 
 */
@ Service
public   class   BuildingAdapter   {
     /** Used to query data from the buildings table in the database. */
    @ Autowired
     private   BuildingRepository  buildingRepo ;
     /** Handles calls to the database about the users in the BluePrints System. */
    @ Autowired
     private   AppUserRepository  userRepo ;
     /** Handles calls to the database about the coordinate data for buildings. */
    @ Autowired
     private   CoordinateRepository  coordinateRepo ;
     /**
     * Returns all the buildings stored in the system.
     * 
     *  @return  all the buildings stored in the system.
     */
     public   List < Building >  getBuildings ()   {
         return  buildingRepo . findAll ();
     }
     /**
     * Returns the building with the corresponding id provided.
     * 
     *  @param  buildingId
     *            - the id of the building being returned.
     *  @return  the building corresponding to the provided id.
     */
     public   Building  getBuilding ( UUID buildingId )   {
         Building  building  =   null ;
        building  =  buildingRepo . findOne ( buildingId );
         return  building ;
     }
     /**
     * Updates the building with corresponding id, with the information provided.
     * 
     *  @param  buildingId
     *            - the id of the building being updated.
     *  @param  buildingName
     *            - the new name of the building.
     *  @return  whether, or not, the building was successfully updated.
     */
     public   boolean  updateBuilding ( UUID buildingId ,   String  buildingName )   {
         boolean  updated  =   false ;
         Building  building  =  buildingRepo . findOne ( buildingId );
         if   ( building  !=   null )   {
            building . setName ( buildingName );
            buildingRepo . save ( building );
            updated  =   true ;
         }
         return  updated ;
     }
     /**
     * Removes the building with the provided id from the system.
     * 
     *  @param  buildingId
     *            - the id of the building being deleted.
     *  @return  whether, or not, the building was successfully removed.
     */
     public   boolean  deleteBuilding ( UUID buildingId )   {
         boolean  deleted  =   false ;
         Building  building  =  getBuilding ( buildingId );
         if   ( building  !=   null )   {
            buildingRepo . delete ( building );
            deleted  =   true ;
         }
         return  deleted ;
     }
     /**
     * Adds a new building with the provided name, and creator id.
     * 
     *  @param  buildingName
     *            - the name of the building.
     *  @param  creatorId
     *            - the id of the person creating the building.
     *  @return  the newly added building.
     */
     public   Building  addBuilding ( String  buildingName ,  UUID creatorId )   {
         Building  building  =   null ;
         AppUser  creator  =  userRepo . findOne ( creatorId );
         if   ( creator  !=   null )   {
            building  =   new   Building ( buildingName ,  creator );
            buildingRepo . save ( building );
         }
         return  building ;
     }
     /**
     * Adds the coordinates to the database for the building with the corresponding
     * building id.
     * 
     *  @param  buildingId
     *            - the id of the building the coordinate belongs to.
     *  @param  coordinateData
     *            - the data being stored in the database.
     *  @return  whether, or not, the data was successfully added.
     */
     public   boolean  addCoordinates ( UUID buildingId ,   String  coordinateData )   {
         boolean  added  =   false ;
         Building  building  =  buildingRepo . findOne ( buildingId );
         if   ( building  !=   null )   {
             BuildingCoordinate  coordinates  =   new   BuildingCoordinate ( building ,  coordinateData );
            coordinateRepo . save ( coordinates );
            added  =   true ;
         }
         return  added ;
     }
     /**
     * Updates the coordinate data for the building with the corresponding building
     * id.
     * 
     *  @param  buildingId
     *            - the id of the building the coordinate belongs to.
     *  @param  coordinateData
     *            - the data being stored in the database.
     *  @return  whether, or not, the data was successfully updated.
     */
     public   boolean  updateCoordinates ( UUID buildingId ,   String  coordinateData )   {
         boolean  updated  =   false ;
         Building  building  =  buildingRepo . findOne ( buildingId );
         if   ( building  !=   null )   {
             BuildingCoordinate  coordinates  =  coordinateRepo . findByBuilding ( building );
            coordinates . setCoordinateData ( coordinateData );
            coordinateRepo . save ( coordinates );
            updated  =   true ;
         }
         return  updated ;
     }
     /**
     * Returns the coordinate data for the building with the corresponding building
     * id.
     * 
     *  @param  buildingId
     *            - the id of the building the coordinates are being requested for.
     *  @return  the coordinates for the building.
     */
     public   BuildingCoordinate  getCoordinates ( UUID buildingId )   {
         BuildingCoordinate  coordinates  =   null ;
         Building  building  =  buildingRepo . findOne ( buildingId );
         if   ( building  !=   null )   {
            coordinates  =  coordinateRepo . findByBuilding ( building );
         }
         return  coordinates ;
     }
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/CommentAdapter.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/CommentAdapter.java
package  edu . kings . cs480 . BluePrints . Adapters ;
import  org . springframework . beans . factory . annotation . Autowired ;
import  org . springframework . stereotype . Service ;
import  edu . kings . cs480 . BluePrints . Database . Comment ;
import  edu . kings . cs480 . BluePrints . Database . CommentRepository ;
import  edu . kings . cs480 . BluePrints . Database . Floor ;
import  edu . kings . cs480 . BluePrints . Database . FloorRepository ;
import  edu . kings . cs480 . BluePrints . Database . AppUser ;
import  edu . kings . cs480 . BluePrints . Database . AppUserRepository ;
import  java . util . UUID ;
import  java . util . List ;
/**
 * This adapter is responsible for handling data involving comment.
 * 
 */
@ Service
public   class   CommentAdapter   {
     /** Handles calls to the Floor table in the database. */
    @ Autowired
     public   FloorRepository  floorRepo ;
     /** Handles calls to the App User table in the database. */
    @ Autowired
     public   AppUserRepository  userRepo ;
     /** Handles calls to the floor comment table in the database. */
    @ Autowired
     public   CommentRepository  commentRepo ;
     /**
     * This method adds a comment to the floor.
     * 
     *  @param  floorId
     *            - the id of the floor that comment is being added to.
     *  @param  creatorId
     *            - the id of the creator of this comment.
     *  @param  commentMsg
     *            - the comment being added to the floor.
     * 
     */
     public   boolean  addComment ( UUID floorId ,  UUID creatorId ,   String  commentMsg )   {
         boolean  added  =   false ;
         AppUser  user  =  userRepo . getOne ( creatorId );
         Floor  floor  =  floorRepo . getOne ( floorId );
         if   ( floor  !=   null   &&  user  !=   null )   {
             Comment  newComment  =   new   Comment ( floor ,  user ,  commentMsg );
            commentRepo . save ( newComment );
            added  =   true ;
         }
         return  added ;
     }
     /**
     * This method updates a comment with the new message provided.
     * 
     *  @param  commentId
     *            - the id of the comment being updated.
     *  @param  editorId
     *            - the id of the user updating this comment.
     *  @param  newMsg
     *            - the content of the new message for the comment.
     */
     public   boolean  updateComment ( UUID commentId ,  UUID editorId ,   String  newMsg )   {
         boolean  updated  =   false ;
         AppUser  user  =  userRepo . findOne ( editorId );
         Comment  comment  =  commentRepo . findOne ( commentId );
         if   ( comment  !=   null   &&  user  !=   null )   {
            comment . setCreator ( user );
            comment . setMessage ( newMsg );
            commentRepo . save ( comment );
            updated  =   true ;
         }
         return  updated ;
     }
     /**
     * This method returns the comments which corresponds to the floor id provided.
     * 
     *  @param  floorId
     *            - the id of the floor the comment belong to.
     *  @return  the comment for corresponding floor id.
     */
     public   List < Comment >  getFloorComments ( UUID floorId )   {
         List < Comment >  floorComment  =   null ;
        floorComment  =  commentRepo . findByFloorIdOrderByCreatedDateAsc ( floorId );
         return  floorComment ;
     }
     public   void  clearFloorComments ( UUID floorId )   {
        commentRepo . delete ( this . getFloorComments ( floorId ));
     }
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/FloorAdapter.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/FloorAdapter.java
package  edu . kings . cs480 . BluePrints . Adapters ;
import  org . springframework . beans . factory . annotation . Autowired ;
import  org . springframework . stereotype . Service ;
import  java . util . UUID ;
import  java . util . List ;
import  java . util . Map ;
import  java . util . HashMap ;
import  java . util . LinkedList ;
import  edu . kings . cs480 . BluePrints . Database . FloorRepository ;
import  edu . kings . cs480 . BluePrints . Database . Floor ;
import  edu . kings . cs480 . BluePrints . Database . Building ;
import  edu . kings . cs480 . BluePrints . Database . BuildingRepository ;
/**
 * This adapter is responsible for handling data involing 
 * floors. 
 */
@ Service
public   class   FloorAdapter    {
     /** Used to handle calls to the database. */
    @ Autowired
     private   FloorRepository  floorRepo ;
    
     /** Used to query data from the buildings table in the database. */
    @ Autowired
     private   BuildingRepository  buildingRepo ;
     /**
     * This method takes a building id, and the name of a floor,
     * then adds it to the system. 
     * 
     *  @param  buildingId - the id of the building the floor is being added to.
     *  @param  floorName - the name of the floor being added to the building.
     * 
     */
     public   Floor  addFloor ( UUID buildingId ,   String  floorName )   {
         Floor  newFloor  =   null ;
         Building  building  =  buildingRepo . getOne ( buildingId );
         if ( building  !=   null )   {
            
            newFloor  =   new   Floor ( building ,  floorName );
            floorRepo . save ( newFloor );
         }
         return  newFloor ;
     }
    
    
   
     public   boolean  deleteFloor ( UUID floorId )   {
        
         boolean  deleted  =   false ;
        
        
         Floor  floor  =  floorRepo . findOne ( floorId );
        
         if ( floor  !=   null )   {
            
            floorRepo . delete ( floor );
            deleted  =   true ;
         }
        
         return  deleted ;
  
     }
    
     public   boolean  deleteFloorsInBuilding ( Building  building )   {
        
         boolean  deleted  =   false ;
     
        
         List < Floor >  floors  =  floorRepo . findByBuilding ( building );
        
         if ( floors  !=   null )   {
             for ( Floor  floor  :  floors )   {
                deleteFloor ( floor . getId ());
             }
            
            deleted  =   true ;
         }
        
         return  deleted ;
        
     }
    
    
     /**
     * Returns all the floors.
     * 
     */
     public   Map < String ,   List < Floor >>  getFloors ()   {
         HashMap < String ,   List < Floor >>  buildingFloors  =   new   HashMap <> ();
         List < Floor >  floors  =  floorRepo . findAll ();
         for ( Floor  floor  :  floors )   {
             Building  building  =  floor . getBuilding ();
             String  buildingId  =  building . getId (). toString ();
             if ( buildingFloors . containsKey ( buildingId ))   {
                buildingFloors . get ( buildingId ). add ( floor );
                 System . out . println ( String . format ( "added Floor %s to list." ,  floor . getName ()));
             }   else   {
                 LinkedList < Floor >  newFloorList  =   new   LinkedList <> ();
                newFloorList . add ( floor );
                buildingFloors . put ( buildingId ,  newFloorList );
                 System . out . println ( String . format ( "Created a new list for Building %s, and added Floor %s." ,  building . getName (),  floor . getName ()));
             }
         }
         return  buildingFloors ;
     }
     /**
     * This method returns the floor which corresponds 
     * to the id provided.
     * 
     *  @param  floorId - the id of the floor being requested.
     *  @return  the floor corresponding to the id provided.
     */
     public   Floor  getFloor ( UUID floorId )   {
         Floor  floor  =   null ;
        floor  =  floorRepo . getOne ( floorId );
         return  floor ;
     }
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/LoggingAdapter.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/LoggingAdapter.java
package  edu . kings . cs480 . BluePrints . Adapters ;