fineract-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nazeer1100126 <...@git.apache.org>
Subject [GitHub] incubator-fineract pull request #288: Email campaign Feature
Date Mon, 06 Mar 2017 08:55:42 GMT
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<String> supportedParams = new HashSet<String>(Arrays.asList(campaignName,
campaignType,localeParamName,dateFormatParamName,
    +            businessRuleId,paramValue,emailMessage,recurrenceStartDate,activationDateParamName,submittedOnDateParamName,closureDateParamName,recurrenceParamName,
    +            emailSubject,stretchyReportId,stretchyReportParamMap,emailAttachmentFileFormatId));
    +
    +    public static final Set<String> supportedParamsForUpdate = new HashSet<>(Arrays.asList(campaignName,
campaignType,localeParamName,dateFormatParamName,
    +            businessRuleId,paramValue,emailMessage,recurrenceStartDate,activationDateParamName,recurrenceParamName));
    +
    +    public static final Set<String> ACTIVATION_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
    +            dateFormatParamName, activationDateParamName));
    +
    +    public static final Set<String> CLOSE_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
    +            dateFormatParamName, closureDateParamName));
    +
    +    public static final Set<String> PREVIEW_REQUEST_DATA_PARAMETERS= new HashSet<String>(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<Map<String, Object>>() {}.getType();
    +        this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, EmailCampaignValidator.supportedParams);
    +        
    +        final JsonElement element = this.fromApiJsonHelper.parse(json);
    +
    +        final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    +
    +        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.
---

Mime
View raw message