예제 #1
0
        public static JObject verifyOuMapping(JObject ouMap, string source, string dest, string directory)
        {
            JObject meta = (JObject)ouMap.GetValue("meta");

            //Get server data
            JObject serverSource = DataFactory.GetServer(source, directory);
            JObject destSource   = DataFactory.GetServer(dest, directory);

            //Check if server sync date matches what is in the ouMap
            //If the server sync dates match, then the file is up to date.
            if (meta.GetValue("sourceSync").ToString() == serverSource.GetValue("lastSync").ToString() && meta.GetValue("destSync").ToString() == destSource.GetValue("lastSync").ToString())
            {
                return(ouMap);
            }

            //Else verify the ouMap file against the source and destination Org Unit files

            //Get org unit data
            JObject orgSource = DataFactory.GetOrgUnits(source, directory);
            JObject orgDest   = DataFactory.GetOrgUnits(dest, directory);

            JArray updateMapping = new JArray();
            JArray unmapped      = new JArray();

            //Check source org units
            foreach (JObject srcOrgUnit in orgSource.GetValue("organisationUnits"))
            {
                bool match = false;

                foreach (JObject mapped in ouMap.GetValue("mapped"))
                {
                    if (mapped.GetValue("sourceID").ToString() == srcOrgUnit.GetValue("id").ToString())
                    {
                        match = true;
                        break;
                    }
                }

                //If no match, add to the unmapped list
                if (!match)
                {
                    srcOrgUnit["type"] = "Source";
                    unmapped.Add(srcOrgUnit);
                }
            }

            //Check destination org units
            foreach (JObject destOrgUnit in orgDest.GetValue("organisationUnits"))
            {
                bool match = false;

                foreach (JObject mapped in ouMap.GetValue("mapped"))
                {
                    if (mapped.GetValue("destID").ToString() == destOrgUnit.GetValue("id").ToString())
                    {
                        match = true;
                        break;
                    }
                }

                //If no match, add to the unmapped list
                if (!match)
                {
                    destOrgUnit["type"] = "Destination";
                    unmapped.Add(destOrgUnit);
                }
            }


            return(ouMap);
        }
예제 #2
0
        public static JObject OUAutoMap(string source, string dest, string directory)
        {
            //Get server data
            JObject serverSource = DataFactory.GetServer(source, directory);
            JObject destSource   = DataFactory.GetServer(dest, directory);

            //Get org unit data
            JObject orgSource = DataFactory.GetOrgUnits(source, directory);
            JObject orgDest   = DataFactory.GetOrgUnits(dest, directory);

            JObject OUMapped     = new JObject();
            JArray  mappedList   = new JArray();
            JArray  unmappedList = new JArray();

            //TODO: Add server sync date to OUMapped
            JObject meta = new JObject();

            meta["source"]      = serverSource.GetValue("ID");
            meta["destination"] = destSource.GetValue("ID");
            meta["sourceSync"]  = serverSource.GetValue("lastSync");
            meta["destSync"]    = destSource.GetValue("lastSync");


            JArray ouSource = (JArray)orgSource.GetValue("organisationUnits");
            JArray ouDest   = (JArray)orgDest.GetValue("organisationUnits");

            bool isMapped = false;

            //Map source to destination
            foreach (JObject s in ouSource)
            {
                foreach (JObject d in ouDest)
                {
                    if (s.GetValue("displayName").ToString() == d.GetValue("displayName").ToString())
                    {
                        JObject mapped = new JObject();
                        mapped["sourceID"] = s.GetValue("id");
                        mapped["destID"]   = d.GetValue("id");
                        mapped["srcName"]  = s.GetValue("displayName");
                        mapped["destName"] = d.GetValue("displayName");

                        mappedList.Add(mapped);

                        isMapped = true;
                        break;
                    }
                }

                //If no match, then add to unmapped list
                if (!isMapped)
                {
                    s["type"] = "Source";
                    unmappedList.Add(s);
                }

                //reset the flag
                isMapped = false;
            }

            //Go through the destination list and see whats not mapped
            foreach (JObject d in ouDest)
            {
                foreach (JObject m in mappedList)
                {
                    if (d.GetValue("displayName").ToString() == m.GetValue("destName").ToString())
                    {
                        isMapped = true;
                        break;
                    }
                }

                //If no match, then add to unmapped list
                if (!isMapped)
                {
                    d["type"] = "Destination";
                    unmappedList.Add(d);
                }

                //reset the flag
                isMapped = false;
            }


            OUMapped["meta"]     = meta;
            OUMapped["mapped"]   = mappedList;
            OUMapped["unmapped"] = unmappedList;

            return(OUMapped);
        }