Skip to content

Commit

Permalink
Merge pull request #4005 from inception-project/feature/4004-Ability-…
Browse files Browse the repository at this point in the history
…to-export-full-type-system-from-layer-detail-panel

#4004 - Ability to export full type system from layer detail panel
  • Loading branch information
reckart committed May 17, 2023
2 parents 58a9e91 + f8a368f commit 5987164
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static de.tudarmstadt.ukp.clarin.webanno.support.WebAnnoConst.SPAN_TYPE;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.enabledWhen;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Objects.isNull;
Expand Down Expand Up @@ -192,8 +193,10 @@ protected void onUpdate(AjaxRequestTarget aTarget)
// Behaviors of layers
add(new CheckBox("readonly").setOutputMarkupPlaceholderTag(true));

add(new AjaxDownloadLink("exportLayersAsJson", this::exportLayerJson));
add(new AjaxDownloadLink("exportLayersAsUima", this::exportUimaTypeSystem));
add(new AjaxDownloadLink("exportLayersAsJson", this::exportLayerAsJson));
add(new AjaxDownloadLink("exportLayersAsUima", this::exportAllLayersAsUimaXml));
add(new AjaxDownloadLink("exportFullTypeSystemAsUima",
this::exportFullTypeSystemAsUimaXml));

// Processing the data in onAfterSubmit so the traits panel can use the
// override onSubmit in its nested form and store the traits before
Expand Down Expand Up @@ -391,26 +394,41 @@ private void actionCancel(AjaxRequestTarget aTarget)
aTarget.addChildren(getPage(), IFeedback.class);
}

private IResourceStream exportUimaTypeSystem()
private IResourceStream exportFullTypeSystemAsUimaXml()
{
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
var tsd = annotationService.getFullProjectTypeSystem(getModelObject().getProject(),
false);
tsd.toXML(bos);
return new InputStreamResourceStream(new ByteArrayInputStream(bos.toByteArray()),
"full-typesystem.xml");
}
catch (Exception e) {
WicketExceptionUtil.handleException(ProjectLayersPanel.LOG, this, e);
return null;
}
}

private IResourceStream exportAllLayersAsUimaXml()
{
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
var tsd = annotationService.getAllProjectTypes(getModelObject().getProject());
tsd.toXML(bos);
return new InputStreamResourceStream(new ByteArrayInputStream(bos.toByteArray()),
"typesystem.xml");
"layers-typesystem.xml");
}
catch (Exception e) {
WicketExceptionUtil.handleException(ProjectLayersPanel.LOG, this, e);
return null;
}
}

private IResourceStream exportLayerJson()
private IResourceStream exportLayerAsJson()
{
try {
String json = LayerImportExportUtils.exportLayerToJson(annotationService,
getModelObject());
return new InputStreamResourceStream(new ByteArrayInputStream(json.getBytes("UTF-8")),
return new InputStreamResourceStream(new ByteArrayInputStream(json.getBytes(UTF_8)),
"layer.json");
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
<wicket:message key="exportLayersAsUima"/>
</a>
</li>
<li>
<a wicket:id="exportFullTypeSystemAsUima" class="dropdown-item">
<wicket:message key="exportFullTypeSystemAsUima"/>
</a>
</li>
</ul>
</span>
<button wicket:id="save" class="btn btn-primary text-nowrap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type.Required=Required field not set
type=Type

exportLayersAsJson=JSON (selected layer)
exportLayersAsUima=UIMA (all layers)
exportLayersAsUima=UIMA XML (all layers)
exportFullTypeSystemAsUima=UIMA XML (full UIMA type system)

validationMode=Validation

Expand Down

0 comments on commit 5987164

Please sign in to comment.