Example #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.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)
Example #2
0
 def test_thing_to_concept(self):
     skosconcept = from_thing(self.concept)
     self.assertTrue(isinstance(skosconcept, SkosConcept))
     self.assertEqual(skosconcept.id, 101)
     self.assertEqual(len(skosconcept.labels), 3)
     self.assertEqual(len(skosconcept.notes), 2)
     self.assertEqual(skosconcept.uri, 'urn:x-atramhasis-demo:TREES:101')
Example #3
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)
Example #4
0
 def test_thing_to_concept(self):
     skosconcept = from_thing(self.concept)
     self.assertTrue(isinstance(skosconcept, SkosConcept))
     self.assertEqual(skosconcept.id, 101)
     self.assertEqual(len(skosconcept.labels), 3)
     self.assertEqual(len(skosconcept.notes), 2)
     self.assertEqual(skosconcept.uri, 'urn:x-atramhasis-demo:TREES:101')
Example #5
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)
Example #6
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)
        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)
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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)
Example #11
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)
Example #12
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)
Example #13
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)
Example #14
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)
Example #15
0
 def test_thing_to_collection(self):
     skoscollection = from_thing(self.collection)
     self.assertTrue(isinstance(skoscollection, SkosCollection))
     self.assertEqual(skoscollection.id, 102)
     self.assertEqual(skoscollection.uri, 'urn:x-atramhasis-demo:TREES:102')
Example #16
0
 def test_thing_to_collection(self):
     skoscollection = from_thing(self.collection)
     self.assertTrue(isinstance(skoscollection, SkosCollection))
     self.assertEqual(skoscollection.id, 102)
     self.assertEqual(skoscollection.uri, 'urn:x-atramhasis-demo:TREES:102')