예제 #1
0
	def getInfo(self, buildingName):
		checkData(locals())
	
		building = Building(buildingName = buildingName)
		building.retrieve()

		return building.getDict()
예제 #2
0
	def getCrossRoomValidationGroups(self, buildingName, roomName = None, validationCategories = None):
		checkData(locals())

		building = Building(buildingName = buildingName)
		building.retrieve()

		return building.getCrossRoomValidationGroups(roomName = roomName, validationCategories = validationCategories)	
예제 #3
0
	def __addOrModifyGroup(self, buildingName, description, crossRoomsValidation, crossRoomsValidationCategories, groupId = None):


		if type(crossRoomsValidation) == int:
			crossRoomsValidation = bool(crossRoomsValidation)
		elif type(crossRoomsValidation) == str or type(crossRoomsValidation) == unicode:

			if str(crossRoomsValidation.upper()) == "TRUE" or str(crossRoomsValidation.upper()) == "1":
				crossRoomsValidation = True
			else:
				crossRoomsValidation = False

		elif type(crossRoomsValidation) != bool:
			raise IncorrectInputDataTypeError("crossRoomsValidation must be a booelan value (True,False) or integer value (1,0)")


		if not crossRoomsValidation:
			crossRoomsValidationCategories = []
		else:
			crossRoomsValidationCategories = json.loads(crossRoomsValidationCategories)


		if crossRoomsValidation and len(crossRoomsValidationCategories) == 0:
			raise MissingInputDataError("Selecting crossRoomsValidation you need to insert at least one rule category in crossRoomsValidationCategories")

		from app.backend.model.group import Group
		group = Group(id = groupId, buildingName = buildingName, description = description, crossRoomsValidation = crossRoomsValidation, crossRoomsValidationCategories = crossRoomsValidationCategories)

		building = Building(buildingName = buildingName)
		building.retrieve()

		return building.addGroup(group).getDict()
예제 #4
0
	def addRoom(self, groupId, roomName, buildingName):
		checkData(locals())

		group = Group(buildingName = buildingName, id = groupId)
		group.retrieve()

		from app.backend.model.room import Room
		room = Room(buildingName = buildingName, roomName = roomName)
		room.retrieve()


		if group.crossRoomsValidation:
			print "\t\t\t\t\t\t\t\tTODO (" + self.__class__.__name__ + ":" + sys._getframe().f_code.co_name + ")  This part of the method as not been tested"
			# In this case we have to check that the room doesn't belong to another CrossRoomValidatioGroup
			from app.backend.model.building import Building
			building = Building(buildingName = buildingName)
			building.retrieve()
			crvgList = building.getCrossRoomValidationGroups(roomName = roomName, validationCategories = group.crossRoomsValidationCategories)

			if len(crvgList) > 0:
				raise WrongBuildingGroupRipartitionError("A room can belong to only one cross validation group per category. Room " + str(roomName) + " in already in group " + str(crvgList[0]))

		group.addRoom(room)

		return room.getDict()
예제 #5
0
	def addRoom(self, roomName, buildingName, description):
		checkData(locals())

		
		from app.backend.model.room import Room
		room = Room(roomName = roomName,  buildingName = buildingName, description = description)

		building = Building(buildingName = buildingName)
		building.retrieve()

		return building.addRoom(room).getDict()
예제 #6
0
	def getUnassignedRooms(self, buildingName):
		checkData(locals())

		building = Building(buildingName = buildingName)
		building.retrieve()

		roomList = []

		for room in building.getUnassignedRooms():
			roomList.append(room.getDict())

		return {"rooms" : roomList}
예제 #7
0
	def checkUserBinding(self, buildingName, username):
		checkData(locals())


		from app.backend.model.user import User

		building = Building(buildingName = buildingName)
		building.retrieve()

		user = User(username = username)
		user.retrieve()

		building.checkUserBinding(user)
예제 #8
0
	def getGroups(self, buildingName, username = None):
		checkData(locals())

		building = Building(buildingName = buildingName)
		building.retrieve()

		groupList = []

		if username:
			from app.backend.model.user import User
			user = User(username = username)
			user.retrieve()

			for buildingGroup in building.getGroups():
				for userGroup in user.getGroups():
					if buildingGroup.buildingName == userGroup.buildingName and buildingGroup.id == userGroup.id:
						groupList.append(userGroup.getDict())
		else:
			for group in building.getGroups():
				groupList.append(group.getDict())

		return {"groups" : groupList}
예제 #9
0
	def getRooms(self, buildingName, username = None):
		checkData(locals())

		building = Building(buildingName = buildingName)
		building.retrieve()

		roomList = []

		if username:
			from app.backend.model.user import User
			user = User(username = username)
			user.retrieve()

			for buildingRoom in building.getRooms():
				for userRoom in user.getRooms():
					if buildingRoom.buildingName == userRoom.buildingName and buildingRoom.roomName == userRoom.roomName:
						roomList.append(userRoom.getDict())
		else:

			for room in building.getRooms():
				roomList.append(room.getDict())


		return {"rooms" : roomList}
예제 #10
0
	def getBuilding(self):
		from app.backend.model.building import Building

		building = Building(buildingName = self.buildingName)
		building.retrieve()
		return building
예제 #11
0
	def test0(self):

		from app.backend.commons.database import Database
		from app.backend.model.building import Building
		from app.backend.model.group import Group
		from app.backend.model.room import Room
		from app.backend.model.user import User
		from app.backend.model.rule import Rule

		print "Starting test..."
		print "Cleaning database..."

		database = Database()
		database.open()
		database.executeWriteQuery("TRUNCATE TABLE buildings")
		database.executeWriteQuery("TRUNCATE TABLE groups")
		database.executeWriteQuery("TRUNCATE TABLE rooms")
		database.executeWriteQuery("TRUNCATE TABLE users")
		database.executeWriteQuery("TRUNCATE TABLE users_rooms")
		database.executeWriteQuery("TRUNCATE TABLE rooms_groups")
		database.executeWriteQuery("TRUNCATE TABLE rules")
		database.close()

		print "Testing model..."

		building = Building(buildingName = "CSE", label = "Computer Science", description = "This is a nice place")
		building.store()

		building = Building(buildingName = "CSE", label = "Computer Science", description = "This is a great place")
		building.store()

 		building = Building(buildingName = "CSE")
 		building.retrieve()
 		print building

 		group = Group(buildingName = "CSE", description = "Questo gruppo eheh")
 		group.store()
 		print group

 		group = Group(id=1, buildingName = "CSE")
 		group.retrieve()
 		print group

 		group = Group(id=1, buildingName = "CSE", description = "we ciao ciao")
 		group.store()

 		group = Group(id=1, buildingName = "CSE")
 		group.retrieve()
 		print group

		room = Room(roomName = "200",  buildingName = "CSE", description = "Bella 3333")
		room.store()

		room = Room(roomName = "200",  buildingName = "CSE")
		room.retrieve()
		print room

		print "room.getBuilding() test"
		print room.getBuilding()

		user = User(username = "******", email = "*****@*****.**", password = "******", personName = "Alessandro Nacci", level = 10)
		user.store()

		room.addUser(user)

		print "user.getRooms() test"
		for room in user.getRooms():
			print room

		print "group.addRoom(room) test"
		group.addRoom(room)
		
		print group

		print "User test 1"
		user = User(username = "******")
		user.retrieve()
		print user

		print "User test 2"
		user = User(username = "******", password="******")
		user.retrieve()
		print user

		print "User test 3"
		user = User(uuid = 1)
		user.retrieve()
		print user

		

		rule = Rule(priority = 1, category = "ELECTRICT222", buildingName = "CSE", groupId = 1, roomName = "200", 
				authorUuid = 1, antecedent = "the ligjt is on", consequent = "turn off the light", enabled = 1, deleted = 0)

		rule.store()

		rule = Rule(id = 1)
		rule.retrieve()

		print rule
		print rule.getBuilding()
		print rule.getGroup()
		print rule.getAuthor()

		print "test group.getRules()"
		ruleList = group.getRules()
		for r in ruleList:
			print r

		print "test room.getRules()"
		ruleList = room.getRules()
		for r in ruleList:
			print r

		print "test room.getRules(author)"
		ruleList = room.getRules(author = user, includeGroupsRules = None)
		for r in ruleList:
			print r

		print "test room.getRules(includeGroupsRules)"
		ruleList = room.getRules(includeGroupsRules = True)
		for r in ruleList:
			print r

		print "test user.getCreatedRules()"
		ruleList = user.getCreatedRules()
		for r in ruleList:
			print r

		group.deleteRoom(room)
		room.deleteUser(user)
		rule.delete()
		user.delete()
		group.delete()
		building.delete()
		room.delete()

		user = User(username = "******")
		user.retrieve()