Skip to content

Commit 5e7b9b9

Browse files
committed
Person name formatter with REST.
1 parent c510786 commit 5e7b9b9

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.nameapi.client.services.formatter.personnameformatter;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
import org.nameapi.ontology5.input.entities.person.InputPerson;
6+
import org.nameapi.ontology5.services.formatter.FormatterProperties;
7+
8+
/**
9+
*
10+
*/
11+
public class PersonNameFormatterArgument {
12+
13+
@NotNull
14+
private final InputPerson inputPerson;
15+
@Nullable
16+
private final FormatterProperties properties;
17+
18+
public PersonNameFormatterArgument(@NotNull InputPerson inputPerson, @Nullable FormatterProperties properties) {
19+
this.inputPerson = inputPerson;
20+
this.properties = properties;
21+
}
22+
23+
@NotNull
24+
public InputPerson getInputPerson() {
25+
return inputPerson;
26+
}
27+
28+
@Nullable
29+
public FormatterProperties getProperties() {
30+
return properties;
31+
}
32+
}

src/main/java/org/nameapi/client/services/formatter/personnameformatter/PersonNameFormatterCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.jetbrains.annotations.NotNull;
66
import org.nameapi.client.services.NameApiBaseCommand;
77
import org.nameapi.ontology5.services.formatter.FormatterResult;
8-
import org.nameapi.ontology5.services.formatter.personnameformatter.PersonNameFormatterArgument;
98

109
import java.util.concurrent.Callable;
1110

@@ -26,7 +25,7 @@ public PersonNameFormatterCommand() {
2625

2726
@Override
2827
public FormatterResult call(@NotNull Optional<PersonNameFormatterArgument> arg, @NotNull ExecutionContext ec) throws Exception {
29-
return getPort(ec).ping(getApiKey(ec));
28+
return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get().getInputPerson(), arg.get().getProperties());
3029
}
3130

3231
@NotNull @Override

src/main/java/org/nameapi/client/services/formatter/personnameformatter/RestPort.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
import com.optimaize.anythingworks.client.rest.http.RestHttpClientResponse;
77
import com.optimaize.anythingworks.common.rest.TypeRef;
88
import org.nameapi.client.services.RestServicePort;
9+
import org.nameapi.ontology5.input.context.Context;
10+
import org.nameapi.ontology5.input.entities.person.InputPerson;
11+
import org.nameapi.ontology5.services.formatter.FormatterProperties;
912
import org.nameapi.ontology5.services.formatter.FormatterResult;
13+
import org.nameapi.ontology5.services.formatter.personnameformatter.PersonNameFormatterInput;
1014

1115
/**
1216
*
@@ -19,13 +23,14 @@ public RestPort(RestHttpClient restApiClient, String servicePath) {
1923
super(restApiClient, servicePath);
2024
}
2125

22-
public FormatterResult ping(String apiKey) {
26+
public FormatterResult call(String apiKey, Context context, InputPerson inputPerson, FormatterProperties properties) {
2327
QueryParams queryParams = QueryParams.create();
2428
queryParams.add("apiKey", apiKey);
2529

26-
RestHttpClientResponse<FormatterResult> response = restApiClient.invokeGet(
27-
servicePath,
30+
RestHttpClientResponse<FormatterResult> response = restApiClient.invokeBody(
31+
servicePath, "POST",
2832
queryParams, HeaderParams.none(),
33+
new PersonNameFormatterInput(context, inputPerson, properties),
2934
returnType
3035
);
3136
return response.getResult().get();

src/test/functional/java/org/nameapi/client/services/formatter/personnameformatter/PersonNameFormatterCommandTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import org.nameapi.client.services.FunctionalTestsNameApiModeFactory;
66
import org.nameapi.client.lib.NameApiRemoteExecutors;
77
import org.nameapi.client.services.AbstractTest;
8-
import org.nameapi.client.services.formatter.FormatterProperties;
9-
import org.nameapi.client.services.formatter.FormatterPropertiesBuilder;
10-
import org.nameapi.client.services.formatter.FormatterResult;
118
import org.nameapi.ontology5.input.entities.person.NaturalInputPerson;
129
import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder;
10+
import org.nameapi.ontology5.services.formatter.FormatterProperties;
11+
import org.nameapi.ontology5.services.formatter.FormatterResult;
1312
import org.testng.annotations.Test;
1413

1514
import static org.testng.Assert.assertEquals;
@@ -26,7 +25,8 @@ public void testCall() throws Exception {
2625
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
2726

2827
NaturalInputPerson person = new NaturalInputPersonBuilder().name(makeName("petra müller")).build();
29-
FormatterProperties properties = new FormatterPropertiesBuilder().build();
28+
// FormatterProperties properties = new FormatterPropertiesBuilder().build();
29+
FormatterProperties properties = new FormatterProperties();
3030
PersonNameFormatterArgument argument = new PersonNameFormatterArgument(person, properties);
3131
FormatterResult formatterResult = executor.execute(command, mode, argument).get();
3232
assertEquals(formatterResult.getFormatted(), "Petra Müller");

0 commit comments

Comments
 (0)