Skip to content
Merged
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
77 changes: 76 additions & 1 deletion docs/src/content/docs/reference/components/bamboohr.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: "BambooHR is a human resources software that helps HR teams manage
BambooHR is a human resources software that helps HR teams manage employee data, hiring, onboarding, time tracking, payroll, performance management, and more in one platform.


Categories: hris
Categories: Human Resources Information System


Type: bambooHr/v1
Expand Down Expand Up @@ -215,3 +215,78 @@ This action does not produce any output.



## Triggers


### Update Employee
Name: updateEmployee

Triggers when specific employee fields are updated.

Type: DYNAMIC_WEBHOOK


#### Output



Type: ARRAY


Items Type: OBJECT


#### Properties
| Name | Type | Description |
|:------------:|:------------:|:-------------------:|
| firstName | STRING | |
| lastName | STRING | |
| employeeNumber | STRING | |





#### JSON Example
```json
{
"label" : "Update Employee",
"name" : "updateEmployee",
"type" : "bambooHr/v1/updateEmployee"
}
```


### New Employee
Name: newEmployee

Triggers when a new employee is created.

Type: POLLING

#### Properties

| Name | Label | Type | Description | Required |
|:---------------:|:--------------:|:------------:|:-------------------:|:--------:|
| fields | null | ARRAY <details> <summary> Items </summary> [STRING] </details> | Fields you want to get from employee. See documentation for available fields. | true |


#### Output

The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.

#### JSON Example
```json
{
"label" : "New Employee",
"name" : "newEmployee",
"parameters" : {
"fields" : [ "" ]
},
"type" : "bambooHr/v1/newEmployee"
}
```


<hr />

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.bytechef.component.bamboohr.action.BambooHrUpdateEmployeeAction;
import com.bytechef.component.bamboohr.action.BambooHrUpdateEmployeeFileAction;
import com.bytechef.component.bamboohr.connection.BambooHrConnection;
import com.bytechef.component.bamboohr.trigger.BambooHrNewEmployeeTrigger;
import com.bytechef.component.bamboohr.trigger.BambooHrUpdateEmployeeTrigger;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
import com.google.auto.service.AutoService;
Expand All @@ -48,6 +50,9 @@ public class BambooHrComponentHandler implements ComponentHandler {
BambooHrUpdateEmployeeAction.ACTION_DEFINITION,
BambooHrGetEmployeeAction.ACTION_DEFINITION,
BambooHrUpdateEmployeeFileAction.ACTION_DEFINITION)
.triggers(
BambooHrUpdateEmployeeTrigger.TRIGGER_DEFINITION,
BambooHrNewEmployeeTrigger.TRIGGER_DEFINITION)
.clusterElements(
tool(BambooHrCreateEmployeeAction.ACTION_DEFINITION),
tool(BambooHrUpdateEmployeeAction.ACTION_DEFINITION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class BambooHrConstants {
public static final String LOCATION = "location";
public static final String NAME = "name";
public static final String SHARE_WITH_EMPLOYEE = "shareWithEmployee";
public static final String LAST_TIME_CHECKED = "lastTimeChecked";

private BambooHrConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.bamboohr.trigger;

import static com.bytechef.component.bamboohr.constant.BambooHrConstants.FIELDS;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.ID;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.LAST_TIME_CHECKED;
import static com.bytechef.component.definition.ComponentDsl.array;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.ComponentDsl.trigger;
import static com.bytechef.component.definition.Context.Http.responseType;

import com.bytechef.component.bamboohr.util.BambooHrUtils;
import com.bytechef.component.definition.ComponentDsl;
import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http;
import com.bytechef.component.definition.OptionsDataSource;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.TriggerContext;
import com.bytechef.component.definition.TriggerDefinition;
import com.bytechef.component.definition.TypeReference;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author Marija Horvat
*/
public class BambooHrNewEmployeeTrigger {

static final List<String> EMPLOYEE_LIST = new ArrayList<>();

public static final ComponentDsl.ModifiableTriggerDefinition TRIGGER_DEFINITION = trigger("newEmployee")
.title("New Employee")
.description("Triggers when a new employee is created.")
.type(TriggerDefinition.TriggerType.POLLING)
.properties(
array(FIELDS)
.description("Fields you want to get from employee. See documentation for available fields.")
.items(string())
.options((OptionsDataSource.TriggerOptionsFunction<String>) BambooHrUtils::getFieldOptions)
.required(true))
.output()
.poll(BambooHrNewEmployeeTrigger::poll);

private BambooHrNewEmployeeTrigger() {
}

protected static TriggerDefinition.PollOutput poll(
Parameters inputParameters, Parameters connectionParameters, Parameters closureParameters,
TriggerContext triggerContext) {

List<String> fields = inputParameters.getRequiredList(FIELDS, String.class);
String queryParameter = String.join(",", fields);

ZoneId zoneId = ZoneId.of("GMT");

LocalDateTime now = LocalDateTime.now(zoneId);

Map<String, Object> body = triggerContext
.http(http -> http.get("/employees/directory"))
.header("accept", "application/json")
.configuration(responseType(Context.Http.ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {});

List<Map<?, ?>> maps = new ArrayList<>();

if (body.get("employees") instanceof List<?> list) {
if (EMPLOYEE_LIST.isEmpty()) {
for (Object o : list) {
if (o instanceof Map<?, ?> map) {
String id = (String) map.get(ID);
EMPLOYEE_LIST.add(id);
}
}
} else {
for (Object o : list) {
if (o instanceof Map<?, ?> map) {
String id = (String) map.get(ID);

if (!EMPLOYEE_LIST.contains(id)) {
maps.add(
triggerContext
.http(http -> http.get("/employees/" + id))
.queryParameter(FIELDS, queryParameter)
.header("accept", "application/json")
.configuration(responseType(Http.ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {}));
}
}
}
}
}
return new TriggerDefinition.PollOutput(maps, Map.of(LAST_TIME_CHECKED, now), false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.bamboohr.trigger;

import static com.bytechef.component.bamboohr.constant.BambooHrConstants.EMPLOYEE_NUMBER;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.FIRST_NAME;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.ID;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.LAST_NAME;
import static com.bytechef.component.definition.ComponentDsl.array;
import static com.bytechef.component.definition.ComponentDsl.object;
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.ComponentDsl.trigger;

import com.bytechef.component.bamboohr.util.BambooHrUtils;
import com.bytechef.component.definition.ComponentDsl;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.TriggerContext;
import com.bytechef.component.definition.TriggerDefinition;
import com.bytechef.component.definition.TriggerDefinition.TriggerType;
import com.bytechef.component.definition.TriggerDefinition.WebhookEnableOutput;
import com.bytechef.component.definition.TypeReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Marija Horvat
*/
public class BambooHrUpdateEmployeeTrigger {

public static final ComponentDsl.ModifiableTriggerDefinition TRIGGER_DEFINITION = trigger("updateEmployee")
.title("Update Employee")
.description("Triggers when specific employee fields are updated.")
.type(TriggerType.DYNAMIC_WEBHOOK)
.properties()
.output(outputSchema(
array()
.items(
object()
.properties(
string(FIRST_NAME),
string(LAST_NAME),
string(EMPLOYEE_NUMBER)))))
.webhookEnable(BambooHrUpdateEmployeeTrigger::webhookEnable)
.webhookDisable(BambooHrUpdateEmployeeTrigger::webhookDisable)
.webhookRequest(BambooHrUpdateEmployeeTrigger::webhookRequest);

private BambooHrUpdateEmployeeTrigger() {
}

protected static WebhookEnableOutput webhookEnable(
Parameters inputParameters, Parameters connectionParameters, String webhookUrl,
String workflowExecutionId, TriggerContext context) {

return new WebhookEnableOutput(
Map.of(ID,
BambooHrUtils.addWebhook(webhookUrl, context)),
null);
}

protected static void webhookDisable(
Parameters inputParameters, Parameters connectionParameters, Parameters outputParameters,
String workflowExecutionId, TriggerContext context) {

BambooHrUtils.deleteWebhook(outputParameters, context);
}

protected static Object webhookRequest(
Parameters inputParameters, Parameters connectionParameters, TriggerDefinition.HttpHeaders headers,
TriggerDefinition.HttpParameters parameters,
TriggerDefinition.WebhookBody body, TriggerDefinition.WebhookMethod method,
TriggerDefinition.WebhookEnableOutput output, TriggerContext context) {

List<Map<String, ?>> outputObject = new ArrayList<>();

if (body.getContent(new TypeReference<Map<String, ?>>() {})
.get("employees") instanceof List<?> list) {
for (Object o : list) {
if (o instanceof Map<?, ?> map) {
Map<String, Map<String, ?>> fields = (Map<String, Map<String, ?>>) map.get("fields");

Map<String, Object> fieldMap = new HashMap<>();

for (Map.Entry<String, Map<String, ?>> fieldEntry : fields.entrySet()) {
String fieldName = fieldEntry.getKey();
Map<String, ?> fieldValue = fieldEntry.getValue();

if (fieldValue.containsKey("value")) {
fieldMap.put(fieldName, fieldValue.get("value"));
}
}
outputObject.add(fieldMap);
}
}
}
return outputObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.bytechef.component.bamboohr.util;

import static com.bytechef.component.bamboohr.constant.BambooHrConstants.EMPLOYEE_NUMBER;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.FIRST_NAME;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.ID;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.LAST_NAME;
import static com.bytechef.component.bamboohr.constant.BambooHrConstants.NAME;
import static com.bytechef.component.definition.ComponentDsl.option;
import static com.bytechef.component.definition.Context.Http.responseType;
Expand All @@ -26,6 +29,7 @@
import com.bytechef.component.definition.Option;
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.TriggerContext;
import com.bytechef.component.definition.TypeReference;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -108,6 +112,34 @@ public static List<Option<String>> getFieldOptions(
return options;
}

public static String addWebhook(
String webhookUrl, TriggerContext context) {

Map<String, ?> body = context.http(http -> http.post("/webhooks"))
.body(Context.Http.Body.of(
"name", "bambooHRWebhook",
"monitorFields", List.of(FIRST_NAME, LAST_NAME, EMPLOYEE_NUMBER),
"postFields", Map.of(
FIRST_NAME, FIRST_NAME,
LAST_NAME, LAST_NAME,
EMPLOYEE_NUMBER, EMPLOYEE_NUMBER),
"url", webhookUrl,
"format", "json"))
.headers(Map.of("accept", List.of("application/json")))
.configuration(Context.Http.responseType(Context.Http.ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {});

return (String) body.get(ID);
}

public static void deleteWebhook(Parameters outputParameters, Context context) {
context.http(http -> http.delete("/webhooks/" + outputParameters.getString(ID)))
.headers(Map.of("accept", List.of("application/json")))
.configuration(Context.Http.responseType(Context.Http.ResponseType.JSON))
.execute();
}

public static ActionOptionsFunction<String> getOptions(String targetName) {
return (inputParameters, connectionParameters, arrayIndex, searchText, context) -> {

Expand Down
Loading