예제 #1
0
    def post(self):
        """
        create a new resource set
        :return: JSON {message:"", status_code:""}
        """
        args = self.reqparse.parse_args()
        parts = args['Authorization'].split()
        user_id = DBHelper.get_user_id(parts[1])

        data = request.get_json()

        if not 'rs_id' or not 'categories' in data:
            raise CustomError('Invalid parameter, <rs_id> and <categories> required', status_code=400)

        if type(data['categories']) is not list:
            raise CustomError('the type of "categories" is a list', status_code=400)

        if DBHelper.check_rs_id(data['rs_id']) is not None:
            raise CustomError(('{0} has been created').format(data['rs_id']), status_code=409)

        DBHelper.set_resource_set(user_id, data['rs_id'], data['categories'])

        # app_log.info(('new resource set {0} created').format(data['rs_id']), extra={'sender': 'DataSource'})

        return {
            'message': 'Created successfully',
            'status_code': 201
        }, 201
예제 #2
0
파일: data.py 프로젝트: HIIT/mydatasource
    def post(self):
        """
        create new data
        :return:
        """
        args = self.reqparse.parse_args()
        parts = args['Authorization'].split()
        user_id = DBHelper.get_user_id(parts[1])

        sample = request.get_json()

        if 'label' not in sample:
            raise CustomError('Parameter <label> missing', status_code=400)
        if 'data' not in sample:
            raise CustomError('Parameter <data> missing', status_code=400)

        label = sample['label']
        data = sample['data']

        lb = DBHelper.get_label_by_name(label)
        if lb is None:
            raise CustomError('Label Not Found', status_code=404)
        label_id = lb.id

        for d in data:
            d.update({
                'user_id': user_id,
                'label_id': label_id
            })
            DBHelper.set_data(d)

        return {
                   'message': 'Upload successfully!',
                   'status_code': 201
               }, 201
예제 #3
0
def register_resource_set(ext_id):
    """
    register resource set to DataOperator
    :param ext_id: String, unique id
    :return: Boolean
    """
    try:
        user_id = DBHelper.get_user_id(ext_id)
        if user_id is False:
            return False

        rs = DBHelper.get_resource_set(user_id)

        for i in rs:
            data = json.dumps(i)
            req = urllib2.Request('http://46.101.30.187:8080/api/protection/resourceSets', data)
            req.add_header('Content-Type', 'application/json')

            f = urllib2.urlopen(req).read()
            obj = json.loads(f)

            con = obj['content'][0]

            DBHelper.set_rs_id({'name': con['name'], 'rs_id': con['rs_id']})
        return True
    except Exception as e:
        print(str(e))
        return None