i have java project, and i will send the details
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/<project>=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
;
import
java
.
util
.
logging
.
Level
;
import
org
.
apache
.
logging
.
log4j
.
LogManager
;
import
org
.
apache
.
logging
.
log4j
.
Logger
;
import
org
.
springframework
.
stereotype
.
Service
;
@
Service
public
class
LoggingAdapter
{
private
final
static
Logger
LOGGER
=
LogManager
.
getLogger
();
public
void
log
(
Level
level
,
String
message
)
{
if
(
level
==
Level
.
INFO
)
{
LOGGER
.
info
(
message
);
}
else
if
(
level
==
Level
.
WARNING
)
{
LOGGER
.
warn
(
message
);
}
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/LoginAdapter.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/LoginAdapter.java
/**
*
*/
package
edu
.
kings
.
cs480
.
BluePrints
.
Adapters
;
import
java
.
security
.
NoSuchAlgorithmException
;
import
java
.
security
.
spec
.
InvalidKeySpecException
;
import
javax
.
naming
.
NamingException
;
import
javax
.
servlet
.
http
.
HttpSession
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
stereotype
.
Service
;
import
org
.
springframework
.
ui
.
Model
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
AppUser
;
/**
* This class represents a wrapper for an active directory connection, which
* provides information about employees and students of King's College.
*/
@
Service
public
class
LoginAdapter
{
// /** Used to log any errors that may error while using the active directory adapter. */
// @Autowired
// private LoggingAdapter loggingAdapter;
@
Autowired
private
UserAdapter
userAdapter
;
/**
* Returns whether, or not, there is a user currently logged into the
* BluePrints system.
*
*
@param
model
* - the model used to store attributes that can be used in the
* page currently being viewed by the user.
*
@param
session
* - the session which keeps track of the currently active user.
*
@return
whether, or not, there is a user currently logged in.
*/
public
boolean
checkLogin
(
Model
model
,
HttpSession
session
)
{
boolean
loggedIn
=
false
;
Object
user
=
session
.
getAttribute
(
"activeUser"
);
if
(
user
!=
null
)
{
AppUser
activeUser
=
(
AppUser
)
user
;
loggedIn
=
true
;
model
.
addAttribute
(
"activeUser"
,
activeUser
);
}
return
loggedIn
;
}
/**
* This helper method tries to log in with the provided password and user
* name and returns whether, or not, it was successful.
*
*
@param
email
* - the email of the user trying to log in.
*
@param
password
* - the password of the user trying to log in.
*
@param
session
* - the session which keeps track of the currently active user.
*
@return
whether, or not, the user was able to login.
*
@throws
NamingException
*/
public
boolean
login
(
String
email
,
String
password
,
HttpSession
session
)
{
boolean
loggedIn
=
false
;
AppUser
user
=
userAdapter
.
getUserByEmail
(
email
);
if
(
user
!=
null
)
{
String
stored
=
user
.
getPassword
();
try
{
if
(
SecurityAdapter
.
check
(
password
,
stored
))
{
loggedIn
=
true
;
session
.
setAttribute
(
"activeUser"
,
user
);
}
}
catch
(
InvalidKeySpecException
|
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
}
return
loggedIn
;
}
/**
* Returns the active user in the provided session, if any.
*
*
@param
session - the session containing the active user.
*
@return
the active user in the provided session, if any.
*/
public
AppUser
getActiveUser
(
HttpSession
session
)
{
AppUser
activeUser
=
null
;
Object
user
=
session
.
getAttribute
(
"activeUser"
);
if
(
user
!=
null
)
{
activeUser
=
(
AppUser
)
user
;
}
return
activeUser
;
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/Mock/MockStaffAdapter.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/Mock/MockStaffAdapter.java
package
edu
.
kings
.
cs480
.
BluePrints
.
Adapters
.
Mock
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
List
;
import
java
.
util
.
UUID
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Adapters
.
StaffAdapter
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
Staff
;
public
class
MockStaffAdapter
implements
StaffAdapter
<
UUID
>
{
private
HashMap
<
UUID
,
Staff
<
UUID
>>
mockStaff
;
public
MockStaffAdapter
(){
mockStaff
=
new
HashMap
<>
();
mockStaff
.
put
(
UUID
.
fromString
(
"8761c1d6-df23-494c-a62e-5dd25bd7ee1a"
),
new
MockStaff
(
"Bob"
,
UUID
.
fromString
(
"8761c1d6-df23-494c-a62e-5dd25bd7ee1a"
),
"[email protected]"
));
mockStaff
.
put
(
UUID
.
fromString
(
"585b434e-4173-43d0-ae56-7d7b219f035f"
),
new
MockStaff
(
"Steven"
,
UUID
.
fromString
(
"585b434e-4173-43d0-ae56-7d7b219f035f"
),
"[email protected]"
));
mockStaff
.
put
(
UUID
.
fromString
(
"2168ac0b-9da7-43e7-9b96-829f54cd87e1"
),
new
MockStaff
(
"Richard"
,
UUID
.
fromString
(
"2168ac0b-9da7-43e7-9b96-829f54cd87e1"
),
"[email protected]"
));
mockStaff
.
put
(
UUID
.
fromString
(
"e15efdfe-bc09-40dc-9ea0-9fdad9b718b4"
),
new
MockStaff
(
"Chadd"
,
UUID
.
fromString
(
"e15efdfe-bc09-40dc-9ea0-9fdad9b718b4"
),
"[email protected]"
));
}
@
Override
public
Staff
<
UUID
>
getStaff
(
UUID staffId
)
{
return
mockStaff
.
get
(
staffId
);
}
@
Override
public
void
deleteStaff
(
UUID staffId
)
{
throw
new
UnsupportedOperationException
(
"Not needed for test"
);
}
@
Override
public
List
<
Staff
<
UUID
>>
getAllStaff
()
{
return
new
ArrayList
<>
(
mockStaff
.
values
());
}
@
Override
public
void
updateStaff
(
UUID staffId
,
String
name
,
String
email
)
{
throw
new
UnsupportedOperationException
(
"Not needed for test"
);
}
private
class
MockStaff
implements
Staff
<
UUID
>
{
private
String
name
;
private
UUID staffId
;
private
String
email
;
public
MockStaff
(
String
name
,
UUID staffId
,
String
email
)
{
this
.
name
=
name
;
this
.
staffId
=
staffId
;
this
.
email
=
email
;
}
@
Override
public
String
getName
()
{
return
name
;
}
@
Override
public
UUID getStaffId
()
{
return
staffId
;
}
@
Override
public
String
getStaffEmail
()
{
return
email
;
}
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/RoomAdapter.java
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/RoomAdapter.java
package
edu
.
kings
.
cs480
.
BluePrints
.
Adapters
;
import
java
.
util
.
LinkedList
;
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
.
Floor
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
Room
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
RoomCoordinateRepository
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
RoomCoordinates
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
RoomRepository
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
StaffAssignment
;
import
edu
.
kings
.
cs480
.
BluePrints
.
Database
.
StaffAssignmentRepository
;
@
Service
public
class
RoomAdapter
{
@
Autowired
private
RoomRepository
roomRepo
;
@
Autowired
private
RoomCoordinateRepository
roomCoordinateRepo
;
@
Autowired
private
FloorAdapter
floorAdapter
;
@
Autowired
private
StaffAssignmentRepository
staffRepo
;
public
Room
getRoom
(
UUID roomId
)
{
Room
room
=
roomRepo
.
findOne
(
roomId
);
return
room
;
}
public
List
<
Room
>
getAllRooms
(
UUID floorId
)
{
List
<
Room
>
rooms
=
null
;
Floor
floor
=
floorAdapter
.
getFloor
(
floorId
);
if
(
floor
!=
null
)
{
rooms
=
roomRepo
.
findByFloor
(
floor
);
}
return
rooms
;
}
public
Room
addRoom
(
String
roomName
,
UUID floorId
)
{
Room
room
=
null
;
Floor
floor
=
floorAdapter
.
getFloor
(
floorId
);
if
(
floor
!=
null
)
{
room
=
new
Room
(
roomName
,
floor
);
roomRepo
.
save
(
room
);
}
return
room
;
}
public
boolean
updateRoom
(
UUID roomId
,
String
newRoomName
)
{
boolean
updated
=
false
;
Room
room
=
roomRepo
.
findOne
(
roomId
);
if
(
room
!=
null
)
{
room
.
setName
(
newRoomName
);
roomRepo
.
save
(
room
);
updated
=
true
;
}
return
updated
;
}
public
boolean
deleteRoom
(
UUID roomId
)
{
boolean
deleted
=
false
;
Room
room
=
roomRepo
.
findOne
(
roomId
);
if
(
room
!=
null
)
{
unassignAllStaff
(
roomId
);
roomCoordinateRepo
.
delete
(
roomId
);
roomRepo
.
delete
(
room
);
deleted
=
true
;
}
return
deleted
;
}
public
boolean
addRoomCoordinates
(
UUID roomId
,
String
roomCoordinateData
)
{
boolean
added
=
false
;
if
(
roomRepo
.
exists
(
roomId
))
{
RoomCoordinates
roomCoordinates
=
new
RoomCoordinates
(
roomId
,
roomCoordinateData
);
roomCoordinateRepo
.
save
(
roomCoordinates
);
added
=
true
;
}
return
added
;
}
public
boolean
deleteRoomCoordinates
(
UUID roomId
)
{
boolean
deleted
=
false
;
RoomCoordinates
coordinates
=
roomCoordinateRepo
.
findOne
(
roomId
);
if
(
coordinates
!=
null
)
{
roomCoordinateRepo
.
delete
(
coordinates
);
deleted
=
false
;
}
return
deleted
;
}
public
boolean
updateRoomCoordinates
(
UUID roomId
,
String
newRoomCoordinateData
)
{
boolean
updated
=
false
;
RoomCoordinates
coordinates
=
roomCoordinateRepo
.
findOne
(
roomId
);
if
(
coordinates
!=
null
)
{
coordinates
.
setCoordinateData
(
newRoomCoordinateData
);
roomCoordinateRepo
.
save
(
coordinates
);
updated
=
true
;
}
return
updated
;
}
public
List
<
RoomCoordinates
>
getAllRoomCoordinates
(
UUID floorId
)
{
List
<
RoomCoordinates
>
roomCoordinates
=
null
;
Floor
floor
=
floorAdapter
.
getFloor
(
floorId
);
if
(
floor
!=
null
)
{
List
<
Room
>
rooms
=
roomRepo
.
findByFloor
(
floor
);
if
(
rooms
!=
null
)
{
roomCoordinates
=
new
LinkedList
<>
();
for
(
Room
room
:
rooms
)
{
RoomCoordinates
coordinates
=
roomCoordinateRepo
.
findOne
(
room
.
getId
());
roomCoordinates
.
add
(
coordinates
);
}
}
}
return
roomCoordinates
;
}
public
RoomCoordinates
getRoomCoordinates
(
UUID roomId
)
{
RoomCoordinates
coordinates
=
roomCoordinateRepo
.
findOne
(
roomId
);
return
coordinates
;
}
public
boolean
clearAllFloorRooms
(
UUID floorId
)
{
boolean
deleted
=
false
;
Floor
floor
=
floorAdapter
.
getFloor
(
floorId
);
if
(
floor
!=
null
)
{
List
<
Room
>
rooms
=
roomRepo
.
findByFloor
(
floor
);
for
(
Room
room
:
rooms
)
{
deleteRoom
(
room
.
getId
());
}
deleted
=
true
;
}
return
deleted
;
}
public
List
<
StaffAssignment
>
getRoomAssignments
(
UUID roomId
){
List
<
StaffAssignment
>
result
=
null
;;
Room
room
=
roomRepo
.
findOne
(
roomId
);
if
(
room
!=
null
)
{
result
=
staffRepo
.
findByRoom
(
room
);
}
return
result
;
}
public
boolean
assignStaffToRooms
(
UUID roomId
,
UUID
[]
staffIds
)
{
boolean
assigned
=
false
;
Room
room
=
roomRepo
.
findOne
(
roomId
);
if
(
room
!=
null
)
{
for
(
UUID staffId
:
staffIds
)
{
StaffAssignment
assignment
=
new
StaffAssignment
(
room
,
staffId
);
staffRepo
.
save
(
assignment
);