From 8ce868467754815b629784ac809c2574ebed71ca Mon Sep 17 00:00:00 2001 From: Hiroyuki Wada Date: Fri, 20 Dec 2024 23:37:40 +0900 Subject: [PATCH] fix: adapt code to support changes in Crew API --- .../connector/smarthr/SmartHRClient.java | 11 ++++ .../connector/smarthr/SmartHRCrewHandler.java | 50 +++++++++++-------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/main/java/jp/openstandia/connector/smarthr/SmartHRClient.java b/src/main/java/jp/openstandia/connector/smarthr/SmartHRClient.java index c1de6a3..737b13f 100644 --- a/src/main/java/jp/openstandia/connector/smarthr/SmartHRClient.java +++ b/src/main/java/jp/openstandia/connector/smarthr/SmartHRClient.java @@ -210,6 +210,7 @@ class Crew { public String employment_type_id; public EmploymentType employment_type; public String position; + public List positions; public String occupation; public List custom_fields; } @@ -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 { diff --git a/src/main/java/jp/openstandia/connector/smarthr/SmartHRCrewHandler.java b/src/main/java/jp/openstandia/connector/smarthr/SmartHRCrewHandler.java index d244dbe..d15f9f6 100644 --- a/src/main/java/jp/openstandia/connector/smarthr/SmartHRCrewHandler.java +++ b/src/main/java/jp/openstandia/connector/smarthr/SmartHRCrewHandler.java @@ -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.*; @@ -254,6 +251,25 @@ public static SchemaDefinition.Builder createSchema(List 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, @@ -283,34 +299,26 @@ public static SchemaDefinition.Builder createSchema(List 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 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