Skip to content

Commit

Permalink
Merge pull request #294 from bullhorn/f/noAllFields
Browse files Browse the repository at this point in the history
Removing find method that defaults to using * fields
  • Loading branch information
johnsully83 authored May 27, 2020
2 parents 74fd751 + 3d2560f commit 8b09d16
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 224 deletions.
9 changes: 0 additions & 9 deletions src/main/java/com/bullhornsdk/data/api/BullhornData.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@
*/
public interface BullhornData {

/**
* Returns all fields for passed in entity type with the passed in id
*
* @param type type of BullhornEntity
* @param id id of BullhornEntity
* @return an entity of type T, or null if an error occurred
*/
public <T extends BullhornEntity> T findEntity(Class<T> type, Integer id);

/**
* Returns all fields for passed in entity type with the passed in id or ids
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,6 @@ public StandardBullhornData(RestApiSession restApiSession) {
this.concurrencyService = new RestConcurrencyService();
}

/**
* {@inheritDoc}
*/
@Override
public <T extends BullhornEntity> T findEntity(Class<T> type, Integer id) {
return this.handleGetEntity(type, id, null, ParamFactory.entityParams());
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ public class MockBullhornData implements BullhornData {
this.mockDataHandler.refreshTestData();
}

/**
* Caches the data in restEntityMap after the first time an entity is fetched.
*/
@Override
public <T extends BullhornEntity> T findEntity(Class<T> type, Integer id) {
return mockDataHandler.findEntity(type, id);
}

@Override
public <T extends BullhornEntity> T findEntity(Class<T> type, Integer id, Set<String> fieldSet) {
return mockDataHandler.findEntity(type, id, fieldSet);
Expand Down
31 changes: 7 additions & 24 deletions src/main/java/com/bullhornsdk/data/api/mock/MockDataHandler.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,6 @@ public class MockDataHandler {
this.restMetaDataMap = mockDataLoader.reloadMetaDataFromCache();
}

/**
* Returns a copy of the entity stored in restEntityMap.
*
* @param type
* @param id
* @return
*/
public <T extends BullhornEntity> T findEntity(Class<T> type, Integer id) {
T entity = getEntityFromMap(type,id);

if(entity == null){
throw new RestApiException("No entity of type "+type.getSimpleName()+" with id "+id+" exists.");
}

return KryoObjectCopyHelper.copy(entity);
}

/**
* Returns a copy of the entity stored in restEntityMap.
*
Expand Down Expand Up @@ -597,7 +580,7 @@ public class MockDataHandler {
public FileWrapper addResumeFileAndPopulateCandidateDescription(Integer candidateId, JavaFile file, String candidateDescription,
String externalId, FileParams params) {

Candidate candidate = findEntity(Candidate.class, candidateId);
Candidate candidate = findEntity(Candidate.class, candidateId, [ "id" ] as Set);
candidate.setDescription(candidateDescription);
updateEntity(candidate);

Expand Down Expand Up @@ -909,7 +892,7 @@ public class MockDataHandler {

private <T extends BullhornEntity> Set<String> checkAndModifyFields(Set<String> fields, Class<T> type){
if(fields == null){
fields = ["id"] as Set;
fields = ["*"] as Set;
}
verifyFields(fields, type)
return modifyFieldsForNestedPropertyAccess(fields);
Expand Down Expand Up @@ -1121,7 +1104,7 @@ public class MockDataHandler {
}else if(propertyIsNullNestedRestEntity(fromProperty,toProperty,path)){
//Set nested RestEntities using the actual entity and not just the nested json. Example: placement.candidate will be set using the id
//of the nested json in placement-data.txt to get the corresponding entity in candidate-data.txt
fromProperty?."${path}" = findEntity(fromProperty?."${path}".getClass(),fromProperty?."${path}".getId());
fromProperty?."${path}" = findEntity(fromProperty?."${path}".getClass(),fromProperty?."${path}".getId(), [ "*" ] as Set);
toProperty?."${path}" = fromProperty?."${path}".getClass().newInstance();
}else if(propertyIsSimpleType(fromProperty,toProperty,path)){
toProperty?."${path}" = fromProperty?."${path}";
Expand Down Expand Up @@ -1176,14 +1159,14 @@ public class MockDataHandler {

private ParsedResume createParsedResume(Integer candidateId, List<Integer> educationIds,List<Integer> workHistoryIds,List<Integer> skillIds,boolean nullOutIds){
ParsedResume parsedResume = new StandardParsedResume();
Candidate candidate = this.findEntity(Candidate.class, candidateId);
Candidate candidate = this.findEntity(Candidate.class, candidateId, [ "*" ] as Set);
if(nullOutIds){
candidate.setId(null);
}
List<CandidateEducation> education = new ArrayList<CandidateEducation>();

for(Integer id: educationIds){
CandidateEducation candidateEducation = this.findEntity(CandidateEducation.class, 1);
CandidateEducation candidateEducation = this.findEntity(CandidateEducation.class, 1, [ "*" ] as Set);
if(nullOutIds){
candidateEducation.setId(null);
candidateEducation.setCandidate(null);
Expand All @@ -1193,7 +1176,7 @@ public class MockDataHandler {

List<CandidateEducation> workHistory = new ArrayList<CandidateEducation>();
for(Integer id: workHistoryIds){
CandidateWorkHistory candiateWorkHistory = this.findEntity(CandidateWorkHistory.class, id);
CandidateWorkHistory candiateWorkHistory = this.findEntity(CandidateWorkHistory.class, id, [ "*" ] as Set);
if(nullOutIds){
candiateWorkHistory.setId(null);
candiateWorkHistory.setCandidate(null);
Expand All @@ -1203,7 +1186,7 @@ public class MockDataHandler {

List<Skill> skills = new ArrayList<Skill>();
for(Integer id: skillIds){
Skill skill = this.findEntity(Skill.class, id);
Skill skill = this.findEntity(Skill.class, id, [ "*" ] as Set);
if(nullOutIds){
skill.setId(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,26 @@ public void setDateLastModified(DateTime dateLastModified) {
this.dateLastModified = dateLastModified;
}


@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
InvoiceStatementExport that = (InvoiceStatementExport) o;
return invoiceStatement.equals(that.invoiceStatement) &&
dateLastModified.equals(that.dateLastModified);
return Objects.equals(invoiceStatement, that.invoiceStatement) &&
Objects.equals(dateLastModified, that.dateLastModified);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), invoiceStatement, dateLastModified);
}

@Override
public String toString() {
return "InvoiceStatementExport{" +
"invoiceStatement=" + invoiceStatement +
", dateLastModified=" + dateLastModified +
"} " + super.toString();
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/bullhornsdk/data/TestNestedEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TestNestedEntities() {
@Test
public void testFindCandidate() {

Candidate entity = bullhornData.findEntity(Candidate.class, testEntities.getCandidateId());
Candidate entity = bullhornData.findEntity(Candidate.class, testEntities.getCandidateId(), Sets.newHashSet("id"));

assertNotNull("Candidate is null", entity);

Expand Down
Loading

0 comments on commit 8b09d16

Please sign in to comment.