11package com .mindee .v2 .clientoptions ;
22
3+ import java .util .Arrays ;
34import java .util .HashMap ;
45import java .util .Map ;
5- import java .util .Objects ;
66import lombok .Data ;
77
8+ /**
9+ * Base parameters for sending a file to a Mindee V2 product.
10+ */
811@ Data
912public abstract class BaseProductParameters {
1013 /**
@@ -23,15 +26,35 @@ public abstract class BaseProductParameters {
2326 */
2427 protected final String [] webhookIds ;
2528
29+ protected BaseProductParameters (String modelId , String alias , String [] webhookIds ) {
30+ if (modelId == null || modelId .trim ().isBlank ()) {
31+ throw new IllegalArgumentException ("modelId cannot be null or whitespace." );
32+ }
33+ if ("" .equals (alias )) {
34+ throw new IllegalArgumentException ("alias cannot be an empty string." );
35+ }
36+ if (
37+ webhookIds != null && Arrays .stream (webhookIds ).anyMatch (id -> id == null || id .isBlank ())
38+ ) {
39+ throw new IllegalArgumentException (
40+ "WebhookIds cannot contain null, empty, or whitespace values."
41+ );
42+ }
43+
44+ this .modelId = modelId .trim ();
45+ this .alias = alias ;
46+ this .webhookIds = webhookIds != null ? webhookIds : new String [0 ];
47+ }
48+
2649 public Map <String , String > getRequestParameters () {
2750 var parameters = new HashMap <String , String >();
2851
2952 parameters .put ("model_id" , this .getModelId ());
3053
31- if (this .getAlias () != null && ! this . getAlias (). isBlank () ) {
54+ if (this .getAlias () != null ) {
3255 parameters .put ("alias" , getAlias ());
3356 }
34- if (this .getWebhookIds ().length > 0 ) {
57+ if (this .getWebhookIds () != null && this . getWebhookIds () .length > 0 ) {
3558 parameters .put ("webhook_ids" , String .join ("," , this .getWebhookIds ()));
3659 }
3760
@@ -49,8 +72,7 @@ protected T self() {
4972 }
5073
5174 protected BaseBuilder (String modelId ) {
52- this .modelId = Objects
53- .requireNonNull (modelId , "The model ID is required in product parameters" );
75+ this .modelId = modelId ;
5476 }
5577
5678 /** Set an alias for the uploaded document. */
@@ -65,5 +87,4 @@ public T webhookIds(String[] webhookIds) {
6587 return self ();
6688 }
6789 }
68-
6990}
0 commit comments