Search in sources :

Example 1 with ExportedAnnotationLayerReference

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference 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)

Example 2 with ExportedAnnotationLayerReference

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference in project webanno by webanno.

the class LayerExporter method exportData.

@Override
public void exportData(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aStage) throws Exception {
    List<ExportedAnnotationLayer> exLayers = new ArrayList<>();
    // Store map of layer and its equivalent exLayer so that the attach type is attached later
    Map<AnnotationLayer, ExportedAnnotationLayer> layerToExLayers = new HashMap<>();
    // Store map of feature and its equivalent exFeature so that the attach feature is attached
    // later
    Map<AnnotationFeature, ExportedAnnotationFeature> featureToExFeatures = new HashMap<>();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aRequest.getProject())) {
        exLayers.add(exportLayerDetails(layerToExLayers, featureToExFeatures, layer));
    }
    // add the attach-type and attach-feature to the exported layers and exported feature
    for (AnnotationLayer layer : layerToExLayers.keySet()) {
        if (layer.getAttachType() != null) {
            layerToExLayers.get(layer).setAttachType(new ExportedAnnotationLayerReference(layer.getAttachType().getName()));
        }
        if (layer.getAttachFeature() != null) {
            layerToExLayers.get(layer).setAttachFeature(new ExportedAnnotationFeatureReference(layer.getAttachFeature()));
        }
    }
    aExProject.setLayers(exLayers);
    LOG.info("Exported [{}] layers for project [{}]", exLayers.size(), aRequest.getProject().getName());
}
Also used : ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) HashMap(java.util.HashMap) ExportedAnnotationLayerReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference) ArrayList(java.util.ArrayList) ExportedAnnotationFeatureReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeatureReference) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

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 ArrayList (java.util.ArrayList)2 BootstrapRadioChoice (de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapRadioChoice)1 BootstrapSelect (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect)1 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)1 CasStorageService (de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService)1 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)1 RELATION_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE)1 SPAN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 LayerSupport (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupport)1 LayerSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry)1 LayerType (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerType)1 LayerConfigurationChangedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent)1 ImportUtil (de.tudarmstadt.ukp.clarin.webanno.export.ImportUtil)1 ExportedAnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature)1 ExportedAnnotationFeatureReference (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeatureReference)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1