Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builder): Builder pattern support for entities creation #4

Merged
merged 2 commits into from
Apr 6, 2018

Conversation

abourdon
Copy link

@abourdon abourdon commented Apr 5, 2018

Hi,

Please accept this PR that adds the ability to use the Builder pattern during FROST-Client's Entity creation:

final Thing thing = ThingBuilder.builder()
  .name("Camera")
  .description("This thing is a camera.")
  .build()

In addition, any FROST-Client's entity builder can be extended. This way, FROST-Client clients could define their own way to construct OGC SensorThings' entities (by creating new FROST-Client's entity builders) and so could help to partially extend the FROST-Client's entity model (#3):

public final class MyCustomObservationBuilder extends AbstractObservationBuilder<MyCustomObservationBuilder> {

    private MyCustomObservationBuilder() {
    }

    public static MyCustomObservationBuilder builder() {
        return new MyCustomObservationBuilder();
    }

    @Override
    protected MyCustomObservationBuilder getSelf() {
        return this;
    }

    /**
     * Can only handle {@link MyCustomResult} type as Observation#result
     */
    public MyCustomObservationBuilder result(final MyCustomResult result) {
        return super.result(result);
    }

}

Finally, this PR includes:

  • A new way to construct FROST-Client's entities, by using the Builder pattern
  • The ability of any FROST-Client's entity builder to be extended to try to be more compatible with FROST-Client client needs
  • A fluent API when using FROST-Client's entity builders
  • A fully compliance with the OGC SensorThings' entities specification when using FROST-Client's entity builders interfaces

Regards,
Aurélien

@hylkevds
Copy link
Member

hylkevds commented Apr 5, 2018

Wow, that looks nice!

Maybe we can somehow get the json parser to also use this...


@Override
protected MultiDatastream getBuildingInstance() {
return new MultiDatastream();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that supposed to be here? It'll return a new MultiDatastream each time...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, well seen ;-) I fix it.

@abourdon
Copy link
Author

abourdon commented Apr 5, 2018

@hylkevds thanks ;-)

IMHO it is not necessary to use it within the JSON parser as you are using the Jackson library that provides lot of nice features based on your entity model. Those builders are more oriented to FROST-Client's users that want to manually create entities.

@hylkevds hylkevds merged commit 7877c3b into FraunhoferIOSB:master Apr 6, 2018
@abourdon
Copy link
Author

abourdon commented Apr 6, 2018

@hylkevds, thanks. Could it be possible to release a 0.16 version that incorporates these changes?

@hylkevds
Copy link
Member

hylkevds commented Apr 6, 2018

Done :)
Forgot to update the change log again...

@abourdon
Copy link
Author

abourdon commented Apr 6, 2018

Thanks! Yes and the README.md should also be updated to point to this new version: https://github.com/FraunhoferIOSB/FROST-Client#using-with-maven

@hylkevds
Copy link
Member

hylkevds commented Apr 6, 2018

Good point... haven't heard back from JFrog/Bintray yet. I'll change the maven howto till they fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants