/** 
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2014 ForgeRock AS. All rights reserved.
 *
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License). You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at
 * http://forgerock.org/license/CDDLv1.0.html
 * See the License for the specific language governing
 * permission and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at http://forgerock.org/license/CDDLv1.0.html
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 */

Sample 5 - Synchronization of Two Resources
-------------------------------------------

This sample demonstrates flowing data between external resources. It simulates
two directory resources using XML files. It is different from sample4 in that 
it routes changes through managed/user, rather than having them directly mapped 
to each other. It also demonstrates the use of a reconciliation report delivered
via email.

For documentation pertaining to this example see:
https://forgerock.org/openidm/doc/bootstrap/samples-guide/index.html#more-sample-5

To try the sample, follow these steps.

  Steps 1 and 2 are optional, and only necessary if you'd like to receive emailed recon summaries.

    1. Copy the samples/misc/external.email.json file into samples/sample5/conf
    $ cd /path/to/openidm
    $ cp samples/misc/external.email.json samples/sample5/conf

    Edit this file to have your email server SMTP details. See https://forgerock.org/openidm/doc/bootstrap/integrators-guide/index.html#chap-mail for more information.

    2. Edit samples/sample5/script/reconStats.js and change these values to your own email addresses:

    var params = {
        //UPDATE THESE VALUES
        from : "openidm@example.com",
        to : "idmadmin1@example.com",
        cc : "idmadmin2@example.com,idmadmin3@example.com",
        subject : "Recon stats for " + source.name + " -> " + target.name,
        type : "text/html"
    }

    3. Start OpenIDM with the configuration for sample 5.
    $ cd /path/to/openidm
    $ ./startup.sh -p samples/sample5
    When you start OpenIDM, it creates a data in the new external resource
    file that represents an AD directory, samples/sample5/data/xml_AD_Data.xml.
    The new file is empty until you run reconciliation.

    4. Run reconciliation.
    $ curl -k -H "Content-type: application/json" -u "openidm-admin:openidm-admin" -X POST "https://localhost:8443/openidm/recon?_action=recon&mapping=systemLdapAccounts_managedUser"
    {"_id":"b149f0e3-4bb9-4790-9266-fab2e5c80ec6","state":"ACTIVE"}
    
    5. Check 
    $ cat /path/to/openidm/samples/sample5/data/xml_AD_Data.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <icf:OpenICFContainer xmlns:icf="http://openidm.forgerock.com/xml/ns/public/resource/openicf/resource-schema-1.xsd"
                          xmlns:ri="http://openidm.forgerock.com/xml/ns/public/resource/instances/resource-schema-extension"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xsi:schemaLocation="http://openidm.forgerock.com/xml/ns/public/resource/instances/resource-schema-extension samples/sample5/data/resource-schema-extension.xsd http://openidm.forgerock.com/xml/ns/public/resource/openicf/resource-schema-1.xsd samples/sample5/data/resource-schema-1.xsd">
       <ri:__ACCOUNT__>
          <ri:firstname>Darth</ri:firstname>
          <icf:__DESCRIPTION__/>
          <icf:__GROUPS__/>
          <icf:__UID__>68077c05-32ae-4438-b250-d23be784ea07</icf:__UID__>
          <icf:__NAME__>DDOE1</icf:__NAME__>
          <ri:email>mail1@example.com</ri:email>
          <icf:__PASSWORD__>initial_Passw0rd</icf:__PASSWORD__>
          <icf:__ENABLE__/>
          <ri:lastname>Doe</ri:lastname>
       </ri:__ACCOUNT__>
    </icf:OpenICFContainer>

    6. Create a new user in the source external resource file,
       samples/sample5/data/xml_LDAP_Data.xml, and run reconciliation again
       to see the result show up in samples/sample5/data/xml_AD_Data.xml.

    7. Login to the UI at https://localhost:8443/. You can use openidm-admin/openidm-admin for admin access or
       DDOE1/TestPassw0rd2 for non-admin access. Updates to DDOE1 will be synced backed to both XML files.

    8. If you have configured the recon email summary in steps 1 and 2, you should have gotten an email 
       that lists the details for the reconciliation.
