Skip to content
Merged

1597 #1763

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/src/content/docs/reference/components/trello.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |






Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String>) TrelloUtils::getBoardOptions)
.required(true),
string(ID)
.label("Card")
.options((ActionOptionsFunction<String>) 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<>() {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public static List<Option<String>> getBoardOptions(
return getOptions(body);
}

public static List<Option<String>> getCardOptions(
Parameters inputParameters, Parameters connectionParameters, Map<String, String> stringStringMap, String s,
Context context) {

List<Map<String, Object>> 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<Option<String>> getListOptions(
Parameters inputParameters, Parameters connectionParameters, Map<String, String> stringStringMap, String s,
Context context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading
Loading