Skip to content

Commit

Permalink
Merge pull request #134 from ALNAUA/candidateWorkHistoryRestTrigger
Browse files Browse the repository at this point in the history
added CandidateWorkHistoryRestTrigger support
  • Loading branch information
johnsully83 authored Mar 25, 2021
2 parents b7e9729 + 9a88abb commit 37abc70
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<CandidateWorkHistory> {

public CandidateWorkHistoryTriggerHelper(Integer updatingUserID, Map<? extends BullhornRelatedEntity, Set<String>> relatedEntityFields) {
super(updatingUserID, CandidateWorkHistory.class, CandidateWorkHistoryRelatedEntity.CANDIDATE_WORK_HISTORY, relatedEntityFields);
}
}
Original file line number Diff line number Diff line change
@@ -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<CandidateWorkHistory, CandidateWorkHistoryRestTriggerHelper, CandidateWorkHistoryRestTriggerTraverser> {

private final Logger log = Logger.getLogger(CandidateWorkHistoryRestTriggerController.class);

@Autowired
public CandidateWorkHistoryRestTriggerController(Optional<List<TriggerValidator<CandidateWorkHistory, CandidateWorkHistoryRestTriggerHelper, CandidateWorkHistoryRestTriggerTraverser>>> 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<String, Object> valuesChanges = (Map<String, Object>) convertToMap(body).get("data");

RestTriggerRequest<CandidateWorkHistory> 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<String, Object> valuesChanges = (Map<String, Object>) convertToMap(body).get("data");

RestTriggerRequest<CandidateWorkHistory> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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<CandidateWorkHistory> {

private final Integer entityID;
private final Map<String, Object> valuesChanged;

public CandidateWorkHistoryRestTriggerHelper(Integer entityID, Map<String, Object> valuesChanged, Integer updatingUserID,
Map<? extends BullhornRelatedEntity, Set<String>> relatedEntityFields) {
super(updatingUserID, relatedEntityFields);
this.entityID = entityID;
this.valuesChanged = valuesChanged;
}

@Override
public Set<String> getPopulatedFields() {
return valuesChanged.keySet();
}

@Override
public Integer getEntityID() {
return entityID;
}

@Override
public Map<String, Object> getValuesChanged() {
return valuesChanged;
}

@Override
protected CandidateWorkHistory instantiateNewEntity() {
return TriggerUtil.populateEntity(entityID, CandidateWorkHistory.class, valuesChanged, CandidateWorkHistory::new, getFields(CandidateWorkHistoryRelatedEntity.CANDIDATE_WORK_HISTORY));
}
}
Original file line number Diff line number Diff line change
@@ -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<CandidateWorkHistory, CandidateWorkHistoryRestTriggerHelper, CandidateWorkHistoryRestTriggerTraverser> {

public CandidateWorkHistoryRestTriggerValidator(Integer order, Map<CandidateWorkHistoryRelatedEntity, Set<String>> relatedEntityFields) {
super(order, relatedEntityFields);
}

public CandidateWorkHistoryRestTriggerValidator(Map<CandidateWorkHistoryRelatedEntity, Set<String>> relatedEntityFields) {
super(relatedEntityFields);
}

}
Original file line number Diff line number Diff line change
@@ -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<CandidateWorkHistory, CandidateWorkHistoryRestTriggerHelper> {

public CandidateWorkHistoryRestTriggerTraverser(Integer entityID, Map<String, Object> valuesChanged, Integer updatingUserID, boolean edit,
Map<? extends BullhornRelatedEntity, Set<String>> relatedEntityFields) {
super(new CandidateWorkHistoryRestTriggerHelper(entityID, valuesChanged, updatingUserID, relatedEntityFields), edit);
}

}

0 comments on commit 37abc70

Please sign in to comment.