コード例 #1
0
ファイル: project.py プロジェクト: andermy/tornado-ifc
 def post(self, productType):
     try:
         #new_project = UserSchema().load(self.data_received())
         new_element = self.data_received()
         space = self.get_argument('space', None)
         system = self.get_argument('system', None)
     except ValidationError as err:
         logger.error(err)
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason=str(err))
     else:
         try:
             productType = m.ProductType.objects.get(
                 {'_id': ObjectId(productType)})
             if space is not None:
                 space = m.IfcSpace.objects.get({'_id': ObjectId(space)})
             if system is not None:
                 system = m.IfcSystem.objects.get({'_id': ObjectId(system)})
             response = m.IfcProduct(
                 name=new_element['name'],
                 buildingType=new_element['building_type'],
                 area=new_element['area']).save()
         except Exception as ex:
             logger.error(ex)
             raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                              reason=str(ex))
         else:
             self.write_response(status_code=HTTPStatus.CREATED,
                                 result=json.loads(
                                     json_util.dumps(
                                         response.to_son().to_dict())))
コード例 #2
0
ファイル: calculation.py プロジェクト: andermy/tornado-ifc
    def get(self, key):
        try:
            df = DataFrame.objects.get({'_id': ObjectId(key)})

        except ValueError:
            raise ErrorThrow(
                status_code=HTTPStatus.BAD_REQUEST,
                reason='no DataFrame found with id {}'.format(key))
        except Exception as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                             reason=str(err))

        else:
            try:
                if df.from_model == True:
                    version = v.VersionResolver(versionObject=df.version)
                    table = s.Table(version.get_latest_version())
                    table.create_from_ifc_products()
                    result = table.to_react_table_json()
                    response = json.loads(json_util.dumps(result.values()))
                    self.write_response(status_code=HTTPStatus.OK,
                                        result=response)
                else:
                    table = s.Table()
            except ValueError:
                raise ErrorThrow(
                    status_code=HTTPStatus.BAD_REQUEST,
                    reason='no DataFrame found with id {}'.format(key))
            except Exception as err:
                logger.error(err)
                raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                                 reason=str(err))
コード例 #3
0
ファイル: project.py プロジェクト: andermy/tornado-ifc
 def delete(self, key):
     try:
         m.Project.objects.get({'_id': ObjectId(key)}).delete()
     except ValueError:
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason='no project found with id {}'.format(key))
     except Exception as ex:
         logger.error(ex)
         raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                          reason=str(ex))
     else:
         self.write_response(status_code=HTTPStatus.OK,
                             message='the project was successfully deleted')
コード例 #4
0
 def delete(self, key):
     try:
         self.collection.delete_one(document_id=key)
     except ValueError:
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason='no project found with id {}'.format(key))
     except Exception as ex:
         logger.error(ex)
         raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                          reason=str(ex))
     else:
         self.write_response(status_code=HTTPStatus.OK,
                             message='the project was successfully deleted')
コード例 #5
0
 def get(self, project):
     try:
         result = m.IfcFile.objects.raw({'project': ObjectId(project)}).values()
     except ValueError:
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason='no file in project')
     except Exception as err:
         logger.error(err)
         raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                          reason=str(err))
     
     self.write_response(status_code=HTTPStatus.OK,
                             result=result.values())
コード例 #6
0
ファイル: project.py プロジェクト: andermy/tornado-ifc
    def get(self, version):
        try:
            q = {"version": ObjectId(version)}
            result = m.IfcSpace.objects.raw({q})

        except ValueError:
            raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                             reason='no Storey found')
        except Exception as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                             reason=str(err))
        else:
            self.write_response(status_code=HTTPStatus.OK, result=result)
コード例 #7
0
 def put(self, key):
     try:
         response = self.collection.update_one(document_id=key,
                                                     document=self.data_received())
     except ValueError:
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                              reason='no project found with id {}'.format(key))
     except Exception as ex:
             logger.error(ex)
             raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                              reason=str(ex))
     else:
         self.write_response(status_code=HTTPStatus.OK,
                             result=response)
コード例 #8
0
 def get(self, version):
     try:
         q = {"version": ObjectId(version)}
         result = self.collection.query(q)
         
     except ValueError:
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason='no product found with id {}'.format(project))
     except Exception as err:
         logger.error(err)
         raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                          reason=str(err))
     else:
         self.write_response(status_code=HTTPStatus.OK,
                             result=result)
コード例 #9
0
 def post(self):
     fileinfo = self.request.files['filearg'][0]
     filename = fileinfo['filename']
     
     version = self.get_body_argument("version", default=None, strip=False)
     vr = v.VersionResolver(version)
     new_version_object = vr.create_new_version()
     
     try:
         with open(os.path.join(self.upload_path, filename), 'wb') as fh:
             fh.write(fileinfo['body'])
             logging.info("%s uploaded %s, saved as %s",
                      str(self.request.remote_ip),
                      str(fileinfo['filename']),
                      filename)
     except IOError as e:
         logging.error("Failed to write file due to IOError %s", str(e))
     else:
         try:
             new_file = m.IfcFile(filename= filename, path= os.path.join(self.upload_path, filename), version= new_version_object, created= datetime.datetime.now(), project=new_version_object.project).save()
         except Exception as ex:
             logger.error(ex)
             raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                              reason=str(ex))
         else:
             self.new_file = new_file
             res = yield self.background_task(new_file)
             self.write_response(status_code=HTTPStatus.CREATED,
                                 result=new_file.values())
コード例 #10
0
 def get(self, key):
     try:
         if not key:
             result = self.collection.find_all()
         else:
             result = self.collection.find_one(document_id=str(key))
     except ValueError:
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason='no project found with id {}'.format(key))
     except Exception as err:
         logger.error(err)
         raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                          reason=str(err))
     
     self.write_response(status_code=HTTPStatus.OK,
                             result=result)
コード例 #11
0
 def put(self, key):
     try:
         new_element = self.data_received()
         old_element = m.ProductType.objects.get({'_id': ObjectId(key)})
         old_element.name = new_element['name']
         old_element.producer = new_element['producer']
         old_element.save()
     except ValueError:
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                              reason='no productType found with id {}'.format(key))
     except Exception as ex:
             logger.error(ex)
             raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                              reason=str(ex))
     else:
         self.write_response(status_code=HTTPStatus.OK,
                             result=json.loads(json_util.dumps(old_element.to_son().to_dict())))
コード例 #12
0
ファイル: project.py プロジェクト: andermy/tornado-ifc
    def get(self, version):
        try:
            storey = self.get_argument('storey', None)
            q = {"version": ObjectId(version)}
            if storey is not None:
                q['storey'] = int(storey)
            result = m.IfcProduct.objects.raw({q})

        except ValueError:
            raise ErrorThrow(
                status_code=HTTPStatus.BAD_REQUEST,
                reason='no product found with id {}'.format(project))
        except Exception as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                             reason=str(err))
        else:
            self.write_response(status_code=HTTPStatus.OK, result=result)
コード例 #13
0
ファイル: project.py プロジェクト: andermy/tornado-ifc
    def get(self, key):
        try:
            if not key:
                result = m.Project.objects.all()
                response = result.values()
            else:
                result = m.Project.objects.get({'_id': ObjectId(key)})
                response = json.loads(
                    json_util.dumps(result.to_son().to_dict()))
        except ValueError:
            raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                             reason='no project found with id {}'.format(key))
        except Exception as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                             reason=str(err))

        self.write_response(status_code=HTTPStatus.OK, result=response)
コード例 #14
0
ファイル: project.py プロジェクト: andermy/tornado-ifc
    def get(self, project):
        try:
            branch = self.get_argument('branch', 'master')
            version = self.get_argument('version', None)
            q = {'project': ObjectId(project), 'branch': branch}
            if version is not None:
                q['version'] = version
            result = m.Version.objects.raw({q}).values()
        except ValueError:
            raise ErrorThrow(
                status_code=HTTPStatus.BAD_REQUEST,
                reason='no project found with id {}'.format(project))
        except Exception as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                             reason=str(err))

        self.write_response(status_code=HTTPStatus.OK, result=result)
コード例 #15
0
    def background_task(self, new_file):
        try:
            if self.new_file.filename.endswith('.ifc'):
                print("It's ifc")
                #ifcData = IfcFile(new_file)

        except Exception as ex:
            logger.error(ex)
            raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                                    reason=str(ex))
コード例 #16
0
    def post(self, key):
        try:
            new_project = self.data_received()

        except ValidationError as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                             reason=str(err))
        else:
            try:
                response = self.collection.insert_one(data=new_project)
            except Exception as ex:
                logger.error(ex)
                raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                                 reason=str(ex))
            else:
                new_project = self.collection.find_one(document_id=response)
                self.write_response(status_code=HTTPStatus.CREATED,
                                    result=new_project)
コード例 #17
0
    def post(self, key):
        try:
            #new_project = UserSchema().load(self.data_received())
            new_element = self.data_received()

        except ValidationError as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                             reason=str(err))
        else:
            try:
                response = m.ProductType(name=new_element['name'], productType=new_element['producer']).save()
            except Exception as ex:
                logger.error(ex)
                raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                                 reason=str(ex))
            else:
                self.write_response(status_code=HTTPStatus.CREATED,
                                    result= json.loads(json_util.dumps(response.to_son().to_dict())))
コード例 #18
0
 def post(self, version):
     try:
         new_DataFrame = self.data_received()
         vr = m.Version.objects.get({'_id': ObjectId(version)})
         from_model = self.get_argument('from_model', None)
         print(from_model)
     except ValidationError as err:
         logger.error(err)
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason=str(err))
     else:
         try:
             response = m.DataFrame(from_model=from_model, name=new_DataFrame['name'], version=vr).save()
         except Exception as ex:
             logger.error(ex)
             raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                              reason=str(ex))
         else:
             self.write_response(status_code=HTTPStatus.CREATED,
                                 result=json.loads(json_util.dumps(response.to_son().to_dict())))
コード例 #19
0
ファイル: project.py プロジェクト: andermy/tornado-ifc
 def post(self, project):
     #Only for creating new branch-version
     try:
         branch = self.get_argument('branch', 'master')
         vs = v.VersionResolver(project=project, branch=branch)
         new_version = vs.create_new_version()
     except ValidationError as err:
         logger.error(err)
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason=str(err))
     else:
         try:
             response = json.loads(
                 json_util.dumps(new_version.to_son().to_dict()))
         except Exception as ex:
             logger.error(ex)
             raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                              reason=str(ex))
         else:
             self.write_response(status_code=HTTPStatus.CREATED,
                                 result=response)
コード例 #20
0
 def post(self, project):
     #Only for creating new branch-version
     try:
         new_version = self.data_received()
         new_version['version'] = 0
         new_version['project'] = ObjectId(project)
     except ValidationError as err:
         logger.error(err)
         raise ErrorThrow(status_code=HTTPStatus.BAD_REQUEST,
                          reason=str(err))
     else:
         try:
             response = self.collection.insert_one(data=new_version)
         except Exception as ex:
             logger.error(ex)
             raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                              reason=str(ex))
         else:
             new_version = self.collection.find_one(document_id=response)
             self.write_response(status_code=HTTPStatus.CREATED,
                                 result=new_version)
コード例 #21
0
ファイル: calculation.py プロジェクト: andermy/tornado-ifc
    def get(self, key):
        try:
            if key:
                result = Calculation.objects.get({'_id': ObjectId(key)})
                response = json.loads(
                    json_util.dumps(result.to_son().to_dict()))
            else:
                dataframe = self.get_argument('dataframe', None)
                result = Calculation.objects.raw(
                    {'dataframe': ObjectId(dataframe)})
                response = result.values()

        except ValueError:
            raise ErrorThrow(
                status_code=HTTPStatus.BAD_REQUEST,
                reason='no calculation found with id {}'.format(key))
        except Exception as err:
            logger.error(err)
            raise ErrorThrow(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
                             reason=str(err))

        self.write_response(status_code=HTTPStatus.OK, result=response)