Esempio n. 1
0
 def get_operation_for_type(self, operation_name, object_type):
     try:
         object_type = FeatureModel if issubclass(object_type, FeatureModel) else object_type
         operations_for_object_type = operations.OPERATIONS_BY_TYPE[object_type]
         return operations_for_object_type[operation_name]
     except KeyError:
         raise InvalidOperationException(operation_name + " isn't an operation for " + object_type)
Esempio n. 2
0
    def get_operation_return_type(self, operation_snippet, current_return_type=FeatureModel):
        operation_name = self.get_operation_name_from_path(operation_snippet)

        if self.is_operation_for_type(operation_name, current_return_type):
            operation = self.get_operation_for_type(operation_name, current_return_type)
        else:
            raise InvalidOperationException(operation_snippet + " isn't a valid operation")

        rem_oper_snippert = operation.get_remaining_operations_snippet(operation_snippet)
        if rem_oper_snippert:
            return self.get_operation_return_type(rem_oper_snippert, current_return_type=operation.return_type)
        return operation.return_type
Esempio n. 3
0
    def execute_operation(self, object, operation_snippet):

        operation_name = self.get_operation_name_from_path(operation_snippet)
        if self.is_operation_for_type(operation_name, type(object)):
            operation = self.get_operation_for_type(operation_name, type(object))
            parameters_converted = operation.convert_parameters(operation_snippet)
            if parameters_converted == None:
                try:
                    operation_result = getattr(object, operation_name)()
                except TypeError:
                    operation_result = getattr(object, operation_name)
            else:
                fcm_instance = FeatureCollectionModel()
                return getattr(fcm_instance, operation_name)(self.serializer_class.Meta.model, parameters_converted[0])
                #operation_result = getattr(FeatureCollectionModel(), operation_name)(*parameters_converted)
                #return operation_result
        else:
            raise InvalidOperationException(operation_snippet + " isn't a valid operation")
Esempio n. 4
0
    def execute_operation(self, object, operation_snippet):
        operation_name = self.get_operation_name_from_path(operation_snippet)
        if self.is_operation_for_type(operation_name, type(object)):
            operation = self.get_operation_for_type(operation_name, type(object))
            parameters_converted = operation.convert_parameters(operation_snippet)
            if parameters_converted == None:
                try:
                    operation_result = getattr(object, operation_name)()
                except TypeError:
                    operation_result = getattr(object, operation_name)
            else:
                operation_result = getattr(object, operation_name)(*parameters_converted)
        else:
            raise InvalidOperationException(operation_snippet + " isn't a valid operation")

        rem_oper_snippert = operation.get_remaining_operations_snippet(operation_snippet)
        if rem_oper_snippert:
            return self.execute_operation(operation_result, rem_oper_snippert)
        return (operation_name, operation_result)