Example #1
0
    def put(self, ident):
        data = self.request.data
        entity = get_one(self.session, Entity,
                         id=ident)  # to ensure that the entity exists

        if 'parent_id' in data:
            get_one(self.session, Entity, id=data['parent_id'])
            entity.parent_id_fk = data['parent_id']

        # add tags and meta
        for key in data:
            if 'tag_' in key:
                tag = get_one(self.session,
                              EntityTag,
                              entity=entity,
                              tag_id_fk=key.split('_')[1])
                tag.value = data[key]
            elif 'meta_' in key:
                meta = get_one(self.session,
                               EntityMeta,
                               entity=entity,
                               meta_id_fk=key.split('_')[1])
                meta.value = data[key]

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {
            'success': True,
            'ID': entity.id,
        }
Example #2
0
    def post(self):
        data = self.request.data
        entity_type = EntityType(name=data['name'])
        self.session.add(entity_type)

        # add tags, meta and series
        for tag in data['tags']:
            self.session.add(TagAttribute(
                entity_type=entity_type,
                name=tag,
            ))
        for meta in data['meta']:
            self.session.add(
                MetaAttribute(
                    entity_type=entity_type,
                    name=meta,
                ))
        for series in data['series']:
            self.session.add(
                SeriesAttribute(
                    entity_type=entity_type,
                    name=series,
                ))

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {
            'success': True,
            'ID': entity_type.id,
        }
Example #3
0
    def put(self, ident):
        data = self.request.data
        entity_type = get_one(self.session, EntityType, id=ident)
        if 'name' in data:
            entity_type.name = data['name']

        # add tags, meta and series
        if 'tags' in data:
            for tag in data['tags']:
                self.session.add(
                    TagAttribute(
                        entity_type=entity_type,
                        name=tag,
                    ))
        if 'meta' in data:
            for meta in data['meta']:
                self.session.add(
                    MetaAttribute(
                        entity_type=entity_type,
                        name=meta,
                    ))
        if 'series' in data:
            for series in data['series']:
                self.session.add(
                    SeriesAttribute(
                        entity_type=entity_type,
                        name=series,
                    ))

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {
            'success': True,
            'ID': entity_type.id,
        }
Example #4
0
    def delete(self, ident):
        alert = get_one(self.session, Alert, id=ident)
        now = time.time()
        alert.delete_ts = now

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True}
Example #5
0
    def post(self, entity_type_id):
        data = self.request.data
        entity_type = get_one(self.session, EntityType, id=entity_type_id)
        tag = TagAttribute(entity_type=entity_type, name=data['name'])
        self.session.add(tag)

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True, 'ID': tag.id}
Example #6
0
    def delete(self, entity_type_id, ident):
        entity_type = get_one(self.session, EntityType, id=entity_type_id)  # check if route is correct
        meta = get_one(self.session, MetaAttribute, entity_type=entity_type, id=ident)
        now = time.time()
        meta.delete_ts = now
        for entity_meta in get_all(self.session, EntityMeta, attribute=meta):
            entity_meta.delete_ts = now

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True}
Example #7
0
    def post(self, entity_type_id):
        data = self.request.data
        entity_type = get_one(self.session, EntityType, id=entity_type_id)
        series = SeriesAttribute(entity_type=entity_type,
                                 name=data['name'],
                                 type=data.get('type', 'real'),
                                 refresh_time=data.get('refresh_time'),
                                 is_favourite=data.get('is_favourite', False))
        self.session.add(series)

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True, 'ID': series.id}
Example #8
0
    def put(self, entity_type_id, ident):
        data = self.request.data
        entity_type = get_one(self.session, EntityType, id=entity_type_id)  # check if route is correct
        meta = get_one(self.session, MetaAttribute, entity_type=entity_type, id=ident)

        if 'name' in data:
            meta.name = data['name']

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {
            'success': True,
            'ID': meta.id,
        }
Example #9
0
    def delete(self, entity_type_id, ident):
        now = time.time()
        entity_type = get_one(self.session, EntityType,
                              id=entity_type_id)  # check if route is correct
        series = get_one(self.session,
                         SeriesAttribute,
                         entity_type=entity_type,
                         id=ident)
        series.delete_ts = now
        for alert in series.alerts:
            alert.delete_ts = now

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True}
Example #10
0
    def put(self, entity_type_id, ident):
        data = self.request.data
        entity_type = get_one(self.session, EntityType, id=entity_type_id)
        series = get_one(self.session,
                         SeriesAttribute,
                         entity_type=entity_type,
                         id=ident)
        if 'refresh_time' in data:
            series.refresh_time = data['refresh_time']
        if 'is_favourite' in data:
            series.is_favourite = data['is_favourite']

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True, 'ID': series.id}
Example #11
0
    def delete(self, entity_type_id, ident):
        entity_type = get_one(self.session, EntityType,
                              id=entity_type_id)  # check if route is correct
        tag = get_one(self.session,
                      TagAttribute,
                      entity_type=entity_type,
                      id=ident)
        now = time.time()
        tag.delete_ts = now
        for entity_tag in get_all(self.session, EntityTag, attribute=tag):
            entity_tag.delete_ts = now

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True}
Example #12
0
    def post(self):
        data = self.request.data
        entity_type = get_one(self.session,
                              EntityType,
                              id=data['entity_type_id'])

        # check if we got all tags and meta
        tag_ids = sorted(
            int(key.split('_')[1]) for key in data if 'tag_' in key)
        meta_ids = sorted(
            int(key.split('_')[1]) for key in data if 'meta_' in key)
        self._assert_got_all_needed_tag_and_meta_ids(entity_type, tag_ids,
                                                     meta_ids)

        entity = Entity(
            entity_type=entity_type,
            parent=None if data['parent_id'] is None else get_one(
                self.session, Entity, id=data['parent_id']),
        )
        self.session.add(entity)

        # add tags and meta
        for key in data:
            if 'tag_' in key:
                self.session.add(
                    EntityTag(
                        entity=entity,
                        attribute=get_one(self.session,
                                          TagAttribute,
                                          id=int(key.split('_')[1])),
                        value=data[key],
                    ))
            elif 'meta_' in key:
                self.session.add(
                    EntityMeta(
                        entity=entity,
                        attribute=get_one(self.session,
                                          MetaAttribute,
                                          id=int(key.split('_')[1])),
                        value=data[key],
                    ))

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {
            'success': True,
            'ID': entity.id,
        }
Example #13
0
    def delete(self, ident):
        entity = get_one(self.session, Entity, id=ident)
        now = time.time()
        entity.delete_ts = now
        for tag in entity.tags:
            tag.delete_ts = now
        for meta in entity.meta:
            meta.delete_ts = now
        for alert in entity.alerts:
            alert.delete_ts = now
        for child in entity.children:
            child.parent = entity.parent

        self.session.commit()
        update_last_data_modification_ts(self.session)
        return {'success': True}