Skip to content

Commit

Permalink
fix: exclude readonly from root key initalization (#7)
Browse files Browse the repository at this point in the history
* fix: exclude readonly from root key initalization

* fix: update version
  • Loading branch information
dominikhorn93 authored Aug 24, 2022
1 parent 271aea1 commit 0720150
Show file tree
Hide file tree
Showing 38 changed files with 112 additions and 50 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
</div>

<!-- ABOUT THE PROJECT -->

## About The Project

*Add a description from your project here.*
<p align="right">(<a href="#top">back to top</a>)</p>



### Built With

The documentation project is built with technologies we use in our projects:
Expand All @@ -38,32 +37,39 @@ The documentation project is built with technologies we use in our projects:
<p align="right">(<a href="#top">back to top</a>)</p>

<!-- ROADMAP -->

## Roadmap

*if you have a ROADMAP for your project add this here*


See the [open issues](#) for a full list of proposed features (and known issues).

<p align="right">(<a href="#top">back to top</a>)</p>

## Set up

*how can i start and fly this project*

Update version: ``mvn versions:set -DnewVersion='0.10.1-SNAPSHOT'``

<p align="right">(<a href="#top">back to top</a>)</p>

## Documentation

*what insights do you have to tell*

<p align="right">(<a href="#top">back to top</a>)</p>

<!-- CONTRIBUTING -->

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any
contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please open an issue with the tag "enhancement", fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
If you have a suggestion that would make this better, please open an issue with the tag "enhancement", fork the repo and
create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a
star! Thanks again!

1. Open an issue with the tag "enhancement"
2. Fork the Project
Expand All @@ -78,6 +84,7 @@ More about this in the [CODE_OF_CONDUCT](/CODE_OF_CONDUCT.md) file.


<!-- LICENSE -->

## License

Distributed under the MIT License. See `LICENSE` file for more information.
Expand All @@ -87,6 +94,7 @@ Distributed under the MIT License. See `LICENSE` file for more information.


<!-- CONTACT -->

## Contact

it@m - [email protected]
Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/digiwf-camunda-connector-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-connector</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/digiwf-camunda-connector-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-connector</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/digiwf-camunda-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-connector</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/digiwf-connector-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>digiwf-connector</artifactId>
<groupId>io.muenchendigital.digiwf</groupId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/digiwf-connector-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-connector</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>


Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/digiwf-connector-starter-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-connector</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/digiwf-connector-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-connector</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-core</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-engine/digiwf-engine-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-engine</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-engine/digiwf-engine-task-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-engine</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-engine/digiwf-engine-task/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-engine</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>


Expand Down
2 changes: 1 addition & 1 deletion digiwf-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-core</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-json-serialization</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public JSONObject generateValue(final String jsonPointer, final String value) {
*/
public JSONObject initialize(final String schema) {
final Schema schemaObj = JsonSerializationService.createSchema(new JSONObject(schema));
final Set<String> rootKeys = this.serializer.extractRootKeys(schemaObj);
final Set<String> rootKeys = this.serializer.extractRootKeys(schemaObj, true);
return this.serializer.generateObject(rootKeys);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public interface JsonSerializer {
*/
Set<String> extractRootKeys(final Schema schema);


/**
* Returns all root keys that are in the json schema.
*
* @param schema
* @param filterReadOnly
* @return root keys
*/
Set<String> extractRootKeys(final Schema schema, Boolean filterReadOnly);

/**
* Extract a value from a json object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,19 @@ public Map<String, Object> merge(final JSONObject source, final JSONObject targe
return this.deepMerge(source, target).toMap();
}

/**
* Returns all root keys that are in the json schema.
*
* @param schema
* @return root keys
*/
@Override
public Set<String> extractRootKeys(final Schema schema) {
public Set<String> extractRootKeys(final Schema schema, final Boolean filterReadOnly) {
if (schema instanceof ObjectSchema) {
final ObjectSchema objectSchema = (ObjectSchema) schema;

if (filterReadOnly) {
return objectSchema.getPropertySchemas()
.keySet()
.stream()
.filter(key -> objectSchema.getPropertySchemas().get(key).isReadOnly() != Boolean.TRUE)
.collect(Collectors.toSet());
}

return new HashSet<>(((ObjectSchema) schema).getPropertySchemas().keySet());
}

Expand All @@ -102,6 +106,17 @@ public Set<String> extractRootKeys(final Schema schema) {
return Collections.emptySet();
}

/**
* Returns all root keys that are in the json schema.
*
* @param schema
* @return root keys
*/
@Override
public Set<String> extractRootKeys(final Schema schema) {
return this.extractRootKeys(schema, false);
}

/**
* Extract a value from a json object
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.muenchendigital.digiwf.json.serialization;


import io.muenchendigital.digiwf.json.serialization.serializer.JsonSerializer;
import io.muenchendigital.digiwf.json.serialization.serializer.JsonSerializerImpl;
import org.assertj.core.api.Assertions;
import org.json.JSONObject;
Expand All @@ -20,10 +21,12 @@
public class JsonSchemaSerializationServiceTest {

private JsonSerializationService jsonSchemaSerializationService;
private JsonSerializer jsonSerializer;

@BeforeEach
private void setUp() {
this.jsonSchemaSerializationService = new JsonSerializationService(new JsonSerializerImpl());
this.jsonSerializer = new JsonSerializerImpl();
this.jsonSchemaSerializationService = new JsonSerializationService(this.jsonSerializer);
}

@Test
Expand Down Expand Up @@ -96,6 +99,33 @@ public void serializeDataAndUpdateWithReadonlyValues() throws URISyntaxException
Assertions.assertThat(serializedData).isEqualTo(validData);
}

@Test
public void serializeWithReadonlyValues() throws URISyntaxException, IOException {
final String rawSchema = this.getSchemaString("/schema/serialization/simpleSchema.json");

final Map<String, Object> source = Map.of(
"stringProp1", "stringValue"
);

final Map<String, Object> target = Map.of(
);


final JSONObject filteredData = this.jsonSchemaSerializationService.filter(rawSchema, source, true);

final Map<String, Object> serializedData = this.jsonSchemaSerializationService.merge(filteredData, new JSONObject(target));
final JSONObject defaultValue = this.jsonSchemaSerializationService.initialize(new JSONObject(rawSchema).toString());
final Map<String, Object> serializedDataWithDefaultValues = this.jsonSchemaSerializationService.merge(new JSONObject(serializedData), defaultValue);

final Map<String, Object> validData = new HashMap<>();

validData.put("stringProp1", "stringValue");
validData.put("stringProp2", "");

//override all
Assertions.assertThat(serializedDataWithDefaultValues).isEqualTo(validData);
}

@Test
public void serializeCombinedSchemaData() throws URISyntaxException, IOException {
final String rawSchema = this.getSchemaString("/schema/serialization/schema.json");
Expand Down Expand Up @@ -453,7 +483,6 @@ public void initializeSimpleSchema() throws URISyntaxException, IOException {
final JSONObject initializedObject = this.jsonSchemaSerializationService.initialize(rawSchema);

Assertions.assertThat(initializedObject.toMap()).isEqualTo(Map.of(
"numberProp1", "",
"stringProp1", "",
"stringProp2", ""
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-json-serialization</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-json-serialization</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion digiwf-libs/digiwf-json-serialization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-libs</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>digiwf-spring-cloudstream-utils</artifactId>
<groupId>io.muenchendigital.digiwf</groupId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<artifactId>digiwf-spring-cloudstream-utils</artifactId>
<groupId>io.muenchendigital.digiwf</groupId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>digiwf-spring-cloudstream-utils</artifactId>
<groupId>io.muenchendigital.digiwf</groupId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions digiwf-libs/digiwf-spring-cloudstream-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>digiwf-spring-cloudstream-utils</artifactId>
<packaging>pom</packaging>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
<name>digiwf-spring-cloudstream-utils</name>
<description>Cloudstream Utils used by DigiWF</description>

<parent>
<groupId>io.muenchendigital.digiwf</groupId>
<artifactId>digiwf-libs</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>0.10.1-SNAPSHOT</version>
</parent>

<modules>
Expand Down
Loading

0 comments on commit 0720150

Please sign in to comment.