diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml
new file mode 100644
index 0000000..e21d04d
--- /dev/null
+++ b/.github/workflows/pull_request.yml
@@ -0,0 +1,37 @@
+name: Build and test for the pull request
+
+on:
+ pull_request:
+ types: [opened, synchronize]
+
+jobs:
+ build:
+ name: Build and test
+ runs-on: ubuntu-latest
+ if: "!contains(github.event.head_commit.message, '[ci skip]')"
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK 11
+ uses: actions/setup-java@v1
+ with:
+ java-version: 11
+ server-id: ossrh
+ server-username: OSSRH_JIRA_USERNAME
+ server-password: OSSRH_JIRA_PASSWORD
+ gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
+ gpg-passphrase: OSSRH_GPG_SECRET_KEY_PASSWORD
+ - uses: actions/cache@v2
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Build with Maven
+ run: mvn -B package
+ - name: Deploy SNAPSHOT version
+ run: mvn -B -DskipTests deploy
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ OSSRH_JIRA_USERNAME: ${{ secrets.OSSRH_JIRA_USERNAME }}
+ OSSRH_JIRA_PASSWORD: ${{ secrets.OSSRH_JIRA_PASSWORD }}
+ OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
\ No newline at end of file
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..ed1f3df
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,64 @@
+name: Release package to the Maven Central Repository
+
+on:
+ push:
+ branches:
+ - main
+
+jobs:
+ build:
+ name: Build and release
+ runs-on: ubuntu-latest
+ if: "!contains(github.event.head_commit.message, '[ci skip]')"
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK
+ uses: actions/setup-java@v1
+ with:
+ java-version: 11
+ server-id: ossrh
+ server-username: OSSRH_JIRA_USERNAME
+ server-password: OSSRH_JIRA_PASSWORD
+ gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
+ gpg-passphrase: OSSRH_GPG_SECRET_KEY_PASSWORD
+ - name: Cache for maven
+ uses: actions/cache@v2
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Setup node
+ uses: actions/setup-node@v1
+ with:
+ node-version: '10.x'
+ - name: Get yarn cache directory path
+ id: yarn-cache-dir-path
+ run: echo "::set-output name=dir::$(yarn cache dir)"
+ - name: Cache for yarn
+ uses: actions/cache@v2
+ with:
+ path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
+ key: ${{ runner.os }}-yarn-maven-semantic-release-v4.5.0
+ restore-keys: |
+ ${{ runner.os }}-yarn-
+ - name: Setup semantic-release
+ run: |
+ yarn global add @conveyal/maven-semantic-release@v4.5.0 semantic-release@15
+ echo "$(yarn global bin)" >> $GITHUB_PATH
+ - name: Test
+ run: mvn -B test
+ - name: Release
+ # maven-semantic-release requires "maven-settings.xml" in the workspace directory
+ run: |
+ mv ~/.m2/settings.xml maven-settings.xml
+ semantic-release --branch main --prepare @conveyal/maven-semantic-release \
+ --publish @semantic-release/github,@conveyal/maven-semantic-release \
+ --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release \
+ --verify-release @conveyal/maven-semantic-release\
+ --use-conveyal-workflow
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ OSSRH_JIRA_USERNAME: ${{ secrets.OSSRH_JIRA_USERNAME }}
+ OSSRH_JIRA_PASSWORD: ${{ secrets.OSSRH_JIRA_PASSWORD }}
+ OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2ebb29
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+target
+*.jar
+.idea
+.DS_Store
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f943cfd
--- /dev/null
+++ b/README.md
@@ -0,0 +1,28 @@
+# SmartHR Connector
+
+## Description
+
+Connector for [SmartHR](https://smarthr.jp/).
+
+## Capabilities and Features
+
+- Schema: YES
+- Provisioning: YES
+- Live Synchronization: No
+- Password: YES
+- Activation: YES
+- Script execution: No
+
+## Build
+
+Install JDK 11+ and [maven3](https://maven.apache.org/download.cgi) then build:
+
+```
+mvn install
+```
+
+After successful the build, you can find `connector-smarthr-*.jar` in `target` directory.
+
+## License
+
+Licensed under the [Apache License 2.0](/LICENSE).
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..87ab7ea
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,268 @@
+
+ 4.0.0
+
+
+ connector-parent
+ com.evolveum.polygon
+ 1.5.0.0
+
+
+
+ jp.openstandia.connector
+ connector-smarthr
+ 0.0.2-SNAPSHOT
+ jar
+
+ SmartHR Connector
+
+
+ SmartHR Connector.
+
+ https://github.com/openstandia/connector-smarthr
+
+
+
+ Apache License, Version 2.0
+ https://www.apache.org/licenses/LICENSE-2.0
+ repo
+
+
+
+
+
+ wadahiro
+ Hiroyuki Wada
+ h2-wada@nri.co.jp
+ Nomura Research Institute, Ltd.
+ +9
+
+
+
+
+ scm:git:https://github.com/openstandia/connector-smarthr.git
+ scm:git:https://github.com/openstandia/connector-smarthr.git
+ https://github.com/openstandia/connector-smarthr
+
+
+
+
+ ossrh
+ https://oss.sonatype.org/content/repositories/snapshots
+
+
+ ossrh
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+
+
+
+
+ jp.openstandia.connector.smarthr
+ SmartHRConnector
+
+
+
+
+ central
+ Maven Central
+ https://repo1.maven.org/maven2
+
+
+ evolveum-nexus-releases
+ Internal Releases
+ https://nexus.evolveum.com/nexus/content/repositories/releases/
+
+
+ evolveum-nexus-snapshots
+ Internal Releases
+ https://nexus.evolveum.com/nexus/content/repositories/snapshots/
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.2
+
+
+ org.apache.maven.surefire
+ surefire-junit-platform
+ 2.22.2
+
+
+
+
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+ 1.6.8
+ true
+
+ ossrh
+ https://oss.sonatype.org/
+ true
+ 20
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.0
+
+
+ attach-sources
+ verify
+
+ jar-no-fork
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 3.2.0
+
+
+ ${java.home}/bin/javadoc
+
+
+
+ attach-javadocs
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ 1.6
+
+
+ --pinentry-mode
+ loopback
+
+
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+
+
+
+
+
+
+ com.squareup.okhttp3
+ okhttp
+ 4.9.0
+
+
+ com.squareup.okhttp3
+ okhttp-urlconnection
+ 4.9.0
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.12.0
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.6.0
+ test
+
+
+
+
+
+ midpoint
+
+
+ com.evolveum.midpoint.gui
+ admin-gui
+ 4.4.2
+ jar
+ classes
+ provided
+
+
+ org.testng
+ testng
+ 6.8
+ test
+
+
+ org.yaml
+ snakeyaml
+
+
+
+
+ net.tirasa.connid
+ connector-framework-contract
+ ${connId.version}
+ test
+
+
+ net.tirasa.connid
+ connector-test-common
+
+
+ org.codehaus.groovy
+ groovy
+
+
+ org.codehaus.groovy
+ groovy-templates
+
+
+ org.codehaus.groovy
+ groovy-bsf
+
+
+ org.codehaus.groovy
+ groovy-jsr223
+
+
+ org.codehaus.groovy
+ groovy-datetime
+
+
+ org.codehaus.groovy
+ groovy-dateutil
+
+
+ org.codehaus.groovy
+ groovy-sql
+
+
+
+
+
+
+
diff --git a/src/main/assembly/connector.xml b/src/main/assembly/connector.xml
new file mode 100644
index 0000000..a2e6d0b
--- /dev/null
+++ b/src/main/assembly/connector.xml
@@ -0,0 +1,43 @@
+
+
+
+ bundle
+
+
+ jar
+
+
+ false
+
+
+
+ ${project.basedir}
+
+
+ LICENSE
+ README.md
+
+
+
+ ${project.build.directory}/classes
+
+
+
+
+
+
+ lib
+ true
+ false
+
+ net.tirasa.connid:connector-framework
+ net.tirasa.connid:connector-framework-internal
+ jp.openstandia.connector:connector-smarthr
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/jp/openstandia/connector/smarthr/SchemaDefinition.java b/src/main/java/jp/openstandia/connector/smarthr/SchemaDefinition.java
new file mode 100644
index 0000000..61638a2
--- /dev/null
+++ b/src/main/java/jp/openstandia/connector/smarthr/SchemaDefinition.java
@@ -0,0 +1,720 @@
+/*
+ * Copyright Nomura Research Institute, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package jp.openstandia.connector.smarthr;
+
+import org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException;
+import org.identityconnectors.framework.common.objects.*;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static jp.openstandia.connector.smarthr.SmartHRUtils.shouldReturn;
+
+public class SchemaDefinition {
+
+ public static Builder newBuilder(ObjectClass objectClass) {
+ Builder schemaBuilder = new Builder(objectClass);
+ return schemaBuilder;
+ }
+
+ public static class Builder {
+ private final ObjectClass objectClass;
+ private final List attributes = new ArrayList<>();
+
+ public Builder(ObjectClass objectClass) {
+ this.objectClass = objectClass;
+ }
+
+ public void addUid(String name,
+ Types typeClass,
+ Class createClass,
+ Class updateClass,
+ Class readClass,
+
+ BiConsumer create,
+ BiConsumer update,
+ Function read,
+
+ String fetchField,
+
+ SchemaOption... options
+ ) {
+ AttributeMapper attr = new AttributeMapper(Uid.NAME, name, typeClass, create, update, read, fetchField, options);
+ this.attributes.add(attr);
+ }
+
+ public void addUid(String name,
+ Types typeClass,
+ Class createOrUpdateClass,
+ Class readClass,
+
+ BiConsumer createOrUpdate,
+ Function read,
+
+ String fetchField,
+
+ SchemaOption... options
+ ) {
+ AttributeMapper attr = new AttributeMapper(Uid.NAME, name, typeClass, createOrUpdate, createOrUpdate, read, fetchField, options);
+ this.attributes.add(attr);
+ }
+
+ public void addName(String name,
+ Types typeClass,
+ Class createClass,
+ Class updateClass,
+ Class readClass,
+
+ BiConsumer create,
+ BiConsumer update,
+ Function read,
+
+ String fetchField,
+
+ SchemaOption... options
+ ) {
+ AttributeMapper attr = new AttributeMapper(Name.NAME, name, typeClass, create, update, read, fetchField, options);
+ this.attributes.add(attr);
+ }
+
+ public void addName(String name,
+ Types typeClass,
+ Class createOrUpdateClass,
+ Class readClass,
+
+ BiConsumer createOrUpdate,
+ Function read,
+
+ String fetchField,
+
+ SchemaOption... options
+ ) {
+ AttributeMapper attr = new AttributeMapper(Name.NAME, name, typeClass, createOrUpdate, createOrUpdate, read, fetchField, options);
+ this.attributes.add(attr);
+ }
+
+ public void add(String name,
+ Types typeClass,
+ Class createClass,
+ Class updateClass,
+ Class readClass,
+
+ BiConsumer create,
+ BiConsumer update,
+ Function read,
+
+ String fetchField,
+
+ SchemaOption... options
+ ) {
+ AttributeMapper attr = new AttributeMapper(name, typeClass, create, update, read, fetchField, options);
+ this.attributes.add(attr);
+ }
+
+ public void add(String name,
+ Types typeClass,
+ Class createOrUpdateClass,
+ Class readClass,
+
+ BiConsumer createOrUpdate,
+ Function read,
+
+ String fetchField,
+
+ SchemaOption... options
+ ) {
+ AttributeMapper attr = new AttributeMapper(name, typeClass, createOrUpdate, createOrUpdate, read, fetchField, options);
+ this.attributes.add(attr);
+ }
+
+ public void addAsMultiple(String name,
+ Types typeClass,
+ Class createClass,
+ Class updateClass,
+ Class readClass,
+
+ BiConsumer, C> create,
+ BiConsumer, U> updateAdd,
+ BiConsumer, U> updateRemove,
+ Function> read,
+
+ String fetchField,
+
+ SchemaOption... options
+ ) {
+ AttributeMapper attr = new AttributeMapper(name, typeClass, create, updateAdd, updateRemove, read, fetchField, options);
+ this.attributes.add(attr);
+ }
+
+ public SchemaDefinition build() {
+ SchemaDefinition schemaDefinition = new SchemaDefinition(objectClass, buildSchemaInfo(), buildAttributeMap());
+ return schemaDefinition;
+ }
+
+ private ObjectClassInfo buildSchemaInfo() {
+ List list = attributes.stream()
+ .map(attr -> {
+ AttributeInfoBuilder define = AttributeInfoBuilder.define(attr.connectorName);
+
+ define.setType(attr.type.typeClass);
+ define.setMultiValued(attr.isMultiple);
+ define.setNativeName(attr.name);
+
+ if (attr.type == Types.UUID) {
+ define.setSubtype(AttributeInfo.Subtypes.STRING_UUID);
+
+ } else if (attr.type == Types.STRING_CASE_IGNORE) {
+ define.setSubtype(AttributeInfo.Subtypes.STRING_CASE_IGNORE);
+
+ } else if (attr.type == Types.STRING_URI) {
+ define.setSubtype(AttributeInfo.Subtypes.STRING_URI);
+
+ } else if (attr.type == Types.STRING_LDAP_DN) {
+ define.setSubtype(AttributeInfo.Subtypes.STRING_LDAP_DN);
+
+ } else if (attr.type == Types.XML) {
+ define.setSubtype(AttributeInfo.Subtypes.STRING_XML);
+
+ } else if (attr.type == Types.JSON) {
+ define.setSubtype(AttributeInfo.Subtypes.STRING_JSON);
+ }
+
+ for (SchemaOption option : attr.options) {
+ switch (option) {
+ case REQUIRED: {
+ define.setRequired(true);
+ break;
+ }
+ case NOT_CREATABLE: {
+ define.setCreateable(false);
+ break;
+ }
+ case NOT_UPDATABLE: {
+ define.setUpdateable(false);
+ break;
+ }
+ case NOT_READABLE: {
+ define.setReadable(false);
+ break;
+ }
+ case NOT_RETURN_BY_DEFAULT: {
+ define.setReturnedByDefault(false);
+ break;
+ }
+ }
+ }
+
+ return define.build();
+ })
+ .collect(Collectors.toList());
+
+ ObjectClassInfoBuilder builder = new ObjectClassInfoBuilder();
+ builder.setType(objectClass.getObjectClassValue());
+ builder.addAllAttributeInfo(list);
+
+ return builder.build();
+ }
+
+ private Map buildAttributeMap() {
+ Map map = attributes.stream()
+ // Use connectorName for the key (to lookup by special name like __UID__
+ .collect(Collectors.toMap(a -> a.connectorName, a -> a));
+ return map;
+ }
+ }
+
+ private final ObjectClass objectClass;
+ private final ObjectClassInfo objectClassInfo;
+ private final Map attributeMap;
+ // Key: attribute name (for connector. e.g. __NAME__)
+ // Value: field name for resource fetching
+ private final Map returnedByDefaultAttributesSet;
+
+ public SchemaDefinition(ObjectClass objectClass, ObjectClassInfo objectClassInfo, Map attributeMap) {
+ this.objectClass = objectClass;
+ this.objectClassInfo = objectClassInfo;
+ this.attributeMap = attributeMap;
+ this.returnedByDefaultAttributesSet = getObjectClassInfo().getAttributeInfo().stream()
+ .filter(i -> i.isReturnedByDefault())
+ .map(i -> i.getName())
+ .collect(Collectors.toMap(n -> n, n -> attributeMap.get(n).fetchField));
+ }
+
+ public ObjectClassInfo getObjectClassInfo() {
+ return objectClassInfo;
+ }
+
+ public Map getReturnedByDefaultAttributesSet() {
+ return returnedByDefaultAttributesSet;
+ }
+
+ public String getFetchField(String name) {
+ AttributeMapper attributeMapper = attributeMap.get(name);
+ if (attributeMapper != null) {
+ return attributeMapper.fetchField;
+ }
+ return null;
+ }
+
+ public T apply(Set attrs, T dest) {
+ for (Attribute attr : attrs) {
+ AttributeMapper attributeMapper = attributeMap.get(attr.getName());
+ if (attributeMapper == null) {
+ throw new InvalidAttributeValueException("Invalid attribute: " + attr.getName());
+ }
+
+ attributeMapper.apply(attr, dest);
+ }
+ return dest;
+ }
+
+ public boolean applyDelta(Set deltas, U dest) {
+ boolean changed = false;
+ for (AttributeDelta delta : deltas) {
+ AttributeMapper attributeMapper = attributeMap.get(delta.getName());
+ if (attributeMapper == null) {
+ throw new InvalidAttributeValueException("Invalid attribute: " + delta.getName());
+ }
+
+ attributeMapper.apply(delta, dest);
+ changed = true;
+ }
+ return changed;
+ }
+
+ public ConnectorObjectBuilder toConnectorObjectBuilder(R source, Set attributesToGet, boolean allowPartialAttributeValues) {
+ final ConnectorObjectBuilder builder = new ConnectorObjectBuilder()
+ .setObjectClass(objectClass);
+
+ AttributeMapper uid = attributeMap.get(Uid.NAME);
+ builder.addAttribute(uid.apply(source));
+
+ // Need to set __NAME__ because it throws IllegalArgumentException
+ AttributeMapper name = attributeMap.get(Name.NAME);
+ builder.addAttribute(name.apply(source));
+
+ for (Map.Entry entry : attributeMap.entrySet()) {
+ if (shouldReturn(attributesToGet, entry.getKey(), returnedByDefaultAttributesSet.containsKey(entry.getKey()))) {
+ Attribute value = entry.getValue().apply(source);
+ if (value != null) {
+ builder.addAttribute(value);
+ }
+ }
+ }
+
+ return builder;
+ }
+
+ public String getType() {
+ return objectClassInfo.getType();
+ }
+
+ public static class Types {
+ public static final Types STRING = new Types(String.class);
+ public static final Types STRING_CASE_IGNORE = new Types(String.class);
+ public static final Types STRING_URI = new Types(String.class);
+ public static final Types STRING_LDAP_DN = new Types(String.class);
+ public static final Types XML = new Types(String.class);
+ public static final Types JSON = new Types(String.class);
+ public static final Types UUID = new Types(String.class);
+ public static final Types INTEGER = new Types(Integer.class);
+ public static final Types LONG = new Types(Long.class);
+ public static final Types FLOAT = new Types(Float.class);
+ public static final Types DOUBLE = new Types(Double.class);
+ public static final Types BOOLEAN = new Types(Boolean.class);
+ public static final Types BIG_DECIMAL = new Types(BigDecimal.class);
+ public static final Types DATE_STRING = new Types(ZonedDateTime.class);
+ public static final Types DATETIME_STRING = new Types(ZonedDateTime.class);
+ public static final Types DATE = new Types(ZonedDateTime.class);
+ public static final Types DATETIME = new Types(ZonedDateTime.class);
+
+ private final Class typeClass;
+
+ private Types(Class typeClass) {
+ this.typeClass = typeClass;
+ }
+ }
+
+ public static SchemaOption[] newOptions(SchemaOption... options) {
+ return options;
+ }
+
+ static enum SchemaOption {
+ REQUIRED,
+ NOT_CREATABLE,
+ NOT_UPDATABLE,
+ NOT_READABLE,
+ NOT_RETURN_BY_DEFAULT,
+ }
+
+ static class AttributeMapper {
+ private final String connectorName;
+ private final String name;
+ private final Types type;
+ boolean isMultiple;
+
+ private final BiConsumer create;
+ private final BiConsumer replace;
+ private final BiConsumer, U> add;
+ private final BiConsumer, U> remove;
+ private final Function read;
+
+ private final String fetchField;
+
+ private final SchemaOption[] options;
+
+ private DateTimeFormatter dateFormat;
+ private DateTimeFormatter dateTimeFormat;
+
+ private static final DateTimeFormatter DEFAULT_DATE_FORMAT = DateTimeFormatter.ISO_LOCAL_DATE;
+ private static final DateTimeFormatter DEFAULT_DATE_TIME_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+
+ public AttributeMapper(String connectorName, String name, Types typeClass,
+ BiConsumer create,
+ BiConsumer replace,
+ Function read,
+ String fetchField,
+ SchemaOption... options
+ ) {
+ this(connectorName, name, typeClass, create, replace, null, null, read, fetchField, false, options);
+ }
+
+ public AttributeMapper(String name, Types typeClass,
+ BiConsumer create,
+ BiConsumer replace,
+ Function read,
+ String fetchField,
+ SchemaOption... options
+ ) {
+ this(name, name, typeClass, create, replace, null, null, read, fetchField, false, options);
+ }
+
+ public AttributeMapper(String name, Types typeClass,
+ BiConsumer create,
+ BiConsumer, U> add,
+ BiConsumer, U> remove,
+ Function read,
+ String fetchField,
+ SchemaOption... options
+ ) {
+ this(name, name, typeClass, create, null, add, remove, read, fetchField, true, options);
+ }
+
+ public AttributeMapper(String connectorName, String name, Types typeClass,
+ BiConsumer create,
+ BiConsumer replace,
+ BiConsumer, U> add,
+ BiConsumer, U> remove,
+ Function read,
+ String fetchField,
+ boolean isMultiple,
+ SchemaOption... options
+ ) {
+ this.connectorName = connectorName;
+ this.name = name;
+ this.type = typeClass;
+ this.create = create;
+ this.replace = replace;
+ this.add = add;
+ this.remove = remove;
+ this.read = read;
+ this.fetchField = fetchField != null ? fetchField : name;
+ this.options = options;
+ this.isMultiple = isMultiple;
+ }
+
+ public boolean isStringType() {
+ return type == Types.STRING || type == Types.STRING_URI || type == Types.STRING_LDAP_DN ||
+ type == Types.STRING_LDAP_DN || type == Types.STRING_CASE_IGNORE || type == Types.XML ||
+ type == Types.JSON || type == Types.UUID;
+ }
+
+ public AttributeMapper dateFormat(DateTimeFormatter dateFormat) {
+ this.dateFormat = dateFormat;
+ return this;
+ }
+
+ public AttributeMapper datetimeFormat(DateTimeFormatter datetimeFormat) {
+ this.dateTimeFormat = datetimeFormat;
+ return this;
+ }
+
+ private String formatDate(ZonedDateTime zonedDateTime) {
+ if (this.dateFormat == null) {
+ return zonedDateTime.format(DEFAULT_DATE_FORMAT);
+ }
+ return zonedDateTime.format(this.dateFormat);
+ }
+
+ private String formatDateTime(ZonedDateTime zonedDateTime) {
+ if (this.dateTimeFormat == null) {
+ return zonedDateTime.format(DEFAULT_DATE_TIME_FORMAT);
+ }
+ return zonedDateTime.format(this.dateFormat);
+ }
+
+ private ZonedDateTime toDate(String dateString) {
+ LocalDate date;
+ if (this.dateFormat == null) {
+ date = LocalDate.parse(dateString, DEFAULT_DATE_FORMAT);
+ } else {
+ date = LocalDate.parse(dateString, this.dateFormat);
+ }
+ return date.atStartOfDay(ZoneId.systemDefault());
+ }
+
+ private ZonedDateTime toDateTime(String dateTimeString) {
+ ZonedDateTime dateTime;
+ if (this.dateTimeFormat == null) {
+ dateTime = ZonedDateTime.parse(dateTimeString, DEFAULT_DATE_TIME_FORMAT);
+ } else {
+ dateTime = ZonedDateTime.parse(dateTimeString, this.dateTimeFormat);
+ }
+ return dateTime;
+ }
+
+ public void apply(Attribute source, C dest) {
+ if (create == null) {
+ return;
+ }
+
+ if (isMultiple) {
+ if (type == Types.DATE_STRING) {
+ List values = source.getValue().stream()
+ .map(v -> (ZonedDateTime) v)
+ .map(v -> (T) formatDate(v))
+ .collect(Collectors.toList());
+ create.accept((T) values, dest);
+
+ } else if (type == Types.DATETIME_STRING) {
+ List values = source.getValue().stream()
+ .map(v -> (ZonedDateTime) v)
+ .map(v -> (T) formatDateTime(v))
+ .collect(Collectors.toList());
+ create.accept((T) values, dest);
+
+ } else {
+ List values = source.getValue().stream().map(v -> (T) v).collect(Collectors.toList());
+ create.accept((T) values, dest);
+ }
+
+ } else {
+ if (isStringType()) {
+ String value = AttributeUtil.getAsStringValue(source);
+ create.accept((T) value, dest);
+
+ } else if (type == Types.INTEGER) {
+ Integer value = AttributeUtil.getIntegerValue(source);
+ create.accept((T) value, dest);
+
+ } else if (type == Types.LONG) {
+ Long value = AttributeUtil.getLongValue(source);
+ create.accept((T) value, dest);
+
+ } else if (type == Types.FLOAT) {
+ Float value = AttributeUtil.getFloatValue(source);
+ create.accept((T) value, dest);
+
+ } else if (type == Types.DOUBLE) {
+ Double value = AttributeUtil.getDoubleValue(source);
+ create.accept((T) value, dest);
+
+ } else if (type == Types.BOOLEAN) {
+ Boolean value = AttributeUtil.getBooleanValue(source);
+ create.accept((T) value, dest);
+
+ } else if (type == Types.BIG_DECIMAL) {
+ BigDecimal value = AttributeUtil.getBigDecimalValue(source);
+ create.accept((T) value, dest);
+
+ } else if (type == Types.DATE || type == Types.DATETIME) {
+ ZonedDateTime date = (ZonedDateTime) AttributeUtil.getSingleValue(source);
+ String formatted = formatDate(date);
+ create.accept((T) formatted, dest);
+
+ } else if (type == Types.DATE_STRING) {
+ ZonedDateTime date = (ZonedDateTime) AttributeUtil.getSingleValue(source);
+ String formatted = formatDate(date);
+ create.accept((T) formatted, dest);
+
+ } else if (type == Types.DATETIME_STRING) {
+ ZonedDateTime date = (ZonedDateTime) AttributeUtil.getSingleValue(source);
+ String formatted = formatDateTime(date);
+ create.accept((T) formatted, dest);
+ }
+ }
+ }
+
+ public void apply(AttributeDelta source, U dest) {
+ if (isMultiple) {
+ if (add == null || remove == null) {
+ return;
+ }
+
+ if (type == Types.DATE_STRING) {
+ List valuesToAdd = safeStream(source.getValuesToAdd())
+ .map(v -> (ZonedDateTime) v)
+ .map(v -> (T) formatDate(v))
+ .collect(Collectors.toList());
+ List valuesToRemove = safeStream(source.getValuesToRemove())
+ .map(v -> (ZonedDateTime) v)
+ .map(v -> (T) formatDate(v))
+ .collect(Collectors.toList());
+
+ if (!valuesToAdd.isEmpty()) {
+ add.accept(valuesToAdd, dest);
+ }
+ if (!valuesToRemove.isEmpty()) {
+ remove.accept(valuesToRemove, dest);
+ }
+
+ } else if (type == Types.DATETIME_STRING) {
+ List valuesToAdd = safeStream(source.getValuesToAdd())
+ .map(v -> (ZonedDateTime) v)
+ .map(v -> (T) formatDateTime(v))
+ .collect(Collectors.toList());
+ List valuesToRemove = safeStream(source.getValuesToRemove())
+ .map(v -> (ZonedDateTime) v)
+ .map(v -> (T) formatDateTime(v))
+ .collect(Collectors.toList());
+
+ if (!valuesToAdd.isEmpty()) {
+ add.accept(valuesToAdd, dest);
+ }
+ if (!valuesToRemove.isEmpty()) {
+ remove.accept(valuesToRemove, dest);
+ }
+
+ } else {
+ List valuesToAdd = safeStream(source.getValuesToAdd()).map(v -> (T) v).collect(Collectors.toList());
+ List valuesToRemove = safeStream(source.getValuesToRemove()).map(v -> (T) v).collect(Collectors.toList());
+
+ if (!valuesToAdd.isEmpty()) {
+ add.accept(valuesToAdd, dest);
+ }
+ if (!valuesToRemove.isEmpty()) {
+ remove.accept(valuesToRemove, dest);
+ }
+ }
+
+ } else {
+ if (replace == null) {
+ return;
+ }
+
+ if (isStringType()) {
+ String value = AttributeDeltaUtil.getAsStringValue(source);
+ replace.accept((T) value, dest);
+
+ } else if (type == Types.INTEGER) {
+ Integer value = AttributeDeltaUtil.getIntegerValue(source);
+ replace.accept((T) value, dest);
+
+ } else if (type == Types.LONG) {
+ Long value = AttributeDeltaUtil.getLongValue(source);
+ replace.accept((T) value, dest);
+
+ } else if (type == Types.FLOAT) {
+ Float value = AttributeDeltaUtil.getFloatValue(source);
+ replace.accept((T) value, dest);
+
+ } else if (type == Types.DOUBLE) {
+ Double value = AttributeDeltaUtil.getDoubleValue(source);
+ replace.accept((T) value, dest);
+
+ } else if (type == Types.BOOLEAN) {
+ Boolean value = AttributeDeltaUtil.getBooleanValue(source);
+ replace.accept((T) value, dest);
+
+ } else if (type == Types.BIG_DECIMAL) {
+ BigDecimal value = AttributeDeltaUtil.getBigDecimalValue(source);
+ replace.accept((T) value, dest);
+
+ } else if (type == Types.DATE || type == Types.DATETIME) {
+ ZonedDateTime date = (ZonedDateTime) AttributeDeltaUtil.getSingleValue(source);
+ replace.accept((T) date, dest);
+
+ } else if (type == Types.DATE_STRING) {
+ ZonedDateTime date = (ZonedDateTime) AttributeDeltaUtil.getSingleValue(source);
+ String formatted = formatDate(date);
+ replace.accept((T) formatted, dest);
+
+ } else if (type == Types.DATETIME_STRING) {
+ ZonedDateTime date = (ZonedDateTime) AttributeDeltaUtil.getSingleValue(source);
+ String formatted = formatDateTime(date);
+ replace.accept((T) formatted, dest);
+ }
+ }
+ }
+
+ public Attribute apply(R source) {
+ if (read == null) {
+ return null;
+ }
+
+ Object value = read.apply(source);
+ if (value == null) {
+ return null;
+ }
+
+ if (isMultiple) {
+ if (type == Types.DATE_STRING) {
+ List values = ((List>) value).stream()
+ .map(v -> (String) v)
+ .map(v -> toDate(v))
+ .collect(Collectors.toList());
+ return AttributeBuilder.build(connectorName, values);
+
+ } else if (type == Types.DATETIME_STRING) {
+ List values = ((List>) value).stream()
+ .map(v -> (String) v)
+ .map(v -> toDateTime(v))
+ .collect(Collectors.toList());
+ return AttributeBuilder.build(connectorName, values);
+
+ } else {
+ return AttributeBuilder.build(connectorName, (List>) value);
+ }
+
+ } else {
+ if (type == Types.DATE_STRING) {
+ ZonedDateTime date = toDate(value.toString());
+ return AttributeBuilder.build(connectorName, date);
+
+ } else if (type == Types.DATETIME_STRING) {
+ ZonedDateTime dateTime = toDateTime(value.toString());
+ return AttributeBuilder.build(connectorName, dateTime);
+ }
+ return AttributeBuilder.build(connectorName, value);
+ }
+ }
+
+ private Stream