You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by "bossenti (via GitHub)" <gi...@apache.org> on 2023/12/01 15:59:34 UTC

[PR] extend SDK by builder for nested properties

bossenti opened a new pull request, #2262:
URL: https://github.com/apache/streampipes/pull/2262

   <!--
     ~ Licensed to the Apache Software Foundation (ASF) under one or more
     ~ contributor license agreements.  See the NOTICE file distributed with
     ~ this work for additional information regarding copyright ownership.
     ~ The ASF licenses this file to You under the Apache License, Version 2.0
     ~ (the "License"); you may not use this file except in compliance with
     ~ the License.  You may obtain a copy of the License at
     ~
     ~    http://www.apache.org/licenses/LICENSE-2.0
     ~
     ~ Unless required by applicable law or agreed to in writing, software
     ~ distributed under the License is distributed on an "AS IS" BASIS,
     ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     ~ See the License for the specific language governing permissions and
     ~ limitations under the License.
     ~
     -->
     
     <!--
   Thanks for contributing! Here are some tips you can follow to help us incorporate your contribution quickly and easily:
   1. If this is your first time, please read our contributor guidelines:
       - https://streampipes.apache.org/getinvolved.html
       - https://cwiki.apache.org/confluence/display/STREAMPIPES/Getting+Started
   2. Make sure the PR title is formatted like: `[#<GitHub issue id>] PR title ...`
   3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., `[WIP][#<GitHub issue id>] PR title ...`.
   4. Please write your PR title to summarize what this PR proposes/fixes.
   5. Link the PR to the corresponding GitHub issue (if present) in the `Development` section in the right menu bar. 
   6. Be sure to keep the PR description updated to reflect all changes.
   7. If possible, provide a concise example to reproduce the issue for a faster review.
   8. Make sure tests pass via `mvn clean install`.
   9. (Optional) If the contribution is large, please file an Apache ICLA
       - http://apache.org/licenses/icla.pdf
   -->
   
   ### Purpose
   <!--
   Please clarify what changes you are proposing and describe how those changes will address the issue.
   Furthermore, describe potential consequences the changes might have.
   -->
   Extend the StreamPipes SDK by the missing builder for nested event properties.
   
   ### Remarks
   <!--
   Is there anything left we need to pay attention on?
   Are there some references that might be important? E.g. links to Confluence, or discussions
   on the mailing list or GitHub.
   -->
   PR introduces (a) breaking change(s): no
   
   PR introduces (a) deprecation(s): no
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] extend SDK by builder for nested properties

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #2262:
URL: https://github.com/apache/streampipes/pull/2262#discussion_r1413428540


##########
streampipes-sdk/src/main/java/org/apache/streampipes/sdk/builder/NestedPropertyBuilder.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.sdk.builder;
+
+import org.apache.streampipes.model.schema.EventProperty;
+import org.apache.streampipes.model.schema.EventPropertyNested;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Builder class for creating instances of {@link EventPropertyNested}.
+ */
+public class NestedPropertyBuilder {
+
+  /**
+   * The {@link EventPropertyNested} being constructed by this builder.
+   */
+  private final EventPropertyNested eventPropertyNested;
+
+  /**
+   * List of {@link EventProperty} instances contained within the {@link EventPropertyNested}.
+   */
+  private final List<EventProperty> containedEventProperties;
+
+  private NestedPropertyBuilder(String propertyName) {
+    if (propertyName == null || propertyName.isEmpty()) {
+      throw new IllegalArgumentException("Property name cannot be null or empty");
+    }
+    this.eventPropertyNested = new EventPropertyNested(propertyName);
+    this.containedEventProperties = new ArrayList<>();
+  }
+
+  /**
+   * Static factory method to create a new instance of the builder.
+   *
+   * @param propertyName The name of the property.
+   * @return A new instance of {@code NestedPropertyBuilder}.
+   */
+  public static NestedPropertyBuilder create(String propertyName) {
+    return new NestedPropertyBuilder(propertyName);
+  }
+
+  /**
+   * Adds a single {@link EventProperty} to the list of nested properties.
+   *
+   * @param eventProperty The {@link EventProperty} to add.
+   * @return This builder instance for method chaining.
+   */
+  public NestedPropertyBuilder withEventProperty(EventProperty eventProperty) {
+    this.containedEventProperties.add(eventProperty);
+    return this;
+  }
+
+  /**
+   * Adds multiple {@link EventProperty} instances to the list of nested properties.
+   *
+   * @param eventProperties The array of {@link EventProperty} instances to add.
+   * @return This builder instance for method chaining.
+   */
+  public NestedPropertyBuilder withEventProperties(EventProperty... eventProperties) {
+    this.containedEventProperties.addAll(List.of(eventProperties));
+    return this;
+  }
+
+  /**
+   * Builds and returns the final {@link EventPropertyNested} instance.
+   * Note: This method creates a new instance to ensure immutability.
+   *
+   * @return The constructed {@link EventPropertyNested}.
+   */
+  public EventPropertyNested build() {
+    // Create a new instance to make the class immutable
+    EventPropertyNested built = new EventPropertyNested(this.eventPropertyNested.getRuntimeName());
+    built.setEventProperties(containedEventProperties);
+    return built;
+  }
+
+  /**
+   * Resets the builder state, allowing it to be reused for creating another instance.
+   *
+   * @return A new instance of {@code NestedPropertyBuilder}.
+   */
+  public NestedPropertyBuilder clear() {

Review Comment:
   It was thought of as a convenience functionality, but I agree with you that it isn't really necessary. I'll remove it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] extend SDK by builder for nested properties

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti merged PR #2262:
URL: https://github.com/apache/streampipes/pull/2262


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] extend SDK by builder for nested properties

Posted by "tenthe (via GitHub)" <gi...@apache.org>.
tenthe commented on code in PR #2262:
URL: https://github.com/apache/streampipes/pull/2262#discussion_r1412372059


##########
streampipes-sdk/src/main/java/org/apache/streampipes/sdk/builder/NestedPropertyBuilder.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.sdk.builder;
+
+import org.apache.streampipes.model.schema.EventProperty;
+import org.apache.streampipes.model.schema.EventPropertyNested;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Builder class for creating instances of {@link EventPropertyNested}.
+ */
+public class NestedPropertyBuilder {
+
+  /**
+   * The {@link EventPropertyNested} being constructed by this builder.
+   */
+  private final EventPropertyNested eventPropertyNested;
+
+  /**
+   * List of {@link EventProperty} instances contained within the {@link EventPropertyNested}.
+   */
+  private final List<EventProperty> containedEventProperties;
+
+  private NestedPropertyBuilder(String propertyName) {
+    if (propertyName == null || propertyName.isEmpty()) {
+      throw new IllegalArgumentException("Property name cannot be null or empty");
+    }
+    this.eventPropertyNested = new EventPropertyNested(propertyName);
+    this.containedEventProperties = new ArrayList<>();
+  }
+
+  /**
+   * Static factory method to create a new instance of the builder.
+   *
+   * @param propertyName The name of the property.
+   * @return A new instance of {@code NestedPropertyBuilder}.
+   */
+  public static NestedPropertyBuilder create(String propertyName) {
+    return new NestedPropertyBuilder(propertyName);
+  }
+
+  /**
+   * Adds a single {@link EventProperty} to the list of nested properties.
+   *
+   * @param eventProperty The {@link EventProperty} to add.
+   * @return This builder instance for method chaining.
+   */
+  public NestedPropertyBuilder withEventProperty(EventProperty eventProperty) {
+    this.containedEventProperties.add(eventProperty);
+    return this;
+  }
+
+  /**
+   * Adds multiple {@link EventProperty} instances to the list of nested properties.
+   *
+   * @param eventProperties The array of {@link EventProperty} instances to add.
+   * @return This builder instance for method chaining.
+   */
+  public NestedPropertyBuilder withEventProperties(EventProperty... eventProperties) {
+    this.containedEventProperties.addAll(List.of(eventProperties));
+    return this;
+  }
+
+  /**
+   * Builds and returns the final {@link EventPropertyNested} instance.
+   * Note: This method creates a new instance to ensure immutability.
+   *
+   * @return The constructed {@link EventPropertyNested}.
+   */
+  public EventPropertyNested build() {
+    // Create a new instance to make the class immutable
+    EventPropertyNested built = new EventPropertyNested(this.eventPropertyNested.getRuntimeName());
+    built.setEventProperties(containedEventProperties);
+    return built;
+  }
+
+  /**
+   * Resets the builder state, allowing it to be reused for creating another instance.
+   *
+   * @return A new instance of {@code NestedPropertyBuilder}.
+   */
+  public NestedPropertyBuilder clear() {

Review Comment:
   Is there a specific reason why this method is included? Otherwise the user can just create a new builder instance



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org