Commit 8f734d18 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

Download Ontology File

parent 92968860
...@@ -24,6 +24,12 @@ ...@@ -24,6 +24,12 @@
</div> </div>
</ul> </ul>
</div> </div>
<div fxFlex fxLayout fxHide.xs fxLayoutAlign="end">
<div>
<input class="btn btn-info" [disabled]="exporting" type="button" value="Download"
(click)="getCurrentOntology()" />
</div>
</div>
</div> </div>
</div> </div>
......
...@@ -85,6 +85,18 @@ export class BoilerplateListComponent implements OnInit { ...@@ -85,6 +85,18 @@ export class BoilerplateListComponent implements OnInit {
this.getInfer(); this.getInfer();
} }
getCurrentOntology(): void {
this.boilerplateService.getCurrentOntolgies(this.route.snapshot.params.gb)
.subscribe(res => {
var url= window.URL.createObjectURL(res);
window.open(url);
},
error => {
this.notifier.notify("warning", 'Fail to download ontology file');
});
}
retrieveBoilerplates(): void { retrieveBoilerplates(): void {
this.boilerplateService.getAll(this.route.snapshot.params.gb) this.boilerplateService.getAll(this.route.snapshot.params.gb)
.subscribe( .subscribe(
......
...@@ -75,4 +75,8 @@ export class BoilerplateService { ...@@ -75,4 +75,8 @@ export class BoilerplateService {
return this.http.get(`${genericbaseUrl}`+`/ontologies`+`/`); return this.http.get(`${genericbaseUrl}`+`/ontologies`+`/`);
} }
getCurrentOntolgies(gb: any): Observable<any> {
return this.http.get(`${genericbaseUrl}`+`/getontology/${gb}`, { responseType: "blob" });
}
} }
...@@ -35,6 +35,7 @@ tramp ...@@ -35,6 +35,7 @@ tramp
# eshell files # eshell files
/eshell/history /eshell/history
/eshell/lastdir /eshell/lastdir
../Ontologies
# elpa packages # elpa packages
/elpa/ /elpa/
......
...@@ -8,6 +8,7 @@ urlpatterns = [ ...@@ -8,6 +8,7 @@ urlpatterns = [
path('users/', user_views.UserList.as_view(), name='api-user-list'), path('users/', user_views.UserList.as_view(), name='api-user-list'),
path('users/<uuid:pk>/', user_views.UserDetail.as_view(), name='api-post-details'), path('users/<uuid:pk>/', user_views.UserDetail.as_view(), name='api-post-details'),
path('ontologies/', requirements_views.OntologiesChoicesViewSet.as_view(), name='api-get-ontologies'), path('ontologies/', requirements_views.OntologiesChoicesViewSet.as_view(), name='api-get-ontologies'),
path('getontology/<int:groupboil>/', requirements_views.GetOntology.as_view(), name='get-current-ontology'),
path('groupboilerplates/', requirements_views.BoilerplateGroupCreateAPIView.as_view(), name='api-groupboilerplates-create'), path('groupboilerplates/', requirements_views.BoilerplateGroupCreateAPIView.as_view(), name='api-groupboilerplates-create'),
path('groupboilerplates/<int:pk>/', requirements_views.BoilerplateGroupDetailsAPIView.as_view(), name='api-groupboilerplates-list'), path('groupboilerplates/<int:pk>/', requirements_views.BoilerplateGroupDetailsAPIView.as_view(), name='api-groupboilerplates-list'),
......
...@@ -39,7 +39,7 @@ class OntologiesChoicesViewSet(APIView): ...@@ -39,7 +39,7 @@ class OntologiesChoicesViewSet(APIView):
data = json.loads(text) data = json.loads(text)
except: except:
pass pass
list_ontology=['Default'] list_ontology=['/Default']
for i in data['datasets'] : for i in data['datasets'] :
list_ontology.append(i['ds.name']) list_ontology.append(i['ds.name'])
ONTOLOGIES_CHOICES = tuple((str(n), str(n)) for n in (list_ontology)) ONTOLOGIES_CHOICES = tuple((str(n), str(n)) for n in (list_ontology))
...@@ -308,3 +308,27 @@ class PrefixChoicesViewSet(ListAPIView): ...@@ -308,3 +308,27 @@ class PrefixChoicesViewSet(ListAPIView):
group_pk = self.kwargs['groupboil'] group_pk = self.kwargs['groupboil']
queryset_cl= BoilerplateGroupClassesInstances.objects.filter(classes_instances_group_of_boilerplate = group_pk) queryset_cl= BoilerplateGroupClassesInstances.objects.filter(classes_instances_group_of_boilerplate = group_pk)
return queryset_cl return queryset_cl
import mimetypes
class GetOntology(APIView):
serializer_class = BoilerplateGroupClassesInstances
def get(self, request, groupboil, format=None):
data = BoilerplateGroupClassesInstances.objects.filter(classes_instances_group_of_boilerplate = groupboil)
filename = data.values('ontology_file')[0]['ontology_file'] + 'infer.ttl'
filepath = data.values('ontology_file')[0]['ontology_file']+'infer.ttl'
try :
path = open(filepath, 'r')
except:
raise APIException("Fail to download ontology file")
# Set the mime type
mime_type, _ = mimetypes.guess_type(filepath)
# Set the return value of the HttpResponse
response = HttpResponse(path, content_type=mime_type)
# Set the HTTP header for sending to browser
response['Content-Disposition'] = "attachment; filename=%s" % filename
# Return the response value
return response
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment