SlideShare a Scribd company logo
1 of 53
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.springbootbuild
er
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=enable
d
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=warn
ing
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.x
ml
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/ActiveDire
ctory/AuthenticatedUser.javaBluePrints/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.
*/
publicclassAuthenticatedUser{
/** Keeps track of the user's king's id. */
privateString kingsid;
/** Keeps track of the user's first name. */
privateString firstName;
/** Keeps track of the user's last name. */
privateString lastName;
/** Keeps track of the user's email address. */
privateString email;
/**
* Creates a user with the provided information.
*
* @param attr
* -
the set of attributes which contains information about this
* user.
*
*/
protectedAuthenticatedUser(Attributes attr)throwsNamingExcep
tion{
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.
*/
publicString getFirstName(){
return firstName;
}
/**
* Returns the user's last name.
*
* @return the user's last name.
*/
publicString getLastName(){
return lastName;
}
/**
* Returns the user's email.
*
* @return the user's email.
*/
publicString getEmail(){
return email;
}
/**
* Returns the user's king's id.
*
* @return the user's king's id.
*/
publicString getKingsId(){
return kingsid;
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/ActiveDire
ctory/AuthenticationService.javaBluePrints/src/main/java/edu/ki
ngs/cs480/BluePrints/ActiveDirectory/AuthenticationService.ja
vapackage 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 Activ
e Directory server.
*
*/
publicclassAuthenticationService{
// the domain name to authenticate against.
privatestaticString domain ="kings.edu";
/**
* AuthenticationService()
*/
privateAuthenticationService(){
}
/**
* authenticate
*
* Try to authenticate against active directory via ldap and re
turn 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 fa
lse.
* @throws NamingException When communication or authe
ntication fails against the domain controller.
*/
publicstaticLdapContext authenticate(String email,String passw
ord)throwsNamingException{
// Define our properties of LDAP.
Hashtable<String,String> adProps =newHashtable<String,String
>();
adProps.put(Context.SECURITY_PRINCIPAL, email);
adProps.put(Context.SECURITY_CREDENTIALS, passwo
rd);
adProps.put(Context.INITIAL_CONTEXT_FACTORY,"co
m.sun.jndi.ldap.LdapCtxFactory");
adProps.put(Context.PROVIDER_URL,"ldap://"+ domain);
// Try created a connection based on the above properties that w
e defined.
try{
returnnewInitialLdapContext(adProps,null);
}
catch(javax.naming.CommunicationException e){
e.printStackTrace();
thrownewNamingException("Failed to connect to "+ domain);
}
catch(NamingException e){
thrownewNamingException("Failed to authenticate against "+ d
omain);
}
}
/**
* getUser
*
* Returns the user object based on the user from AD, otherw
ise return null.
*
* @param email The email to retrieve.
* @param context The context connection to the AD director
y.
* @return A user if the user exists, otherwise return null.
*/
publicstaticAuthenticatedUser getUser(String email,LdapContex
t context){
try{
String[] requestedAttrs =newString[]{"sn","givenName","Kings
ID","mail","userPrincipalName"};
// Setup a search control.
SearchControls controls =newSearchControls();
// Limit our search, otherwise we will time out traversing the w
hole directory.
controls.setSearchScope(javax.naming.directory.Search
Controls.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 LDA
P.
// TODO: Refactor this.
NamingEnumeration<SearchResult> result = context.search("O
U=User_New,DC=kings,DC=edu","(& (userPrincipalName="+e
mail+")(objectClass=user))", controls);
// Search our attributes until we come across one that matches th
e email we specified.
if(result.hasMore()){
Attributes attr = result.next().getAttributes();
Attribute user = attr.get("userPrincipalName");
if(user!=null)returnnewAuthenticatedUser(attr);
}
}
catch(NamingException e){
// TODO: Handle this gracefully.
//System.out.println(e.toString());
e.printStackTrace();
}
returnnull;
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/
BuildingAdapter.javaBluePrints/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.CoordinateReposito
ry;
/**
* This class is responsible for handling method used in the Map
Manager Page.
*
*/
@Service
publicclassBuildingAdapter{
/** Used to query data from the buildings table in the database.
*/
@Autowired
privateBuildingRepository buildingRepo;
/** Handles calls to the database about the users in the BluePrin
ts System. */
@Autowired
privateAppUserRepository userRepo;
/** Handles calls to the database about the coordinate data for b
uildings. */
@Autowired
privateCoordinateRepository coordinateRepo;
/**
* Returns all the buildings stored in the system.
*
* @return all the buildings stored in the system.
*/
publicList<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.
*/
publicBuilding getBuilding(UUID buildingId){
Building building =null;
building = buildingRepo.findOne(buildingId);
return building;
}
/**
* Updates the building with corresponding id, with the infor
mation 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 upd
ated.
*/
publicboolean updateBuilding(UUID buildingId,String building
Name){
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 rem
oved.
*/
publicboolean 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 i
d.
*
* @param buildingName
* - the name of the building.
* @param creatorId
* - the id of the person creating the building.
* @return the newly added building.
*/
publicBuilding addBuilding(String buildingName, UUID creator
Id){
Building building =null;
AppUser creator = userRepo.findOne(creatorId);
if(creator !=null){
building =newBuilding(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.
*/
publicboolean addCoordinates(UUID buildingId,String coordina
teData){
boolean added =false;
Building building = buildingRepo.findOne(buildingId);
if(building !=null){
BuildingCoordinate coordinates =newBuildingCoordinate(buildi
ng, coordinateData);
coordinateRepo.save(coordinates);
added =true;
}
return added;
}
/**
* Updates the coordinate data for the building with the corre
sponding 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
.
*/
publicboolean updateCoordinates(UUID buildingId,String coord
inateData){
boolean updated =false;
Building building = buildingRepo.findOne(buildingId);
if(building !=null){
BuildingCoordinate coordinates = coordinateRepo.findByBuildi
ng(building);
coordinates.setCoordinateData(coordinateData);
coordinateRepo.save(coordinates);
updated =true;
}
return updated;
}
/**
* Returns the coordinate data for the building with the corre
sponding building
* id.
*
* @param buildingId
* -
the id of the building the coordinates are being requested for.
* @return the coordinates for the building.
*/
publicBuildingCoordinate 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.javaBluePrints/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.CommentRepositor
y;
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 comm
ent.
*
*/
@Service
publicclassCommentAdapter{
/** Handles calls to the Floor table in the database. */
@Autowired
publicFloorRepository floorRepo;
/** Handles calls to the App User table in the database. */
@Autowired
publicAppUserRepository userRepo;
/** Handles calls to the floor comment table in the database. */
@Autowired
publicCommentRepository 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.
*
*/
publicboolean addComment(UUID floorId, UUID creatorId,Stri
ng commentMsg){
boolean added =false;
AppUser user = userRepo.getOne(creatorId);
Floor floor = floorRepo.getOne(floorId);
if(floor !=null&& user !=null){
Comment newComment =newComment(floor, user, commentMs
g);
commentRepo.save(newComment);
added =true;
}
return added;
}
/**
* This method updates a comment with the new message pro
vided.
*
* @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.
*/
publicboolean updateComment(UUID commentId, UUID editorI
d,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 th
e floor id provided.
*
* @param floorId
* - the id of the floor the comment belong to.
* @return the comment for corresponding floor id.
*/
publicList<Comment> getFloorComments(UUID floorId){
List<Comment> floorComment =null;
floorComment = commentRepo.findByFloorIdOrderByCre
atedDateAsc(floorId);
return floorComment;
}
publicvoid clearFloorComments(UUID floorId){
commentRepo.delete(this.getFloorComments(floorId));
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/F
loorAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Blue
Prints/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
publicclassFloorAdapter{
/** Used to handle calls to the database. */
@Autowired
privateFloorRepository floorRepo;
/** Used to query data from the buildings table in the database.
*/
@Autowired
privateBuildingRepository 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.
*
*/
publicFloor addFloor(UUID buildingId,String floorName){
Floor newFloor =null;
Building building = buildingRepo.getOne(buildingId);
if(building !=null){
newFloor =newFloor(building, floorName);
floorRepo.save(newFloor);
}
return newFloor;
}
publicboolean deleteFloor(UUID floorId){
boolean deleted =false;
Floor floor = floorRepo.findOne(floorId);
if(floor !=null){
floorRepo.delete(floor);
deleted =true;
}
return deleted;
}
publicboolean 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.
*
*/
publicMap<String,List<Floor>> getFloors(){
HashMap<String,List<Floor>> buildingFloors =newHashMap<>
();
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 =newLinkedList<>();
newFloorList.add(floor);
buildingFloors.put(buildingId, newFloorList);
System.out.println(String.format("Created a new list for Buildin
g %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.
*/
publicFloor getFloor(UUID floorId){
Floor floor =null;
floor = floorRepo.getOne(floorId);
return floor;
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/L
oggingAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Bl
uePrints/Adapters/LoggingAdapter.javapackage 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
publicclassLoggingAdapter{
privatefinalstaticLogger LOGGER =LogManager.getLogger();
publicvoid log(Level level,String message){
if(level ==Level.INFO){
LOGGER.info(message);
}elseif(level ==Level.WARNING){
LOGGER.warn(message);
}
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/L
oginAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Blue
Prints/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 connec
tion, which
* provides information about employees and students of King's
College.
*/
@Service
publicclassLoginAdapter{
// /** Used to log any errors that may error while using the acti
ve directory adapter. */
// @Autowired
// private LoggingAdapter loggingAdapter;
@Autowired
privateUserAdapter userAdapter;
/**
* Returns whether, or not, there is a user currently logged in
to 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
.
*/
publicboolean 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 passw
ord 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
*/
publicboolean login(String email,String password,HttpSession s
ession){
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.
*/
publicAppUser 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.javaBluePrints/src/main/java/edu/kings
/cs480/BluePrints/Adapters/Mock/MockStaffAdapter.javapackag
e 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;
publicclassMockStaffAdapterimplementsStaffAdapter<UUID>{
privateHashMap<UUID,Staff<UUID>> mockStaff;
publicMockStaffAdapter(){
mockStaff =newHashMap<>();
mockStaff.put(UUID.fromString("8761c1d6-df23-494c-
a62e-
5dd25bd7ee1a"),newMockStaff("Bob", UUID.fromString("8761
c1d6-df23-494c-a62e-5dd25bd7ee1a"),"[email protected]"));
mockStaff.put(UUID.fromString("585b434e-4173-43d0-
ae56-
7d7b219f035f"),newMockStaff("Steven", UUID.fromString("58
5b434e-4173-43d0-ae56-7d7b219f035f"),"[email protected]"));
mockStaff.put(UUID.fromString("2168ac0b-9da7-43e7-
9b96-
829f54cd87e1"),newMockStaff("Richard", UUID.fromString("2
168ac0b-9da7-43e7-9b96-829f54cd87e1"),"[email protected]"));
mockStaff.put(UUID.fromString("e15efdfe-bc09-40dc-
9ea0-
9fdad9b718b4"),newMockStaff("Chadd", UUID.fromString("e1
5efdfe-bc09-40dc-9ea0-9fdad9b718b4"),"[email protected]"));
}
@Override
publicStaff<UUID> getStaff(UUID staffId){
return mockStaff.get(staffId);
}
@Override
publicvoid deleteStaff(UUID staffId){
thrownewUnsupportedOperationException("Not needed for test"
);
}
@Override
publicList<Staff<UUID>> getAllStaff(){
returnnewArrayList<>(mockStaff.values());
}
@Override
publicvoid updateStaff(UUID staffId,String name,String email){
thrownewUnsupportedOperationException("Not needed for test"
);
}
privateclassMockStaffimplementsStaff<UUID>{
privateString name;
private UUID staffId;
privateString email;
publicMockStaff(String name, UUID staffId,String email){
this.name = name;
this.staffId = staffId;
this.email = email;
}
@Override
publicString getName(){
return name;
}
@Override
public UUID getStaffId(){
return staffId;
}
@Override
publicString getStaffEmail(){
return email;
}
}
}
BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/
RoomAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Blu
ePrints/Adapters/RoomAdapter.javapackage edu.kings.cs480.Bl
uePrints.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.RoomCoordinateRe
pository;
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.StaffAssignmentRe
pository;
@Service
publicclassRoomAdapter{
@Autowired
privateRoomRepository roomRepo;
@Autowired
privateRoomCoordinateRepository roomCoordinateRepo;
@Autowired
privateFloorAdapter floorAdapter;
@Autowired
privateStaffAssignmentRepository staffRepo;
publicRoom getRoom(UUID roomId){
Room room = roomRepo.findOne(roomId);
return room;
}
publicList<Room> getAllRooms(UUID floorId){
List<Room> rooms =null;
Floor floor = floorAdapter.getFloor(floorId);
if(floor !=null){
rooms = roomRepo.findByFloor(floor);
}
return rooms;
}
publicRoom addRoom(String roomName, UUID floorId){
Room room =null;
Floor floor = floorAdapter.getFloor(floorId);
if(floor !=null){
room =newRoom(roomName, floor);
roomRepo.save(room);
}
return room;
}
publicboolean updateRoom(UUID roomId,String newRoomNam
e){
boolean updated =false;
Room room = roomRepo.findOne(roomId);
if(room !=null){
room.setName(newRoomName);
roomRepo.save(room);
updated =true;
}
return updated;
}
publicboolean 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;
}
publicboolean addRoomCoordinates(UUID roomId,String room
CoordinateData){
boolean added =false;
if(roomRepo.exists(roomId)){
RoomCoordinates roomCoordinates =newRoomCoordinates(roo
mId, roomCoordinateData);
roomCoordinateRepo.save(roomCoordinates);
added =true;
}
return added;
}
publicboolean deleteRoomCoordinates(UUID roomId){
boolean deleted =false;
RoomCoordinates coordinates = roomCoordinateRepo.findOne(r
oomId);
if(coordinates !=null){
roomCoordinateRepo.delete(coordinates);
deleted =false;
}
return deleted;
}
publicboolean updateRoomCoordinates(UUID roomId,String ne
wRoomCoordinateData){
boolean updated =false;
RoomCoordinates coordinates = roomCoordinateRepo.findOne(r
oomId);
if(coordinates !=null){
coordinates.setCoordinateData(newRoomCoordinateDat
a);
roomCoordinateRepo.save(coordinates);
updated =true;
}
return updated;
}
publicList<RoomCoordinates> getAllRoomCoordinates(UUID fl
oorId){
List<RoomCoordinates> roomCoordinates =null;
Floor floor = floorAdapter.getFloor(floorId);
if(floor !=null){
List<Room> rooms = roomRepo.findByFloor(floor);
if(rooms !=null){
roomCoordinates =newLinkedList<>();
for(Room room : rooms){
RoomCoordinates coordinates = roomCoordinateRepo.findOne(r
oom.getId());
roomCoordinates.add(coordinates);
}
}
}
return roomCoordinates;
}
publicRoomCoordinates getRoomCoordinates(UUID roomId){
RoomCoordinates coordinates = roomCoordinateRepo.findOne(r
oomId);
return coordinates;
}
publicboolean 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;
}
publicList<StaffAssignment> getRoomAssignments(UUID room
Id){
List<StaffAssignment> result =null;;
Room room = roomRepo.findOne(roomId);
if(room !=null){
result = staffRepo.findByRoom(room);
}
return result;
}
publicboolean assignStaffToRooms(UUID roomId, UUID[] staff
Ids){
boolean assigned =false;
Room room = roomRepo.findOne(roomId);
if(room !=null){
for(UUID staffId : staffIds){
StaffAssignment assignment =newStaffAssignment(room, staffI
d);
staffRepo.save(assignment);
CS 300 Final Project/Exam
You’ve been presented with a copy of BluePrints, the 2017-
2018 CS480/481 project. This project
is a web site designed to allow easy editing of building, floor,
and room data for the MonarchMaps
project (’16-’17). This project has a number of dependencies,
and zero unit tests. It relies fairly heavily
on Spring and Spring MVC to manage *many* of those
dependencies so you are in reasonably good
shape compared to other legacy projects. This represents a
fairly realistic request in business and the
time frame (2 weeks) is likely a much larger timeframe than you
would normally have OR the
application’s scope would be much larger.
I have updated this project to no longer depend on a remote
Postgres SQL database, but instead
use Spring’s built-in, in-memory database H2. This means you
do not have to connect to or worry about
conflicts with a database, however, nothing is actually persisted
between sessions. When you run this
project (using Eclipse’s “Run on Server” feature), you’ll be able
to point your browser at
http://localhost:8080/BluePrints to investigate the live app. I’ll
be pushing a .sql file into your repository
within a few days to auto-seed the H2 database with some test
data and will supply you a dummy
login/password at that point. In the meantime, you can still get
familiar with the code!
Your task is to add the following feature/change, leveraging the
techniques you’ve learned
throughout this course and make sure you are creating proper
unit tests for the feature and any code
you must modify. Some areas of the code may not work
properly, and you’ll need to investigate/fix
those areas using characterization tests to explore. I am not
mandating a specific number of tests, but
you should adequately ensure you are testing what you’re
changing.
We no longer want to “hard delete” any comment from the
system. Comments are
attached to floors. Instead “soft delete” them by setting a
deleted flag on the
comment. Soft-deleted comments should not normally be
accessible under normal
operations but should still be stored in the table. We want to
capture the date/time
the comment was deleted, and the user who did the deletion.
There are several things to consider, here. The project is using
Jpa, which you can read more
about at https://spring.io/guides/gs/accessing-data-jpa/. Pay
particular attention to how the
@Repository annotation works, especially in creating “find”
methods… Here are a few suggestions to
get you started:
• Do some quick sketching/outlining to see how the classes
interact
• Refactor the classes and interfaces in the
edu.kings.cs480.BluePrints.Database
package to split the “Model” classes from the @Repository
interfaces to simplify the scope of
what you’re working on
• Start by getting the field on each object to work, then look to
override the delete behavior, and
finally the find behavior
http://localhost:8080/BluePrints
http://localhost:8080/BluePrints
https://spring.io/guides/gs/accessing-data-jpa/
https://spring.io/guides/gs/accessing-data-jpa/
• You may or may not have to create concrete implementations
of the @Repository interfaces
depending on your approach
• Follow the existing application conventions for how “users”
are stored my mimicking how the
“creator”/created_by fields work
• Be *cautious* when a floor is deleted – currently, a deleted
floor hard-deletes all of its
comments; this behavior must also change
o Pay attention to the relationship between Floor and Comment;
and note how a
Comment ignores if the comment creator cannot be found in the
AppUsers data… <that
is a hint>
Your work is your own. Please do not share code as that will
fall under the college’s academic
dishonesty and plagiarism guidelines.
I pushed a few changes to everyone's repos for the final project.
Changes include:
* SQL script to automatically seed test data
* Fixed a number of issues with unavailable/out of date
dependencies
* I adjusted the LoginAdapter so you can login with any
password and the username of 'admin'; the passwords in the
database are one-way encrypted and there was no
documentation... :-(
Please make sure to *PULL* before you continue working. If
you run into any issues, please let me know.
I've created a private copy repo for each of you based on the
"BluePrints" project that was a CS480 final project last year.
This is an Eclipse project, targeting Tomcat 8.5, Java 1.8, and
JUnit 4, which is as close as I can reasonably get to the lab
computers in Admin 425.
If you want to run at home, get Eclipse for JEE (exact version
I'm
using: https://www.eclipse.org/downloads/download.php?file=/t
echnology/epp/downloads/release/2018-12/R/eclipse-jee-2018-
12-R-win32-x86_64.zip&mirror_id=1249), Tomcat 8.5
(http://mirror.olnevhost.net/pub/apache/tomcat/tomcat-
8/v8.5.40/bin/apache-tomcat-8.5.40-windows-x64.zip), and Java
EE JDK 8 (1.8)
(https://www.oracle.com/technetwork/java/javaee/downloads/ja
va-ee-sdk-downloads-3908423.html). I created a folder at
C:Java and unzipped/installed all to there. (If you're using a
Mac, you'll need to download alternate links, of course!)
In Eclipse, go to Window -> Preferences, Servers +-> Runtime
Environments, and click Add. Choose Tomcat 8.5, then pick the
directory you unzipped from.
From there, File -> Import..., Choose "Git" +-> "Projects from
Git", "Clone from URI", and clone from GitHub as usual. On
the new project wizard, it should detect the Eclipse project and
get things going pretty smoothly from there. It should build
after a few moments, and allow you to choose "Run", and then
set up a new Apache Tomcat run configuration. If you browse
out to http://localhost:8080/BluePrints , you should receive a
login window (note: nothing works from here).
For now, focus on exploring the code a bit, and make sure it
builds. I'll have the actual final assignment published in Moodle
in the next couple of days.
CS 300 Final Project/Exam
You’ve been presented with a copy of BluePrints, the 2017-
2018 CS480/481 project. This project
is a web site designed to allow easy editing of building, floor,
and room data for the MonarchMaps
project (’16-’17). This project has a number of dependencies,
and zero unit tests. It relies fairly heavily
on Spring and Spring MVC to manage *many* of those
dependencies so you are in reasonably good
shape compared to other legacy projects. This represents a
fairly realistic request in business and the
time frame (2 weeks) is likely a much larger timeframe than you
would normally have OR the
application’s scope would be much larger.
I have updated this project to no longer depend on a remote
Postgres SQL database, but instead
use Spring’s built-in, in-memory database H2. This means you
do not have to connect to or worry about
conflicts with a database, however, nothing is actually persisted
between sessions. When you run this
project (using Eclipse’s “Run on Server” feature), you’ll be able
to point your browser at
http://localhost:8080/BluePrints to investigate the live app. I’ll
be pushing a .sql file into your repository
within a few days to auto-seed the H2 database with some test
data and will supply you a dummy
login/password at that point. In the meantime, you can still get
familiar with the code!
Your task is to add the following feature/change, leveraging the
techniques you’ve learned
throughout this course and make sure you are creating proper
unit tests for the feature and any code
you must modify. Some areas of the code may not work
properly, and you’ll need to investigate/fix
those areas using characterization tests to explore. I am not
mandating a specific number of tests, but
you should adequately ensure you are testing what you’re
changing.
We no longer want to “hard delete” any comment from the
system. Comments are
attached to floors. Instead “soft delete” them by setting a
deleted flag on the
comment. Soft-deleted comments should not normally be
accessible under normal
operations but should still be stored in the table. We want to
capture the date/time
the comment was deleted, and the user who did the deletion.
There are several things to consider, here. The project is using
Jpa, which you can read more
about at https://spring.io/guides/gs/accessing-data-jpa/. Pay
particular attention to how the
@Repository annotation works, especially in creating “find”
methods… Here are a few suggestions to
get you started:
• Do some quick sketching/outlining to see how the classes
interact
• Refactor the classes and interfaces in the
edu.kings.cs480.BluePrints.Database
package to split the “Model” classes from the @Repository
interfaces to simplify the scope of
what you’re working on
• Start by getting the field on each object to work, then look to
override the delete behavior, and
finally the find behavior
http://localhost:8080/BluePrints
http://localhost:8080/BluePrints
https://spring.io/guides/gs/accessing-data-jpa/
https://spring.io/guides/gs/accessing-data-jpa/
• You may or may not have to create concrete implementations
of the @Repository interfaces
depending on your approach
• Follow the existing application conventions for how “users”
are stored my mimicking how the
“creator”/created_by fields work
• Be *cautious* when a floor is deleted – currently, a deleted
floor hard-deletes all of its
comments; this behavior must also change
o Pay attention to the relationship between Floor and Comment;
and note how a
Comment ignores if the comment creator cannot be found in the
AppUsers data… <that
is a hint>
Your work is your own. Please do not share code as that will
fall under the college’s academic
dishonesty and plagiarism guidelines.
BluePrints.classpathBluePrints.gitignoretargetl.docx

More Related Content

Similar to BluePrints.classpathBluePrints.gitignoretargetl.docx

Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 

Similar to BluePrints.classpathBluePrints.gitignoretargetl.docx (20)

Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
Struts database access
Struts database accessStruts database access
Struts database access
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Spine.js
Spine.jsSpine.js
Spine.js
 
Backbone to React. What it says about awesome UI Code.
Backbone to React. What it says about awesome UI Code.Backbone to React. What it says about awesome UI Code.
Backbone to React. What it says about awesome UI Code.
 
Painless Javascript Unit Testing
Painless Javascript Unit TestingPainless Javascript Unit Testing
Painless Javascript Unit Testing
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Browser testing with nightwatch.js - Drupal Europe
Browser testing with nightwatch.js - Drupal EuropeBrowser testing with nightwatch.js - Drupal Europe
Browser testing with nightwatch.js - Drupal Europe
 
Django
DjangoDjango
Django
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 

More from moirarandell

BOOK REVIEWS How to write a book review There are two .docx
BOOK REVIEWS How to write a book review  There are two .docxBOOK REVIEWS How to write a book review  There are two .docx
BOOK REVIEWS How to write a book review There are two .docx
moirarandell
 
Book required Current Issues and Enduring Questions, by Sylvan Ba.docx
Book required Current Issues and Enduring Questions, by Sylvan Ba.docxBook required Current Issues and Enduring Questions, by Sylvan Ba.docx
Book required Current Issues and Enduring Questions, by Sylvan Ba.docx
moirarandell
 
Book ListBecker, Ernest The Denial of D.docx
Book ListBecker, Ernest                          The Denial of D.docxBook ListBecker, Ernest                          The Denial of D.docx
Book ListBecker, Ernest The Denial of D.docx
moirarandell
 
BOOK 1984 MiniProject What makes a human beingOne .docx
BOOK 1984 MiniProject What makes a human beingOne .docxBOOK 1984 MiniProject What makes a human beingOne .docx
BOOK 1984 MiniProject What makes a human beingOne .docx
moirarandell
 
Bonnie Morgen First Day on the Job and Facing an Ethical Di.docx
Bonnie Morgen First Day on the Job and Facing an Ethical Di.docxBonnie Morgen First Day on the Job and Facing an Ethical Di.docx
Bonnie Morgen First Day on the Job and Facing an Ethical Di.docx
moirarandell
 
Boley A Negro Town in the American West (1908) The commu.docx
Boley A Negro Town in the American West (1908)  The commu.docxBoley A Negro Town in the American West (1908)  The commu.docx
Boley A Negro Town in the American West (1908) The commu.docx
moirarandell
 
Bolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docx
Bolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docxBolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docx
Bolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docx
moirarandell
 
BoF Professional Member Exclusive articles & analysis availa.docx
BoF Professional  Member Exclusive articles & analysis availa.docxBoF Professional  Member Exclusive articles & analysis availa.docx
BoF Professional Member Exclusive articles & analysis availa.docx
moirarandell
 

More from moirarandell (20)

BOOK REVIEWS How to write a book review There are two .docx
BOOK REVIEWS How to write a book review  There are two .docxBOOK REVIEWS How to write a book review  There are two .docx
BOOK REVIEWS How to write a book review There are two .docx
 
Book Review #3- The Spirit Catches You and You Fall Down”Ch.docx
Book Review #3- The Spirit Catches You and You Fall Down”Ch.docxBook Review #3- The Spirit Catches You and You Fall Down”Ch.docx
Book Review #3- The Spirit Catches You and You Fall Down”Ch.docx
 
Book required Current Issues and Enduring Questions, by Sylvan Ba.docx
Book required Current Issues and Enduring Questions, by Sylvan Ba.docxBook required Current Issues and Enduring Questions, by Sylvan Ba.docx
Book required Current Issues and Enduring Questions, by Sylvan Ba.docx
 
Book Review #1- The Spirit Catches You and You Fall Down”Chapte.docx
Book Review #1- The Spirit Catches You and You Fall Down”Chapte.docxBook Review #1- The Spirit Catches You and You Fall Down”Chapte.docx
Book Review #1- The Spirit Catches You and You Fall Down”Chapte.docx
 
Book reportGringo viejo- Carlos FuentesThe written book repo.docx
Book reportGringo viejo- Carlos FuentesThe written book repo.docxBook reportGringo viejo- Carlos FuentesThe written book repo.docx
Book reportGringo viejo- Carlos FuentesThe written book repo.docx
 
Book reference Kouzes, James M. and Posner, Barry Z. The Leadership.docx
Book reference Kouzes, James M. and Posner, Barry Z. The Leadership.docxBook reference Kouzes, James M. and Posner, Barry Z. The Leadership.docx
Book reference Kouzes, James M. and Posner, Barry Z. The Leadership.docx
 
BOOK PICTURE I POSTED TOO. Go to the the textbook, study chapt.docx
BOOK PICTURE I POSTED TOO. Go to the the textbook, study chapt.docxBOOK PICTURE I POSTED TOO. Go to the the textbook, study chapt.docx
BOOK PICTURE I POSTED TOO. Go to the the textbook, study chapt.docx
 
Book ListBecker, Ernest The Denial of D.docx
Book ListBecker, Ernest                          The Denial of D.docxBook ListBecker, Ernest                          The Denial of D.docx
Book ListBecker, Ernest The Denial of D.docx
 
Book list below.docx
Book list below.docxBook list below.docx
Book list below.docx
 
Book is Media Literacy. Eighth EditionW.JamesPotte.docx
Book is Media Literacy. Eighth EditionW.JamesPotte.docxBook is Media Literacy. Eighth EditionW.JamesPotte.docx
Book is Media Literacy. Eighth EditionW.JamesPotte.docx
 
Book Forensic and Investigative AccountingPlease answer t.docx
Book Forensic and Investigative AccountingPlease answer t.docxBook Forensic and Investigative AccountingPlease answer t.docx
Book Forensic and Investigative AccountingPlease answer t.docx
 
Book Criminoloy Second EditionRead Chapter 6. Please submit .docx
Book Criminoloy Second EditionRead Chapter 6. Please submit .docxBook Criminoloy Second EditionRead Chapter 6. Please submit .docx
Book Criminoloy Second EditionRead Chapter 6. Please submit .docx
 
Book Discussion #2 Ideas(may select 1 or more to respond to).docx
Book Discussion #2 Ideas(may select 1 or more to respond to).docxBook Discussion #2 Ideas(may select 1 or more to respond to).docx
Book Discussion #2 Ideas(may select 1 or more to respond to).docx
 
BOOK 1984 MiniProject What makes a human beingOne .docx
BOOK 1984 MiniProject What makes a human beingOne .docxBOOK 1984 MiniProject What makes a human beingOne .docx
BOOK 1984 MiniProject What makes a human beingOne .docx
 
Bonnie Morgen First Day on the Job and Facing an Ethical Di.docx
Bonnie Morgen First Day on the Job and Facing an Ethical Di.docxBonnie Morgen First Day on the Job and Facing an Ethical Di.docx
Bonnie Morgen First Day on the Job and Facing an Ethical Di.docx
 
Bonds are a vital source of financing to governments and corpora.docx
Bonds are a vital source of financing to governments and corpora.docxBonds are a vital source of financing to governments and corpora.docx
Bonds are a vital source of financing to governments and corpora.docx
 
Bond Company adopted the dollar-value LIFO inventory method on Janua.docx
Bond Company adopted the dollar-value LIFO inventory method on Janua.docxBond Company adopted the dollar-value LIFO inventory method on Janua.docx
Bond Company adopted the dollar-value LIFO inventory method on Janua.docx
 
Boley A Negro Town in the American West (1908) The commu.docx
Boley A Negro Town in the American West (1908)  The commu.docxBoley A Negro Town in the American West (1908)  The commu.docx
Boley A Negro Town in the American West (1908) The commu.docx
 
Bolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docx
Bolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docxBolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docx
Bolsonaro and Brazils Illiberal Backlash Wendy Hunter, Timo.docx
 
BoF Professional Member Exclusive articles & analysis availa.docx
BoF Professional  Member Exclusive articles & analysis availa.docxBoF Professional  Member Exclusive articles & analysis availa.docx
BoF Professional Member Exclusive articles & analysis availa.docx
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

BluePrints.classpathBluePrints.gitignoretargetl.docx

  • 3. 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=enable d 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=warn ing 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.x ml 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
  • 8. 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/ActiveDire ctory/AuthenticatedUser.javaBluePrints/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. */ publicclassAuthenticatedUser{ /** Keeps track of the user's king's id. */ privateString kingsid; /** Keeps track of the user's first name. */ privateString firstName; /** Keeps track of the user's last name. */ privateString lastName; /** Keeps track of the user's email address. */ privateString email; /** * Creates a user with the provided information.
  • 9. * * @param attr * - the set of attributes which contains information about this * user. * */ protectedAuthenticatedUser(Attributes attr)throwsNamingExcep tion{ 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. */ publicString getFirstName(){ return firstName; } /** * Returns the user's last name. * * @return the user's last name. */ publicString getLastName(){ return lastName; }
  • 10. /** * Returns the user's email. * * @return the user's email. */ publicString getEmail(){ return email; } /** * Returns the user's king's id. * * @return the user's king's id. */ publicString getKingsId(){ return kingsid; } } BluePrints/src/main/java/edu/kings/cs480/BluePrints/ActiveDire ctory/AuthenticationService.javaBluePrints/src/main/java/edu/ki ngs/cs480/BluePrints/ActiveDirectory/AuthenticationService.ja vapackage 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;
  • 11. import javax.naming.ldap.LdapContext; /** * AuthenticationService * * Provides an interface to authenticate against the King's Activ e Directory server. * */ publicclassAuthenticationService{ // the domain name to authenticate against. privatestaticString domain ="kings.edu"; /** * AuthenticationService() */ privateAuthenticationService(){ } /** * authenticate * * Try to authenticate against active directory via ldap and re turn 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 fa lse. * @throws NamingException When communication or authe ntication fails against the domain controller. */ publicstaticLdapContext authenticate(String email,String passw ord)throwsNamingException{
  • 12. // Define our properties of LDAP. Hashtable<String,String> adProps =newHashtable<String,String >(); adProps.put(Context.SECURITY_PRINCIPAL, email); adProps.put(Context.SECURITY_CREDENTIALS, passwo rd); adProps.put(Context.INITIAL_CONTEXT_FACTORY,"co m.sun.jndi.ldap.LdapCtxFactory"); adProps.put(Context.PROVIDER_URL,"ldap://"+ domain); // Try created a connection based on the above properties that w e defined. try{ returnnewInitialLdapContext(adProps,null); } catch(javax.naming.CommunicationException e){ e.printStackTrace(); thrownewNamingException("Failed to connect to "+ domain); } catch(NamingException e){ thrownewNamingException("Failed to authenticate against "+ d omain); } } /** * getUser * * Returns the user object based on the user from AD, otherw ise return null. * * @param email The email to retrieve. * @param context The context connection to the AD director y. * @return A user if the user exists, otherwise return null. */
  • 13. publicstaticAuthenticatedUser getUser(String email,LdapContex t context){ try{ String[] requestedAttrs =newString[]{"sn","givenName","Kings ID","mail","userPrincipalName"}; // Setup a search control. SearchControls controls =newSearchControls(); // Limit our search, otherwise we will time out traversing the w hole directory. controls.setSearchScope(javax.naming.directory.Search Controls.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 LDA P. // TODO: Refactor this. NamingEnumeration<SearchResult> result = context.search("O U=User_New,DC=kings,DC=edu","(& (userPrincipalName="+e mail+")(objectClass=user))", controls); // Search our attributes until we come across one that matches th e email we specified. if(result.hasMore()){ Attributes attr = result.next().getAttributes(); Attribute user = attr.get("userPrincipalName"); if(user!=null)returnnewAuthenticatedUser(attr); } } catch(NamingException e){ // TODO: Handle this gracefully. //System.out.println(e.toString()); e.printStackTrace();
  • 14. } returnnull; } } BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/ BuildingAdapter.javaBluePrints/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.CoordinateReposito ry; /**
  • 15. * This class is responsible for handling method used in the Map Manager Page. * */ @Service publicclassBuildingAdapter{ /** Used to query data from the buildings table in the database. */ @Autowired privateBuildingRepository buildingRepo; /** Handles calls to the database about the users in the BluePrin ts System. */ @Autowired privateAppUserRepository userRepo; /** Handles calls to the database about the coordinate data for b uildings. */ @Autowired privateCoordinateRepository coordinateRepo; /** * Returns all the buildings stored in the system. * * @return all the buildings stored in the system. */ publicList<Building> getBuildings(){ return buildingRepo.findAll(); } /** * Returns the building with the corresponding id provided. * * @param buildingId * - the id of the building being returned.
  • 16. * @return the building corresponding to the provided id. */ publicBuilding getBuilding(UUID buildingId){ Building building =null; building = buildingRepo.findOne(buildingId); return building; } /** * Updates the building with corresponding id, with the infor mation 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 upd ated. */ publicboolean updateBuilding(UUID buildingId,String building Name){ boolean updated =false; Building building = buildingRepo.findOne(buildingId); if(building !=null){ building.setName(buildingName); buildingRepo.save(building); updated =true; } return updated;
  • 17. } /** * 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 rem oved. */ publicboolean 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 i d. * * @param buildingName * - the name of the building. * @param creatorId * - the id of the person creating the building. * @return the newly added building. */ publicBuilding addBuilding(String buildingName, UUID creator Id){
  • 18. Building building =null; AppUser creator = userRepo.findOne(creatorId); if(creator !=null){ building =newBuilding(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. */ publicboolean addCoordinates(UUID buildingId,String coordina teData){ boolean added =false; Building building = buildingRepo.findOne(buildingId); if(building !=null){ BuildingCoordinate coordinates =newBuildingCoordinate(buildi ng, coordinateData);
  • 19. coordinateRepo.save(coordinates); added =true; } return added; } /** * Updates the coordinate data for the building with the corre sponding 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 . */ publicboolean updateCoordinates(UUID buildingId,String coord inateData){ boolean updated =false; Building building = buildingRepo.findOne(buildingId); if(building !=null){ BuildingCoordinate coordinates = coordinateRepo.findByBuildi ng(building); coordinates.setCoordinateData(coordinateData); coordinateRepo.save(coordinates); updated =true; } return updated;
  • 20. } /** * Returns the coordinate data for the building with the corre sponding building * id. * * @param buildingId * - the id of the building the coordinates are being requested for. * @return the coordinates for the building. */ publicBuildingCoordinate 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.javaBluePrints/src/main/java/edu/kings/cs480/ BluePrints/Adapters/CommentAdapter.java package edu.kings.cs480.BluePrints.Adapters; import org.springframework.beans.factory.annotation.Autowired ;
  • 21. import org.springframework.stereotype.Service; import edu.kings.cs480.BluePrints.Database.Comment; import edu.kings.cs480.BluePrints.Database.CommentRepositor y; 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 comm ent. * */ @Service publicclassCommentAdapter{ /** Handles calls to the Floor table in the database. */ @Autowired publicFloorRepository floorRepo; /** Handles calls to the App User table in the database. */ @Autowired publicAppUserRepository userRepo; /** Handles calls to the floor comment table in the database. */ @Autowired publicCommentRepository commentRepo; /** * This method adds a comment to the floor.
  • 22. * * @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. * */ publicboolean addComment(UUID floorId, UUID creatorId,Stri ng commentMsg){ boolean added =false; AppUser user = userRepo.getOne(creatorId); Floor floor = floorRepo.getOne(floorId); if(floor !=null&& user !=null){ Comment newComment =newComment(floor, user, commentMs g); commentRepo.save(newComment); added =true; } return added; } /** * This method updates a comment with the new message pro vided. *
  • 23. * @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. */ publicboolean updateComment(UUID commentId, UUID editorI d,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 th e floor id provided. * * @param floorId * - the id of the floor the comment belong to. * @return the comment for corresponding floor id. */
  • 24. publicList<Comment> getFloorComments(UUID floorId){ List<Comment> floorComment =null; floorComment = commentRepo.findByFloorIdOrderByCre atedDateAsc(floorId); return floorComment; } publicvoid clearFloorComments(UUID floorId){ commentRepo.delete(this.getFloorComments(floorId)); } } BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/F loorAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Blue Prints/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;
  • 25. 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 publicclassFloorAdapter{ /** Used to handle calls to the database. */ @Autowired privateFloorRepository floorRepo; /** Used to query data from the buildings table in the database. */ @Autowired privateBuildingRepository 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. * */ publicFloor addFloor(UUID buildingId,String floorName){ Floor newFloor =null;
  • 26. Building building = buildingRepo.getOne(buildingId); if(building !=null){ newFloor =newFloor(building, floorName); floorRepo.save(newFloor); } return newFloor; } publicboolean deleteFloor(UUID floorId){ boolean deleted =false; Floor floor = floorRepo.findOne(floorId); if(floor !=null){ floorRepo.delete(floor); deleted =true; } return deleted; } publicboolean deleteFloorsInBuilding(Building building){
  • 27. 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. * */ publicMap<String,List<Floor>> getFloors(){ HashMap<String,List<Floor>> buildingFloors =newHashMap<> (); List<Floor> floors = floorRepo.findAll(); for(Floor floor : floors){ Building building = floor.getBuilding(); String buildingId = building.getId().toString(); if(buildingFloors.containsKey(buildingId)){
  • 28. buildingFloors.get(buildingId).add(floor); System.out.println(String.format("added Floor %s to list.", floor .getName())); }else{ LinkedList<Floor> newFloorList =newLinkedList<>(); newFloorList.add(floor); buildingFloors.put(buildingId, newFloorList); System.out.println(String.format("Created a new list for Buildin g %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. */ publicFloor getFloor(UUID floorId){ Floor floor =null; floor = floorRepo.getOne(floorId); return floor; } }
  • 29. BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/L oggingAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Bl uePrints/Adapters/LoggingAdapter.javapackage 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 publicclassLoggingAdapter{ privatefinalstaticLogger LOGGER =LogManager.getLogger(); publicvoid log(Level level,String message){ if(level ==Level.INFO){ LOGGER.info(message); }elseif(level ==Level.WARNING){ LOGGER.warn(message); } } } BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/L oginAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Blue Prints/Adapters/LoginAdapter.java/** * */
  • 30. 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 connec tion, which * provides information about employees and students of King's College. */ @Service publicclassLoginAdapter{ // /** Used to log any errors that may error while using the acti ve directory adapter. */ // @Autowired // private LoggingAdapter loggingAdapter; @Autowired privateUserAdapter userAdapter; /** * Returns whether, or not, there is a user currently logged in
  • 31. to 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 . */ publicboolean 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 passw ord and user * name and returns whether, or not, it was successful. *
  • 32. * @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 */ publicboolean login(String email,String password,HttpSession s ession){ 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(); } }
  • 33. 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. */ publicAppUser 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.javaBluePrints/src/main/java/edu/kings /cs480/BluePrints/Adapters/Mock/MockStaffAdapter.javapackag e 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;
  • 34. import edu.kings.cs480.BluePrints.Database.Staff; publicclassMockStaffAdapterimplementsStaffAdapter<UUID>{ privateHashMap<UUID,Staff<UUID>> mockStaff; publicMockStaffAdapter(){ mockStaff =newHashMap<>(); mockStaff.put(UUID.fromString("8761c1d6-df23-494c- a62e- 5dd25bd7ee1a"),newMockStaff("Bob", UUID.fromString("8761 c1d6-df23-494c-a62e-5dd25bd7ee1a"),"[email protected]")); mockStaff.put(UUID.fromString("585b434e-4173-43d0- ae56- 7d7b219f035f"),newMockStaff("Steven", UUID.fromString("58 5b434e-4173-43d0-ae56-7d7b219f035f"),"[email protected]")); mockStaff.put(UUID.fromString("2168ac0b-9da7-43e7- 9b96- 829f54cd87e1"),newMockStaff("Richard", UUID.fromString("2 168ac0b-9da7-43e7-9b96-829f54cd87e1"),"[email protected]")); mockStaff.put(UUID.fromString("e15efdfe-bc09-40dc- 9ea0- 9fdad9b718b4"),newMockStaff("Chadd", UUID.fromString("e1 5efdfe-bc09-40dc-9ea0-9fdad9b718b4"),"[email protected]")); } @Override
  • 35. publicStaff<UUID> getStaff(UUID staffId){ return mockStaff.get(staffId); } @Override publicvoid deleteStaff(UUID staffId){ thrownewUnsupportedOperationException("Not needed for test" ); } @Override publicList<Staff<UUID>> getAllStaff(){ returnnewArrayList<>(mockStaff.values()); } @Override publicvoid updateStaff(UUID staffId,String name,String email){ thrownewUnsupportedOperationException("Not needed for test" ); } privateclassMockStaffimplementsStaff<UUID>{ privateString name; private UUID staffId;
  • 36. privateString email; publicMockStaff(String name, UUID staffId,String email){ this.name = name; this.staffId = staffId; this.email = email; } @Override publicString getName(){ return name; } @Override public UUID getStaffId(){ return staffId; } @Override publicString getStaffEmail(){ return email; } } } BluePrints/src/main/java/edu/kings/cs480/BluePrints/Adapters/ RoomAdapter.javaBluePrints/src/main/java/edu/kings/cs480/Blu ePrints/Adapters/RoomAdapter.javapackage edu.kings.cs480.Bl
  • 37. uePrints.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.RoomCoordinateRe pository; 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.StaffAssignmentRe pository; @Service publicclassRoomAdapter{ @Autowired privateRoomRepository roomRepo; @Autowired privateRoomCoordinateRepository roomCoordinateRepo; @Autowired privateFloorAdapter floorAdapter; @Autowired privateStaffAssignmentRepository staffRepo; publicRoom getRoom(UUID roomId){
  • 38. Room room = roomRepo.findOne(roomId); return room; } publicList<Room> getAllRooms(UUID floorId){ List<Room> rooms =null; Floor floor = floorAdapter.getFloor(floorId); if(floor !=null){ rooms = roomRepo.findByFloor(floor); } return rooms; } publicRoom addRoom(String roomName, UUID floorId){ Room room =null; Floor floor = floorAdapter.getFloor(floorId); if(floor !=null){ room =newRoom(roomName, floor); roomRepo.save(room); }
  • 39. return room; } publicboolean updateRoom(UUID roomId,String newRoomNam e){ boolean updated =false; Room room = roomRepo.findOne(roomId); if(room !=null){ room.setName(newRoomName); roomRepo.save(room); updated =true; } return updated; } publicboolean deleteRoom(UUID roomId){ boolean deleted =false; Room room = roomRepo.findOne(roomId); if(room !=null){ unassignAllStaff(roomId); roomCoordinateRepo.delete(roomId); roomRepo.delete(room); deleted =true; }
  • 40. return deleted; } publicboolean addRoomCoordinates(UUID roomId,String room CoordinateData){ boolean added =false; if(roomRepo.exists(roomId)){ RoomCoordinates roomCoordinates =newRoomCoordinates(roo mId, roomCoordinateData); roomCoordinateRepo.save(roomCoordinates); added =true; } return added; } publicboolean deleteRoomCoordinates(UUID roomId){ boolean deleted =false; RoomCoordinates coordinates = roomCoordinateRepo.findOne(r oomId); if(coordinates !=null){ roomCoordinateRepo.delete(coordinates); deleted =false; } return deleted;
  • 41. } publicboolean updateRoomCoordinates(UUID roomId,String ne wRoomCoordinateData){ boolean updated =false; RoomCoordinates coordinates = roomCoordinateRepo.findOne(r oomId); if(coordinates !=null){ coordinates.setCoordinateData(newRoomCoordinateDat a); roomCoordinateRepo.save(coordinates); updated =true; } return updated; } publicList<RoomCoordinates> getAllRoomCoordinates(UUID fl oorId){ List<RoomCoordinates> roomCoordinates =null; Floor floor = floorAdapter.getFloor(floorId); if(floor !=null){ List<Room> rooms = roomRepo.findByFloor(floor); if(rooms !=null){
  • 42. roomCoordinates =newLinkedList<>(); for(Room room : rooms){ RoomCoordinates coordinates = roomCoordinateRepo.findOne(r oom.getId()); roomCoordinates.add(coordinates); } } } return roomCoordinates; } publicRoomCoordinates getRoomCoordinates(UUID roomId){ RoomCoordinates coordinates = roomCoordinateRepo.findOne(r oomId); return coordinates; } publicboolean clearAllFloorRooms(UUID floorId){ boolean deleted =false; Floor floor = floorAdapter.getFloor(floorId); if(floor !=null){ List<Room> rooms = roomRepo.findByFloor(floor); for(Room room : rooms){
  • 43. deleteRoom(room.getId()); } deleted =true; } return deleted; } publicList<StaffAssignment> getRoomAssignments(UUID room Id){ List<StaffAssignment> result =null;; Room room = roomRepo.findOne(roomId); if(room !=null){ result = staffRepo.findByRoom(room); } return result; } publicboolean assignStaffToRooms(UUID roomId, UUID[] staff Ids){ boolean assigned =false; Room room = roomRepo.findOne(roomId); if(room !=null){ for(UUID staffId : staffIds){ StaffAssignment assignment =newStaffAssignment(room, staffI
  • 44. d); staffRepo.save(assignment); CS 300 Final Project/Exam You’ve been presented with a copy of BluePrints, the 2017- 2018 CS480/481 project. This project is a web site designed to allow easy editing of building, floor, and room data for the MonarchMaps project (’16-’17). This project has a number of dependencies, and zero unit tests. It relies fairly heavily on Spring and Spring MVC to manage *many* of those dependencies so you are in reasonably good shape compared to other legacy projects. This represents a fairly realistic request in business and the time frame (2 weeks) is likely a much larger timeframe than you would normally have OR the application’s scope would be much larger. I have updated this project to no longer depend on a remote Postgres SQL database, but instead use Spring’s built-in, in-memory database H2. This means you do not have to connect to or worry about
  • 45. conflicts with a database, however, nothing is actually persisted between sessions. When you run this project (using Eclipse’s “Run on Server” feature), you’ll be able to point your browser at http://localhost:8080/BluePrints to investigate the live app. I’ll be pushing a .sql file into your repository within a few days to auto-seed the H2 database with some test data and will supply you a dummy login/password at that point. In the meantime, you can still get familiar with the code! Your task is to add the following feature/change, leveraging the techniques you’ve learned throughout this course and make sure you are creating proper unit tests for the feature and any code you must modify. Some areas of the code may not work properly, and you’ll need to investigate/fix those areas using characterization tests to explore. I am not mandating a specific number of tests, but you should adequately ensure you are testing what you’re changing. We no longer want to “hard delete” any comment from the system. Comments are attached to floors. Instead “soft delete” them by setting a deleted flag on the
  • 46. comment. Soft-deleted comments should not normally be accessible under normal operations but should still be stored in the table. We want to capture the date/time the comment was deleted, and the user who did the deletion. There are several things to consider, here. The project is using Jpa, which you can read more about at https://spring.io/guides/gs/accessing-data-jpa/. Pay particular attention to how the @Repository annotation works, especially in creating “find” methods… Here are a few suggestions to get you started: • Do some quick sketching/outlining to see how the classes interact • Refactor the classes and interfaces in the edu.kings.cs480.BluePrints.Database package to split the “Model” classes from the @Repository interfaces to simplify the scope of what you’re working on • Start by getting the field on each object to work, then look to override the delete behavior, and finally the find behavior http://localhost:8080/BluePrints
  • 47. http://localhost:8080/BluePrints https://spring.io/guides/gs/accessing-data-jpa/ https://spring.io/guides/gs/accessing-data-jpa/ • You may or may not have to create concrete implementations of the @Repository interfaces depending on your approach • Follow the existing application conventions for how “users” are stored my mimicking how the “creator”/created_by fields work • Be *cautious* when a floor is deleted – currently, a deleted floor hard-deletes all of its comments; this behavior must also change o Pay attention to the relationship between Floor and Comment; and note how a Comment ignores if the comment creator cannot be found in the AppUsers data… <that is a hint> Your work is your own. Please do not share code as that will fall under the college’s academic dishonesty and plagiarism guidelines.
  • 48. I pushed a few changes to everyone's repos for the final project. Changes include: * SQL script to automatically seed test data * Fixed a number of issues with unavailable/out of date dependencies * I adjusted the LoginAdapter so you can login with any password and the username of 'admin'; the passwords in the database are one-way encrypted and there was no documentation... :-( Please make sure to *PULL* before you continue working. If you run into any issues, please let me know. I've created a private copy repo for each of you based on the "BluePrints" project that was a CS480 final project last year. This is an Eclipse project, targeting Tomcat 8.5, Java 1.8, and JUnit 4, which is as close as I can reasonably get to the lab computers in Admin 425. If you want to run at home, get Eclipse for JEE (exact version I'm using: https://www.eclipse.org/downloads/download.php?file=/t echnology/epp/downloads/release/2018-12/R/eclipse-jee-2018- 12-R-win32-x86_64.zip&mirror_id=1249), Tomcat 8.5 (http://mirror.olnevhost.net/pub/apache/tomcat/tomcat- 8/v8.5.40/bin/apache-tomcat-8.5.40-windows-x64.zip), and Java EE JDK 8 (1.8) (https://www.oracle.com/technetwork/java/javaee/downloads/ja va-ee-sdk-downloads-3908423.html). I created a folder at C:Java and unzipped/installed all to there. (If you're using a Mac, you'll need to download alternate links, of course!) In Eclipse, go to Window -> Preferences, Servers +-> Runtime Environments, and click Add. Choose Tomcat 8.5, then pick the directory you unzipped from. From there, File -> Import..., Choose "Git" +-> "Projects from Git", "Clone from URI", and clone from GitHub as usual. On the new project wizard, it should detect the Eclipse project and get things going pretty smoothly from there. It should build
  • 49. after a few moments, and allow you to choose "Run", and then set up a new Apache Tomcat run configuration. If you browse out to http://localhost:8080/BluePrints , you should receive a login window (note: nothing works from here). For now, focus on exploring the code a bit, and make sure it builds. I'll have the actual final assignment published in Moodle in the next couple of days. CS 300 Final Project/Exam You’ve been presented with a copy of BluePrints, the 2017- 2018 CS480/481 project. This project is a web site designed to allow easy editing of building, floor, and room data for the MonarchMaps project (’16-’17). This project has a number of dependencies, and zero unit tests. It relies fairly heavily on Spring and Spring MVC to manage *many* of those dependencies so you are in reasonably good shape compared to other legacy projects. This represents a fairly realistic request in business and the time frame (2 weeks) is likely a much larger timeframe than you would normally have OR the application’s scope would be much larger. I have updated this project to no longer depend on a remote Postgres SQL database, but instead
  • 50. use Spring’s built-in, in-memory database H2. This means you do not have to connect to or worry about conflicts with a database, however, nothing is actually persisted between sessions. When you run this project (using Eclipse’s “Run on Server” feature), you’ll be able to point your browser at http://localhost:8080/BluePrints to investigate the live app. I’ll be pushing a .sql file into your repository within a few days to auto-seed the H2 database with some test data and will supply you a dummy login/password at that point. In the meantime, you can still get familiar with the code! Your task is to add the following feature/change, leveraging the techniques you’ve learned throughout this course and make sure you are creating proper unit tests for the feature and any code you must modify. Some areas of the code may not work properly, and you’ll need to investigate/fix those areas using characterization tests to explore. I am not mandating a specific number of tests, but you should adequately ensure you are testing what you’re changing. We no longer want to “hard delete” any comment from the system. Comments are
  • 51. attached to floors. Instead “soft delete” them by setting a deleted flag on the comment. Soft-deleted comments should not normally be accessible under normal operations but should still be stored in the table. We want to capture the date/time the comment was deleted, and the user who did the deletion. There are several things to consider, here. The project is using Jpa, which you can read more about at https://spring.io/guides/gs/accessing-data-jpa/. Pay particular attention to how the @Repository annotation works, especially in creating “find” methods… Here are a few suggestions to get you started: • Do some quick sketching/outlining to see how the classes interact • Refactor the classes and interfaces in the edu.kings.cs480.BluePrints.Database package to split the “Model” classes from the @Repository interfaces to simplify the scope of what you’re working on • Start by getting the field on each object to work, then look to override the delete behavior, and
  • 52. finally the find behavior http://localhost:8080/BluePrints http://localhost:8080/BluePrints https://spring.io/guides/gs/accessing-data-jpa/ https://spring.io/guides/gs/accessing-data-jpa/ • You may or may not have to create concrete implementations of the @Repository interfaces depending on your approach • Follow the existing application conventions for how “users” are stored my mimicking how the “creator”/created_by fields work • Be *cautious* when a floor is deleted – currently, a deleted floor hard-deletes all of its comments; this behavior must also change o Pay attention to the relationship between Floor and Comment; and note how a Comment ignores if the comment creator cannot be found in the AppUsers data… <that is a hint> Your work is your own. Please do not share code as that will fall under the college’s academic dishonesty and plagiarism guidelines.