示例#1
0
 def getByOutletId(cls, outlet_id):
     assert isinstance(outlet_id, unicode)
     q = Outlet.query()
     q = q.filter(cls.outletId == outlet_id)
     keys = q.fetch(keys_only=True, limit=2)
     if len(keys) == 0:
         raise EntityNotFound({"outletId": outlet_id})
     if len(keys) >= 2:
         raise EntityNotFound({"outletId": outlet_id})
     return keys[0].get()
示例#2
0
    def POST(self, jrequest, jresponse):
        assert isinstance(jrequest, JsonRpcRequest)
        assert isinstance(jresponse, JsonRpcResponse)
        jresponse.setId()
        try:
            email = jrequest.getValue("email")[0]
            raw_password = jrequest.getValue("password")[0]
        except Exception:
            raise InvalidParams(
                "email and password are required for method=login.")
        try:
            email_user = EmailUser.getByEmail(email)
        except Exception:
            raise EntityNotFound("EmailUser entity is not found",
                                 {"email": email})
        assert isinstance(email_user, EmailUser)
        email_user.matchPassword(
            raw_password)  # raises PasswordMismatch if password not matches
        #        email_user.saveToSession()

        assert email_user.odenkiId is not None
        odenki_user = OdenkiUser.getByOdenkiId(email_user.odenkiId)
        odenki_user.saveToSession()
        EmailUser.deleteFromSession()

        jresponse.setResultValue("EmailUser", email_user)
        jresponse.setResultValue("OdenkiUser", odenki_user)
示例#3
0
 def getByProductNameSerialNumberModuleIdSensorId(cls, product_name_data,
                                                  serial_number_data,
                                                  module_id_data,
                                                  sensor_id_data):
     assert isinstance(product_name_data, Data) and isinstance(
         serial_number_data, Data) and isinstance(
             module_id_data, Data) and isinstance(sensor_id_data, Data)
     query = ndb.Query(kind="Sensor")
     query = query.filter(cls.productName == product_name_data.dataId)
     query = query.filter(cls.serialNumber == serial_number_data.dataId)
     query = query.filter(cls.moduleId == module_id_data.dataId)
     query = query.filter(cls.sensorId == sensor_id_data.dataId)
     keys = query.fetch(keys_only=True, limit=2)
     if len(keys) == 0:
         raise EntityNotFound(
             "Sensor", {
                 "product_name_data": product_name_data,
                 "serial_number_data": serial_number_data,
                 "module_id_data": module_id_data,
                 "sensor_id_name": sensor_id_data
             })
     if len(keys) == 2:
         raise EntityDuplicated({
             "product_name_data": product_name_data,
             "serial_number_data": serial_number_data,
             "module_id_name": module_id_data,
             "sensor_id_data": sensor_id_data
         })
     return keys[0].get()
示例#4
0
 def loadFromSession(cls):
     session = gaesessions.get_current_session()
     assert isinstance(session, gaesessions.Session)
     if not session.has_key(cls.SESSION_KEY):
         raise EntityNotFound(cls, {"in": "session"})
     gmail_user = session[cls.SESSION_KEY]
     assert isinstance(gmail_user, GmailUser)
     return gmail_user
示例#5
0
 def keyByOdenkiId(cls, odenki_id):
     query = cls.queryByOdenkiId(odenki_id)
     keys = query.fetch(keys_only=True, limit=2)
     if len(keys) == 0:
         raise EntityNotFound(cls, {"odenkiId": odenki_id})
     if len(keys) == 2:
         raise EntityDuplicated(cls, {"odenkiId": odenki_id})
     return keys[0]
示例#6
0
 def getByFieldAndString(cls, field, string):
     query = cls.queryByFieldAndString(field, string)
     keys = query.fetch(keys_only=True, limit=2)
     if len(keys) == 2:
         raise EntityDuplicated()
     if len(keys) == 0:
         raise EntityNotFound("Data", {"field": field, "string": string})
     return keys[0].get()
示例#7
0
 def loadFromSession(cls):
     session = gaesessions.get_current_session()
     assert isinstance(session, gaesessions.Session)
     if not session.has_key(cls.SESSION_KEY):
         raise EntityNotFound(message="OdenkiUser is not in the session.")
     odenki_user = session[cls.SESSION_KEY]
     assert isinstance(odenki_user, OdenkiUser)
     return odenki_user
示例#8
0
 def getByUniqueSensorId(cls, unique_sensor_id):
     query = ndb.Query(kind="Sensor")
     query = query.filter(Sensor.uniqueSensorId == unique_sensor_id)
     keys = query.get(keys_only=True, limit=2)
     if len(keys >= 2):
         raise EntityDuplicated({"equipmentId": unique_sensor_id})
     if len(keys == 0):
         raise EntityNotFound({"equipmentId": unique_sensor_id})
     return keys[0].get()
示例#9
0
 def loadFromSession(cls):
     session = get_current_session()
     assert isinstance(session, Session)
     try:
         outlet = session[cls.SESSION_KEY]
         assert isinstance(outlet, Outlet)
         return outlet
     except KeyError:
         raise EntityNotFound("No Outlet in the session.")
示例#10
0
 def keyByOdenkiId(cls, odenki_id):
     assert isinstance(odenki_id, int)
     query = cls.queryByOdenkiId(odenki_id)
     keys = query.fetch(keys_only=True, limit=2)
     if len(keys) == 0:
         raise EntityNotFound({"odenkiId": odenki_id}, "OdenkiUser.keyByOdenkiId")
     if len(keys) == 2:
         raise EntityDuplicated({"odenkiId":odenki_id}, "OdenkiUser.keyByOdenkiId")
     return keys[0]
示例#11
0
 def getByCard(cls, card_type, card_id):
     q = Outlet.query()
     q = q.filter(cls.cardId == card_id)
     q = q.filter(cls.cardType == card_type)
     keys = q.fetch(keys_only=True, limit=2)
     if len(keys) == 0:
         raise EntityNotFound({"cardId": card_id, "cardType": card_type})
     if len(keys) >= 2:
         raise EntityDuplicated({"cardId": card_id, "cardType": card_type})
     return keys[0].get()
示例#12
0
 def getByEmailUserId(cls, email_user_id):
     assert isinstance(email_user_id, int)
     query = ndb.Query(kind="EmailUser")
     query = query.filter(cls.emailUserId == email_user_id)
     query = query.filter(cls.invalidatedDateTime == None)
     keys = query.fetch(limit=2, keys_only=True)
     if len(keys) == 0:
         raise EntityNotFound(cls, {"emailUserId": email_user_id})
     if len(keys) == 2:
         raise EntityDuplicated(cls, {"emailUserId": email_user_id})
     return keys[0].get()
示例#13
0
 def getByNonce(cls, nonce):
     assert isinstance(nonce, unicode)
     query = ndb.Query(kind="EmailUser")
     query = query.filter(cls.nonce == nonce)
     query = query.filter(cls.invalidatedDateTime == None)
     keys = query.fetch(limit=2, keys_only=True)
     if len(keys) == 2:
         raise EntityDuplicated({"nonce": nonce},
                                "EmailUser.getByNonce failed")
     if len(keys) == 0:
         raise EntityNotFound({"nonce": nonce},
                              "EmailUser.getByNonce failed")
     return keys[0].get()
示例#14
0
 def keyByTwitterId(cls, twitter_id):
     assert isinstance(twitter_id, int)
     query = cls.queryByTwitterId(twitter_id)
     keys = query.fetch(keys_only=True, limit=2)
     if len(keys) == 0:
         raise EntityNotFound(cls, {"twitterId":twitter_id})
     if len(keys) == 2:
         twitter_user_1 = keys[0].get()
         assert isinstance(twitter_user_1, TwitterUser)
         twitter_user_2 = keys[1].get()
         assert isinstance(twitter_user_2, TwitterUser)
         if twitter_user_1.odenkiId == twitter_user_2.odenkiId:
             twitter_user_2.key.delete()
             return twitter_user_1.key
         raise EntityDuplicated({"twitter_user_1": twitter_user_1,
                                 "twitter_user_2": twitter_user_2})
     return keys[0]
示例#15
0
class FieldAndString(JsonRpcDispatcher):
    def GET(self, jrequest, jresponse):
        assert isinstance(jrequest, JsonRpcRequest)
        assert isinstance(jresponse, JsonRpcResponse)
        jresponse.setId()
        try:
            field = unicode(jrequest.getPathInfo(3))
            string = unicode(jrequest.getPathInfo(4))
        except Exception, e:
            jresponse.setErrorInvalidParameter(e)
            return
        data_keys = Data.fetchByFieldAndString(field, string)
        if data_keys is None or len(data_keys) == 0:
            raise EntityNotFound()
        for data_key in data_keys:
            data = data_key.get()
            jresponse.addResult(data)
示例#16
0
 def keyByOdenkiId(cls, odenki_id):
     query = cls.queryByOdenkiId(odenki_id)
     keys = query.fetch(keys_only=True, limit=2)
     if len(keys) == 0:
         raise EntityNotFound({"kind": cls.__name__,
                               "odenkiId": odenki_id})
     if len(keys) == 2:
         gmail_user_1 = keys[0].get()
         assert isinstance(gmail_user_1, GmailUser)
         gmail_user_2 = keys[1].get()
         assert isinstance(gmail_user_2, GmailUser)
         if gmail_user_1.gmailId == gmail_user_2.gmailId:
             gmail_user_2.key.delete_async()
             return gmail_user_1.key
         raise EntityDuplicated({"odenkiId": odenki_id,
                                 "gmail_user_1": gmail_user_1,
                                 "gmail_user_2": gmail_user_2})
     return keys[0]
示例#17
0
 def keyByGmailId(cls, gmail_id):
     assert isinstance(gmail_id, str) #user_id() returns str, not unicode
     query = cls.queryByGmailId(gmail_id)
     keys = query.fetch(keys_only=True, limit=2)
     assert isinstance(keys, list)
     if len(keys) == 0:
         raise EntityNotFound({"kind": cls.__name__ , "gmailId":gmail_id})
     if len(keys) == 2:
         gmail_user_1 = keys[0].get()
         assert isinstance(gmail_user_1, GmailUser)
         gmail_user_2 = keys[1].get()
         assert isinstance(gmail_user_2, GmailUser)
         if gmail_user_1.odenkiId == gmail_user_2.odenkiId:
             gmail_user_2.key.delete_async()
             return gmail_user_1.key
         raise EntityDuplicated({"gmail_user_1": gmail_user_1, "gmail_user_2": gmail_user_2,
                                 "gmailId":gmail_id})
     return keys[0]
示例#18
0
 def getByDataId(cls, data_id):
     assert isinstance(data_id, int)
     client = Client()
     data = client.get(cls._getMemcacheKeyByDataId(data_id))
     if data: return data
     query = ndb.Query(kind="Data")
     query = query.filter(cls.dataId == data_id)
     #query = query.order(cls.dataId)
     data_keys = query.fetch(keys_only=True, limit=2)
     if data_keys is None: return
     if len(data_keys) == 0:
         raise EntityNotFound("Data", {"dataId": data_id})
     if len(data_keys) > 1:
         warn(
             "%s Data entities with dataId %s were found" %
             (len(data_keys), data_id), RuntimeWarning)
     data = data_keys[0].get()
     assert isinstance(data, Data)
     client.set(cls._getMemcacheKeyByDataId(data_id), data)
     return data