Skip to content

Commit

Permalink
Bugfix: Prevent identical method names on same type and in global sch…
Browse files Browse the repository at this point in the history
…ema methods (these would be either not work because of them hiding each other and would also get lost during a deployment export)
  • Loading branch information
vigorouscoding committed Jun 10, 2024
1 parent 5442629 commit 2090e22
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.structr.common.SecurityContext;
import org.structr.common.View;
import org.structr.common.error.ErrorBuffer;
import org.structr.common.error.ErrorToken;
import org.structr.common.error.FrameworkException;
import org.structr.common.error.SemanticErrorToken;
import org.structr.common.event.RuntimeEventLog;
Expand Down Expand Up @@ -179,10 +180,32 @@ public boolean isValid(final ErrorBuffer errorBuffer) {
valid &= ValidationHelper.isValidStringMatchingRegex(this, name, schemaMethodNamePattern, errorBuffer);

final Set<String> propertyViews = Services.getInstance().getConfigurationProvider().getPropertyViews();
final String methodname = getProperty(AbstractNode.name);
final String thisMethodName = getProperty(AbstractNode.name);

if (methodname != null && propertyViews.contains(methodname)) {
errorBuffer.add(new SemanticErrorToken(this.getType(), "name", "already_exists").withValue(methodname).withDetail("A method cannot have the same name as a view"));
if (thisMethodName != null && propertyViews.contains(thisMethodName)) {
errorBuffer.add(new SemanticErrorToken(this.getType(), "name", "already_exists").withValue(thisMethodName).withDetail("A method cannot have the same name as a view"));
}

// check case-insensitive name uniqueness on current level (type or user-defined functions)
final AbstractSchemaNode parentOrNull = this.getProperty(SchemaMethod.schemaNode);

try {

final List<SchemaMethod> userDefinedFunctions = StructrApp.getInstance().nodeQuery(SchemaMethod.class).and(SchemaMethod.name, thisMethodName).and(SchemaMethod.schemaNode, parentOrNull).getAsList();

for (final SchemaMethod schemaMethod : userDefinedFunctions) {

if (thisMethodName.equalsIgnoreCase(schemaMethod.getName()) && !this.getUuid().equals(schemaMethod.getUuid())) {

errorBuffer.add(new SemanticErrorToken(this.getType(), "name", "already_exists").withValue(thisMethodName).withDetail("Multiple methods with identical names (case-insensitive) are not supported on the same level"));
valid = false;
}
}

} catch (FrameworkException fex) {

errorBuffer.add(new SemanticErrorToken(this.getType(),"none", "exception_occurred").withValue(thisMethodName).withDetail("Exception occurred while checking uniqueness of method name - please retry. Cause: " + fex.getMessage()));
valid = false;
}

return valid;
Expand Down

0 comments on commit 2090e22

Please sign in to comment.