Skip to content

Commit

Permalink
fix: adapt code to support changes in Crew API
Browse files Browse the repository at this point in the history
  • Loading branch information
wadahiro committed Dec 20, 2024
1 parent 36c2ec6 commit 8ce8684
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
11 changes: 11 additions & 0 deletions src/main/java/jp/openstandia/connector/smarthr/SmartHRClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Crew {
public String employment_type_id;
public EmploymentType employment_type;
public String position;
public List<Position> positions;
public String occupation;
public List<CustomField> custom_fields;
}
Expand Down Expand Up @@ -237,6 +238,16 @@ class Department {
public Integer position;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
class Position {
public String id;
public String name;
public Integer rank;
public String code;
public String created_at;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
class JobTitle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static jp.openstandia.connector.smarthr.SchemaDefinition.SchemaOption.*;
Expand Down Expand Up @@ -254,6 +251,25 @@ public static SchemaDefinition.Builder createSchema(List<SmartHRClient.CrewCusto
(source) -> source.position,
null
);
// readonly
sb.add("raw_positions",
SchemaDefinition.Types.JSON,
SmartHRClient.Crew.class,
SmartHRClient.Crew.class,
null,
(source) -> {
if (source.positions == null) {
return null;
}
try {
return mapper.writeValueAsString(source.positions);
} catch (JsonProcessingException ignore) {
return null;
}
},
"positions",
NOT_CREATABLE, NOT_UPDATABLE, NOT_RETURN_BY_DEFAULT
);
sb.add("occupation",
SchemaDefinition.Types.STRING,
SmartHRClient.Crew.class,
Expand Down Expand Up @@ -283,34 +299,26 @@ public static SchemaDefinition.Builder createSchema(List<SmartHRClient.CrewCusto
(source, dest) -> dest.department_ids = source,
(add, dest) -> dest.department_ids.addAll(add),
(remove, dest) -> dest.department_ids.removeAll(remove),
(source) -> source.departments != null ? source.departments.stream().map(d -> d.id).collect(Collectors.toList()) : null,
(source) -> source.departments != null ? source.departments.stream()
.filter(Objects::nonNull)
.map(d -> d.id).collect(Collectors.toList()) : null,
null
);
// readonly
sb.addAsMultiple("raw_departments",
sb.add("raw_departments",
SchemaDefinition.Types.JSON,
SmartHRClient.Crew.class,
SmartHRClient.Crew.class,
SmartHRClient.Crew.class,
null,
null,
null,
(source) -> {
if (source.departments == null) {
return null;
}
List<String> depts = source.departments.stream()
.map(d -> {
// TODO use jackson native feature
try {
return mapper.writeValueAsString(d);
} catch (JsonProcessingException ignore) {
return null;
}
})
.filter(d -> d != null)
.collect(Collectors.toList());
return depts;
try {
return mapper.writeValueAsString(source.departments);
} catch (JsonProcessingException ignore) {
return null;
}
},
"departments",
NOT_CREATABLE, NOT_UPDATABLE, NOT_RETURN_BY_DEFAULT
Expand Down

0 comments on commit 8ce8684

Please sign in to comment.