Skip to content

Commit eab35db

Browse files
authored
Merge pull request #66 from TheWorldAvatar/StackHost-blank-as-empty
StackHost treat blank as empty
2 parents 192370d + 0b1b9b3 commit eab35db

File tree

10 files changed

+43
-38
lines changed

10 files changed

+43
-38
lines changed

stack-clients/.vscode/tasks.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"cwd": "${cwd}/../stack-manager",
1515
"shell": {
1616
"executable": "bash",
17-
"args": [
18-
"-c"
19-
]
2017
}
2118
},
2219
"group": {
@@ -35,9 +32,6 @@
3532
"cwd": "${cwd}/../stack-data-uploader",
3633
"shell": {
3734
"executable": "bash",
38-
"args": [
39-
"-c"
40-
]
4135
}
4236
},
4337
"group": {
@@ -67,10 +61,7 @@
6761
],
6862
"options": {
6963
"shell": {
70-
"executable": "bash",
71-
"args": [
72-
"-c"
73-
]
64+
"executable": "bash"
7465
}
7566
},
7667
"group": {

stack-clients/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
stack-client:
3-
image: ghcr.io/theworldavatar/stack-client${IMAGE_SUFFIX}:1.52.0
3+
image: ghcr.io/theworldavatar/stack-client${IMAGE_SUFFIX}:1.53.0
44
secrets:
55
- blazegraph_password
66
- postgis_password

stack-clients/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.cmclinnovations</groupId>
99
<artifactId>stack-clients</artifactId>
10-
<version>1.52.0</version>
10+
<version>1.53.0</version>
1111

1212
<name>Stack Clients</name>
1313
<url>https://theworldavatar.io</url>

stack-clients/src/main/java/com/cmclinnovations/stack/clients/core/StackHost.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ public StackHost(String hostName) {
2323
}
2424

2525
public Optional<String> getProto() {
26-
return proto;
26+
return proto.filter(p -> !p.isBlank());
2727
}
2828

2929
public Optional<String> getName() {
30-
return name;
30+
return name.filter(n -> !n.isBlank());
3131
}
3232

3333
public Optional<String> getPort() {
34-
return port;
34+
return port.filter(p -> !p.isBlank());
3535
}
3636

3737
public Optional<String> getPath() {
38-
return path;
38+
return path.filter(p -> !p.isBlank());
3939
}
4040

4141
public Builder getStringBuilder() {
@@ -52,42 +52,42 @@ public class Builder {
5252
private boolean finalSlash = false;
5353

5454
public Builder withProto() {
55-
proto.ifPresent(p -> protoOut = p);
55+
getProto().ifPresent(p -> protoOut = p);
5656
return this;
5757
}
5858

5959
public Builder withProto(String defaultProto) {
60-
protoOut = proto.orElse(defaultProto);
60+
protoOut = getProto().orElse(defaultProto);
6161
return this;
6262
}
6363

6464
public Builder withName() {
65-
name.ifPresent(n -> nameOut = n);
65+
getName().ifPresent(n -> nameOut = n);
6666
return this;
6767
}
6868

6969
public Builder withName(String defaultName) {
70-
nameOut = name.orElse(defaultName);
70+
nameOut = getName().orElse(defaultName);
7171
return this;
7272
}
7373

7474
public Builder withPort() {
75-
port.ifPresent(p -> portOut = p);
75+
getPort().ifPresent(p -> portOut = p);
7676
return this;
7777
}
7878

7979
public Builder withPort(String defaultPort) {
80-
portOut = port.orElse(defaultPort);
80+
portOut = getPort().orElse(defaultPort);
8181
return this;
8282
}
8383

8484
public Builder withPath() {
85-
path.ifPresent(p -> pathOut = p);
85+
getPath().ifPresent(p -> pathOut = p);
8686
return this;
8787
}
8888

8989
public Builder withPath(String defaultPath) {
90-
pathOut = path.orElse(defaultPath);
90+
pathOut = getPath().orElse(defaultPath);
9191
return this;
9292
}
9393

stack-clients/src/main/java/com/cmclinnovations/stack/services/GrlcService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import com.cmclinnovations.stack.clients.core.EndpointNames;
44
import com.cmclinnovations.stack.clients.core.StackClient;
5+
import com.cmclinnovations.stack.clients.core.StackHost;
56
import com.cmclinnovations.stack.clients.rdf4j.Rdf4jEndpointConfig;
67
import com.cmclinnovations.stack.services.config.ServiceConfig;
78

89
public class GrlcService extends ContainerService {
910

1011
public static final String TYPE = "grlc";
1112

13+
private static final String EXTERNAL_PORT_KEY = "EXTERNAL_PORT";
1214
private static final String GRLC_SERVER_NAME_KEY = "GRLC_SERVER_NAME";
1315
private static final String GRLC_SPARQL_ENDPOINT_KEY = "GRLC_SPARQL_ENDPOINT";
1416

@@ -19,13 +21,12 @@ public GrlcService(String stackName, ServiceConfig config) {
1921
@Override
2022
protected void doPreStartUpConfiguration() {
2123

22-
// String serverName = (StackClient.getStackHost()
23-
// .getWithDefaults(null, "", "", "") + "rest/")
24-
// .replaceAll("/+", "\\\\/");
25-
26-
String serverName = StackClient.getStackHost().getStringBuilder()
27-
.withName()
28-
.withPort()
24+
StackHost stackHost = StackClient.getStackHost();
25+
String serverName = stackHost.getStringBuilder()
26+
// Assume running locally if name not set
27+
.withName("localhost")
28+
// Assume using Nginx external port if name not set, otherwise no port (80/443 assumed)
29+
.withPort(stackHost.getName().isPresent() ? null : System.getenv(EXTERNAL_PORT_KEY))
2930
.withPath()
3031
.withExtraPath("rest")
3132
.build()

stack-clients/src/test/java/com/cmclinnovations/stack/StackHostTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.cmclinnovations.stack.clients.utils.JsonHelper;
1010
import com.fasterxml.jackson.databind.ObjectMapper;
1111

12-
public class StackHostTest {
12+
class StackHostTest {
1313
ObjectMapper objectMapper = JsonHelper.getMapper();
1414

1515
@Test
@@ -45,6 +45,19 @@ void testNameJson() {
4545
() -> Assertions.assertEquals("host", stackHost.getStringBuilder().withName().build()));
4646
}
4747

48+
@Test
49+
void testEmptyStrings() {
50+
StackHost stackHostDefault = new StackHost();
51+
StackHost stackHostJson = Assertions
52+
.assertDoesNotThrow(() -> objectMapper.readValue("{\"proto\":\"\", \"name\":\"\",\"port\":\" \",\"path\":\" \"}", StackHost.class));
53+
Assertions.assertAll(
54+
() -> Assertions.assertEquals(stackHostDefault.getProto(), stackHostJson.getProto()),
55+
() -> Assertions.assertEquals(stackHostDefault.getName(), stackHostJson.getName()),
56+
() -> Assertions.assertEquals(stackHostDefault.getPort(), stackHostJson.getPort()),
57+
() -> Assertions.assertEquals(stackHostDefault.getPath(), stackHostJson.getPath()),
58+
() -> Assertions.assertEquals("", stackHostJson.getStringBuilder().withName().build()));
59+
}
60+
4861
@Test
4962
void testWithNameConstructor() {
5063
StackHost stackHost = new StackHost("myhost");

stack-data-uploader/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
stack-data-uploader:
3-
image: ghcr.io/theworldavatar/stack-data-uploader${IMAGE_SUFFIX}:1.52.0
3+
image: ghcr.io/theworldavatar/stack-data-uploader${IMAGE_SUFFIX}:1.53.0
44
secrets:
55
- blazegraph_password
66
- postgis_password

stack-data-uploader/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.cmclinnovations</groupId>
99
<artifactId>stack-data-uploader</artifactId>
10-
<version>1.52.0</version>
10+
<version>1.53.0</version>
1111

1212
<name>Stack Data Uploader</name>
1313
<url>https://theworldavatar.io</url>
@@ -38,7 +38,7 @@
3838
<dependency>
3939
<groupId>com.cmclinnovations</groupId>
4040
<artifactId>stack-clients</artifactId>
41-
<version>1.52.0</version>
41+
<version>1.53.0</version>
4242
</dependency>
4343

4444
<dependency>

stack-manager/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
stack-manager:
3-
image: ghcr.io/theworldavatar/stack-manager${IMAGE_SUFFIX}:1.52.0
3+
image: ghcr.io/theworldavatar/stack-manager${IMAGE_SUFFIX}:1.53.0
44
environment:
55
EXTERNAL_PORT: "${EXTERNAL_PORT-3838}"
66
STACK_BASE_DIR: "${STACK_BASE_DIR}"

stack-manager/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.cmclinnovations</groupId>
99
<artifactId>stack-manager</artifactId>
10-
<version>1.52.0</version>
10+
<version>1.53.0</version>
1111

1212
<name>Stack Manager</name>
1313
<url>https://theworldavatar.io</url>
@@ -38,7 +38,7 @@
3838
<dependency>
3939
<groupId>com.cmclinnovations</groupId>
4040
<artifactId>stack-clients</artifactId>
41-
<version>1.52.0</version>
41+
<version>1.53.0</version>
4242
</dependency>
4343

4444
<dependency>

0 commit comments

Comments
 (0)