Skip to content

Commit

Permalink
Changed version to SNAPSHOT, and updated tests etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Davenport committed Jun 11, 2024
1 parent 73e2bc1 commit 1a875c7
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'org.brapi'
version = '0.1.0'
version = '0.2.0-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

Expand Down
7 changes: 6 additions & 1 deletion java/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ publishing {
repositories {
maven {
name = "OSSRH"
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
if(project.version.endsWith('-SNAPSHOT')) {
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
} else {
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}

credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ public BrAPIClass readSchema(Path schemaPath, String module) throws BrAPISchemaR
public BrAPIClass readSchema(Path path, String schema, String module) throws BrAPISchemaReaderException {
try {
return createBrAPISchemas(path, objectMapper.readTree(schema), module).collect(Response.toList()).mapResult(list -> list.get(0)).
getResultOrThrow(response -> new RuntimeException(response.getMessagesCombined(",")));
getResultOrThrow(response -> new RuntimeException(
String.format("Can not read schema at '%s' in module '%s' from '%s', due to '%s'", path, module, schema, response.getMessagesCombined(","))));
} catch (RuntimeException | JsonProcessingException e) {
throw new BrAPISchemaReaderException(e);
throw new BrAPISchemaReaderException(String.format("Can not read schema at '%s' in module '%s' from '%s', due to '%s'", path, module, schema, e.getMessage()), e);
}
}

Expand Down Expand Up @@ -152,9 +153,9 @@ private Stream<Response<BrAPIClass>> createBrAPISchemas(Path path) {
}

private String findModule(Path path) {
String module = path.getParent().getFileName().toString();
String module = path != null ? path.getParent().getFileName().toString() : null;

return COMMON_MODULES.contains(module) ? null : module;
return module != null && COMMON_MODULES.contains(module) ? null : module;
}

private Stream<Response<BrAPIClass>> createBrAPISchemas(Path path, String module) {
Expand Down Expand Up @@ -211,7 +212,7 @@ private Response<BrAPIType> createType(Path path, JsonNode jsonNode, String fall
if (isEnum) {
return fail(Response.ErrorType.VALIDATION, String.format("Object Type '%s' can not be an enum!", fallbackName));
} else {
return createObjectType(path, jsonNode, findNameFromTitle(jsonNode).getResultIfPresentOrElseResult(fallbackName), module, isRequestPath(path));
return createObjectType(path, jsonNode, findNameFromTitle(jsonNode).getResultIfPresentOrElseResult(fallbackName), module);
}
}

Expand Down Expand Up @@ -261,10 +262,6 @@ private Response<BrAPIType> createType(Path path, JsonNode jsonNode, String fall

}

private boolean isRequestPath(Path path) {
return path.getParent().getFileName().endsWith("Requests") ;
}

private Response<String> findNameFromTitle(JsonNode jsonNode) {
return findString(jsonNode, "title", false).mapResult(name -> name != null ? name.replace(" ", "") : null);
}
Expand Down Expand Up @@ -307,11 +304,10 @@ private Response<BrAPIType> createArrayType(Path path, JsonNode jsonNode, String
map(() -> success(builder.build()));
}

private Response<BrAPIType> createObjectType(Path path, JsonNode jsonNode, String name, String module, boolean request) {
private Response<BrAPIType> createObjectType(Path path, JsonNode jsonNode, String name, String module) {

BrAPIObjectType.BrAPIObjectTypeBuilder builder = BrAPIObjectType.builder().
name(name).
request(request).
module(module);

findString(jsonNode, "description", false).
Expand Down Expand Up @@ -357,8 +353,10 @@ private Response<BrAPIObjectProperty> createProperty(Path path, JsonNode jsonNod
private Response<BrAPIMetadata> parseMetadata(JsonNode metadata) {
BrAPIMetadata.BrAPIMetadataBuilder builder = BrAPIMetadata.builder();

return findBoolean(metadata, "primaryModel", false).
return findBoolean(metadata, "primaryModel", false, false).
onSuccessDoWithResult(builder::primaryModel).
merge(findBoolean(metadata, "request", false, false)).
onSuccessDoWithResult(builder::request).
map(() -> success(builder.build()));
}

Expand Down Expand Up @@ -458,15 +456,15 @@ private Response<String> findString(JsonNode parentNode, String fieldName, boole
});
}

private Response<Boolean> findBoolean(JsonNode parentNode, String fieldName, boolean required) {
private Response<Boolean> findBoolean(JsonNode parentNode, String fieldName, boolean required, boolean defaultValue) {
return findChildNode(parentNode, fieldName, required).mapResultToResponse(jsonNode -> {
if (jsonNode instanceof BooleanNode booleanNode) {
return success(booleanNode.asBoolean());
}
return required ?
fail(Response.ErrorType.VALIDATION,
String.format("Child node type '%s' was not BooleanNode with field name '%s' for parent node '%s'", jsonNode.getClass().getName(), parentNode, fieldName)) :
Response.empty();
Response.success(defaultValue);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ public class BrAPISchemaReaderException extends Exception {
public BrAPISchemaReaderException(Exception cause) {
super(cause) ;
}

/** Constructs a new exception with the specified detail message and cause.
* Note that the detail message associated with cause is not automatically incorporated in this exception's detail message.
* @param message – the detail message (which is saved for later retrieval by the getMessage() method).
* @param cause – the cause (which is saved for later retrieval by the getCause() method).
* (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
*/
public BrAPISchemaReaderException(String message, Exception cause) {
super(message, cause) ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Response<GraphQLSchema> generate() {
}

private boolean isInputType(BrAPIClass type) {
return type instanceof BrAPIObjectType && ((BrAPIObjectType) type).isRequest() ;
return type instanceof BrAPIObjectType && type.getMetadata() != null && type.getMetadata().isRequest() ;
}

private boolean isPrimaryModel(BrAPIClass type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
@Value
public class BrAPIMetadata {
boolean primaryModel ;
boolean request ;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public class BrAPIObjectType implements BrAPIClass {
String description;
String module;
BrAPIMetadata metadata;
boolean request;
List<BrAPIObjectProperty> properties;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ void readDirectories() {
assertNotNull(listRequest);
assertEquals("ListRequest", listRequest.getName());
assertNull(listRequest.getModule());
assertNull(listRequest.getMetadata());
assertNotNull(listRequest.getMetadata());
assertTrue(listRequest.getMetadata().isRequest());

} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Expand Down Expand Up @@ -100,7 +102,17 @@ void readSchemaPath() {
assertEquals("Trial", trialSchema.getName());
assertEquals("BrAPI-Core", trialSchema.getModule());
assertNull(listTypeSchema.getMetadata());

BrAPIClass listRequest =
new BrAPISchemaReader().readSchema(Path.of(ClassLoader.getSystemResource("BrAPI-Schema/Requests/ListRequest.json").toURI()), null);

assertNotNull(listRequest);
assertEquals("ListRequest", listRequest.getName());
assertNull(listRequest.getModule());
assertNotNull(listRequest.getMetadata());
assertTrue(listRequest.getMetadata().isRequest());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Expand Down Expand Up @@ -132,7 +144,19 @@ void readSchemaString() {
assertEquals("Trial", trialSchema.getName());
assertEquals("BrAPI-Core", trialSchema.getModule());
assertNull(listTypeSchema.getMetadata());

path = Paths.get(Objects.requireNonNull(this.getClass().getResource("/BrAPI-Schema/Requests/ListRequest.json")).toURI());

BrAPIClass listRequest =
new BrAPISchemaReader().readSchema(null, String.join("\n", Files.readAllLines(path, Charset.defaultCharset())), null);

assertNotNull(listRequest);
assertEquals("ListRequest", listRequest.getName());
assertNull(listRequest.getModule());
assertNotNull(listRequest.getMetadata());
assertTrue(listRequest.getMetadata().isRequest());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void generate() {
try {
schema = new GraphQLGenerator().generate(Path.of(ClassLoader.getSystemResource("BrAPI-Schema").toURI()));
} catch (URISyntaxException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
assertNotNull(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void generate() {
specifications = new OpenAPIGenerator(OpenAPIGeneratorOptions.builder().separatingByModule(false).build()).
generate(Path.of(ClassLoader.getSystemResource("BrAPI-Schema").toURI()), Path.of(ClassLoader.getSystemResource("OpenAPI-Components").toURI()));
} catch (URISyntaxException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
assertNotNull(specifications);
Expand All @@ -43,6 +44,7 @@ void generateByModule() {
specifications = new OpenAPIGenerator(OpenAPIGeneratorOptions.builder().separatingByModule(true).build()).
generate(Path.of(ClassLoader.getSystemResource("BrAPI-Schema").toURI()), Path.of(ClassLoader.getSystemResource("OpenAPI-Components").toURI()));
} catch (URISyntaxException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
assertNotNull(specifications);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
"listType": {
"$ref": "../BrAPI-Core/ListType.json#/$defs/ListType"
}
},
"brapi-metadata": {
"request": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@
}
}
}
]
],
"brapi-metadata": {
"request": true
}
}
},
"$id": "https://brapi.org/Specification/BrAPI-Schema/Requests/LocationRequest.json",
Expand Down

0 comments on commit 1a875c7

Please sign in to comment.