Search in sources :

Example 1 with InputStreamResourceStream

use of de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream in project webanno by webanno.

the class LayerDetailForm method exportUimaTypeSystem.

private IResourceStream exportUimaTypeSystem() {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        TypeSystemDescription tsd = annotationService.getAllProjectTypes(getModelObject().getProject());
        tsd.toXML(bos);
        return new InputStreamResourceStream(new ByteArrayInputStream(bos.toByteArray()));
    } catch (Exception e) {
        error("Unable to generate the UIMA type system file: " + ExceptionUtils.getRootCauseMessage(e));
        ProjectLayersPanel.LOG.error("Unable to generate the UIMA type system file", e);
        RequestCycle.get().find(IPartialPageRequestHandler.class).ifPresent(handler -> handler.addChildren(getPage(), IFeedback.class));
        return null;
    }
}
Also used : ExportedAnnotationLayerReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Strings.escapeMarkup(org.apache.wicket.util.string.Strings.escapeMarkup) CasStorageService(de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService) LambdaAjaxFormChoiceComponentUpdatingBehavior(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxFormChoiceComponentUpdatingBehavior) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) TextField(org.apache.wicket.markup.html.form.TextField) StringUtils(org.apache.commons.lang3.StringUtils) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) InputStreamResourceStream(de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream) LambdaBehavior.visibleWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen) ByteArrayInputStream(java.io.ByteArrayInputStream) LayerConfigurationChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent) Arrays.asList(java.util.Arrays.asList) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Objects.isNull(java.util.Objects.isNull) LayerSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry) IModel(org.apache.wicket.model.IModel) LambdaModelAdapter(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaModelAdapter) Label(org.apache.wicket.markup.html.basic.Label) LambdaBehavior.enabledWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.enabledWhen) Collections.emptyList(java.util.Collections.emptyList) LayerType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerType) Model(org.apache.wicket.model.Model) Component(org.apache.wicket.Component) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) BootstrapRadioChoice(de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapRadioChoice) Collectors(java.util.stream.Collectors) IFeedback(org.apache.wicket.feedback.IFeedback) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) PropertyModel(org.apache.wicket.model.PropertyModel) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) FeatureSelectionForm(de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.FeatureSelectionForm) ApplicationEventPublisherHolder(de.tudarmstadt.ukp.clarin.webanno.support.spring.ApplicationEventPublisherHolder) IResourceStream(org.apache.wicket.util.resource.IResourceStream) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Form(org.apache.wicket.markup.html.form.Form) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StringResourceModel(org.apache.wicket.model.StringResourceModel) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) EnumChoiceRenderer(org.apache.wicket.markup.html.form.EnumChoiceRenderer) CheckBox(org.apache.wicket.markup.html.form.CheckBox) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ArrayList(java.util.ArrayList) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) BootstrapSelect(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect) ChallengeResponseDialog(de.tudarmstadt.ukp.clarin.webanno.support.dialog.ChallengeResponseDialog) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) AjaxDownloadLink(de.tudarmstadt.ukp.clarin.webanno.support.wicket.AjaxDownloadLink) TextArea(org.apache.wicket.markup.html.form.TextArea) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) LayerExportMode(de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.LayerExportMode) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) RELATION_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE) SPAN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE) LayerSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupport) ImportUtil(de.tudarmstadt.ukp.clarin.webanno.export.ImportUtil) JSONUtil(de.tudarmstadt.ukp.clarin.webanno.support.JSONUtil) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) LambdaAjaxLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink) LambdaModel(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaModel) IPartialPageRequestHandler(org.apache.wicket.core.request.handler.IPartialPageRequestHandler) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) InputStreamResourceStream(de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with InputStreamResourceStream

use of de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream in project webanno by webanno.

the class LayerDetailForm method exportLayerJson.

private IResourceStream exportLayerJson() {
    try {
        AnnotationLayer layer = getModelObject();
        List<ExportedAnnotationLayer> exLayers = new ArrayList<>();
        ExportedAnnotationLayer exMainLayer = ImportUtil.exportLayerDetails(null, null, layer, annotationService);
        exLayers.add(exMainLayer);
        // that, otherwise we would be missing it during re-import.
        if (layer.getAttachType() != null) {
            AnnotationLayer attachLayer = layer.getAttachType();
            ExportedAnnotationLayer exAttachLayer = ImportUtil.exportLayerDetails(null, null, attachLayer, annotationService);
            exMainLayer.setAttachType(new ExportedAnnotationLayerReference(exAttachLayer.getName()));
            exLayers.add(exAttachLayer);
        }
        return new InputStreamResourceStream(new ByteArrayInputStream(JSONUtil.toPrettyJsonString(exLayers).getBytes("UTF-8")));
    } catch (Exception e) {
        error("Unable to generate the JSON file: " + ExceptionUtils.getRootCauseMessage(e));
        ProjectLayersPanel.LOG.error("Unable to generate the JSON file", e);
        RequestCycle.get().find(IPartialPageRequestHandler.class).ifPresent(handler -> handler.addChildren(getPage(), IFeedback.class));
        return null;
    }
}
Also used : ExportedAnnotationLayerReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Strings.escapeMarkup(org.apache.wicket.util.string.Strings.escapeMarkup) CasStorageService(de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService) LambdaAjaxFormChoiceComponentUpdatingBehavior(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxFormChoiceComponentUpdatingBehavior) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) TextField(org.apache.wicket.markup.html.form.TextField) StringUtils(org.apache.commons.lang3.StringUtils) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) InputStreamResourceStream(de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream) LambdaBehavior.visibleWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen) ByteArrayInputStream(java.io.ByteArrayInputStream) LayerConfigurationChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent) Arrays.asList(java.util.Arrays.asList) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Objects.isNull(java.util.Objects.isNull) LayerSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry) IModel(org.apache.wicket.model.IModel) LambdaModelAdapter(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaModelAdapter) Label(org.apache.wicket.markup.html.basic.Label) LambdaBehavior.enabledWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.enabledWhen) Collections.emptyList(java.util.Collections.emptyList) LayerType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerType) Model(org.apache.wicket.model.Model) Component(org.apache.wicket.Component) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) BootstrapRadioChoice(de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapRadioChoice) Collectors(java.util.stream.Collectors) IFeedback(org.apache.wicket.feedback.IFeedback) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) PropertyModel(org.apache.wicket.model.PropertyModel) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) FeatureSelectionForm(de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.FeatureSelectionForm) ApplicationEventPublisherHolder(de.tudarmstadt.ukp.clarin.webanno.support.spring.ApplicationEventPublisherHolder) IResourceStream(org.apache.wicket.util.resource.IResourceStream) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Form(org.apache.wicket.markup.html.form.Form) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StringResourceModel(org.apache.wicket.model.StringResourceModel) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) EnumChoiceRenderer(org.apache.wicket.markup.html.form.EnumChoiceRenderer) CheckBox(org.apache.wicket.markup.html.form.CheckBox) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ArrayList(java.util.ArrayList) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) BootstrapSelect(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect) ChallengeResponseDialog(de.tudarmstadt.ukp.clarin.webanno.support.dialog.ChallengeResponseDialog) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) AjaxDownloadLink(de.tudarmstadt.ukp.clarin.webanno.support.wicket.AjaxDownloadLink) TextArea(org.apache.wicket.markup.html.form.TextArea) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) LayerExportMode(de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.LayerExportMode) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) RELATION_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE) SPAN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE) LayerSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupport) ImportUtil(de.tudarmstadt.ukp.clarin.webanno.export.ImportUtil) JSONUtil(de.tudarmstadt.ukp.clarin.webanno.support.JSONUtil) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) LambdaAjaxLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink) LambdaModel(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaModel) IPartialPageRequestHandler(org.apache.wicket.core.request.handler.IPartialPageRequestHandler) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) InputStreamResourceStream(de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ExportedAnnotationLayerReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer)

Aggregations

BootstrapRadioChoice (de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapRadioChoice)2 BootstrapSelect (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect)2 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)2 CasStorageService (de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService)2 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)2 RELATION_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE)2 SPAN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE)2 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)2 LayerSupport (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupport)2 LayerSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry)2 LayerType (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerType)2 LayerConfigurationChangedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent)2 ImportUtil (de.tudarmstadt.ukp.clarin.webanno.export.ImportUtil)2 ExportedAnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer)2 ExportedAnnotationLayerReference (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 JSONUtil (de.tudarmstadt.ukp.clarin.webanno.support.JSONUtil)2 ChallengeResponseDialog (de.tudarmstadt.ukp.clarin.webanno.support.dialog.ChallengeResponseDialog)2 LambdaAjaxButton (de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton)2