예제 #1
0
 def create(self, request, *args, **kwargs):
     if not self.versioned_object:
         return HttpResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED)
     serializer = self.get_serializer(data=request.DATA,
                                      files=request.FILES)
     if serializer.is_valid():
         self.pre_save(serializer.object)
         try:
             self.object = serializer.save(
                 force_insert=True, versioned_object=self.versioned_object)
             if serializer.is_valid():
                 self.post_save(self.object, created=True)
                 headers = self.get_success_headers(serializer.data)
                 serializer = SourceVersionDetailSerializer(
                     self.object, context={'request': request})
                 version = self.object
                 export_source.delay(version.id)
                 return Response(serializer.data,
                                 status=status.HTTP_201_CREATED,
                                 headers=headers)
         except IntegrityError, e:
             result = {
                 'error':
                 str(e),
                 'detail':
                 'Source version  \'%s\' already exist. ' %
                 serializer.data.get('id')
             }
             return Response(result, status=status.HTTP_409_CONFLICT)
예제 #2
0
 def handle_export_source_version(self):
     version = self.get_object()
     try:
         export_source.delay(version.id)
         return 202
     except AlreadyQueued:
         return 409
예제 #3
0
 def handle_export_source_version(self):
     version = self.get_object()
     try:
         export_source.delay(version.id)
         return 202
     except AlreadyQueued:
         return 409
예제 #4
0
 def post(self, request, *args, **kwargs):
     version = self.get_object()
     logger.debug('Source Export requested for version %s (post)' % version)
     if version.has_export():
         return HttpResponse(status=204)
     else:
         export_source.delay(version.id)
         return HttpResponse(status=200)
예제 #5
0
 def create(self, request, *args, **kwargs):
     if not self.versioned_object:
         return HttpResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED)
     serializer = self.get_serializer(data=request.DATA, files=request.FILES)
     if serializer.is_valid():
         self.pre_save(serializer.object)
         try:
             self.object = serializer.save(force_insert=True, versioned_object=self.versioned_object)
             if serializer.is_valid():
                 self.post_save(self.object, created=True)
                 headers = self.get_success_headers(serializer.data)
                 serializer = SourceVersionDetailSerializer(self.object, context={'request': request})
                 version = self.object
                 export_source.delay(version.id)
                 return Response(serializer.data, status=status.HTTP_201_CREATED,
                                 headers=headers)
         except IntegrityError, e:
             result = {'error':str(e), 'detail':'Source version  \'%s\' already exist. ' % serializer.data.get('id')}
             return Response(result, status=status.HTTP_409_CONFLICT)
예제 #6
0
    def get(self, request, *args, **kwargs):
        version = self.get_object()
        logger.debug('Export requested for source version %s - Requesting AWS-S3 key' % version)
        key = version.get_export_key()
        url, status = None, 204
        if key:
            logger.debug('   Key retreived for source version %s - Generating URL' % version)
            url, status = key.generate_url(60), 200
            logger.debug('   URL retreived for source version %s - Responding to client' % version)
        else:
            logger.debug('   Key does not exist for source version %s' % version)
            export_source.delay(version.id)
        response = HttpResponse(status=status)
        response['exportURL'] = url

        # Set headers to ensure sure response is not cached by a client
        response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
        response['Pragma'] = 'no-cache'
        response['Expires'] = '0'
        return response
예제 #7
0
    def handle(self, *args, **options):
        user = self.create_admin_user()

        version = 'v2019-07-01'

        source_version = SourceVersion.objects.filter(mnemonic=version)
        if source_version.exists():
            return

        org = self.create_organization(user, 'CIEL')

        source = self.create_source(user, org, 'CIEL')

        demo_file = open('./demo-data/ciel_' + version + '_c2k.json', 'rb')
        importer = ConceptsImporter(source,
                                    demo_file,
                                    user,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr),
                                    save_validation_errors=False)
        importer.import_concepts(**options)

        demo_file = open('./demo-data/ciel_' + version + '_m2k.json', 'rb')
        importer = MappingsImporter(source, demo_file,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr), user)
        importer.import_mappings(**options)

        new_version = SourceVersion.for_base_object(source,
                                                    version,
                                                    released=True)
        SourceVersion.persist_new(new_version,
                                  versioned_object=source,
                                  force_insert=True)
        update_children_for_resource_version.delay(new_version.id, 'source')

        export_source.delay(new_version.id)