use of de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent in project webanno by webanno.
the class CasStorageServiceImplTest method testThatLayerChangeEventInvalidatesCachedCas.
@Test
public void testThatLayerChangeEventInvalidatesCachedCas() throws Exception {
// Setup fixture
SourceDocument doc = makeSourceDocument(4l, 4l, "test");
String user = "test";
try (CasStorageSession session = openNested(true)) {
String text = "This is a test";
createCasFile(doc, user, text);
}
// Actual test
int casIdentity1;
try (CasStorageSession session = openNested(true)) {
JCas cas = sut.readCas(doc, user).getJCas();
casIdentity1 = System.identityHashCode(cas);
}
int casIdentity2;
try (CasStorageSession session = openNested(true)) {
JCas cas = sut.readCas(doc, user).getJCas();
casIdentity2 = System.identityHashCode(cas);
}
sut.beforeLayerConfigurationChanged(new LayerConfigurationChangedEvent(this, doc.getProject()));
int casIdentity3;
try (CasStorageSession session = openNested(true)) {
JCas cas = sut.readCas(doc, user).getJCas();
casIdentity3 = System.identityHashCode(cas);
}
assertThat(casIdentity1).as("Getting the CAS a second time returns the same instance from memory").isEqualTo(casIdentity2);
assertThat(casIdentity1).as("After a type system change event must return a different CAS instance").isNotEqualTo(casIdentity3);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent in project webanno by webanno.
the class FeatureDetailForm method actionSave.
private void actionSave(AjaxRequestTarget aTarget, Form<?> aForm) {
AnnotationFeature feature = getModelObject();
String name = feature.getUiName();
name = name.replaceAll("\\W", "");
// Check if feature name is not from the restricted names list
if (WebAnnoConst.RESTRICTED_FEATURE_NAMES.contains(name)) {
error("'" + feature.getUiName().toLowerCase() + " (" + name + ")'" + " is a reserved feature name. Please use a different name " + "for the feature.");
return;
}
if (RELATION_TYPE.equals(getModelObject().getLayer().getType()) && (name.equals(WebAnnoConst.FEAT_REL_SOURCE) || name.equals(WebAnnoConst.FEAT_REL_TARGET) || name.equals(FIRST) || name.equals(NEXT))) {
error("'" + feature.getUiName().toLowerCase() + " (" + name + ")'" + " is a reserved feature name on relation layers. . Please " + "use a different name for the feature.");
return;
}
// And only uses alphanumeric characters
if (StringUtils.isNumeric(name.substring(0, 1)) || name.substring(0, 1).equals("_") || !StringUtils.isAlphanumeric(name.replace("_", ""))) {
error("Feature names must start with a letter and consist only of " + "letters, digits, or underscores.");
return;
}
if (isNull(feature.getId())) {
feature.setLayer(getModelObject().getLayer());
feature.setProject(getModelObject().getLayer().getProject());
if (annotationService.existsFeature(feature.getName(), feature.getLayer())) {
error("This feature is already added for this layer!");
return;
}
if (annotationService.existsFeature(name, feature.getLayer())) {
error("This feature already exists!");
return;
}
feature.setName(name);
FeatureSupport<?> fs = featureSupportRegistry.getFeatureSupport(featureType.getModelObject().getFeatureSupportId());
// Let the feature support finalize the configuration of the feature
fs.configureFeature(feature);
}
// Save feature
annotationService.createFeature(feature);
// Clear currently selected feature / feature details
setModelObject(null);
success("Settings for feature [" + feature.getUiName() + "] saved.");
aTarget.addChildren(getPage(), IFeedback.class);
aTarget.add(findParent(ProjectLayersPanel.class).get(MID_FEATURE_DETAIL_FORM));
aTarget.add(findParent(ProjectLayersPanel.class).get(MID_FEATURE_SELECTION_FORM));
// Trigger LayerConfigurationChangedEvent
applicationEventPublisherHolder.get().publishEvent(new LayerConfigurationChangedEvent(this, feature.getProject()));
}
use of de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent in project webanno by webanno.
the class FeatureDetailForm method actionDelete.
private void actionDelete(AjaxRequestTarget aTarget, Form aForm) {
confirmationDialog.setChallengeModel(new StringResourceModel("DeleteFeatureDialog.text", this).setParameters(escapeMarkup(getModelObject().getName())));
confirmationDialog.setResponseModel(Model.of(getModelObject().getName()));
confirmationDialog.show(aTarget);
confirmationDialog.setConfirmAction((_target) -> {
annotationService.removeFeature(getModelObject());
Project project = getModelObject().getProject();
setModelObject(null);
documentService.upgradeAllAnnotationDocuments(project);
// Trigger LayerConfigurationChangedEvent
applicationEventPublisherHolder.get().publishEvent(new LayerConfigurationChangedEvent(this, project));
_target.add(getPage());
});
}
use of de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent in project webanno by webanno.
the class LayerDetailForm method actionDelete.
private void actionDelete(AjaxRequestTarget aTarget, Form aForm) {
confirmationDialog.setChallengeModel(new StringResourceModel("DeleteLayerDialog.text", this).setParameters(escapeMarkup(getModelObject().getName())));
confirmationDialog.setResponseModel(Model.of(getModelObject().getName()));
confirmationDialog.show(aTarget);
confirmationDialog.setConfirmAction((_target) -> {
annotationService.removeLayer(getModelObject());
Project project = getModelObject().getProject();
setModelObject(null);
documentService.upgradeAllAnnotationDocuments(project);
// Trigger LayerConfigurationChangedEvent
applicationEventPublisherHolder.get().publishEvent(new LayerConfigurationChangedEvent(this, project));
_target.add(getPage());
});
}
use of de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent in project webanno by webanno.
the class LayerDetailForm method actionSave.
private void actionSave(AjaxRequestTarget aTarget, Form<?> aForm) {
aTarget.add(getParent());
aTarget.addChildren(getPage(), IFeedback.class);
AnnotationLayer layer = LayerDetailForm.this.getModelObject();
final Project project = layer.getProject();
// Set type name only when the layer is initially created. After that, only the UI
// name may be updated. Also any validation related to the type name only needs to
// happen on the initial creation.
boolean isNewLayer = isNull(layer.getId());
if (isNewLayer) {
String layerName = StringUtils.capitalize(layer.getUiName());
layerName = layerName.replaceAll("\\W", "");
if (layerName.isEmpty()) {
error("Unable to derive internal name from [" + layer.getUiName() + "]. Please choose a different initial name and rename after the " + "layer has been created.");
return;
}
if (!Character.isJavaIdentifierStart(layerName.charAt(0))) {
error("Initial layer name cannot start with [" + layerName.charAt(0) + "]. Please choose a different initial name and rename after the " + "layer has been created.");
return;
}
if (annotationService.existsLayer(TYPE_PREFIX + layerName, project)) {
error("A layer with the name [" + TYPE_PREFIX + layerName + "] already exists in this project.");
return;
}
layer.setName(TYPE_PREFIX + layerName);
}
if (layer.getType().equals(RELATION_TYPE) && layer.getAttachType() == null) {
error("A relation layer needs to attach to a span layer.");
return;
}
annotationService.createOrUpdateLayer(layer);
// persisted in the database.
if (isNewLayer) {
TypeAdapter adapter = annotationService.getAdapter(layer);
adapter.initialize(annotationService);
}
success("Settings for layer [" + layer.getUiName() + "] saved.");
aTarget.addChildren(getPage(), IFeedback.class);
aTarget.add(findParent(ProjectLayersPanel.class));
aTarget.add(featureDetailForm);
aTarget.add(featureSelectionForm);
// Trigger LayerConfigurationChangedEvent
applicationEventPublisherHolder.get().publishEvent(new LayerConfigurationChangedEvent(this, project));
}
Aggregations