Esempio n. 1
0
    def _createStandardActivity(cls, identifier, interfaceAddress, methodUri,
                                temporalContext, timeSeries, valueObjects):
        '''
		@type identifier, methodUri: string; 
		@type valueObjects: a list of ValueObjects.
		others are object 
		'''
        from SmartAPI.model.Activity import Activity
        from SmartAPI.model.Entity import Entity

        if identifier is not None:
            a = Activity(identifier)
        else:
            a = Activity()
        a.setMethod(methodUri)
        e = Entity()
        if valueObjects is not None:
            for vo in valueObjects:
                e.addValueObject(vo)

        a.addEntity(e)
        if interfaceAddress is not None:
            a.addInterface(interfaceAddress)
        if temporalContext is not None:
            a.setTemporalContext(temporalContext)
        if timeSeries is not None:
            a.addTimeSerie(timeSeries)

        return a
Esempio n. 2
0
    def createRequest(cls, key, method, senderIdentity, entity,
                      temporalContext, timeSeries, *valueObjects):
        from SmartAPI.factory.RequestFactory import RequestFactory
        from SmartAPI.model.Request import Request
        from SmartAPI.model.Activity import Activity
        from SmartAPI.model.Entity import Entity
        from SmartAPI.model.ValueObject import ValueObject

        if (senderIdentity is None) or (senderIdentity == ""):
            senderIdentity = cls.defaultIdentity
        r = RequestFactory().create(senderIdentity)

        if entity is None:
            raise NonePointerException(
                "Cannot create read request for null Entity.")

        # TODO should actually search for possible activity identifier uri in object.valueobject.capabilities
        a = Activity()
        r.addActivity(a)
        if key is not None:
            a.encrypt(key)

        a.setMethod(method)

        # 		if entity.hasIdentifierUri():
        # 			e = Entity(entity.getIdentifierUri())
        # 		else:
        # 			e = Entity()
        e = entity
        e.setValueObjects([])

        if temporalContext is not None:
            a.setTemporalContext(temporalContext)

        if timeSeries is not None:
            a.addTimeSerie(timeSeries)

        a.addEntity(e)

        if (valueObjects is None
                or len(valueObjects) == 0) and method == RESOURCE.WRITE:
            valueObjects = entity.getValueObjects()

        if valueObjects is not None:
            for v in valueObjects:
                #  				vo = ValueObject(quantity = v.getQuantity(), unit = v.getUnit(), dataType = v.getDataType(), description = v.getDescription())
                #  				if v.hasIdentifierUri():
                #  					vo.setIdentifierUri(v.getIdentifierUri())
                #  				if method == RESOURCE.WRITE:
                #  					vo.setValue(v.getValue())
                # 				e.addValueObject(vo)
                e.addValueObject(v)

        return r