# Path: cognitive/app/models.py
# class Workflow(models.Model):
#     experiment = models.OneToOneField(Experiment)
#     graph_data = models.CharField(max_length=100)
# 
# class Experiment(models.Model):
#     EXPERIMENT_STATUS = (
#         ('Stop', ' Saved as stop'),
#         ('InComplete', 'More information required'),
#         ('InExecution', 'Execution started'),
#         ('Error', ' Error when executed'),
#         ('Completed', 'Executed Successfully'),
#     )
#     user = models.ForeignKey(User)
#     name = models.CharField(max_length=50)
#     status = models.CharField(max_length=50, choices=EXPERIMENT_STATUS, default='Stop')
#     created_time = models.DateTimeField(auto_now=True)
#     modified_time = models.DateTimeField(auto_now=True)
#     execution_start_time = models.DateTimeField(blank=True, null=True)
#     execution_end_time = models.DateTimeField(blank=True, null=True)
#     component_start_id = models.IntegerField(blank=True, null=True)
# 
#     class Meta:
#         ordering = ['-modified_time']
# 
# Path: cognitive/app/serializers.py
# class WorkflowSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Workflow
# 
# Path: cognitive/app/views.py
# def send_response(method, serializer):
#     if method == 'GET':
#         return Response(serializer.data)
#     elif method == 'POST':
#         if serializer.is_valid():
#             return Response(serializer.data, status=status.HTTP_201_CREATED)
#         else:
#             return Response(
#                 serializer.errors, status=status.HTTP_400_BAD_REQUEST)
#     elif method == 'PUT':
#         if serializer.is_valid():
#             return Response(serializer.data)
#         else:
#             return Response(
#                 serializer.errors, status=status.HTTP_400_BAD_REQUEST)
#     elif method == 'DELETE':
#         return Response(status=status.HTTP_204_NO_CONTENT)


from ..models import Workflow, Experiment
from ..serializers import WorkflowSerializer
from ..views import send_response
from rest_framework import viewsets
from rest_framework.renderers import JSONRenderer
import json
        except Workflow.DoesNotExist:
            print "Workflow is not yet created. Creating one"
            serializer = WorkflowSerializer(data=request.data)
            if serializer.is_valid():
                serializer.save()
            return send_response(request.method, serializer)
        else:
            print "Workflow already exists. Modifying one"
            serializer = WorkflowSerializer(workflow, data=request.data)
            if serializer.is_valid():
                serializer.save()
            return send_response(request.method, serializer)

    def update(self, request, pk=None):
        """
        Update a workflow for an experiment
        ---
        request_serializer: WorkflowSerializer
        """
        exp = Workflow.objects.get(pk=pk)
        serializer = WorkflowSerializer(exp, data=request.data)
        if serializer.is_valid():
            serializer.save()
        return send_response(request.method, serializer)

    def destroy(self, request, pk=None):
        """
        Delete a workflow for an experiment
        ---
        """

# Path: cognitive/app/models.py
# class Workflow(models.Model):
#     experiment = models.OneToOneField(Experiment)
#     graph_data = models.CharField(max_length=100)
# 
# class Experiment(models.Model):
#     EXPERIMENT_STATUS = (
#         ('Stop', ' Saved as stop'),
#         ('InComplete', 'More information required'),
#         ('InExecution', 'Execution started'),
#         ('Error', ' Error when executed'),
#         ('Completed', 'Executed Successfully'),
#     )
#     user = models.ForeignKey(User)
#     name = models.CharField(max_length=50)
#     status = models.CharField(max_length=50, choices=EXPERIMENT_STATUS, default='Stop')
#     created_time = models.DateTimeField(auto_now=True)
#     modified_time = models.DateTimeField(auto_now=True)
#     execution_start_time = models.DateTimeField(blank=True, null=True)
#     execution_end_time = models.DateTimeField(blank=True, null=True)
#     component_start_id = models.IntegerField(blank=True, null=True)
# 
#     class Meta:
#         ordering = ['-modified_time']
# 
# Path: cognitive/app/serializers.py
# class WorkflowSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Workflow
# 
# Path: cognitive/app/views.py
# def send_response(method, serializer):
#     if method == 'GET':
#         return Response(serializer.data)
#     elif method == 'POST':
#         if serializer.is_valid():
#             return Response(serializer.data, status=status.HTTP_201_CREATED)
#         else:
#             return Response(
#                 serializer.errors, status=status.HTTP_400_BAD_REQUEST)
#     elif method == 'PUT':
#         if serializer.is_valid():
#             return Response(serializer.data)
#         else:
#             return Response(
#                 serializer.errors, status=status.HTTP_400_BAD_REQUEST)
#     elif method == 'DELETE':
#         return Response(status=status.HTTP_204_NO_CONTENT)


# Path: cognitive/app/api/workflows.py
from ..models import Workflow, Experiment
from ..serializers import WorkflowSerializer
from ..views import send_response
from rest_framework import viewsets
from rest_framework.renderers import JSONRenderer
import json

        except Workflow.DoesNotExist:
            print "Workflow is not yet created. Creating one"
            serializer = WorkflowSerializer(data=request.data)
            if serializer.is_valid():
                serializer.save()
            return send_response(request.method, serializer)
        else:
            print "Workflow already exists. Modifying one"
            serializer = WorkflowSerializer(workflow, data=request.data)
            if serializer.is_valid():
                serializer.save()
            return send_response(request.method, serializer)

    def update(self, request, pk=None):
        """
        Update a workflow for an experiment
        ---
        request_serializer: WorkflowSerializer
        """
        exp = Workflow.objects.get(pk=pk)
        serializer = WorkflowSerializer(exp, data=request.data)
        if serializer.is_valid():
            serializer.save()
        return send_response(request.method, serializer)

    def destroy(self, request, pk=None):
        """
        Delete a workflow for an experiment
        ---
        """

        exp = Workflow.objects.get(pk=pk)