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)
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)
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)
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)