/*
*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you 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 org.wso2.carbon.identity.user.store.configuration.ui.utils;


import org.wso2.carbon.core.AbstractAdmin;
import org.wso2.carbon.identity.user.store.configuration.stub.api.Properties;
import org.wso2.carbon.identity.user.store.configuration.stub.api.Property;

import java.util.Map;


public class UserStoreUIUtils extends AbstractAdmin {
    /**
     * Merge the defined property values of an available user store with the required set of properties
     *
     * @param properties
     * @param tempProperties
     * @return
     */
    public static Properties mergePropertyValues(Properties properties, Map<String, String> tempProperties) {
        Property[] mandatories = properties.getMandatoryProperties();
        Property[] optionals = properties.getOptionalProperties();

        if (mandatories[0] != null) {
            for (int i = 0; i < mandatories.length; i++) {
                Property property = mandatories[i];
                if (tempProperties.get(property.getName()) != null) {
                    mandatories[i].setValue(tempProperties.get(property.getName()));
                }
            }
        }

        if (optionals[0] != null) {
            for (int i = 0; i < optionals.length; i++) {
                Property property = optionals[i];
                if (tempProperties.get(property.getName()) != null) {
                    optionals[i].setValue(tempProperties.get(property.getName()));
                }
            }
        }
        properties.setMandatoryProperties(mandatories);
        properties.setOptionalProperties(optionals);
        return properties;
    }

}

@@ -1449,16 +1449,92 @@
 rties();
+%0A        Property%5B%5D advancedProperties = properties.getAdvancedProperties();
 %0A%0A      
@@ -2204,32 +2204,408 @@
     %7D%0A        %7D%0A
+%0A        if (advancedProperties%5B0%5D != null) %7B%0A            for (int i = 0; i %3C advancedProperties.length; i++) %7B%0A                Property property = advancedProperties%5Bi%5D;%0A                if (tempProperties.get(property.getName()) != null) %7B%0A                    advancedProperties%5Bi%5D.setValue(tempProperties.get(property.getName()));%0A                %7D%0A            %7D%0A        %7D%0A%0A
         properti
@@ -2693,24 +2693,86 @@
 optionals);%0A
+        properties.setAdvancedProperties(advancedProperties);%0A
         retu

Fix for IDENTITY-2646