Skip to content
Snippets Groups Projects
Commit f3759642 authored by René Schöne's avatar René Schöne
Browse files

working on relations

- add null check before mapping application only if endpoint is not a primitive type
parent 46572237
No related branches found
No related tags found
1 merge request!27Resolve "Feature: Send endpoint for relations"
Pipeline #12647 passed
......@@ -183,6 +183,10 @@ aspect Mappings {
}
// --- isPrimitiveType ---
syn boolean EndpointDefinition.isPrimitiveType() = getEndpointTarget().isPrimitiveType();
syn boolean EndpointTarget.isPrimitiveType() = false;
eq TokenEndpointTarget.isPrimitiveType() = getToken().isPrimitiveType();
eq AttributeEndpointTarget.isPrimitiveType() = new SimpleJavaTypeUse(getTypeName()).isPrimitiveType();
syn boolean TokenComponent.isPrimitiveType() = effectiveJavaTypeUse().isPrimitiveType();
syn boolean JavaTypeUse.isPrimitiveType() = false;
eq SimpleJavaTypeUse.isPrimitiveType() {
......
{{#Send}}
{{^PrimitiveType}}
if ({{firstInputVarName}} == null) {
{{preemptiveReturn}}
}
{{/PrimitiveType}}
{{/Send}}
{{{lastDefinitionToType}}} {{lastResult}};
try {
{{#innerMappingDefinitions}}
......
......@@ -14,7 +14,13 @@ public boolean {{parentTypeName}}.{{connectMethodName}}(String {{connectParamete
{{#configLoggingEnabledForWrites}}
{{logDebug}}("[Send] {{entityName}} = {{log_}} -> {{log_}}", {{getterMethodCall}}, {{connectParameterName}});
{{/configLoggingEnabledForWrites}}
if ({{lastValueGetterCall}} != null) {
handler.publish(topic, {{lastValueGetterCall}});
{{#configLoggingEnabledForWrites}}
} else {
{{logWarn}}("[Send] {{entityName}} -> {{log_}}: can't send null.", {{connectParameterName}});
{{/configLoggingEnabledForWrites}}
}
}{{#IndexBasedListAccess}}, index{{/IndexBasedListAccess}}, connectToken);
{{updateMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
if (writeCurrentValue) {
......
......@@ -667,6 +667,7 @@ task compileRelationIncremental(type: RagConnectTest) {
inputFiles = [file('src/test/01-input/relation/Test.relast'),
file('src/test/01-input/relation/Test.connect')]
rootNode = 'Root'
logWrites = true
extraOptions = defaultRagConnectOptionsAnd(['--experimental-jastadd-329'])
}
relast {
......
......@@ -15,13 +15,13 @@ send SenderRoot.BiOptionalB using ConcatValues;
send SenderRoot.BiListB using ConcatValueList;
ConcatValues maps B b to String {:
return b.getValue() + b.getInner().getInnerValue();
return b.getValue() + "+" + b.getInner().getInnerValue();
:}
ConcatValueList maps java.util.List<B> list to String {:
StringBuilder sb = new StringBuilder();
for (B b : list) {
sb.append(b.getValue() + b.getInner().getInnerValue()).append(";");
sb.append(b.getValue() + "+" + b.getInner().getInnerValue()).append(";");
}
return sb.toString();
:}
......
......@@ -4,18 +4,6 @@ aspect MakeCodeCompile {
}
aspect MakeCodeWork {
//public boolean SenderRoot.connectMyA(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectOptionalA(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectListA(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectBiMyA(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectBiOptionalA(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectBiListA(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectMyB(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectOptionalB(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectListB(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectBiMyB(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectBiOptionalB(String uriString, boolean sendCurrentValue) { return true; }
//public boolean SenderRoot.connectBiListB(String uriString, boolean sendCurrentValue) { return true; }
}
aspect NameResolution {
// overriding customID guarantees to produce the same JSON representation for equal lists
......@@ -32,4 +20,13 @@ aspect NameResolution {
protected String Inner.customID() {
return getClass().getSimpleName() + getInnerValue();
}
// override resolving of SenderRoot for As in ReceiverRoot
refine RefResolverStubs eq A.resolveToMyAByToken(String id) = getParent() != null ? resolveToMyAByTokenInh(id) : null;
inh SenderRoot A.resolveToMyAByTokenInh(String id);
eq SenderRoot.getA().resolveToMyAByTokenInh(String id) = globallyResolveSenderRootByToken(id);
eq ReceiverRoot.getChild().resolveToMyAByTokenInh(String id) = getFakeSenderRoot(id);
syn nta SenderRoot ReceiverRoot.getFakeSenderRoot(String id) = new SenderRoot();
}
......@@ -6,11 +6,9 @@ import org.junit.jupiter.api.Tag;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.function.Supplier;
import static java.util.function.Predicate.isEqual;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -149,7 +147,7 @@ public class RelationTest extends AbstractMqttTest {
// TODO implement test
// TODO also check disconnect
check(6, "a1", null, tuple(), null, null, tuple(),
"b1", "", tuple(), "", "", tuple());
"b1", null, tuple(), null, null, tuple());
}
@Override
......@@ -212,11 +210,17 @@ public class RelationTest extends AbstractMqttTest {
}
private void assertNullOrB(String expected, String actual, String alias) {
assertEquals(Objects.requireNonNullElse(expected, ""), actual, alias);
final String expectedValue;
if (expected == null) {
expectedValue = "";
} else {
expectedValue = expected + "+inner" + expected;
}
assertEquals(expectedValue, actual, alias);
}
private void assertListEqualsForB(List<Object> expected, String actual, String alias) {
String[] actualTokens = actual.split(";");
String[] actualTokens = actual.isEmpty() ? new String[0] : actual.split(";");
assertEquals(expected.size(), actualTokens.length, alias + ".size");
for (int i = 0, expectedSize = expected.size(); i < expectedSize; i++) {
String s = (String) expected.get(i);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment