From 9a88abbacff68022e86b6a0a8255bac7a129d923 Mon Sep 17 00:00:00 2001 From: Oleksandr Naumov Date: Wed, 10 Mar 2021 19:57:05 +0200 Subject: [PATCH] added CandidateWorkHistoryRestTrigger support --- .../CandidateWorkHistoryTriggerHelper.java | 16 ++++ .../CandidateWorkHistoryRelatedEntity.java | 2 +- ...idateWorkHistoryRestTriggerController.java | 83 +++++++++++++++++++ ...CandidateWorkHistoryRestTriggerHelper.java | 44 ++++++++++ ...didateWorkHistoryRestTriggerValidator.java | 21 +++++ ...didateWorkHistoryRestTriggerTraverser.java | 18 ++++ 6 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/client/core/base/model/helper/impl/CandidateWorkHistoryTriggerHelper.java create mode 100644 src/main/java/com/client/core/resttrigger/controller/candidateworkhistory/CandidateWorkHistoryRestTriggerController.java create mode 100644 src/main/java/com/client/core/resttrigger/model/helper/impl/CandidateWorkHistoryRestTriggerHelper.java create mode 100644 src/main/java/com/client/core/resttrigger/workflow/node/impl/CandidateWorkHistoryRestTriggerValidator.java create mode 100644 src/main/java/com/client/core/resttrigger/workflow/traversing/CandidateWorkHistoryRestTriggerTraverser.java diff --git a/src/main/java/com/client/core/base/model/helper/impl/CandidateWorkHistoryTriggerHelper.java b/src/main/java/com/client/core/base/model/helper/impl/CandidateWorkHistoryTriggerHelper.java new file mode 100644 index 00000000..691fb42e --- /dev/null +++ b/src/main/java/com/client/core/base/model/helper/impl/CandidateWorkHistoryTriggerHelper.java @@ -0,0 +1,16 @@ +package com.client.core.base.model.helper.impl; + +import com.bullhornsdk.data.model.entity.core.standard.CandidateWorkHistory; +import com.client.core.base.model.helper.AbstractTriggerHelper; +import com.client.core.base.model.relatedentity.BullhornRelatedEntity; +import com.client.core.base.model.relatedentity.CandidateWorkHistoryRelatedEntity; + +import java.util.Map; +import java.util.Set; + +public abstract class CandidateWorkHistoryTriggerHelper extends AbstractTriggerHelper { + + public CandidateWorkHistoryTriggerHelper(Integer updatingUserID, Map> relatedEntityFields) { + super(updatingUserID, CandidateWorkHistory.class, CandidateWorkHistoryRelatedEntity.CANDIDATE_WORK_HISTORY, relatedEntityFields); + } +} diff --git a/src/main/java/com/client/core/base/model/relatedentity/CandidateWorkHistoryRelatedEntity.java b/src/main/java/com/client/core/base/model/relatedentity/CandidateWorkHistoryRelatedEntity.java index 38c4e323..2036d12e 100644 --- a/src/main/java/com/client/core/base/model/relatedentity/CandidateWorkHistoryRelatedEntity.java +++ b/src/main/java/com/client/core/base/model/relatedentity/CandidateWorkHistoryRelatedEntity.java @@ -6,7 +6,7 @@ public enum CandidateWorkHistoryRelatedEntity implements BullhornRelatedEntity { CANDIDATE_WORK_HISTORY( - "candidate(id,name)", "clientCorporation(id,name)", "companyName", "endDate", + "id", "candidate(id,name)", "clientCorporation(id,name)", "companyName", "endDate", "jobOrder(id,title)", "placement(id,status)", "startDate", "title" ), CANDIDATE("id", "name", "email", "phone", "owner(id,name)"), diff --git a/src/main/java/com/client/core/resttrigger/controller/candidateworkhistory/CandidateWorkHistoryRestTriggerController.java b/src/main/java/com/client/core/resttrigger/controller/candidateworkhistory/CandidateWorkHistoryRestTriggerController.java new file mode 100644 index 00000000..67222992 --- /dev/null +++ b/src/main/java/com/client/core/resttrigger/controller/candidateworkhistory/CandidateWorkHistoryRestTriggerController.java @@ -0,0 +1,83 @@ +package com.client.core.resttrigger.controller.candidateworkhistory; + +import com.bullhornsdk.data.model.entity.core.standard.CandidateWorkHistory; +import com.client.core.base.model.relatedentity.CandidateWorkHistoryRelatedEntity; +import com.client.core.base.workflow.node.TriggerValidator; +import com.client.core.resttrigger.controller.AbstractRestTriggerController; +import com.client.core.resttrigger.model.api.RestTriggerRequest; +import com.client.core.resttrigger.model.api.RestTriggerResponse; +import com.client.core.resttrigger.model.helper.impl.CandidateWorkHistoryRestTriggerHelper; +import com.client.core.resttrigger.workflow.traversing.CandidateWorkHistoryRestTriggerTraverser; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +@Controller +@RequestMapping("/resttrigger/candidateworkhistory/*") +public class CandidateWorkHistoryRestTriggerController extends AbstractRestTriggerController { + + private final Logger log = Logger.getLogger(CandidateWorkHistoryRestTriggerController.class); + + @Autowired + public CandidateWorkHistoryRestTriggerController(Optional>> triggerValidators) { + super(CandidateWorkHistory.class, triggerValidators, CandidateWorkHistoryRelatedEntity.values()); + } + + /** + * Called when candidate is added + * + * @param body + * + * @return the json parsed form response message + */ + @RequestMapping(value = { "add" }, method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE }) + @ResponseBody + public RestTriggerResponse addEntity(@RequestBody String body) { + log.info("---------------------------- Starting Candidate Work History Add Validation Process From Rest Trigger ----------------------------------------"); + + Map valuesChanges = (Map) convertToMap(body).get("data"); + + RestTriggerRequest restTriggerRequest = convertToObject(body); + + Integer entityID = restTriggerRequest.getMeta().getEntityId(); + Integer updatingUserID = restTriggerRequest.getMeta().getUserId(); + + CandidateWorkHistoryRestTriggerTraverser traverser = new CandidateWorkHistoryRestTriggerTraverser(entityID, valuesChanges, updatingUserID, false, getRelatedEntityFields()); + + return handleRequest(traverser, valuesChanges); + } + + /** + * Called when candidate is edited + * + * @param body + * + * @return the json parsed form response message + */ + @RequestMapping(value = { "edit" }, method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE }) + @ResponseBody + public RestTriggerResponse editEntity(@RequestBody String body) { + log.info("---------------------------- Starting Candidate Work History Edit Validation Process From Rest Trigger ----------------------------------------"); + + Map valuesChanges = (Map) convertToMap(body).get("data"); + + RestTriggerRequest restTriggerRequest = convertToObject(body); + + Integer entityID = restTriggerRequest.getMeta().getEntityId(); + Integer updatingUserID = restTriggerRequest.getMeta().getUserId(); + + CandidateWorkHistoryRestTriggerTraverser traverser = new CandidateWorkHistoryRestTriggerTraverser(entityID, valuesChanges, updatingUserID, true, getRelatedEntityFields()); + + return handleRequest(traverser, valuesChanges); + } + +} diff --git a/src/main/java/com/client/core/resttrigger/model/helper/impl/CandidateWorkHistoryRestTriggerHelper.java b/src/main/java/com/client/core/resttrigger/model/helper/impl/CandidateWorkHistoryRestTriggerHelper.java new file mode 100644 index 00000000..df3e4566 --- /dev/null +++ b/src/main/java/com/client/core/resttrigger/model/helper/impl/CandidateWorkHistoryRestTriggerHelper.java @@ -0,0 +1,44 @@ +package com.client.core.resttrigger.model.helper.impl; + +import com.bullhornsdk.data.model.entity.core.standard.CandidateWorkHistory; +import com.client.core.base.model.helper.impl.CandidateWorkHistoryTriggerHelper; +import com.client.core.base.model.relatedentity.BullhornRelatedEntity; +import com.client.core.base.model.relatedentity.CandidateWorkHistoryRelatedEntity; +import com.client.core.base.util.TriggerUtil; +import com.client.core.resttrigger.model.helper.RestTriggerHelper; + +import java.util.Map; +import java.util.Set; + +public class CandidateWorkHistoryRestTriggerHelper extends CandidateWorkHistoryTriggerHelper implements RestTriggerHelper { + + private final Integer entityID; + private final Map valuesChanged; + + public CandidateWorkHistoryRestTriggerHelper(Integer entityID, Map valuesChanged, Integer updatingUserID, + Map> relatedEntityFields) { + super(updatingUserID, relatedEntityFields); + this.entityID = entityID; + this.valuesChanged = valuesChanged; + } + + @Override + public Set getPopulatedFields() { + return valuesChanged.keySet(); + } + + @Override + public Integer getEntityID() { + return entityID; + } + + @Override + public Map getValuesChanged() { + return valuesChanged; + } + + @Override + protected CandidateWorkHistory instantiateNewEntity() { + return TriggerUtil.populateEntity(entityID, CandidateWorkHistory.class, valuesChanged, CandidateWorkHistory::new, getFields(CandidateWorkHistoryRelatedEntity.CANDIDATE_WORK_HISTORY)); + } +} diff --git a/src/main/java/com/client/core/resttrigger/workflow/node/impl/CandidateWorkHistoryRestTriggerValidator.java b/src/main/java/com/client/core/resttrigger/workflow/node/impl/CandidateWorkHistoryRestTriggerValidator.java new file mode 100644 index 00000000..06f2f443 --- /dev/null +++ b/src/main/java/com/client/core/resttrigger/workflow/node/impl/CandidateWorkHistoryRestTriggerValidator.java @@ -0,0 +1,21 @@ +package com.client.core.resttrigger.workflow.node.impl; + +import com.bullhornsdk.data.model.entity.core.standard.CandidateWorkHistory; +import com.client.core.base.model.relatedentity.CandidateWorkHistoryRelatedEntity; +import com.client.core.resttrigger.model.helper.impl.CandidateWorkHistoryRestTriggerHelper; +import com.client.core.resttrigger.workflow.traversing.CandidateWorkHistoryRestTriggerTraverser; + +import java.util.Map; +import java.util.Set; + +public abstract class CandidateWorkHistoryRestTriggerValidator extends AbstractRestTriggerValidator { + + public CandidateWorkHistoryRestTriggerValidator(Integer order, Map> relatedEntityFields) { + super(order, relatedEntityFields); + } + + public CandidateWorkHistoryRestTriggerValidator(Map> relatedEntityFields) { + super(relatedEntityFields); + } + +} diff --git a/src/main/java/com/client/core/resttrigger/workflow/traversing/CandidateWorkHistoryRestTriggerTraverser.java b/src/main/java/com/client/core/resttrigger/workflow/traversing/CandidateWorkHistoryRestTriggerTraverser.java new file mode 100644 index 00000000..32f257cb --- /dev/null +++ b/src/main/java/com/client/core/resttrigger/workflow/traversing/CandidateWorkHistoryRestTriggerTraverser.java @@ -0,0 +1,18 @@ +package com.client.core.resttrigger.workflow.traversing; + +import com.bullhornsdk.data.model.entity.core.standard.CandidateWorkHistory; +import com.client.core.base.model.relatedentity.BullhornRelatedEntity; +import com.client.core.base.workflow.traversing.AbstractTriggerTraverser; +import com.client.core.resttrigger.model.helper.impl.CandidateWorkHistoryRestTriggerHelper; + +import java.util.Map; +import java.util.Set; + +public class CandidateWorkHistoryRestTriggerTraverser extends AbstractTriggerTraverser { + + public CandidateWorkHistoryRestTriggerTraverser(Integer entityID, Map valuesChanged, Integer updatingUserID, boolean edit, + Map> relatedEntityFields) { + super(new CandidateWorkHistoryRestTriggerHelper(entityID, valuesChanged, updatingUserID, relatedEntityFields), edit); + } + +}