Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1542 #1768

Merged
merged 4 commits into from
Nov 23, 2024
Merged

1542 #1768

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
13 changes: 13 additions & 0 deletions docs/src/content/docs/reference/components/object-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,16 @@ Type: BOOLEAN



### Merge Two Objects
Merge two objects into one. If there is any property with the same name, the source value will be used.

#### Properties

| Name | Type | Control Type | Description |
|:--------------:|:------------:|:--------------------:|:-------------------:|
| Source | {} | OBJECT_BUILDER | The source object to merge. |
| Target | {} | OBJECT_BUILDER | The target object to merge into. |




Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.bytechef.component.object.helper.action.ObjectHelperContainsAction;
import com.bytechef.component.object.helper.action.ObjectHelperDeleteKeyValuePairAction;
import com.bytechef.component.object.helper.action.ObjectHelperEqualsAction;
import com.bytechef.component.object.helper.action.ObjectHelperMergeTwoObjectsAction;
import com.google.auto.service.AutoService;

/**
Expand All @@ -44,7 +45,8 @@ public class ObjectHelperComponentHandler implements ComponentHandler {
ObjectHelperAddKeyValuePairsAction.ACTION_DEFINITION,
ObjectHelperContainsAction.ACTION_DEFINITION,
ObjectHelperDeleteKeyValuePairAction.ACTION_DEFINITION,
ObjectHelperEqualsAction.ACTION_DEFINITION);
ObjectHelperEqualsAction.ACTION_DEFINITION,
ObjectHelperMergeTwoObjectsAction.ACTION_DEFINITION);

@Override
public ComponentDefinition getDefinition() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.object.helper.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.object;
import static com.bytechef.component.object.helper.constant.ObjectHelperConstants.SOURCE;
import static com.bytechef.component.object.helper.constant.ObjectHelperConstants.TARGET;

import com.bytechef.component.definition.ActionContext;
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.Parameters;
import java.util.HashMap;

/**
* @author Monika Kušter
*/
public class ObjectHelperMergeTwoObjectsAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("mergeTwoObjects")
.title("Merge Two Objects")
.description(
"Merge two objects into one. If there is any property with the same name, the source value will be used.")
.properties(
object(SOURCE)
.label("Source")
.description("The source object to merge.")
.required(true),
object(TARGET)
.label("Target")
.description("The target object to merge into.")
.required(true))
.output()
.perform(ObjectHelperMergeTwoObjectsAction::perform);

private ObjectHelperMergeTwoObjectsAction() {
}

protected static Object perform(
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) {

return new HashMap<String, Object>() {
{
putAll(inputParameters.getRequiredMap(TARGET, Object.class));
putAll(inputParameters.getRequiredMap(SOURCE, Object.class));
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.object.helper.action;

import static com.bytechef.component.object.helper.constant.ObjectHelperConstants.SOURCE;
import static com.bytechef.component.object.helper.constant.ObjectHelperConstants.TARGET;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

import com.bytechef.component.definition.ActionContext;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.test.definition.MockParametersFactory;
import java.util.Map;
import org.junit.jupiter.api.Test;

/**
* @author Monika Kušter
*/
class ObjectHelperMergeTwoObjectsActionTest {

private final ActionContext actionContext = mock(ActionContext.class);
private final Parameters mockedParameters = MockParametersFactory.create(
Map.of(
SOURCE, Map.of("key1", "value1", "key2", "value2"),
TARGET, Map.of("key1", "newValue", "key2", "value2")));

@Test
void testPerform() {
Object result = ObjectHelperMergeTwoObjectsAction.perform(mockedParameters, mockedParameters, actionContext);

assertEquals(Map.of("key1", "value1", "key2", "value2"), result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1266,9 +1266,67 @@
"perform" : { },
"processErrorResponse" : null,
"workflowNodeDescription" : null
}, {
"batch" : null,
"deprecated" : null,
"description" : "Merge two objects into one. If there is any property with the same name, the source value will be used.",
"help" : null,
"metadata" : null,
"name" : "mergeTwoObjects",
"outputDefinition" : {
"output" : null,
"outputResponse" : null,
"outputSchema" : null,
"sampleOutput" : null
},
"properties" : [ {
"advancedOption" : null,
"description" : "The source object to merge.",
"displayCondition" : null,
"expressionEnabled" : null,
"hidden" : null,
"metadata" : { },
"required" : true,
"name" : "source",
"type" : "OBJECT",
"defaultValue" : null,
"exampleValue" : null,
"label" : "Source",
"placeholder" : null,
"additionalProperties" : null,
"multipleValues" : null,
"options" : null,
"properties" : null,
"controlType" : "OBJECT_BUILDER",
"optionsDataSource" : null
}, {
"advancedOption" : null,
"description" : "The target object to merge into.",
"displayCondition" : null,
"expressionEnabled" : null,
"hidden" : null,
"metadata" : { },
"required" : true,
"name" : "target",
"type" : "OBJECT",
"defaultValue" : null,
"exampleValue" : null,
"label" : "Target",
"placeholder" : null,
"additionalProperties" : null,
"multipleValues" : null,
"options" : null,
"properties" : null,
"controlType" : "OBJECT_BUILDER",
"optionsDataSource" : null
} ],
"title" : "Merge Two Objects",
"perform" : { },
"processErrorResponse" : null,
"workflowNodeDescription" : null
} ],
"connection" : null,
"triggers" : null,
"dataStream" : null,
"unifiedApi" : null
"triggers" : null,
"unifiedApi" : null,
"connection" : null
}
Loading