diff --git a/docs/src/content/docs/reference/components/trello.md b/docs/src/content/docs/reference/components/trello.md index cf764c30a52..f64f98b31de 100644 --- a/docs/src/content/docs/reference/components/trello.md +++ b/docs/src/content/docs/reference/components/trello.md @@ -132,3 +132,36 @@ Type: OBJECT +### Get Card +Gets a card details. + +#### Properties + +| Name | Type | Control Type | Description | +|:--------------:|:------------:|:--------------------:|:-------------------:| +| Board | STRING | SELECT | Board where card is located. | +| Card | STRING | SELECT | | + + +### Output + + + +Type: OBJECT + + +#### Properties + +| Type | Control Type | +|:------------:|:--------------------:| +| STRING | TEXT | +| STRING | TEXT | +| STRING | TEXT | +| STRING | TEXT | +| STRING | TEXT | + + + + + + diff --git a/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/TrelloComponentHandler.java b/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/TrelloComponentHandler.java index e2029904201..eb07f051101 100644 --- a/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/TrelloComponentHandler.java +++ b/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/TrelloComponentHandler.java @@ -23,6 +23,7 @@ import com.bytechef.component.definition.ComponentDefinition; import com.bytechef.component.trello.action.TrelloCreateBoardAction; import com.bytechef.component.trello.action.TrelloCreateCardAction; +import com.bytechef.component.trello.action.TrelloGetCardAction; import com.bytechef.component.trello.connection.TrelloConnection; import com.bytechef.component.trello.trigger.TrelloNewCardTrigger; import com.google.auto.service.AutoService; @@ -44,7 +45,8 @@ public class TrelloComponentHandler implements ComponentHandler { .connection(TrelloConnection.CONNECTION_DEFINITION) .actions( TrelloCreateBoardAction.ACTION_DEFINITION, - TrelloCreateCardAction.ACTION_DEFINITION) + TrelloCreateCardAction.ACTION_DEFINITION, + TrelloGetCardAction.ACTION_DEFINITION) .triggers(TrelloNewCardTrigger.TRIGGER_DEFINITION); @Override diff --git a/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/action/TrelloGetCardAction.java b/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/action/TrelloGetCardAction.java new file mode 100644 index 00000000000..4d89386def7 --- /dev/null +++ b/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/action/TrelloGetCardAction.java @@ -0,0 +1,68 @@ +/* + * Copyright 2023-present ByteChef Inc. + * + * Licensed 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 + * + * https://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 com.bytechef.component.trello.action; + +import static com.bytechef.component.definition.ComponentDsl.action; +import static com.bytechef.component.definition.ComponentDsl.outputSchema; +import static com.bytechef.component.definition.ComponentDsl.string; +import static com.bytechef.component.trello.constant.TrelloConstants.CARD_OUTPUT_PROPERTY; +import static com.bytechef.component.trello.constant.TrelloConstants.ID; +import static com.bytechef.component.trello.constant.TrelloConstants.ID_BOARD; + +import com.bytechef.component.definition.ActionContext; +import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition; +import com.bytechef.component.definition.Context.Http; +import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction; +import com.bytechef.component.definition.Parameters; +import com.bytechef.component.definition.TypeReference; +import com.bytechef.component.trello.util.TrelloUtils; + +/** + * @author Monika Kušter + */ +public class TrelloGetCardAction { + + public static final ModifiableActionDefinition ACTION_DEFINITION = action("getCard") + .title("Get Card") + .description("Gets a card details.") + .properties( + string(ID_BOARD) + .label("Board") + .description("Board where card is located.") + .options((ActionOptionsFunction) TrelloUtils::getBoardOptions) + .required(true), + string(ID) + .label("Card") + .options((ActionOptionsFunction) TrelloUtils::getCardOptions) + .optionsLookupDependsOn(ID_BOARD) + .required(true)) + .output(outputSchema(CARD_OUTPUT_PROPERTY)) + .perform(TrelloGetCardAction::perform); + + private TrelloGetCardAction() { + } + + public static Object perform( + Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) { + + return actionContext + .http(http -> http.get("/cards/" + inputParameters.getRequiredString(ID))) + .configuration(Http.responseType(Http.ResponseType.JSON)) + .execute() + .getBody(new TypeReference<>() {}); + } +} diff --git a/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/util/TrelloUtils.java b/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/util/TrelloUtils.java index 3ca654d7652..3b471b83105 100644 --- a/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/util/TrelloUtils.java +++ b/server/libs/modules/components/trello/src/main/java/com/bytechef/component/trello/util/TrelloUtils.java @@ -52,6 +52,19 @@ public static List> getBoardOptions( return getOptions(body); } + public static List> getCardOptions( + Parameters inputParameters, Parameters connectionParameters, Map stringStringMap, String s, + Context context) { + + List> body = context + .http(http -> http.get("/boards/" + inputParameters.getRequiredString(ID_BOARD) + "/cards")) + .configuration(responseType(ResponseType.JSON)) + .execute() + .getBody(new TypeReference<>() {}); + + return getOptions(body); + } + public static List> getListOptions( Parameters inputParameters, Parameters connectionParameters, Map stringStringMap, String s, Context context) { diff --git a/server/libs/modules/components/trello/src/test/java/com/bytechef/component/trello/action/TrelloGetCardActionTest.java b/server/libs/modules/components/trello/src/test/java/com/bytechef/component/trello/action/TrelloGetCardActionTest.java new file mode 100644 index 00000000000..d706b2c873b --- /dev/null +++ b/server/libs/modules/components/trello/src/test/java/com/bytechef/component/trello/action/TrelloGetCardActionTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023-present ByteChef Inc. + * + * Licensed 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 + * + * https://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 com.bytechef.component.trello.action; + +import static com.bytechef.component.trello.constant.TrelloConstants.ID; +import static com.bytechef.component.trello.constant.TrelloConstants.ID_BOARD; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.bytechef.component.definition.Parameters; +import com.bytechef.component.definition.TypeReference; +import com.bytechef.component.test.definition.MockParametersFactory; +import java.util.Map; +import org.junit.jupiter.api.Test; + +/** + * @author Monika Kušter + */ +class TrelloGetCardActionTest extends AbstractTrelloActionTest { + + private static final Object mockedObject = mock(Object.class); + + @Test + void testPerform() { + Parameters mockedParameters = MockParametersFactory.create( + Map.of(ID_BOARD, "abc", ID, "card")); + + when(mockedResponse.getBody(any(TypeReference.class))) + .thenReturn(mockedObject); + + assertEquals(mockedObject, + TrelloGetCardAction.perform(mockedParameters, mockedParameters, mockedActionContext)); + } +} diff --git a/server/libs/modules/components/trello/src/test/java/com/bytechef/component/trello/util/TrelloUtilsTest.java b/server/libs/modules/components/trello/src/test/java/com/bytechef/component/trello/util/TrelloUtilsTest.java index 9f66295049e..cb7c68f2ff1 100644 --- a/server/libs/modules/components/trello/src/test/java/com/bytechef/component/trello/util/TrelloUtilsTest.java +++ b/server/libs/modules/components/trello/src/test/java/com/bytechef/component/trello/util/TrelloUtilsTest.java @@ -64,6 +64,13 @@ void testGetBoardOptions() { TrelloUtils.getBoardOptions(mockedParameters, mockedParameters, Map.of(), "", mockedContext)); } + @Test + void testGetCardOptions() { + assertEquals( + expectedOptions, + TrelloUtils.getBoardOptions(mockedParameters, mockedParameters, Map.of(), "", mockedContext)); + } + @Test void testGetListOptions() { assertEquals( diff --git a/server/libs/modules/components/trello/src/test/resources/definition/trello_v1.json b/server/libs/modules/components/trello/src/test/resources/definition/trello_v1.json index d074cec0567..f1e821f63c3 100644 --- a/server/libs/modules/components/trello/src/test/resources/definition/trello_v1.json +++ b/server/libs/modules/components/trello/src/test/resources/definition/trello_v1.json @@ -13,75 +13,6 @@ "resources" : null, "version" : 1, "title" : "Trello", - "connection" : { - "authorizations" : [ { - "detectOn" : null, - "description" : null, - "name" : "custom", - "properties" : [ { - "advancedOption" : null, - "description" : null, - "displayCondition" : null, - "expressionEnabled" : null, - "hidden" : null, - "metadata" : { }, - "required" : true, - "name" : "key", - "type" : "STRING", - "defaultValue" : null, - "exampleValue" : null, - "label" : "Key", - "placeholder" : null, - "controlType" : "TEXT", - "languageId" : null, - "maxLength" : null, - "minLength" : null, - "options" : null, - "optionsDataSource" : null - }, { - "advancedOption" : null, - "description" : null, - "displayCondition" : null, - "expressionEnabled" : null, - "hidden" : null, - "metadata" : { }, - "required" : true, - "name" : "token", - "type" : "STRING", - "defaultValue" : null, - "exampleValue" : null, - "label" : "Token", - "placeholder" : null, - "controlType" : "TEXT", - "languageId" : null, - "maxLength" : null, - "minLength" : null, - "options" : null, - "optionsDataSource" : null - } ], - "refreshOn" : null, - "title" : null, - "type" : "CUSTOM", - "acquire" : null, - "apply" : { }, - "clientId" : null, - "pkce" : null, - "refresh" : null, - "refreshUrl" : null, - "scopes" : null, - "tokenUrl" : null, - "authorizationUrl" : null, - "clientSecret" : null, - "refreshToken" : null, - "oauth2AuthorizationExtraQueryParameters" : null, - "authorizationCallback" : null - } ], - "properties" : null, - "version" : 1, - "authorizationRequired" : null, - "baseUri" : { }, - "test" : null - }, "actions" : [ { "batch" : null, "deprecated" : null, @@ -133,8 +64,8 @@ } ], "title" : "Create Board", "perform" : { }, - "processErrorResponse" : null, - "workflowNodeDescription" : null + "workflowNodeDescription" : null, + "processErrorResponse" : null }, { "batch" : null, "deprecated" : null, @@ -480,8 +411,315 @@ } ], "title" : "Create Card", "perform" : { }, - "processErrorResponse" : null, - "workflowNodeDescription" : null + "workflowNodeDescription" : null, + "processErrorResponse" : null + }, { + "batch" : null, + "deprecated" : null, + "description" : "Gets a card details.", + "help" : null, + "metadata" : null, + "name" : "getCard", + "outputDefinition" : { + "output" : null, + "outputResponse" : { + "outputSchema" : { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : null, + "type" : "OBJECT", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "additionalProperties" : null, + "multipleValues" : null, + "options" : null, + "properties" : [ { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "id", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "desc", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "idBoard", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "idList", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "name", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + } ], + "controlType" : "OBJECT_BUILDER", + "optionsDataSource" : null + }, + "sampleOutput" : null + }, + "outputSchema" : { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : null, + "type" : "OBJECT", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "additionalProperties" : null, + "multipleValues" : null, + "options" : null, + "properties" : [ { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "id", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "desc", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "idBoard", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "idList", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : null, + "name" : "name", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : null, + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + } ], + "controlType" : "OBJECT_BUILDER", + "optionsDataSource" : null + }, + "sampleOutput" : null + }, + "properties" : [ { + "advancedOption" : null, + "description" : "Board where card is located.", + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "idBoard", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Board", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : { + "optionsLookupDependsOn" : null, + "options" : { } + } + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "id", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Card", + "placeholder" : null, + "controlType" : "SELECT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : { + "optionsLookupDependsOn" : [ "idBoard" ], + "options" : { } + } + } ], + "title" : "Get Card", + "perform" : { }, + "workflowNodeDescription" : null, + "processErrorResponse" : null } ], "dataStream" : null, "triggers" : [ { @@ -790,18 +1028,87 @@ "type" : "DYNAMIC_WEBHOOK", "webhookRawBody" : null, "workflowSyncExecution" : null, - "deduplicate" : null, "poll" : null, + "deduplicate" : null, "webhookDisable" : { }, "webhookEnable" : { }, + "dynamicWebhookRefresh" : null, "webhookRequest" : { }, + "workflowNodeDescription" : null, + "processErrorResponse" : null, "listenerDisable" : null, "listenerEnable" : null, "webhookValidate" : null, - "processErrorResponse" : null, - "workflowNodeDescription" : null, - "dynamicWebhookRefresh" : null, "webhookValidateOnEnable" : null } ], - "unifiedApi" : null + "unifiedApi" : null, + "connection" : { + "authorizations" : [ { + "detectOn" : null, + "description" : null, + "name" : "custom", + "properties" : [ { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "key", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Key", + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + }, { + "advancedOption" : null, + "description" : null, + "displayCondition" : null, + "expressionEnabled" : null, + "hidden" : null, + "metadata" : { }, + "required" : true, + "name" : "token", + "type" : "STRING", + "defaultValue" : null, + "exampleValue" : null, + "label" : "Token", + "placeholder" : null, + "controlType" : "TEXT", + "languageId" : null, + "maxLength" : null, + "minLength" : null, + "options" : null, + "optionsDataSource" : null + } ], + "refreshOn" : null, + "title" : null, + "type" : "CUSTOM", + "acquire" : null, + "apply" : { }, + "authorizationCallback" : null, + "authorizationUrl" : null, + "clientId" : null, + "clientSecret" : null, + "oauth2AuthorizationExtraQueryParameters" : null, + "pkce" : null, + "refresh" : null, + "refreshUrl" : null, + "scopes" : null, + "refreshToken" : null, + "tokenUrl" : null + } ], + "properties" : null, + "version" : 1, + "authorizationRequired" : null, + "baseUri" : { }, + "test" : null + } } \ No newline at end of file