示例#1
0
	def addCapsule(self, request):
		"""add a new capsule, edit and delete is not allowed
		"""
		# probabilmente ci deve essere un sistema migliore di fare
		# questo passaggio dei parametri
		openingDate = request.openingDate
		closingDate = request.closingDate
		lat = request.lat
		lng = request.lng
		tll = request.tll
		anonymous = request.anonymous
		encrypt = request.encrypted
		content = request.content

		user =  TSCEndpoint.get_current_user()
		TSCid = TSCController.addCapsule(openingDate, closingDate, \
			lat, lng, tll, anonymous, encrypt, user, content)
		if TSCid is None:
			response = TSCResponseMessage(
				TSCid = None,
				status = TSCController.TSCCTRL_KO,
				statusMessage = 'Capsule not created.',
				content = '',
				items = [] )
		else:
			L.info("Capsule created")
			response = TSCResponseMessage(
				TSCid = TSCid,
				status = TSCController.TSCCTRL_OK,
				statusMessage = 'Capsule correctly created',
				content = '',
				items = [] )

		return response
示例#2
0
    def addCapsule(self, request):
        """add a new capsule, edit and delete is not allowed
		"""
        # probabilmente ci deve essere un sistema migliore di fare
        # questo passaggio dei parametri
        openingDate = request.openingDate
        closingDate = request.closingDate
        lat = request.lat
        lng = request.lng
        tll = request.tll
        anonymous = request.anonymous
        encrypt = request.encrypted
        content = request.content

        user = TSCEndpoint.get_current_user()
        TSCid = TSCController.addCapsule(openingDate, closingDate, \
         lat, lng, tll, anonymous, encrypt, user, content)
        if TSCid is None:
            response = TSCResponseMessage(TSCid=None,
                                          status=TSCController.TSCCTRL_KO,
                                          statusMessage='Capsule not created.',
                                          content='',
                                          items=[])
        else:
            L.info("Capsule created")
            response = TSCResponseMessage(
                TSCid=TSCid,
                status=TSCController.TSCCTRL_OK,
                statusMessage='Capsule correctly created',
                content='',
                items=[])

        return response
示例#3
0
    def listCapsule(self, request):
        """list capsule depending on search parameters
		This will be the most used api
		"""
        user = TSCEndpoint.get_current_user()

        ( rc, items ) = TSCController.searchCapsule(
          TSCid = request.TSCid, \
          seen = request.seen, \
          anonymous = request.anonymous, \
          encrypt=request.encrypt, \
          user = user)

        L.info("Logging degli items")
        L.info(items)
        if not rc == TSCController.TSCCTRL_OK:
            raise endpoints.InternalServerErrorException("Something goes bad")
        return TSCResponseMessage( TSCid = None, status = TSCController.TSCCTRL_OK, \
         statusMessage = '', items = items )
示例#4
0
	def listCapsule(self, request):
		"""list capsule depending on search parameters
		This will be the most used api
		"""
		user = TSCEndpoint.get_current_user()

		( rc, items ) = TSCController.searchCapsule(
				TSCid = request.TSCid, \
				seen = request.seen, \
				anonymous = request.anonymous, \
				encrypt=request.encrypt, \
				user = user)

		L.info("Logging degli items")
		L.info(items)
		if not rc == TSCController.TSCCTRL_OK :
			raise endpoints.InternalServerErrorException("Something goes bad")
		return TSCResponseMessage( TSCid = None, status = TSCController.TSCCTRL_OK, \
			statusMessage = '', items = items )
示例#5
0
    def radar(self, request):
        """target distance.
		say how far is the device from the TSC.
		It's not a good idea keep querying the server.
		Very few logic, can stay here.
		"""
        TSCid = request.TSCid
        #tsc = TimespaceCapsule.getByTSCid(TSCid)

        (rc, distance) = TSCController.radar(TSCid, request.lat, request.lng)

        if rc == TSCController.TSCCTRL_OK:
            return TSCResponseMessage(TSCid=TSCid,
                                      status=TSCController.TSCCTRL_KO,
                                      content=str(distance),
                                      items=[])

        return TSCResponseMessage(TSCid=TSCid,
                                  status=TSCController.TSCCTRL_KO,
                                  items=[])
示例#6
0
	def radar(self, request):
		"""target distance.
		say how far is the device from the TSC.
		It's not a good idea keep querying the server.
		Very few logic, can stay here.
		"""
		TSCid = request.TSCid
		#tsc = TimespaceCapsule.getByTSCid(TSCid)

		( rc, distance ) = TSCController.radar(TSCid, request.lat, request.lng)

		if rc == TSCController.TSCCTRL_OK:
			return TSCResponseMessage(
				TSCid = TSCid,
				status = TSCController.TSCCTRL_KO,
				content = str( distance ),
				items = [] )

		return TSCResponseMessage(
			TSCid = TSCid,
			status = TSCController.TSCCTRL_KO,
			items = [] )
示例#7
0
    def openCapsule(self, request):
        """request to open the capsule,
		if capsule is not for anonymous on first run will be assigned to
		the user and only the owener can request the opening
		"""
        TSCid = request.TSCid
        user = TSCEndpoint.get_current_user()

        (rc, response) = TSCController.openCapsule(TSCid, request.lat,
                                                   request.lng,
                                                   request.password, user)
        # assign the capsule if not anonymous and not yet assigned
        if rc == TSCController.TSCCTRL_BADTSCID:
            raise endpoints.NotFoundException('Bad tscid!')
        elif rc == TSCController.TSCCTRL_BADUSER:
            raise endpoints.BadRequestException("Can't find a user")
        elif rc == TSCController.TSCCTRL_ASSIGNED:
            return TSCResponseMessage(TSCid=TSCid,
                                      status=TSCController.TSCCTRL_OK,
                                      statusMessage='Assigned!',
                                      content='',
                                      items=[])
        # anything which does not fit into the above cases
        elif rc != TSCController.TSCCTRL_OK:
            return TSCResponseMessage(TSCid=TSCid,
                                      status=rc,
                                      statusMessage='TSCController rc',
                                      content='',
                                      items=[])

        return TSCResponseMessage(TSCid=TSCid,
                                  status=TSCController.TSCCTRL_KO
                                  if response.code != TimespaceCapsule.TSC_OK
                                  else TSCController.TSCCTRL_OK,
                                  statusMessage="disclose code: " +
                                  TimespaceCapsule.MESSAGE[response.code],
                                  content=response.data,
                                  items=[])
示例#8
0
	def openCapsule(self, request):
		"""request to open the capsule,
		if capsule is not for anonymous on first run will be assigned to
		the user and only the owener can request the opening
		"""
		TSCid = request.TSCid
		user = TSCEndpoint.get_current_user()

		( rc, response ) = TSCController.openCapsule(TSCid, request.lat, request.lng, request.password, user)
		# assign the capsule if not anonymous and not yet assigned
		if rc == TSCController.TSCCTRL_BADTSCID:
			raise endpoints.NotFoundException('Bad tscid!')
		elif rc == TSCController.TSCCTRL_BADUSER:
				raise endpoints.BadRequestException("Can't find a user")
		elif rc == TSCController.TSCCTRL_ASSIGNED:
			return TSCResponseMessage(
				TSCid = TSCid,
				status = TSCController.TSCCTRL_OK,
				statusMessage = 'Assigned!',
				content = '',
				items = [] )
		# anything which does not fit into the above cases
		elif rc != TSCController.TSCCTRL_OK:
			return TSCResponseMessage(
				TSCid = TSCid,
				status = rc,
				statusMessage = 'TSCController rc',
				content = '',
				items = [] )

		return TSCResponseMessage(
			TSCid = TSCid,
			status = TSCController.TSCCTRL_KO
				if response.code != TimespaceCapsule.TSC_OK
				else TSCController.TSCCTRL_OK,
			statusMessage = "disclose code: "+ TimespaceCapsule.MESSAGE[response.code],
			content = response.data,
			items = [] )