示例#1
0
    def add_concept(self):
        """
        Add a new concept to a conceptscheme

        :raises atramhasis.errors.ValidationError: If the provided json can't be validated
        """
        validated_json_concept = self._validate_concept(self._get_json_body(), self.provider.conceptscheme_id)
        cid = self.skos_manager.get_next_cid(self.provider.conceptscheme_id)
        if not cid:
            cid = 0
        cid += 1
        if validated_json_concept["type"] == "concept":
            concept = Concept()
        else:
            concept = Collection()
        concept.concept_id = cid
        concept.conceptscheme_id = self.provider.conceptscheme_id
        concept.uri = self.provider.uri_generator.generate(id=concept.concept_id)
        map_concept(concept, validated_json_concept, self.skos_manager)
        concept = self.skos_manager.save(concept)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = "201"
        self.request.response.location = self.request.route_path(
            "skosprovider.c", scheme_id=self.scheme_id, c_id=concept.concept_id
        )
        return from_thing(concept)
示例#2
0
    def add_concept(self):
        '''
        Add a new concept to a conceptscheme

        :raises atramhasis.errors.ValidationError: If the provided json can't be validated
        '''
        validated_json_concept = self._validate_concept(self._get_json_body(), self.provider.conceptscheme_id)
        cid = self.db.query(
            func.max(Thing.concept_id)
        ).filter_by(conceptscheme_id=self.provider.conceptscheme_id).first()[0]
        if not cid:
            cid = 0
        cid += 1
        if validated_json_concept['type'] == 'concept':
            concept = Concept()
        else:
            concept = Collection()
        concept.concept_id = cid
        concept.conceptscheme_id = self.provider.conceptscheme_id
        concept.uri = self.provider.uri_generator.generate(id=cid)
        map_concept(concept, validated_json_concept, self.request.db)
        self.db.add(concept)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = '201'
        self.request.response.location = self.request.route_path(
            'skosprovider.c', scheme_id=self.scheme_id, c_id=concept.concept_id)
        return from_thing(concept)
示例#3
0
文件: crud.py 项目: JDeVos/atramhasis
    def add_concept(self):
        '''
        Add a new concept to a conceptscheme

        :raises atramhasis.errors.ValidationError: If the provided json can't be validated
        '''
        validated_json_concept = self._validate_concept(
            self._get_json_body(), self.provider.conceptscheme_id)
        cid = self.db.query(func.max(Thing.concept_id)).filter_by(
            conceptscheme_id=self.provider.conceptscheme_id).first()[0]
        if not cid:
            cid = 0
        cid += 1
        if validated_json_concept['type'] == 'concept':
            concept = Concept()
        else:
            concept = Collection()
        concept.concept_id = cid
        concept.conceptscheme_id = self.provider.conceptscheme_id
        concept.uri = self.provider.uri_generator.generate(id=cid)
        map_concept(concept, validated_json_concept, self.request.db)
        self.db.add(concept)
        self.db.flush()

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = '201'
        self.request.response.location = self.request.route_path(
            'skosprovider.c',
            scheme_id=self.scheme_id,
            c_id=concept.concept_id)
        return from_thing(concept)
示例#4
0
    def delete_concept(self):
        """
        Delete an existing concept

        :raises atramhasis.errors.ConceptNotFoundException: If the concept can't be found
        """
        c_id = self.request.matchdict["c_id"]
        try:
            concept = self.skos_manager.get_thing(c_id, self.provider.conceptscheme_id)
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
        self.skos_manager.delete_thing(concept)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = "200"
        return from_thing(concept)
示例#5
0
    def delete_concept(self):
        '''
        Delete an existing concept

        :raises atramhasis.errors.ConceptNotFoundException: If the concept can't be found
        '''
        c_id = self.request.matchdict['c_id']
        try:
            concept = self.db.query(Thing).filter_by(concept_id=c_id,
                                                     conceptscheme_id=self.provider.conceptscheme_id).one()
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
        self.db.delete(concept)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = '200'
        return from_thing(concept)
示例#6
0
    def edit_concept(self):
        """
        Edit an existing concept

        :raises atramhasis.errors.ConceptNotFoundException: If the concept can't be found
        :raises atramhasis.errors.ValidationError: If the provided json can't be validated
        """
        c_id = self.request.matchdict["c_id"]
        validated_json_concept = self._validate_concept(self._get_json_body(), self.provider.conceptscheme_id)
        try:
            concept = self.skos_manager.get_thing(c_id, self.provider.conceptscheme_id)
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
        map_concept(concept, validated_json_concept, self.skos_manager)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = "200"
        return from_thing(concept)
示例#7
0
文件: crud.py 项目: JDeVos/atramhasis
    def delete_concept(self):
        '''
        Delete an existing concept

        :raises atramhasis.errors.ConceptNotFoundException: If the concept can't be found
        '''
        c_id = self.request.matchdict['c_id']
        try:
            concept = self.db.query(Thing).filter_by(
                concept_id=c_id,
                conceptscheme_id=self.provider.conceptscheme_id).one()
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
        self.db.delete(concept)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = '200'
        return from_thing(concept)
示例#8
0
    def edit_concept(self):
        '''
        Edit an existing concept

        :raises atramhasis.errors.ConceptNotFoundException: If the concept can't be found
        :raises atramhasis.errors.ValidationError: If the provided json can't be validated
        '''
        c_id = self.request.matchdict['c_id']
        validated_json_concept = self._validate_concept(self._get_json_body(), self.provider.conceptscheme_id)
        try:
            concept = self.db.query(Thing).filter_by(concept_id=c_id,
                                                     conceptscheme_id=self.provider.conceptscheme_id).one()
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
        map_concept(concept, validated_json_concept, self.request.db)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = '200'
        return from_thing(concept)
示例#9
0
文件: crud.py 项目: JDeVos/atramhasis
    def edit_concept(self):
        '''
        Edit an existing concept

        :raises atramhasis.errors.ConceptNotFoundException: If the concept can't be found
        :raises atramhasis.errors.ValidationError: If the provided json can't be validated
        '''
        c_id = self.request.matchdict['c_id']
        validated_json_concept = self._validate_concept(
            self._get_json_body(), self.provider.conceptscheme_id)
        try:
            concept = self.db.query(Thing).filter_by(
                concept_id=c_id,
                conceptscheme_id=self.provider.conceptscheme_id).one()
        except NoResultFound:
            raise ConceptNotFoundException(c_id)
        map_concept(concept, validated_json_concept, self.request.db)

        invalidate_scheme_cache(self.scheme_id)

        self.request.response.status = '200'
        return from_thing(concept)
示例#10
0
 def invalidate_scheme_tree(self):
     scheme_id = self.request.matchdict['scheme_id']
     invalidate_scheme_cache(scheme_id)
     return Response(status_int=200)
示例#11
0
 def invalidate_scheme_tree(self):
     scheme_id = self.request.matchdict['scheme_id']
     invalidate_scheme_cache(scheme_id)
     return Response(status_int=200)