<%
/*
 * Copyright (c) 2015, 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.
 */

/*
 @Deprecated
 */

var uri = request.getRequestURI();
var uriMatcher = new URIMatcher(String(uri));

var log = new Log("api/policy-api.jag");

var constants = require("/modules/constants.js");
var policyModule = require("/app/modules/business-controllers/group.js")["groupModule"];

var result;
if (uriMatcher.match("/{context}/api/policies/update")) {
    payload = request.getContent();
    policyModule.updatePolicyPriorities(payload);
} else if (uriMatcher.match("/{context}/api/policies/{id}/delete")) {
    elements = uriMatcher.elements();
    policyId = elements.id;
    try {
        result = policyModule.deletePolicy(policyId);
    } catch (e) {
        log.error("Exception occurred while trying to delete policy for id:" + policyId, e);
        // http status code 500 refers to - Internal Server Error.
        result = 500;
    }
}

// returning the result.
if (result) {
    response.content = result;
}
%>