Esempio n. 1
0
    def _tellObserver(self, tuple_, tuples, session, payloadFilt):
        tupleSelector = TupleSelector(EventDBPropertyTable.tupleName(), {})
        self._tupleDataObserver.notifyOfTupleUpdate(tupleSelector)

        tupleSelector = TupleSelector(EventDBPropertyTuple.tupleName(), {})
        self._tupleDataObserver.notifyOfTupleUpdate(tupleSelector)

        return True
Esempio n. 2
0
    def importInternalGroups(self, importHash: str, groupsVortexMsg: bytes):
        #: result: InternalGroupImportResultTuple
        result = yield importInternalGroups.delay(importHash, groupsVortexMsg)

        self._tupleDataObserver.notifyOfTupleUpdate(
            TupleSelector(InternalGroupTuple.tupleName(), {}))

        self._tupleDataObserver.notifyOfTupleUpdate(
            TupleSelector(GroupDetailTuple.tupleName(), {}))

        return result
Esempio n. 3
0
    def importInternalUsers(self, importHash: str, usersVortexMsg: bytes):
        #: result: InternalUserImportResultTuple
        result = yield importInternalUsers.delay(importHash, usersVortexMsg)

        self._tupleDataObserver.notifyOfTupleUpdate(
            TupleSelector(InternalUserTuple.tupleName(), {}))

        self._tupleDataObserver.notifyOfTupleUpdate(
            TupleSelector(UserDetailTuple.tupleName(), {}))

        self._tupleDataObserver.notifyOfTupleUpdate(
            TupleSelector(UserListItemTuple.tupleName(), {}))

        return result
    def replaceProperties(self, modelSetKey: str,
                          propertiesEncodedPayload: str) -> Deferred:
        yield runPyInPg(logger,
                        self._dbSessionCreator,
                        EventDBImportPropertiesInPgTask.replaceProperties,
                        None,
                        modelSetKey,
                        propertiesEncodedPayload)

        tupleSelector = TupleSelector(EventDBPropertyTable.tupleName(), {})
        self._tupleObservable.notifyOfTupleUpdate(tupleSelector)

        tupleSelector = TupleSelector(EventDBPropertyTuple.tupleName(), {})
        self._tupleObservable.notifyOfTupleUpdate(tupleSelector)
    def _loadTraceConfigIntoCache(
        self,
        modelSetKey: str,
        traceConfigTuples: List[GraphDbTraceConfigTuple],
        deletedTraceConfigKeys: Set[str] = set()):
        subCache = self._cache[modelSetKey]

        traceKeysUpdated: Set[str] = {
            traceConfig.key
            for traceConfig in traceConfigTuples
        }

        deletedTraceConfigKeys -= traceKeysUpdated

        for traceConfig in traceConfigTuples:
            subCache[traceConfig.key] = traceConfig

        for traceConfigKey in deletedTraceConfigKeys:
            if traceConfigKey in subCache:
                subCache.pop(traceConfigKey)

        logger.debug(
            "Received TraceConfig updates from server,"
            "%s %s removed, %s added/updated", modelSetKey,
            len(deletedTraceConfigKeys), len(traceKeysUpdated))

        self._tupleObservable.notifyOfTupleUpdate(
            TupleSelector(GraphDbTraceConfigTuple.tupleType(),
                          dict(modelSetKey=modelSetKey)))
 def _tellObserver(self, tuple_, tuples, session, payloadFilt):
     selector = {}
     # Copy any filter values into the selector
     # selector["lookupName"] = payloadFilt["lookupName"]
     tupleSelector = TupleSelector(StringIntTuple.tupleName(), selector)
     self._tupleDataObserver.notifyOfTupleUpdate(tupleSelector)
     return True
    def _processCreateBranch(self, action: CreateBranchActionTuple):
        try:
            # Perform update using SQLALchemy
            dbSession = self._dbSessionCreator()

            dbItem = None
            mergeItem = BranchDetailTable.fromTuple(action.branchDetail)

            if action.branchDetail.id is not None:
                rows = dbSession.query(BranchDetailTable) \
                    .filter(BranchDetailTable.id == action.branchDetailId) \
                    .all()
                if rows:
                    dbItem = rows[0]
                    dbItem.merge(mergeItem)

            if not dbItem:
                newItem = BranchDetailTable.fromTuple(action.branchDetail)
                dbSession.add(newItem)

            dbSession.commit()

            # Notify the observer of the update
            # This tuple selector must exactly match what the UI observes
            tupleSelector = TupleSelector(
                BranchDetailTuple.tupleName(),
                dict(modelSetKey=newItem.modelSetKey))
            self._tupleObservable.notifyOfTupleUpdate(tupleSelector)

        except Exception as e:
            logger.exception(e)

        finally:
            # Always close the dbSession after we create it
            dbSession.close()
Esempio n. 8
0
    def processTupleAction(self, tupleAction: TupleActionABC) -> Deferred:
        yield None

        assert isinstance(tupleAction, BranchLiveEditTupleAction), \
            "tupleAction is not BranchLiveEditTupleAction"

        # Ignore the updates
        if tupleAction.actionType == BranchLiveEditTupleAction.EDITING_STARTED:
            return

        coordSetId = tupleAction.branchTuple.coordSetId
        key = tupleAction.branchTuple.key

        tuple_ = BranchLiveEditTuple()
        tuple_.branchTuple = tupleAction.branchTuple
        tuple_.updatedByUser = tupleAction.updatedByUser
        tuple_.uiUpdateDate = tupleAction.dateTime
        tuple_.serverUpdateDate = datetime.now(pytz.utc)
        tuple_.updateFromActionType = tupleAction.actionType

        self._cache[(coordSetId, key)] = tuple_

        self._tupleObservable.notifyOfTupleUpdate(
            TupleSelector(BranchLiveEditTuple.tupleName(), {
                "coordSetId": coordSetId,
                "key": key
            })
        )
Esempio n. 9
0
    def _processNewTuples(self, lookupTuples):

        if not lookupTuples:
            return

        firstTupleType = lookupTuples[0].tupleType()
        if DispLevel.tupleType() == firstTupleType:
            self._levelLookups = lookupTuples

        elif DispLayer.tupleType() == firstTupleType:
            self._layerLookups = lookupTuples

        elif DispColor.tupleType() == firstTupleType:
            self._colorLookups = lookupTuples

        elif DispLineStyle.tupleType() == firstTupleType:
            self._lineStyleLookups = lookupTuples

        elif DispTextStyle.tupleType() == firstTupleType:
            self._textStyleLookups = lookupTuples

        else:
            raise NotImplementedError("Cache not implemented for %s" %
                                      firstTupleType)

        self._tupleObservable.notifyOfTupleUpdate(
            TupleSelector(firstTupleType, {}))
Esempio n. 10
0
    def _processNewTuples(self, coordSetTuples):
        if not coordSetTuples:
            return

        self._coordSetCache = {c.id: c for c in coordSetTuples}

        self._tupleObservable.notifyOfTupleUpdate(
            TupleSelector(ModelCoordSet.tupleName(), {}))
Esempio n. 11
0
    def _forceLogout(self, ormSession, userName, deviceToken):

        ormSession.query(UserLoggedIn) \
            .filter(UserLoggedIn.userName == userName) \
            .filter(UserLoggedIn.deviceToken == deviceToken) \
            .delete(synchronize_session=False)

        self._clientTupleObservable.notifyOfTupleUpdate(
            TupleSelector(UserLoggedInTuple.tupleType(),
                          selector=dict(deviceToken=deviceToken)))
    def _afterCommit(self, tuple_, tuples, session, payloadFilt):
        selector = {}
        # Copy any filter values into the selector
        selector["likeTitle"] = payloadFilt["likeTitle"]
        tupleSelector = TupleSelector(InternalUserTuple.tupleName(), selector)
        self._tupleDataObserver.notifyOfTupleUpdate(tupleSelector)

        self._tupleDataObserver.notifyOfTupleUpdate(
            TupleSelector(UserDetailTuple.tupleName(), {}))

        self._tupleDataObserver.notifyOfTupleUpdate(
            TupleSelector(UserListItemTuple.tupleName(), {}))

        for tuple in tuples:
            tuple.groupIds = []
            for group in tuple.groups:
                tuple.groupIds.append(group.id)

        return True
Esempio n. 13
0
    def start(self):
        (self._tupleObserver.subscribeToTupleSelector(
            TupleSelector(DispLevel.tupleType(),
                          {})).subscribe(self._processNewTuples))

        (self._tupleObserver.subscribeToTupleSelector(
            TupleSelector(DispLayer.tupleType(),
                          {})).subscribe(self._processNewTuples))

        (self._tupleObserver.subscribeToTupleSelector(
            TupleSelector(DispColor.tupleType(),
                          {})).subscribe(self._processNewTuples))

        (self._tupleObserver.subscribeToTupleSelector(
            TupleSelector(DispLineStyle.tupleType(),
                          {})).subscribe(self._processNewTuples))

        (self._tupleObserver.subscribeToTupleSelector(
            TupleSelector(DispTextStyle.tupleType(),
                          {})).subscribe(self._processNewTuples))
    def _removeTraceConfigFromCache(self, modelSetKey: str,
                                    traceConfigKeys: List[str]):
        subCache = self._cache[modelSetKey]

        logger.debug("Received TraceConfig deletes from server, %s %s removed",
                     modelSetKey, len(traceConfigKeys))

        for traceConfigKey in traceConfigKeys:
            if traceConfigKey in subCache:
                subCache.pop(traceConfigKey)

        self._tupleObservable.notifyOfTupleUpdate(
            TupleSelector(GraphDbTraceConfigTuple.tupleType(),
                          dict(modelSetKey=modelSetKey)))
Esempio n. 15
0
    def login(self, loginTuple: UserLoginAction):
        """
        Returns Deferred[UserLoginResponseTuple]

        """
        loginResponse = None
        try:
            loginResponse = yield self._loginInDb(loginTuple)

            if loginTuple.isFieldService:
                yield self._fieldServiceHookApi.callLoginHooks(loginResponse)

        # except UserAlreadyLoggedInError as e:
        #     pass
        #
        # except DeviceAlreadyLoggedInError as e:
        #     pass
        #
        # except UserIsNotLoggedInToThisDeviceError as e:
        #     pass

        except Exception as e:

            # Log the user out again if the hooks fail
            logoutTuple = UserLogoutAction(userName=loginTuple.userName,
                                           deviceToken=loginTuple.deviceToken)

            # Force logout, we don't care if it works or not.
            try:
                yield self._logoutInDb(logoutTuple)
            except UserIsNotLoggedInToThisDeviceError:
                pass

            raise e

        self._clientTupleObservable.notifyOfTupleUpdate(
            TupleSelector(UserLoggedInTuple.tupleType(),
                          selector=dict(deviceToken=loginTuple.deviceToken)))

        self._adminTupleObservable.notifyOfTupleUpdateForTuple(
            LoggedInUserStatusTuple.tupleType())

        return loginResponse
Esempio n. 16
0
    def updateBranch(self, branchTuple: BranchTuple):
        ts = TupleSelector(
            BranchLiveEditTuple.tupleType(), dict(
                coordSetId=branchTuple.coordSetId,
                key=branchTuple.key
            )
        )

        if not self._tupleObservable.hasTupleSubscribers(ts):
            return

        cacheKey = (branchTuple.coordSetId, branchTuple.key)

        liveEditTuple = BranchLiveEditTuple()
        liveEditTuple.branchTuple = branchTuple
        liveEditTuple.uiUpdateDate = branchTuple.updatedDate
        liveEditTuple.serverUpdateDate = datetime.now(pytz.utc)
        liveEditTuple.updateFromActionType = BranchLiveEditTuple.EDITING_SAVED
        self._cache[cacheKey] = liveEditTuple
    def __processUpdateFromClient(self,
                                  tupleAction: TupleActionABC) -> Deferred:

        dbSession = self._dbSessionCreator()
        try:
            encodedPayload = yield Payload(tuples=[tupleAction.branchTuple]) \
                .toEncodedPayloadDefer()

            yield updateBranches.delay(tupleAction.modelSetId, encodedPayload)

            # Load the branch from the DB and tell the LiveDb update
            # that there is an update.
            branchIndex = dbSession.query(BranchIndex) \
                .filter(BranchIndex.coordSetId == tupleAction.branchTuple.coordSetId) \
                .filter(BranchIndex.key == tupleAction.branchTuple.key) \
                .one()

            branchTuple = BranchTuple.loadFromJson(branchIndex.packedJson,
                                                   branchIndex.importHash,
                                                   branchIndex.importGroupHash)

            self._liveEditController.updateBranch(branchTuple)

            self._updateBranchKeyToIdMap()

            self._tupleObservable.notifyOfTupleUpdate(
                TupleSelector(
                    BranchLiveEditTuple.tupleType(),
                    dict(coordSetId=tupleAction.branchTuple.coordSetId,
                         key=tupleAction.branchTuple.key)))

        except Exception as e:
            logger.exception(e)

        finally:
            dbSession.close()
Esempio n. 18
0
 def _notifyObserver(self, tupleName: str, userId: str) -> None:
     self._tupleObserver.notifyOfTupleUpdate(
         TupleSelector(tupleName, {"userId": userId}))
Esempio n. 19
0
 def _sendLogoutUpdate(self, deviceToken: str):
     self._clientTupleObservable.notifyOfTupleUpdate(
         TupleSelector(UserLoggedInTuple.tupleType(),
                       selector=dict(deviceToken=deviceToken)))
Esempio n. 20
0
 def _tellObserver(self, tuple_, tuples, session, payloadFilt):
     self._tupleDataObserver.notifyOfTupleUpdate(
         TupleSelector(SearchObjectTypeTuple.tupleName(), {}))
     return True
Esempio n. 21
0
 def _afterCommit(self, tuple_, tuples, session, payloadFilt):
     self._tupleDataObserver.notifyOfTupleUpdate(
         TupleSelector(UserLoginUiSettingTuple.tupleName(), {}))
     return True
 def _tellObserver(self, tuple_, tuples, session, payloadFilt):
     self._tupleDataObserver.notifyOfTupleUpdate(
         TupleSelector(DocDbPropertyTuple.tupleName(), {})
     )
     return True
 def _updateBranchKeyToIdMap(self):
     self._tupleObservable.notifyOfTupleUpdate(
         TupleSelector(BranchKeyToIdMapTuple.tupleType(), {}))
 def _tellObserver(self, tuple_, tuples, session, payloadFilt):
     self._tupleObservable.notifyOfTupleUpdate(
         TupleSelector(SettingProperty.tupleName(), {}))
     return True
Esempio n. 25
0
 def _tellObserver(self, tuple_, tuples, session, payloadFilt):
     self._tupleDataObserver.notifyOfTupleUpdate(
         TupleSelector(InternalGroupTuple.tupleName(), {}))
     self._tupleDataObserver.notifyOfTupleUpdate(
         TupleSelector(GroupDetailTuple.tupleName(), {}))
     return True
Esempio n. 26
0
 def start(self):
     (self._tupleObserver
      .subscribeToTupleSelector(TupleSelector(ModelSet.tupleName(), {}))
      .subscribe(self._processNewTuples))
import logging
from datetime import datetime

import pytz
from twisted.internet import task

from vortex.DeferUtil import deferToThreadWrapWithLogger
from vortex.Payload import Payload
from vortex.TupleSelector import TupleSelector
from vortex.handler.TupleDataObservableHandler import TuplesProviderABC, \
    TupleDataObservableHandler
from vortex.test.TestTuple import TestTuple
from vortex.test.TupleDataForTest import makeTestTupleData

logger = logging.getLogger(__name__)
testTuples1Selector = TupleSelector("testTuples1", {"count": 4})

testTuples2Selector = TupleSelector("testTuples2", {"count": 7})


class TestTupleProvider(TuplesProviderABC):
    @deferToThreadWrapWithLogger(logger)
    def makeVortexMsg(self, filt: dict, tupleSelector: TupleSelector) -> bytes:
        count = tupleSelector.selector["count"]
        tuples = makeTestTupleData(count)

        for t in tuples:
            t.aDate = datetime.now(pytz.utc)
            t.aDict = tupleSelector.selector
            t.aString = tupleSelector.name