Skip to content

Commit 9dea480

Browse files
monikakusterivicac
authored andcommitted
568 refactor
1 parent f87efb2 commit 9dea480

13 files changed

+86
-139
lines changed

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/action/ShopifyCancelOrderAction.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
import static com.bytechef.component.shopify.constant.ShopifyConstants.RESTOCK;
3131
import static com.bytechef.component.shopify.constant.ShopifyConstants.STAFF_NOTE;
3232
import static com.bytechef.component.shopify.constant.ShopifyConstants.USER_ERRORS_PROPERTY;
33-
import static com.bytechef.component.shopify.util.ShopifyUtils.checkForUserError;
34-
import static com.bytechef.component.shopify.util.ShopifyUtils.sendGraphQlQuery;
33+
import static com.bytechef.component.shopify.util.ShopifyUtils.executeGraphQlOperation;
3534

36-
import com.bytechef.component.definition.ActionDefinition;
35+
import com.bytechef.component.definition.ActionDefinition.OptionsFunction;
3736
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3837
import com.bytechef.component.definition.Context;
3938
import com.bytechef.component.definition.Parameters;
@@ -47,7 +46,7 @@
4746
public class ShopifyCancelOrderAction {
4847

4948
public static final ModifiableActionDefinition ACTION_DEFINITION = action("cancelOrder")
50-
.title("Cancel an order")
49+
.title("Cancel Order")
5150
.description(
5251
"Cancels an order, with options for refunding, restocking inventory, and customer notification." +
5352
"Order cancellation is irreversible.")
@@ -56,7 +55,7 @@ public class ShopifyCancelOrderAction {
5655
.label("Order ID")
5756
.description("ID of the order to cancel.")
5857
.required(true)
59-
.options((ActionDefinition.OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions),
58+
.options((OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions),
6059
string(REASON)
6160
.label("Reason")
6261
.description("The reason for canceling the order.")
@@ -109,9 +108,7 @@ public class ShopifyCancelOrderAction {
109108
private ShopifyCancelOrderAction() {
110109
}
111110

112-
public static Object perform(
113-
Parameters inputParameters, Parameters connectionParameters, Context context) {
114-
111+
public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
115112
String query = """
116113
mutation OrderCancel(
117114
$orderId: ID!
@@ -150,18 +147,10 @@ mutation OrderCancel(
150147
ORDER_ID, inputParameters.getRequiredString(ORDER_ID),
151148
REASON, inputParameters.getRequiredString(REASON),
152149
REFUND_METHOD,
153-
Map.of(
154-
ORIGINAL_PAYMENT_METHODS_REFUND,
155-
inputParameters.getBoolean(ORIGINAL_PAYMENT_METHODS_REFUND)),
150+
Map.of(ORIGINAL_PAYMENT_METHODS_REFUND, inputParameters.getBoolean(ORIGINAL_PAYMENT_METHODS_REFUND)),
156151
RESTOCK, inputParameters.getRequiredBoolean(RESTOCK),
157152
STAFF_NOTE, inputParameters.getString(STAFF_NOTE, ""));
158153

159-
Map<String, Object> body = sendGraphQlQuery(query, context, variables);
160-
161-
Object bodyContent = body.get("orderCancel");
162-
163-
checkForUserError(bodyContent);
164-
165-
return bodyContent;
154+
return executeGraphQlOperation(query, context, variables, "orderCancel");
166155
}
167156
}

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/action/ShopifyCloseOrderAction.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
import static com.bytechef.component.shopify.constant.ShopifyConstants.INPUT;
2828
import static com.bytechef.component.shopify.constant.ShopifyConstants.ORDER_ID;
2929
import static com.bytechef.component.shopify.constant.ShopifyConstants.USER_ERRORS_PROPERTY;
30-
import static com.bytechef.component.shopify.util.ShopifyUtils.checkForUserError;
31-
import static com.bytechef.component.shopify.util.ShopifyUtils.sendGraphQlQuery;
30+
import static com.bytechef.component.shopify.util.ShopifyUtils.executeGraphQlOperation;
3231

33-
import com.bytechef.component.definition.ActionDefinition;
32+
import com.bytechef.component.definition.ActionDefinition.OptionsFunction;
3433
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3534
import com.bytechef.component.definition.Context;
3635
import com.bytechef.component.definition.Parameters;
@@ -53,7 +52,7 @@ public class ShopifyCloseOrderAction {
5352
.label("Order ID")
5453
.description("ID of the order to close.")
5554
.required(true)
56-
.options((ActionDefinition.OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions))
55+
.options((OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions))
5756
.output(
5857
outputSchema(
5958
object()
@@ -109,12 +108,6 @@ mutation OrderClose($input: OrderCloseInput!) {
109108

110109
Map<String, Object> variables = Map.of(INPUT, Map.of(ID, inputParameters.getRequiredString(ORDER_ID)));
111110

112-
Map<String, Object> body = sendGraphQlQuery(query, context, variables);
113-
114-
Object bodyContent = body.get("orderClose");
115-
116-
checkForUserError(bodyContent);
117-
118-
return bodyContent;
111+
return executeGraphQlOperation(query, context, variables, "orderClose");
119112
}
120113
}

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/action/ShopifyCreateOrderAction.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
import static com.bytechef.component.shopify.constant.ShopifyConstants.QUANTITY;
3131
import static com.bytechef.component.shopify.constant.ShopifyConstants.USER_ERRORS_PROPERTY;
3232
import static com.bytechef.component.shopify.util.ShopifyOptionsUtils.getLineItemsList;
33-
import static com.bytechef.component.shopify.util.ShopifyUtils.checkForUserError;
34-
import static com.bytechef.component.shopify.util.ShopifyUtils.sendGraphQlQuery;
33+
import static com.bytechef.component.shopify.util.ShopifyUtils.executeGraphQlOperation;
3534

3635
import com.bytechef.component.definition.ActionDefinition.OptionsFunction;
3736
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
@@ -133,12 +132,6 @@ mutation orderCreate($order: OrderCreateOrderInput!, $options: OrderCreateOption
133132

134133
Map<String, Object> variables = Map.of(ORDER, Map.of(LINE_ITEMS, lineItems));
135134

136-
Map<String, Object> body = sendGraphQlQuery(query, context, variables);
137-
138-
Object bodyContent = body.get("orderCreate");
139-
140-
checkForUserError(bodyContent);
141-
142-
return bodyContent;
135+
return executeGraphQlOperation(query, context, variables, "orderCreate");
143136
}
144137
}

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/action/ShopifyDeleteOrderAction.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
import static com.bytechef.component.definition.ComponentDsl.string;
2323
import static com.bytechef.component.shopify.constant.ShopifyConstants.ORDER_ID;
2424
import static com.bytechef.component.shopify.constant.ShopifyConstants.USER_ERRORS_PROPERTY;
25-
import static com.bytechef.component.shopify.util.ShopifyUtils.checkForUserError;
26-
import static com.bytechef.component.shopify.util.ShopifyUtils.sendGraphQlQuery;
25+
import static com.bytechef.component.shopify.util.ShopifyUtils.executeGraphQlOperation;
2726

28-
import com.bytechef.component.definition.ActionDefinition;
27+
import com.bytechef.component.definition.ActionDefinition.OptionsFunction;
2928
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3029
import com.bytechef.component.definition.Context;
3130
import com.bytechef.component.definition.Parameters;
@@ -46,7 +45,7 @@ public class ShopifyDeleteOrderAction {
4645
.label("Order ID")
4746
.description("ID of the order to delete.")
4847
.required(true)
49-
.options((ActionDefinition.OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions))
48+
.options((OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions))
5049
.output(
5150
outputSchema(
5251
object()
@@ -74,12 +73,6 @@ mutation OrderDelete($orderId: ID!) {
7473

7574
Map<String, Object> variables = Map.of(ORDER_ID, inputParameters.getRequiredString(ORDER_ID));
7675

77-
Map<String, Object> body = sendGraphQlQuery(query, context, variables);
78-
79-
Object bodyContent = body.get("orderDelete");
80-
81-
checkForUserError(bodyContent);
82-
83-
return bodyContent;
76+
return executeGraphQlOperation(query, context, variables, "orderDelete");
8477
}
8578
}

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/action/ShopifyGetOrderAction.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import static com.bytechef.component.definition.ComponentDsl.string;
2424
import static com.bytechef.component.shopify.constant.ShopifyConstants.ID;
2525
import static com.bytechef.component.shopify.constant.ShopifyConstants.ORDER_ID;
26-
import static com.bytechef.component.shopify.util.ShopifyUtils.sendGraphQlQuery;
26+
import static com.bytechef.component.shopify.util.ShopifyUtils.executeGraphQlOperation;
2727

28-
import com.bytechef.component.definition.ActionDefinition;
28+
import com.bytechef.component.definition.ActionDefinition.OptionsFunction;
2929
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3030
import com.bytechef.component.definition.Context;
3131
import com.bytechef.component.definition.Parameters;
@@ -44,7 +44,7 @@ public class ShopifyGetOrderAction {
4444
string(ORDER_ID)
4545
.label("Order ID")
4646
.description("ID of the order you want to fetch.")
47-
.options((ActionDefinition.OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions)
47+
.options((OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions)
4848
.required(true))
4949
.output(
5050
outputSchema(
@@ -89,9 +89,7 @@ public class ShopifyGetOrderAction {
8989
private ShopifyGetOrderAction() {
9090
}
9191

92-
public static Object perform(
93-
Parameters inputParameters, Parameters connectionParameters, Context context) {
94-
92+
public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
9593
String query = """
9694
query GetOrder($id: ID!) {
9795
order(id: $id) {
@@ -119,8 +117,6 @@ query GetOrder($id: ID!) {
119117

120118
Map<String, Object> variables = Map.of(ID, inputParameters.getRequiredString(ORDER_ID));
121119

122-
Map<String, Object> body = sendGraphQlQuery(query, context, variables);
123-
124-
return body.get("order");
120+
return executeGraphQlOperation(query, context, variables, "order");
125121
}
126122
}

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/action/ShopifyUpdateOrderAction.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
import static com.bytechef.component.shopify.constant.ShopifyConstants.ORDER_ID;
2929
import static com.bytechef.component.shopify.constant.ShopifyConstants.TAGS;
3030
import static com.bytechef.component.shopify.constant.ShopifyConstants.USER_ERRORS_PROPERTY;
31-
import static com.bytechef.component.shopify.util.ShopifyUtils.checkForUserError;
32-
import static com.bytechef.component.shopify.util.ShopifyUtils.sendGraphQlQuery;
31+
import static com.bytechef.component.shopify.util.ShopifyUtils.executeGraphQlOperation;
3332

34-
import com.bytechef.component.definition.ActionDefinition;
33+
import com.bytechef.component.definition.ActionDefinition.OptionsFunction;
3534
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3635
import com.bytechef.component.definition.Context;
3736
import com.bytechef.component.definition.Parameters;
@@ -53,7 +52,7 @@ public class ShopifyUpdateOrderAction {
5352
.label("Order ID")
5453
.description("ID of the order to update.")
5554
.required(true)
56-
.options((ActionDefinition.OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions),
55+
.options((OptionsFunction<String>) ShopifyOptionsUtils::getOrderIdOptions),
5756
string(NOTE)
5857
.label("Note")
5958
.description("An optional note that a shop owner can attach to the order.")
@@ -62,7 +61,8 @@ public class ShopifyUpdateOrderAction {
6261
.label("Email")
6362
.description("The customer's email address.")
6463
.required(false),
65-
array(TAGS).label("Tags")
64+
array(TAGS)
65+
.label("Tags")
6666
.description("Tags attached to the order.")
6767
.items(
6868
string("tag")
@@ -118,12 +118,6 @@ mutation OrderUpdate($input: OrderInput!) {
118118
EMAIL, inputParameters.getString(EMAIL, ""),
119119
TAGS, inputParameters.getList(TAGS, List.of())));
120120

121-
Map<String, Object> body = sendGraphQlQuery(query, context, variables);
122-
123-
Object bodyContent = body.get("orderUpdate");
124-
125-
checkForUserError(bodyContent);
126-
127-
return bodyContent;
121+
return executeGraphQlOperation(query, context, variables, "orderUpdate");
128122
}
129123
}

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/connection/ShopifyConnection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class ShopifyConnection {
4141
.formatted(connectionParameters.getRequiredString(SHOP_NAME)))
4242
.authorizations(
4343
authorization(AuthorizationType.OAUTH2_AUTHORIZATION_CODE)
44+
.title("OAuth2 Authorization Code")
4445
.properties(
4546
string(SHOP_NAME)
4647
.label("Shop Name")

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/trigger/ShopifyNewCancelledOrderTrigger.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.bytechef.component.shopify.trigger;
1818

19-
import static com.bytechef.component.definition.ComponentDsl.object;
20-
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
2119
import static com.bytechef.component.definition.ComponentDsl.trigger;
2220
import static com.bytechef.component.shopify.constant.ShopifyConstants.ID;
2321
import static com.bytechef.component.shopify.util.ShopifyTriggerUtils.subscribeWebhook;
@@ -44,7 +42,7 @@ public class ShopifyNewCancelledOrderTrigger {
4442
.title("New Cancelled Order")
4543
.description("Triggers when order is cancelled.")
4644
.type(TriggerType.DYNAMIC_WEBHOOK)
47-
.output(outputSchema(object().properties()))
45+
.output()
4846
.webhookEnable(ShopifyNewCancelledOrderTrigger::webhookEnable)
4947
.webhookDisable(ShopifyNewCancelledOrderTrigger::webhookDisable)
5048
.webhookRequest(ShopifyNewCancelledOrderTrigger::webhookRequest);

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/trigger/ShopifyNewOrderTrigger.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.bytechef.component.shopify.trigger;
1818

19-
import static com.bytechef.component.definition.ComponentDsl.object;
20-
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
2119
import static com.bytechef.component.definition.ComponentDsl.trigger;
2220
import static com.bytechef.component.shopify.constant.ShopifyConstants.ID;
2321
import static com.bytechef.component.shopify.util.ShopifyTriggerUtils.subscribeWebhook;
@@ -44,7 +42,7 @@ public class ShopifyNewOrderTrigger {
4442
.title("New Order")
4543
.description("Triggers when new order is created.")
4644
.type(TriggerType.DYNAMIC_WEBHOOK)
47-
.output(outputSchema(object().properties()))
45+
.output()
4846
.webhookEnable(ShopifyNewOrderTrigger::webhookEnable)
4947
.webhookDisable(ShopifyNewOrderTrigger::webhookDisable)
5048
.webhookRequest(ShopifyNewOrderTrigger::webhookRequest);
@@ -56,8 +54,7 @@ protected static WebhookEnableOutput webhookEnable(
5654
Parameters inputParameters, Parameters connectionParameters, String webhookUrl,
5755
String workflowExecutionId, TriggerContext context) {
5856

59-
return new WebhookEnableOutput(Map.of(ID, subscribeWebhook(webhookUrl, "DRAFT_ORDERS_CREATE", context)),
60-
null);
57+
return new WebhookEnableOutput(Map.of(ID, subscribeWebhook(webhookUrl, "DRAFT_ORDERS_CREATE", context)), null);
6158
}
6259

6360
protected static void webhookDisable(

server/libs/modules/components/shopify/src/main/java/com/bytechef/component/shopify/trigger/ShopifyNewPaidOrderTrigger.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.bytechef.component.shopify.trigger;
1818

19-
import static com.bytechef.component.definition.ComponentDsl.object;
20-
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
2119
import static com.bytechef.component.definition.ComponentDsl.trigger;
2220
import static com.bytechef.component.shopify.constant.ShopifyConstants.ID;
2321
import static com.bytechef.component.shopify.util.ShopifyTriggerUtils.subscribeWebhook;
@@ -44,7 +42,7 @@ public class ShopifyNewPaidOrderTrigger {
4442
.title("New Paid Order")
4543
.description("Triggers when paid order is created.")
4644
.type(TriggerType.DYNAMIC_WEBHOOK)
47-
.output(outputSchema(object().properties()))
45+
.output()
4846
.webhookEnable(ShopifyNewPaidOrderTrigger::webhookEnable)
4947
.webhookDisable(ShopifyNewPaidOrderTrigger::webhookDisable)
5048
.webhookRequest(ShopifyNewPaidOrderTrigger::webhookRequest);
@@ -56,8 +54,7 @@ protected static WebhookEnableOutput webhookEnable(
5654
Parameters inputParameters, Parameters connectionParameters, String webhookUrl,
5755
String workflowExecutionId, TriggerContext context) {
5856

59-
return new WebhookEnableOutput(Map.of(ID, subscribeWebhook(webhookUrl, "ORDERS_PAID", context)),
60-
null);
57+
return new WebhookEnableOutput(Map.of(ID, subscribeWebhook(webhookUrl, "ORDERS_PAID", context)), null);
6158
}
6259

6360
protected static void webhookDisable(

0 commit comments

Comments
 (0)