onValidate-notification.js revision f8eb547a5996303c92e9482cf659642871c7252c
0N/A/**
2362N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
0N/A * Copyright (c) 2011-2012 ForgeRock AS. All rights reserved.
0N/A *
0N/A * The contents of this file are subject to the terms
2362N/A * of the Common Development and Distribution License
0N/A * (the License). You may not use this file except in
2362N/A * compliance with the License.
0N/A *
0N/A * You can obtain a copy of the License at
0N/A * http://forgerock.org/license/CDDLv1.0.html
0N/A * See the License for the specific language governing
0N/A * permission and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * Header Notice in each file and include the License file
0N/A * at http://forgerock.org/license/CDDLv1.0.html
0N/A * If applicable, add the following below the CDDL Header,
0N/A * with the fields enclosed by brackets [] replaced by
2362N/A * your own identifying information:
2362N/A * "Portions Copyrighted [year] [name of copyright owner]"
2362N/A */
0N/A
0N/A/**
0N/A * @author jdabrowski
0N/A *
0N/A * This script validates if notification is valid.
0N/A */
0N/A
0N/Avar errors = [];
0N/A
0N/Afunction requiredValidator(toValidate, fieldName) {
0N/A if (!toValidate || toValidate === "") {
0N/A errors.push(fieldName + " is required");
0N/A }
0N/A}
0N/A
0N/Afunction isNotificationValid() {
0N/A var notification = openidm.decrypt(object);
0N/A
0N/A if ( (!notification.requester || notification.requester === "")
0N/A && (!notification.requesterId || notification.requesterId === "") ) {
0N/A errors.push("Notification Requester or Requester ID is required");
0N/A }
0N/A
0N/A requiredValidator(notification.receiverId, "Notification Receiver");
0N/A requiredValidator(notification.createDate, "Create Date");
0N/A requiredValidator(notification.type, "Notification Type");
0N/A requiredValidator(notification.message, "Notification Message");
0N/A
0N/A if(errors.length > 0) {
0N/A throw errors;
0N/A }
0N/A};
0N/A
0N/AisNotificationValid();