Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C2DA6200C2F for ; Mon, 6 Mar 2017 09:55:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C1704160B73; Mon, 6 Mar 2017 08:55:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E7923160B76 for ; Mon, 6 Mar 2017 09:55:47 +0100 (CET) Received: (qmail 55686 invoked by uid 500); 6 Mar 2017 08:55:47 -0000 Mailing-List: contact issues-help@fineract.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@fineract.incubator.apache.org Delivered-To: mailing list issues@fineract.incubator.apache.org Received: (qmail 55677 invoked by uid 99); 6 Mar 2017 08:55:47 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2017 08:55:47 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B03D318495F for ; Mon, 6 Mar 2017 08:55:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -7.019 X-Spam-Level: X-Spam-Status: No, score=-7.019 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id dsYI5c_Yps2d for ; Mon, 6 Mar 2017 08:55:44 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 9E9575FDDC for ; Mon, 6 Mar 2017 08:55:43 +0000 (UTC) Received: (qmail 55014 invoked by uid 99); 6 Mar 2017 08:55:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2017 08:55:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C33EEDF9A3; Mon, 6 Mar 2017 08:55:42 +0000 (UTC) From: nazeer1100126 To: issues@fineract.incubator.apache.org Reply-To: issues@fineract.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-fineract pull request #288: Email campaign Feature Content-Type: text/plain Message-Id: <20170306085542.C33EEDF9A3@git1-us-west.apache.org> Date: Mon, 6 Mar 2017 08:55:42 +0000 (UTC) archived-at: Mon, 06 Mar 2017 08:55:48 -0000 Github user nazeer1100126 commented on a diff in the pull request: https://github.com/apache/incubator-fineract/pull/288#discussion_r104363617 --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/data/EmailCampaignValidator.java --- @@ -0,0 +1,256 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.fineract.infrastructure.campaigns.email.data; + +import com.google.gson.JsonElement; +import com.google.gson.reflect.TypeToken; +import org.apache.commons.lang.StringUtils; +import org.joda.time.LocalDate; +import org.apache.fineract.infrastructure.core.data.ApiParameterError; +import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; +import org.apache.fineract.infrastructure.core.exception.InvalidJsonException; +import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.apache.fineract.infrastructure.campaigns.email.domain.EmailCampaignType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Type; +import java.util.*; + +@Component +public class EmailCampaignValidator { + + + + public static final String RESOURCE_NAME = "email"; + public static final String campaignName = "campaignName"; + public static final String campaignType = "campaignType"; + public static final String businessRuleId = "businessRuleId"; + public static final String stretchyReportId = "stretchyReportId"; + public static final String stretchyReportParamMap = "stretchyReportParamMap"; + public static final String paramValue = "paramValue"; + public static final String emailSubject = "emailSubject"; + public static final String emailMessage = "emailMessage"; + public static final String emailAttachmentFileFormatId = "emailAttachmentFileFormatId"; + public static final String activationDateParamName = "activationDate"; + public static final String recurrenceStartDate = "recurrenceStartDate"; + public static final String submittedOnDateParamName = "submittedOnDate"; + public static final String closureDateParamName = "closureDate"; + public static final String recurrenceParamName = "recurrence"; + public static final String statusParamName = "status"; + + public static final String localeParamName = "locale"; + public static final String dateFormatParamName = "dateFormat"; + + + private final FromJsonHelper fromApiJsonHelper; + + + public static final Set supportedParams = new HashSet(Arrays.asList(campaignName, campaignType,localeParamName,dateFormatParamName, + businessRuleId,paramValue,emailMessage,recurrenceStartDate,activationDateParamName,submittedOnDateParamName,closureDateParamName,recurrenceParamName, + emailSubject,stretchyReportId,stretchyReportParamMap,emailAttachmentFileFormatId)); + + public static final Set supportedParamsForUpdate = new HashSet<>(Arrays.asList(campaignName, campaignType,localeParamName,dateFormatParamName, + businessRuleId,paramValue,emailMessage,recurrenceStartDate,activationDateParamName,recurrenceParamName)); + + public static final Set ACTIVATION_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, + dateFormatParamName, activationDateParamName)); + + public static final Set CLOSE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, + dateFormatParamName, closureDateParamName)); + + public static final Set PREVIEW_REQUEST_DATA_PARAMETERS= new HashSet(Arrays.asList(paramValue,emailMessage)); + + @Autowired + public EmailCampaignValidator(FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + + public void validateCreate(String json){ + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, EmailCampaignValidator.supportedParams); + + final JsonElement element = this.fromApiJsonHelper.parse(json); + + final List dataValidationErrors = new ArrayList(); + + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(EmailCampaignValidator.RESOURCE_NAME); + + final String campaignName = this.fromApiJsonHelper.extractStringNamed(EmailCampaignValidator.campaignName,element); + baseDataValidator.reset().parameter(EmailCampaignValidator.campaignName).value(campaignName).notBlank().notExceedingLengthOf(100); + + + final Long campaignType = this.fromApiJsonHelper.extractLongNamed(EmailCampaignValidator.campaignType,element); + baseDataValidator.reset().parameter(EmailCampaignValidator.campaignType).value(campaignType).notNull().integerGreaterThanZero(); + + if(campaignType.intValue() == EmailCampaignType.SCHEDULE.getValue()){ + final String recurrenceParamName = this.fromApiJsonHelper.extractStringNamed(EmailCampaignValidator.recurrenceParamName, element); + baseDataValidator.reset().parameter(EmailCampaignValidator.recurrenceParamName).value(recurrenceParamName).notBlank(); + + final String recurrenceStartDate = this.fromApiJsonHelper.extractStringNamed(EmailCampaignValidator.recurrenceStartDate, element); + baseDataValidator.reset().parameter(EmailCampaignValidator.recurrenceStartDate).value(recurrenceStartDate).notBlank(); + } + + final Long businessRuleId = this.fromApiJsonHelper.extractLongNamed(EmailCampaignValidator.businessRuleId,element); + baseDataValidator.reset().parameter(EmailCampaignValidator.businessRuleId).value(businessRuleId).notNull().integerGreaterThanZero(); + + final String emailMessage = this.fromApiJsonHelper.extractStringNamed(EmailCampaignValidator.emailMessage, element); --- End diff -- Email Subject Line is not considered? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---