Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2824 - Layer name with special characters causes problems in search #5046

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT;
import static java.util.Arrays.asList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.substringAfterLast;

import java.io.Serializable;

Expand Down Expand Up @@ -63,9 +65,15 @@ public class AnnotationLayer
@Column(name = "id")
private Long id;

@Column(name = "name", nullable = false)
private String name;

@Column(nullable = false)
private String uiName;

@Column(name = "short_name", nullable = true)
private String shortName;

@Column(nullable = false)
private String type;

Expand All @@ -82,9 +90,6 @@ public class AnnotationLayer
@Column(length = 64000)
private String onClickJavascriptAction;

@Column(name = "name", nullable = false)
private String name;

@ManyToOne
// @ForeignKey(ConstraintMode.NO_CONSTRAINT)
@JoinColumn(name = "annotation_type", //
Expand Down Expand Up @@ -148,6 +153,7 @@ private AnnotationLayer(Builder builder)
{
this.id = builder.id;
this.uiName = builder.uiName;
this.shortName = builder.shortName;
this.type = builder.type;
this.description = builder.description;
this.enabled = builder.enabled;
Expand Down Expand Up @@ -223,6 +229,29 @@ public void setDescription(String aDescription)
description = aDescription;
}

/**
* The name under which the layer should be accessible when searching
*
* @param aShortName
*/
public void setShortName(String aShortName)
{
shortName = aShortName;
}

public String getShortName()
{
if (isBlank(shortName)) {
if (name != null && name.contains(".")) {
return substringAfterLast(name, ".");
}

return name;
}

return shortName;
}

/**
* The name displayed to the user in the UI.
*
Expand Down Expand Up @@ -573,14 +602,15 @@ public static Builder builder()
public static final class Builder
{
private Long id;
private String name;
private String uiName;
private String shortName;
private String type;
private String description;
private boolean enabled = true;
private boolean builtIn = false;
private boolean readonly = false;
private String onClickJavascriptAction;
private String name;
private AnnotationLayer attachType;
private AnnotationFeature attachFeature;
private Project project;
Expand Down Expand Up @@ -623,6 +653,12 @@ public Builder withUiName(String uiName)
return this;
}

public Builder withShortName(String aSearchName)
{
shortName = aSearchName;
return this;
}

public Builder withType(String type)
{
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1394,4 +1394,15 @@
<changeSet author="INCEpTION Team" id="20240629-14-pg" dbms="postgresql">
<sql>ALTER TABLE annotation_feature ALTER "curatable" TYPE BOOLEAN USING ("curatable"::int::bool)</sql>
</changeSet>

<changeSet author="INCEpTION Team" id="20240907-01">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="annotation_type" columnName="short_name" />
</not>
</preConditions>
<addColumn tableName="annotation_type">
<column name="short_name" type="VARCHAR(255)"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ public interface AnnotationSchemaService
*/
boolean existsLayer(String name, Project project);

/**
* Check if an {@link AnnotationLayer} exists with this short name in the given {@link Project}.
*
* @param shortName
* the layer name.
* @param project
* the project.
* @return if the layer exists.
*/
boolean existsLayerWithShortName(String shortName, Project project);

/**
* check if an {@link AnnotationLayer} exists with this name and type in this {@link Project}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,23 @@ public boolean existsLayer(String aName, Project aProject)
}
}

@Override
@Transactional(noRollbackFor = NoResultException.class)
public boolean existsLayerWithShortName(String aShortName, Project aProject)
{
try {
entityManager.createQuery(
"FROM AnnotationLayer WHERE shortName = :shortName AND project = :project",
AnnotationLayer.class).setParameter("shortName", aShortName) //
.setParameter("project", aProject) //
.getSingleResult();
return true;
}
catch (NoResultException e) {
return false;
}
}

@Override
@Transactional(noRollbackFor = NoResultException.class)
public boolean existsLayer(String aName, String aType, Project aProject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enabled=Enabled

id=ID
name=Name
shortName=Short name
slug=URL slug
description=Description
format=Format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class LayerDetailForm
private DropDownChoice<AnnotationLayer> attachTypeSelect;
private Label effectiveAttachType;
private TextField<String> uiName;
private TextField<String> shortName;

private FeatureSelectionForm featureSelectionForm;
private FeatureDetailForm featureDetailForm;
Expand Down Expand Up @@ -129,6 +130,11 @@ public LayerDetailForm(String id, IModel<AnnotationLayer> aSelectedLayer,
uiName.setOutputMarkupId(true);
uiName.setRequired(true);
add(uiName);

shortName = new TextField<String>("shortName");
shortName.setOutputMarkupId(true);
add(shortName);

add(new TextArea<String>("description").setOutputMarkupPlaceholderTag(true));

add(new Label("name").add(visibleWhen(() -> isNotBlank(getModelObject().getName()))));
Expand Down Expand Up @@ -373,6 +379,13 @@ private void actionSave(AjaxRequestTarget aTarget, Form<AnnotationLayer> aForm)
return;
}

if (annotationService.existsLayerWithShortName(shortLayerName, project)) {
error("A layer with the short name [" + shortLayerName
+ "] already exists in this project.");
return;
}

layer.setShortName(shortLayerName);
layer.setName(layerName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
<a wicket:id="technicalPropertiesHelpLink"/>
</div>
<div class="card-body">
<div class="form-row form-floating">
<input wicket:id="shortName" class="form-control" wicket:message="placeholder:shortName"/>
<label wicket:for="shortName">
<wicket:label key="shortName"/>
</label>
</div>
<div class="form-row form-floating" wicket:enclosure="name">
<span wicket:id="name" class="form-control" readonly/>
<label>
Expand Down