<%

var log = new Log();
var userName = session.get("user");
var scimClient = require('/controllers/scim-providers/scimAdminClient.jag');

var i18n = session.get("i18n");

function edit(){

    try{
    	
        try{
            require('../../authenticationHandler.jag');

        }catch(e){
            log.error(e);
            response.sendRedirect("login.jag?e=1&error=AuthenticationFail");
            return;
        }

//		var consumerId = userName + session.get("tenant.domain");
        var provider = request.getParameter("providerId");

        var providers = session.get("scimProviders");
        var editProvider  = null;
        for each (var p in providers){
            if(p.providerId === provider){
                editProvider = p;
                break;
            }
        }


        if(editProvider == null){
            response.sendRedirect("../../my_scim_providers.jag?e=1&error=provider_name_incorrect");
            return;
        }

        var req = <con:deleteUserProvider xmlns:con="http://config.common.scim.identity.carbon.wso2.org">
                                 <con:consumerId></con:consumerId>
                                 <con:providerId></con:providerId>
                              </con:deleteUserProvider>;


//        req.*::consumerId.setChildren(consumerId);
        req.*::providerId.setChildren(provider);
        scimClient.deleteUserSCIMProvider(req);

        response.sendRedirect("../../my_scim_providers.jag?s=1&sMsg=scim_deleted");
    }
    catch(e){
        log.error(e);
        response.sendRedirect("../../index.jag?e=1&error=" + e);

    }

}

edit();


%>