Class AbstractPayloadBuilder<T extends AbstractPayloadBuilder<T>>

java.lang.Object
net.ygbstudio.powerwp4j.base.extension.builders.AbstractPayloadBuilder<T>
Type Parameters:
T - the concrete payload builder subtype
Direct Known Subclasses:
WPBasicPayloadBuilder

public abstract class AbstractPayloadBuilder<T extends AbstractPayloadBuilder<T>> extends Object
Abstract class for payload builders that can be used to simplify the process of building payloads for the WordPress REST API. From this class, you can create your own payload builders that can be used to interact with the methods provided by the HttpRequestService class.

Methods that return the payload builder are chainable and inherited by all subclasses, so that builders can relay on the same behaviour or specialize it for their specific needs.

Note that it is possible to reuse the same builder in cases where your flow requires it. To do that, call clear() before building a new payload. The clear operation is chainable so you can start your builder with it and chain the elements you need after a clean start.

See Also:
  • Field Details

    • author

      protected Integer author
      WordPress author ID.
    • status

      protected String status
      WordPress post status value.
    • type

      protected String type
      WordPress post type value.
    • format

      protected String format
      WordPress post format value.
    • commentStatus

      protected String commentStatus
      WordPress comment status value.
    • categories

      protected List<Integer> categories
      Category IDs associated with the payload.
    • tags

      protected List<Integer> tags
      Tag IDs associated with the payload.
    • slug

      protected String slug
      URL slug for the payload.
    • name

      protected String name
      Taxonomy name for taxonomy payloads.
    • description

      protected String description
      Taxonomy description for taxonomy payloads.
    • title

      protected String title
      Post title.
    • content

      protected String content
      Post content.
    • excerpt

      protected String excerpt
      Post excerpt.
    • password

      protected String password
      Password for password-protected content.
    • sticky

      protected Boolean sticky
      Whether the post is sticky.
    • featuredMedia

      protected Integer featuredMedia
      Featured media attachment ID.
  • Constructor Details

    • AbstractPayloadBuilder

      protected AbstractPayloadBuilder()
      Creates an empty payload builder base.
  • Method Details

    • self

      protected T self()
      Returns the current instance of the payload builder. This is a protected method used for chaining method calls.

      The cast to type T is safe because the method is only called within the class hierarchy and this class is parameterized with the type of the subclass.

      Returns:
      the current instance of the payload builder
    • status

      public T status(@NotNull @NotNull PostStatusEnum postStatus)
      Sets the post status.
      Parameters:
      postStatus - the post status to set
      Returns:
      the payload builder
    • type

      public T type(@NotNull @NotNull PostTypeEnum postType)
      Sets the post type.
      Parameters:
      postType - the post type to set
      Returns:
      the payload builder
    • format

      public T format(@NotNull @NotNull PostFormatEnum postFormat)
      Sets the post format.
      Parameters:
      postFormat - the post format to set
      Returns:
      the payload builder
    • categories

      public T categories(@NotNull @NotNull List<Integer> categories)
      Sets the categories.
      Parameters:
      categories - the categories to set
      Returns:
      the payload builder
    • tags

      public T tags(@NotNull @NotNull List<Integer> tags)
      Sets the tags.
      Parameters:
      tags - the tags to set
      Returns:
      the payload builder
    • slug

      public T slug(@NotNull @NotNull String slug)
      Sets the slug.
      Parameters:
      slug - the slug to set
      Returns:
      the payload builder
    • name

      public T name(@NotNull @NotNull String name)
      Sets the name.
      Parameters:
      name - the name to set
      Returns:
      the payload builder
    • description

      public T description(@NotNull @NotNull String description)
      Sets the description.
      Parameters:
      description - the description to set
      Returns:
      the payload builder
    • title

      public T title(@NotNull @NotNull String title)
      Sets the title.
      Parameters:
      title - the title to set
      Returns:
      the payload builder
    • content

      public T content(@NotNull @NotNull String content)
      Sets the content.
      Parameters:
      content - the content to set
      Returns:
      the payload builder
    • excerpt

      public T excerpt(@NotNull @NotNull String excerpt)
      Sets the excerpt.
      Parameters:
      excerpt - the excerpt to set
      Returns:
      the payload builder
    • author

      public T author(@NotNull @NotNull Integer author)
      Sets the author.
      Parameters:
      author - the author to set
      Returns:
      the payload builder
    • password

      public T password(@NotNull @NotNull String password)
      Sets the password.
      Parameters:
      password - the password to set
      Returns:
      the payload builder
    • commentStatus

      public T commentStatus(@NotNull @NotNull CommentStatusEnum status)
      Sets the comment status.
      Parameters:
      status - the comment status to set
      Returns:
      the payload builder
    • sticky

      public T sticky(@NotNull @NotNull Boolean sticky)
      Sets the sticky status.
      Parameters:
      sticky - the sticky status to set
      Returns:
      the payload builder
    • featuredMedia

      public T featuredMedia(@NotNull @NotNull Integer featuredMedia)
      Sets the featured media.
      Parameters:
      featuredMedia - the featured media to set
      Returns:
      the payload builder
    • clear

      public final T clear()
      Resets all fields of the builder to their initial state. This method is marked as final to ensure consistent behavior across all subclasses. Collections are cleared rather than set to null to prevent memory leaks.
      Returns:
      the current builder instance for method chaining
      See Also:
    • build

      public abstract tools.jackson.databind.JsonNode build()
      Builds the payload as a JsonNode.
      Returns:
      the built payload as a JsonNode