Repository: apache/streampipes
Pull request #2202 (2023-11-17 15:17:24)

feat: create builder for AssetLink
<!--
  ~ 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.
-->

### 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



Patch:
diff --git a/pom.xml b/pom.xml
index fef4b34cc0..bccd9c07c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
+
 <!--
 ~ Licensed to the Apache Software Foundation (ASF) under one or more
 ~ contributor license agreements.  See the NOTICE file distributed with
@@ -143,6 +144,7 @@
         <maven.dependency.check.plugin.version>8.4.0</maven.dependency.check.plugin.version>
         <maven-shade-plugin.version>3.4.1</maven-shade-plugin.version>
         <maven.version>3.8.7</maven.version>
+        <typescript-generator-maven-plugin.version>3.2.1263</typescript-generator-maven-plugin.version>
 
 
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -956,6 +958,11 @@
 
         <pluginManagement>
             <plugins>
+                <plugin>
+                    <groupId>cz.habarta.typescript-generator</groupId>
+                    <artifactId>typescript-generator-maven-plugin</artifactId>
+                    <version>${typescript-generator-maven-plugin.version}</version>
+                </plugin>
                 <plugin>
                     <groupId>net.revelc.code.formatter</groupId>
                     <artifactId>formatter-maven-plugin</artifactId>
diff --git a/streampipes-model-client/pom.xml b/streampipes-model-client/pom.xml
index 59452446eb..aed5bbfbfd 100644
--- a/streampipes-model-client/pom.xml
+++ b/streampipes-model-client/pom.xml
@@ -60,7 +60,6 @@
             <plugin>
                 <groupId>cz.habarta.typescript-generator</groupId>
                 <artifactId>typescript-generator-maven-plugin</artifactId>
-                <version>3.2.1263</version>
                 <executions>
                     <execution>
                         <id>generate</id>
diff --git a/streampipes-model/pom.xml b/streampipes-model/pom.xml
index 7a4dae6a6c..be1c634faf 100644
--- a/streampipes-model/pom.xml
+++ b/streampipes-model/pom.xml
@@ -78,7 +78,6 @@
             <plugin>
                 <groupId>cz.habarta.typescript-generator</groupId>
                 <artifactId>typescript-generator-maven-plugin</artifactId>
-                <version>3.2.1263</version>
                 <executions>
                     <execution>
                         <id>generate</id>
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/assets/AssetLinkBuilder.java b/streampipes-model/src/main/java/org/apache/streampipes/model/assets/AssetLinkBuilder.java
new file mode 100644
index 0000000000..68f127a0f6
--- /dev/null
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/assets/AssetLinkBuilder.java
@@ -0,0 +1,119 @@
+/*
+ * 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.model.assets;
+
+/**
+ * Builder class for creating instances of {@link AssetLink}.
+ * <p>
+ * Example usage:
+ * <pre>
+ * {@code
+ * AssetLink assetLink = AssetLinkBuilder.create()
+ *     .withResourceId("123")
+ *     .withLinkType("type")
+ *     .withLinkLabel("label")
+ *     .withQueryHint("hint")
+ *     .withEditingDisabled(false)
+ *     .build();
+ * }
+ * </pre>
+ */
+public class AssetLinkBuilder {
+  private final AssetLink assetLink;
+
+  /**
+   * Constructs a new AssetLinkBuilder.
+   */
+  private AssetLinkBuilder() {
+    this.assetLink = new AssetLink();
+  }
+
+  /**
+   * Static method to create a new instance of AssetLinkBuilder.
+   *
+   * @return A new instance of AssetLinkBuilder.
+   */
+  public static AssetLinkBuilder create() {
+    return new AssetLinkBuilder();
+  }
+
+  /**
+   * Sets the resource ID for the AssetLink being built.
+   *
+   * @param resourceId The resource ID to set.
+   * @return The AssetLinkBuilder instance for method chaining.
+   */
+  public AssetLinkBuilder withResourceId(String resourceId) {
+    this.assetLink.setResourceId(resourceId);
+    return this;
+  }
+
+  /**
+   * Sets the link type for the AssetLink being built.
+   *
+   * @param linkType The link type to set.
+   * @return The AssetLinkBuilder instance for method chaining.
+   */
+  public AssetLinkBuilder withLinkType(String linkType) {
+    this.assetLink.setLinkType(linkType);
+    return this;
+  }
+
+  /**
+   * Sets the link label for the AssetLink being built.
+   *
+   * @param linkLabel The link label to set.
+   * @return The AssetLinkBuilder instance for method chaining.
+   */
+  public AssetLinkBuilder withLinkLabel(String linkLabel) {
+    this.assetLink.setLinkLabel(linkLabel);
+    return this;
+  }
+
+  /**
+   * Sets the query hint for the AssetLink being built.
+   *
+   * @param queryHint The query hint to set.
+   * @return The AssetLinkBuilder instance for method chaining.
+   */
+  public AssetLinkBuilder withQueryHint(String queryHint) {
+    this.assetLink.setQueryHint(queryHint);
+    return this;
+  }
+
+  /**
+   * Sets whether editing is disabled for the AssetLink being built.
+   *
+   * @param editingDisabled Whether editing is disabled.
+   * @return The AssetLinkBuilder instance for method chaining.
+   */
+  public AssetLinkBuilder withEditingDisabled(boolean editingDisabled) {
+    this.assetLink.setEditingDisabled(editingDisabled);
+    return this;
+  }
+
+  /**
+   * Builds and returns the final instance of AssetLink.
+   *
+   * @return The constructed AssetLink instance.
+   */
+  public AssetLink build() {
+    return this.assetLink;
+  }
+}
\ No newline at end of file


Test patch:
diff --git a/streampipes-model/src/test/java/org/apache/streampipes/model/assets/AssetLinkBuilderTest.java b/streampipes-model/src/test/java/org/apache/streampipes/model/assets/AssetLinkBuilderTest.java
new file mode 100644
index 0000000000..4f237ebdbc
--- /dev/null
+++ b/streampipes-model/src/test/java/org/apache/streampipes/model/assets/AssetLinkBuilderTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.model.assets;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class AssetLinkBuilderTest {
+
+  @Test
+  public void withoutEditingDisabled() {
+    AssetLink assetLink = AssetLinkBuilder.create()
+            .withResourceId("123")
+            .withLinkType("type")
+            .withLinkLabel("label")
+            .withQueryHint("hint")
+            .withEditingDisabled(false)
+            .build();
+
+    assertEquals("123", assetLink.getResourceId());
+    assertEquals("type", assetLink.getLinkType());
+    assertEquals("label", assetLink.getLinkLabel());
+    assertEquals("hint", assetLink.getQueryHint());
+    assertFalse(assetLink.isEditingDisabled());
+  }
+
+  @Test
+  public void withEditingDisabled() {
+    AssetLink assetLink = AssetLinkBuilder.create()
+            .withResourceId("456")
+            .withLinkType("anotherType")
+            .withLinkLabel("anotherLabel")
+            .withQueryHint("anotherHint")
+            .withEditingDisabled(true)
+            .build();
+
+    assertEquals("456", assetLink.getResourceId());
+    assertEquals("anotherType", assetLink.getLinkType());
+    assertEquals("anotherLabel", assetLink.getLinkLabel());
+    assertEquals("anotherHint", assetLink.getQueryHint());
+    assertTrue(assetLink.isEditingDisabled());
+  }
+}