You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by emmanuelnnaa <gi...@git.apache.org> on 2016/08/02 10:31:01 UTC

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

GitHub user emmanuelnnaa opened a pull request:

    https://github.com/apache/incubator-fineract/pull/191

    commit for FINERACT-65 (Implement ability to schedule & e-mail reports)

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/emmanuelnnaa/incubator-fineract FINERACT-65

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-fineract/pull/191.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #191
    
----
commit c737eafa6fa54d026240dfd606c55f03b7fc1d9f
Author: Emmanuel Nnaa <em...@musoni.eu>
Date:   2016-08-02T10:29:15Z

    commit for FINERACT-65 (Implement ability to schedule & e-mail reports)

----


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73289640
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadReportingServiceImpl.java ---
    @@ -485,4 +487,10 @@ public ReportParameterData mapRow(final ResultSet rs, @SuppressWarnings("unused"
             }
         }
     
    -}
    \ No newline at end of file
    +    @Override
    +    public ByteArrayOutputStream generatePentahoReportAsOutputStream(String reportName, String outputTypeParam,
    +            Map<String, String> queryParams, Locale locale, AppUser runReportAsUser, StringBuilder errorLog) {
    +        // TODO Auto-generated method stub
    +        return null;
    --- End diff --
    
    What is the use of this method? Just return null?


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73293627
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRepositoryWrapper.java ---
    @@ -0,0 +1,56 @@
    +/**
    + * 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.reportmailingjob.domain;
    +
    +import org.apache.fineract.infrastructure.reportmailingjob.exception.ReportMailingJobNotFoundException;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.stereotype.Service;
    +
    +@Service
    +public class ReportMailingJobRepositoryWrapper {
    +    private final ReportMailingJobRepository reportMailingJobRepository;
    +    
    +    @Autowired
    +    public ReportMailingJobRepositoryWrapper(final ReportMailingJobRepository reportMailingJobRepository) {
    +        this.reportMailingJobRepository = reportMailingJobRepository;
    +    }
    +    
    +    /** 
    +     * find report mailing job by ID, throw a "entity not found" exception if the job does not exist
    +     * 
    +     * @param id -- the identifier of the report mailing job to be found
    +     * @return ReportMailingJob object
    +     **/
    +    public ReportMailingJob findOneThrowExceptionIfNotFound(final Long id) {
    +        final ReportMailingJob reportMailingJob = this.reportMailingJobRepository.findOne(id);
    +        
    +        if (reportMailingJob == null || reportMailingJob.isDeleted()) {
    +            throw new ReportMailingJobNotFoundException(id);
    +        }
    +        
    +        return reportMailingJob;
    +    }
    +    
    +    /** 
    +     * @return ReportMailingJobRepository Jpa Repository object
    +     **/
    +    public ReportMailingJobRepository getReportMailingJobRepository() {
    --- End diff --
    
    Is this method required?


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by emmanuelnnaa <gi...@git.apache.org>.
Github user emmanuelnnaa commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73839176
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java ---
    @@ -2736,4 +2736,27 @@ public CommandWrapperBuilder deleteSelfServiceBeneficiaryTPT(final Long benefici
             return this;
     	}
     
    -}
    \ No newline at end of file
    +	public CommandWrapperBuilder createReportMailingJob(final String entityName) {
    +        this.actionName = "CREATE";
    +        this.entityName = entityName;
    +        this.entityId = null;
    +        this.href = "/reportmailingjobs";
    +        return this;
    +    }
    +    
    +    public CommandWrapperBuilder updateReportMailingJob(final String entityName, final Long entityId) {
    --- End diff --
    
    @nazeer1100126 
    
    permission name = "REPORTMAILINGJOB" which is the same as the entity name.


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73314684
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java ---
    @@ -0,0 +1,495 @@
    +/**
    + * 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.reportmailingjob.service;
    +
    +import java.io.ByteArrayOutputStream;
    +import java.io.File;
    +import java.io.FileOutputStream;
    +import java.io.IOException;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +
    +import javax.ws.rs.core.MultivaluedMap;
    +import javax.ws.rs.core.Response;
    +
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.fineract.infrastructure.core.api.JsonCommand;
    +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
    +import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
    +import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
    +import org.apache.fineract.infrastructure.core.service.DateUtils;
    +import org.apache.fineract.infrastructure.dataqueries.domain.Report;
    +import org.apache.fineract.infrastructure.dataqueries.domain.ReportRepositoryWrapper;
    +import org.apache.fineract.infrastructure.dataqueries.service.ReadReportingService;
    +import org.apache.fineract.infrastructure.documentmanagement.contentrepository.FileSystemContentRepository;
    +import org.apache.fineract.infrastructure.jobs.annotation.CronTarget;
    +import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
    +import org.apache.fineract.infrastructure.jobs.service.JobName;
    +import org.apache.fineract.infrastructure.report.provider.ReportingProcessServiceProvider;
    +import org.apache.fineract.infrastructure.report.service.ReportingProcessService;
    +import org.apache.fineract.infrastructure.reportmailingjob.ReportMailingJobConstants;
    +import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobEmailAttachmentFileFormat;
    +import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobEmailData;
    +import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobPreviousRunStatus;
    +import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobStretchyReportParamDateOption;
    +import org.apache.fineract.infrastructure.reportmailingjob.domain.ReportMailingJob;
    +import org.apache.fineract.infrastructure.reportmailingjob.domain.ReportMailingJobRepository;
    +import org.apache.fineract.infrastructure.reportmailingjob.domain.ReportMailingJobRepositoryWrapper;
    +import org.apache.fineract.infrastructure.reportmailingjob.domain.ReportMailingJobRunHistory;
    +import org.apache.fineract.infrastructure.reportmailingjob.domain.ReportMailingJobRunHistoryRepository;
    +import org.apache.fineract.infrastructure.reportmailingjob.util.ReportMailingJobDateUtil;
    +import org.apache.fineract.infrastructure.reportmailingjob.validation.ReportMailingJobValidator;
    +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
    +import org.apache.fineract.portfolio.calendar.service.CalendarUtils;
    +import org.apache.fineract.useradministration.domain.AppUser;
    +import org.joda.time.DateTime;
    +import org.joda.time.LocalDate;
    +import org.joda.time.format.DateTimeFormat;
    +import org.joda.time.format.DateTimeFormatter;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.dao.DataIntegrityViolationException;
    +import org.springframework.stereotype.Service;
    +import org.springframework.transaction.annotation.Transactional;
    +
    +import com.sun.jersey.core.util.MultivaluedMapImpl;
    +
    +@Service
    +public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJobWritePlatformService {
    +    
    +    private final static Logger logger = LoggerFactory.getLogger(ReportMailingJobWritePlatformServiceImpl.class);
    +    private final ReportRepositoryWrapper reportRepositoryWrapper;
    +    private final ReportMailingJobValidator reportMailingJobValidator;
    +    private final ReportMailingJobRepositoryWrapper reportMailingJobRepositoryWrapper;
    +    private final ReportMailingJobRepository reportMailingJobRepository;
    +    private final PlatformSecurityContext platformSecurityContext;
    +    private final ReportMailingJobEmailService reportMailingJobEmailService;
    +    private final ReadReportingService readReportingService;
    +    private final ReportingProcessServiceProvider reportingProcessServiceProvider;
    +    private final ReportMailingJobRunHistoryRepository reportMailingJobRunHistoryRepository;
    +    private final static String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    +    
    +    @Autowired
    +    public ReportMailingJobWritePlatformServiceImpl(final ReportRepositoryWrapper reportRepositoryWrapper, 
    +            final ReportMailingJobValidator reportMailingJobValidator, 
    +            final ReportMailingJobRepositoryWrapper reportMailingJobRepositoryWrapper, 
    +            final ReportMailingJobRepository reportMailingJobRepository, 
    +            final PlatformSecurityContext platformSecurityContext, 
    +            final ReportMailingJobEmailService reportMailingJobEmailService,  
    +            final ReadReportingService readReportingService, 
    +            final ReportMailingJobRunHistoryRepository reportMailingJobRunHistoryRepository, 
    +            final ReportingProcessServiceProvider reportingProcessServiceProvider) {
    +        this.reportRepositoryWrapper = reportRepositoryWrapper;
    +        this.reportMailingJobValidator = reportMailingJobValidator;
    +        this.reportMailingJobRepositoryWrapper = reportMailingJobRepositoryWrapper;
    +        this.reportMailingJobRepository = reportMailingJobRepositoryWrapper.getReportMailingJobRepository();
    +        this.platformSecurityContext = platformSecurityContext;
    +        this.reportMailingJobEmailService = reportMailingJobEmailService;
    +        this.readReportingService = readReportingService;
    +        this.reportMailingJobRunHistoryRepository = reportMailingJobRunHistoryRepository;
    +        this.reportingProcessServiceProvider = reportingProcessServiceProvider;
    +    }
    +
    +    @Override
    +    @Transactional
    +    public CommandProcessingResult createReportMailingJob(JsonCommand jsonCommand) {
    +        try {
    +            // validate the create request
    +            this.reportMailingJobValidator.validateCreateRequest(jsonCommand);
    +            
    +            final AppUser appUser = this.platformSecurityContext.authenticatedUser();
    +            
    +            // get the stretchy Report object
    +            final Report stretchyReport = this.reportRepositoryWrapper.findOneThrowExceptionIfNotFound(jsonCommand.longValueOfParameterNamed(
    +                    ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME));
    +            
    +            // create an instance of ReportMailingJob class from the JsonCommand object
    +            final ReportMailingJob reportMailingJob = ReportMailingJob.newInstance(jsonCommand, stretchyReport, new LocalDate(), appUser, appUser);
    +            
    +            // save entity
    +            this.reportMailingJobRepository.save(reportMailingJob);
    +            
    +            return new CommandProcessingResultBuilder().withCommandId(jsonCommand.commandId()).
    +                    withEntityId(reportMailingJob.getId()).build();
    +        } catch (final DataIntegrityViolationException dve) {
    +            handleDataIntegrityIssues(jsonCommand, dve);
    +            
    +            return CommandProcessingResult.empty();
    +        }
    +    }
    +
    +    @Override
    +    @Transactional
    +    public CommandProcessingResult updateReportMailingJob(Long reportMailingJobId, JsonCommand jsonCommand) {
    +        try {
    +            // validate the update request
    +            this.reportMailingJobValidator.validateUpdateRequest(jsonCommand);
    +            
    +            // retrieve the ReportMailingJob object from the database
    +            final ReportMailingJob reportMailingJob = this.reportMailingJobRepositoryWrapper.findOneThrowExceptionIfNotFound(reportMailingJobId);
    +            
    +            final Map<String, Object> changes = reportMailingJob.update(jsonCommand);
    +            
    +            // get the recurrence rule string
    +            final String recurrence = reportMailingJob.getRecurrence();
    +            
    +            // get the next run DateTime from the ReportMailingJob entity
    +            DateTime nextRunDateTime = reportMailingJob.getNextRunDateTime();
    +            
    +            // check if the stretchy report id was updated
    +            if (changes.containsKey(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME)) {
    +                final Long stretchyReportId = (Long) changes.get(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME);
    +                final Report stretchyReport = this.reportRepositoryWrapper.findOneThrowExceptionIfNotFound(stretchyReportId);
    +                
    +                // update the stretchy report
    +                reportMailingJob.update(stretchyReport);
    +            }
    +            
    +            // check if the recurrence was updated
    +            if (changes.containsKey(ReportMailingJobConstants.RECURRENCE_PARAM_NAME)) {
    +                
    +                // go ahead if the recurrence is not null
    +                if (StringUtils.isNotBlank(recurrence)) {
    +                    // set the start DateTime to the current tenant date time
    +                    DateTime startDateTime = DateUtils.getLocalDateTimeOfTenant().toDateTime();
    +                    
    +                    // check if the start DateTime was updated
    +                    if (changes.containsKey(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME)) {
    +                        // get the updated start DateTime
    +                        startDateTime = reportMailingJob.getStartDateTime();
    +                    }
    +                    
    +                    startDateTime = reportMailingJob.getStartDateTime();
    +                    
    +                    // get the next recurring DateTime
    +                    final DateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, startDateTime);
    +                    
    +                    // update the next run time property
    +                    reportMailingJob.updateNextRunDateTime(nextRecurringDateTime);
    +                    
    +                 // check if the next run DateTime is not empty and the recurrence is empty
    +                } else if (StringUtils.isBlank(recurrence) && (nextRunDateTime != null)) {
    +                    // the next run DateTime should be set to null
    +                    reportMailingJob.updateNextRunDateTime(null);
    +                }
    +            }
    +            
    +            if (changes.containsKey(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME)) {
    +                final DateTime startDateTime = reportMailingJob.getStartDateTime();
    +                
    +                // initially set the next recurring date time to the new start date time
    +                DateTime nextRecurringDateTime = startDateTime;
    +                
    +                // ensure that the recurrence pattern string is not empty
    +                if (StringUtils.isNotBlank(recurrence)) {
    +                    // get the next recurring DateTime
    +                    nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, startDateTime);
    +                }
    +                
    +                // update the next run time property
    +                reportMailingJob.updateNextRunDateTime(nextRecurringDateTime);
    +            }
    +            
    +            if (!changes.isEmpty()) {
    +                // save and flush immediately so any data integrity exception can be handled in the "catch" block
    +                this.reportMailingJobRepository.saveAndFlush(reportMailingJob);
    +            }
    +            
    +            return new CommandProcessingResultBuilder().
    +                    withCommandId(jsonCommand.commandId()).
    +                    withEntityId(reportMailingJob.getId()).
    +                    with(changes).
    +                    build();
    +        } catch (final DataIntegrityViolationException dve) {
    +            handleDataIntegrityIssues(jsonCommand, dve);
    +            
    +            return CommandProcessingResult.empty();
    +        }
    +    }
    +
    +    @Override
    +    @Transactional
    +    public CommandProcessingResult deleteReportMailingJob(Long reportMailingJobId) {
    +        // retrieve the ReportMailingJob object from the database
    +        final ReportMailingJob reportMailingJob = this.reportMailingJobRepositoryWrapper.findOneThrowExceptionIfNotFound(reportMailingJobId);
    +        
    +        // delete the report mailing job by setting the isDeleted property to 1 and altering the name
    +        reportMailingJob.delete();
    +        
    +        // save the report mailing job entity
    +        this.reportMailingJobRepository.save(reportMailingJob);
    +        
    +        return new CommandProcessingResultBuilder().withEntityId(reportMailingJobId).build();
    +    }
    +    
    +    @Override
    +    @CronTarget(jobName = JobName.EXECUTE_REPORT_MAILING_JOBS)
    +    public void executeReportMailingJobs() throws JobExecutionException {
    +        final Collection<ReportMailingJob> reportMailingJobCollection = this.reportMailingJobRepository.findByIsActiveTrueAndIsDeletedFalse();
    +        
    +        for (ReportMailingJob reportMailingJob : reportMailingJobCollection) {
    +            // get the tenant's date as a DateTime object
    +            final DateTime localDateTimeOftenant = DateUtils.getLocalDateTimeOfTenant().toDateTime();
    +            final DateTime nextRunDateTime = reportMailingJob.getNextRunDateTime();
    +            
    +            if (nextRunDateTime != null && nextRunDateTime.isBefore(localDateTimeOftenant)) {
    +                // get the emailAttachmentFileFormat enum object
    +                final ReportMailingJobEmailAttachmentFileFormat emailAttachmentFileFormat = ReportMailingJobEmailAttachmentFileFormat.
    +                        newInstance(reportMailingJob.getEmailAttachmentFileFormat());
    +                
    +                if (emailAttachmentFileFormat != null && emailAttachmentFileFormat.isValid()) {
    +                    final Report stretchyReport = reportMailingJob.getStretchyReport();
    +                    final String reportName = (stretchyReport != null) ? stretchyReport.getReportName() : null;
    +                    final StringBuilder errorLog = new StringBuilder();
    +                    final Map<String, String> validateStretchyReportParamMap = this.reportMailingJobValidator.
    +                            validateStretchyReportParamMap(reportMailingJob.getStretchyReportParamMap());
    +                    MultivaluedMap<String, String> reportParams = new MultivaluedMapImpl();
    +                    
    +                    if (validateStretchyReportParamMap != null) {
    +                        Iterator<Map.Entry<String, String>> validateStretchyReportParamMapEntries = validateStretchyReportParamMap.entrySet().iterator();
    +                        
    +                        while (validateStretchyReportParamMapEntries.hasNext()) {
    +                            Map.Entry<String, String> validateStretchyReportParamMapEntry = validateStretchyReportParamMapEntries.next();
    +                            String key = validateStretchyReportParamMapEntry.getKey();
    +                            String value = validateStretchyReportParamMapEntry.getValue();
    +                            
    +                            if (StringUtils.containsIgnoreCase(key, "date")) {
    +                                ReportMailingJobStretchyReportParamDateOption reportMailingJobStretchyReportParamDateOption = 
    +                                        ReportMailingJobStretchyReportParamDateOption.newInstance(value);
    +                                
    +                                if (reportMailingJobStretchyReportParamDateOption.isValid()) {
    +                                    value = ReportMailingJobDateUtil.getDateAsString(reportMailingJobStretchyReportParamDateOption);
    +                                }
    +                            }
    +                            
    +                            reportParams.add(key, value);
    +                        }
    +                    }
    +                    
    +                    // generate the report output stream, method in turn call another that sends the file to the email recipients
    +                    this.generateReportOutputStream(reportMailingJob, emailAttachmentFileFormat, reportParams, reportName, errorLog);
    +                    
    +                    // update the previous run time, next run time, status, error log properties
    +                    this.updateReportMailingJobAfterJobExecution(reportMailingJob, errorLog, localDateTimeOftenant);
    +                }
    +            }
    +        }
    +    }
    +    
    +    /** 
    +     * update the report mailing job entity after job execution 
    +     * 
    +     * @param reportMailingJob -- the report mailing job entity
    +     * @param errorLog -- StringBuilder object containing the error log if any
    +     * @param jobStartDateTime -- the start DateTime of the job
    +     * @return None
    +     **/
    +    private void updateReportMailingJobAfterJobExecution(final ReportMailingJob reportMailingJob, final StringBuilder errorLog, 
    +            final DateTime jobStartDateTime) {
    +        final String recurrence = reportMailingJob.getRecurrence();
    +        final DateTime nextRunDateTime = reportMailingJob.getNextRunDateTime();
    +        ReportMailingJobPreviousRunStatus reportMailingJobPreviousRunStatus = ReportMailingJobPreviousRunStatus.SUCCESS;
    +        
    +        reportMailingJob.updatePreviousRunErrorLog(null);
    +        
    +        if (errorLog != null && errorLog.length() > 0) {
    +            reportMailingJobPreviousRunStatus = ReportMailingJobPreviousRunStatus.ERROR;
    +            reportMailingJob.updatePreviousRunErrorLog(errorLog.toString());
    +        }
    +        
    +        reportMailingJob.increaseNumberOfRunsByOne();
    +        reportMailingJob.updatePreviousRunStatus(reportMailingJobPreviousRunStatus.getValue());
    +        reportMailingJob.updatePreviousRunDateTime(reportMailingJob.getNextRunDateTime());
    +        
    +        // check if the job has a recurrence pattern, if not deactivate the job. The job will only run once
    +        if (StringUtils.isEmpty(recurrence)) {
    +            // deactivate job
    +            reportMailingJob.deactivate();
    +            
    +            // job will only run once, no next run time
    +            reportMailingJob.updateNextRunDateTime(null);
    +        } else if (nextRunDateTime != null) {
    +            final DateTime nextRecurringDateTime = this.createNextRecurringDateTime(recurrence, nextRunDateTime);
    +            
    +            // finally update the next run date time property
    +            reportMailingJob.updateNextRunDateTime(nextRecurringDateTime);
    +        }
    +        
    +        // save the ReportMailingJob entity
    +        this.reportMailingJobRepository.save(reportMailingJob);
    +        
    +        // create a new report mailing job run history entity
    +        this.createReportMailingJobRunHistroryAfterJobExecution(reportMailingJob, errorLog, jobStartDateTime, 
    +                reportMailingJobPreviousRunStatus.getValue());
    +    }
    +    
    +    /**
    +     * create the next recurring DateTime from recurrence pattern, start DateTime and current DateTime
    +     * 
    +     * @param recurrencePattern
    +     * @param startDateTime
    +     * @return DateTime object
    +     */
    +    private DateTime createNextRecurringDateTime(final String recurrencePattern, final DateTime startDateTime) {
    +        DateTime nextRecurringDateTime = null;
    +        
    +        // the recurrence pattern/rule cannot be empty
    +        if (StringUtils.isNotBlank(recurrencePattern) && startDateTime != null) {
    +            final LocalDate nextDayLocalDate = startDateTime.plus(1).toLocalDate();
    +            final LocalDate nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, startDateTime.toLocalDate(), 
    +                    nextDayLocalDate);
    +            final String nextDateTimeString = nextRecurringLocalDate + " " + startDateTime.getHourOfDay() + ":" + startDateTime.getMinuteOfHour() 
    +                    + ":" + startDateTime.getSecondOfMinute();
    +            final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(DATETIME_FORMAT);
    +            
    +            nextRecurringDateTime = DateTime.parse(nextDateTimeString, dateTimeFormatter);
    +        }
    +        
    +        return nextRecurringDateTime;
    +    }
    +    
    +    /** 
    +     * create a new report mailing job run history entity after job execution
    +     * 
    +     * @param reportMailingJob -- the report mailing job entity
    +     * @param errorLog -- StringBuilder object containing the error log if any
    +     * @param jobStartDateTime -- the start DateTime of the job
    +     * @param jobRunStatus -- the status of the job (success/error)
    +     * @return None
    +     **/
    +    private void createReportMailingJobRunHistroryAfterJobExecution(final ReportMailingJob reportMailingJob, final StringBuilder errorLog, 
    +            final DateTime jobStartDateTime, final String jobRunStatus) {
    +        final DateTime jobEndDateTime = DateUtils.getLocalDateTimeOfTenant().toDateTime();
    +        final String errorLogToString = (errorLog != null) ? errorLog.toString() : null;
    +        final ReportMailingJobRunHistory reportMailingJobRunHistory = ReportMailingJobRunHistory.newInstance(reportMailingJob, jobStartDateTime, 
    +                jobEndDateTime, jobRunStatus, null, errorLogToString);
    +        
    +        this.reportMailingJobRunHistoryRepository.save(reportMailingJobRunHistory);
    +    }
    +
    +    /** 
    +     * Handle any SQL data integrity issue 
    +     *
    +     * @param jsonCommand -- JsonCommand object
    +     * @param dve -- data integrity exception object
    +     * @return None
    +     **/
    +    private void handleDataIntegrityIssues(final JsonCommand jsonCommand, final DataIntegrityViolationException dve) {
    +        final Throwable realCause = dve.getMostSpecificCause();
    +        
    +        if (realCause.getMessage().contains(ReportMailingJobConstants.NAME_PARAM_NAME)) {
    +            final String name = jsonCommand.stringValueOfParameterNamed(ReportMailingJobConstants.NAME_PARAM_NAME);
    +            throw new PlatformDataIntegrityException("error.msg.report.mailing.job.duplicate.name", "Report mailing job with name `" + name + "` already exists",
    +                    ReportMailingJobConstants.NAME_PARAM_NAME, name);
    +        }
    +
    +        logger.error(dve.getMessage(), dve);
    +        
    +        throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue",
    +                "Unknown data integrity issue with resource: " + realCause.getMessage());
    +    }
    +    
    +    /** 
    +     * generate the report output stream
    +     * 
    +     * @param reportMailingJob
    +     * @param emailAttachmentFileFormat
    +     * @param reportParams
    +     * @param reportName
    +     * @param errorLog
    +     * @return the error log StringBuilder object
    +     */
    +    private StringBuilder generateReportOutputStream(final ReportMailingJob reportMailingJob, final ReportMailingJobEmailAttachmentFileFormat emailAttachmentFileFormat, 
    +            final MultivaluedMap<String, String> reportParams, final String reportName, final StringBuilder errorLog) {
    +        
    +        try {
    +            final String reportType = this.readReportingService.getReportType(reportName);
    +            final ReportingProcessService reportingProcessService = this.reportingProcessServiceProvider.findReportingProcessService(reportType);
    +            
    +            if (reportingProcessService != null) {
    +                final Response processReport = reportingProcessService.processRequest(reportName, reportParams);
    +                final Object reponseObject = (processReport != null) ? processReport.getEntity() : null;
    +                
    +                if (reponseObject != null && reponseObject.getClass().equals(ByteArrayOutputStream.class)) {
    +                    final ByteArrayOutputStream byteArrayOutputStream = ByteArrayOutputStream.class.cast(reponseObject);
    +                    final String fileLocation = FileSystemContentRepository.FINERACT_BASE_DIR + File.separator + "";
    +                    final String fileNameWithoutExtension = fileLocation + File.separator + reportName;
    +                    
    +                    // check if file directory exists, if not create directory
    +                    if (!new File(fileLocation).isDirectory()) {
    +                        new File(fileLocation).mkdirs();
    +                    }
    +                    
    +                    if ((byteArrayOutputStream == null) || byteArrayOutputStream.size() == 0) {
    +                        errorLog.append("Report processing failed, empty output stream created");
    +                    } else if ((errorLog != null && errorLog.length() == 0) && (byteArrayOutputStream.size() > 0)) {
    +                        final String fileName = fileNameWithoutExtension + "." + emailAttachmentFileFormat.getValue();
    +                        
    +                        // send the file to email recipients
    +                        this.sendReportFileToEmailRecipients(reportMailingJob, fileName, byteArrayOutputStream, errorLog);
    +                    }
    +                } else {
    +                    errorLog.append("Response object entity is not equal to ByteArrayOutputStream ---------- ");
    +                }
    +            } else {
    +                errorLog.append("ReportingProcessService object is null ---------- ");
    +            }
    +        } catch (Exception e) {
    +            errorLog.append("The ReportMailingJobWritePlatformServiceImpl.generateReportOutputStream method threw an Exception: "
    +                    + e + " ---------- ");
    +        }
    +        
    +        return errorLog;
    +    }
    +    
    +    /** 
    +     * send report file to email recipients
    +     * 
    +     * @param reportMailingJob
    +     * @param fileName
    +     * @param byteArrayOutputStream
    +     * @param errorLog
    +     */
    +    private void sendReportFileToEmailRecipients(final ReportMailingJob reportMailingJob, final String fileName, 
    +            final ByteArrayOutputStream byteArrayOutputStream, final StringBuilder errorLog) {
    +        final Set<String> emailRecipients = this.reportMailingJobValidator.validateEmailRecipients(reportMailingJob.getEmailRecipients());
    +        
    +        try {
    +            final File file = new File(fileName);
    --- End diff --
    
    Don't you need to close this file instance once mail is sent?


---
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.
---

[GitHub] incubator-fineract issue #191: commit for FINERACT-65 (Implement ability to ...

Posted by emmanuelnnaa <gi...@git.apache.org>.
Github user emmanuelnnaa commented on the issue:

    https://github.com/apache/incubator-fineract/pull/191
  
    @nazeer1100126 
    Will create a new pull request.


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by emmanuelnnaa <gi...@git.apache.org>.
Github user emmanuelnnaa commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73839123
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java ---
    @@ -2736,4 +2736,27 @@ public CommandWrapperBuilder deleteSelfServiceBeneficiaryTPT(final Long benefici
             return this;
     	}
     
    -}
    \ No newline at end of file
    +	public CommandWrapperBuilder createReportMailingJob(final String entityName) {
    +        this.actionName = "CREATE";
    +        this.entityName = entityName;
    +        this.entityId = null;
    +        this.href = "/reportmailingjobs";
    +        return this;
    +    }
    +    
    +    public CommandWrapperBuilder updateReportMailingJob(final String entityName, final Long entityId) {
    +        this.actionName = "UPDATE";
    +        this.entityName = entityName;
    +        this.entityId = entityId;
    +        this.href = "/reportmailingjobs/" + entityId;
    +        return this;
    +    }
    +    
    +    public CommandWrapperBuilder deleteReportMailingJob(final String entityName, final Long entityId) {
    --- End diff --
    
    @nazeer1100126 
    
    permission name = "REPORTMAILINGJOB" which is the same as the entity name.


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by emmanuelnnaa <gi...@git.apache.org>.
Github user emmanuelnnaa commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73838915
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobRepositoryWrapper.java ---
    @@ -0,0 +1,56 @@
    +/**
    + * 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.reportmailingjob.domain;
    +
    +import org.apache.fineract.infrastructure.reportmailingjob.exception.ReportMailingJobNotFoundException;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.stereotype.Service;
    +
    +@Service
    +public class ReportMailingJobRepositoryWrapper {
    +    private final ReportMailingJobRepository reportMailingJobRepository;
    +    
    +    @Autowired
    +    public ReportMailingJobRepositoryWrapper(final ReportMailingJobRepository reportMailingJobRepository) {
    +        this.reportMailingJobRepository = reportMailingJobRepository;
    +    }
    +    
    +    /** 
    +     * find report mailing job by ID, throw a "entity not found" exception if the job does not exist
    +     * 
    +     * @param id -- the identifier of the report mailing job to be found
    +     * @return ReportMailingJob object
    +     **/
    +    public ReportMailingJob findOneThrowExceptionIfNotFound(final Long id) {
    +        final ReportMailingJob reportMailingJob = this.reportMailingJobRepository.findOne(id);
    +        
    +        if (reportMailingJob == null || reportMailingJob.isDeleted()) {
    +            throw new ReportMailingJobNotFoundException(id);
    +        }
    +        
    +        return reportMailingJob;
    +    }
    +    
    +    /** 
    +     * @return ReportMailingJobRepository Jpa Repository object
    +     **/
    +    public ReportMailingJobRepository getReportMailingJobRepository() {
    --- End diff --
    
    @nazeer1100126 
    
    Both methods are used in the "org.apache.fineract.infrastructure.reportmailingjob.service.ReportMailingJobWritePlatformServiceImpl" class.


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73292182
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/api/ReportMailingJobApiResource.java ---
    @@ -0,0 +1,157 @@
    +/**
    + * 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.reportmailingjob.api;
    +
    +import java.util.Collection;
    +
    +import javax.ws.rs.Consumes;
    +import javax.ws.rs.DELETE;
    +import javax.ws.rs.GET;
    +import javax.ws.rs.POST;
    +import javax.ws.rs.PUT;
    +import javax.ws.rs.Path;
    +import javax.ws.rs.PathParam;
    +import javax.ws.rs.Produces;
    +import javax.ws.rs.core.Context;
    +import javax.ws.rs.core.MediaType;
    +import javax.ws.rs.core.UriInfo;
    +
    +import org.apache.fineract.commands.domain.CommandWrapper;
    +import org.apache.fineract.commands.service.CommandWrapperBuilder;
    +import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
    +import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
    +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
    +import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
    +import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
    +import org.apache.fineract.infrastructure.reportmailingjob.ReportMailingJobConstants;
    +import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobData;
    +import org.apache.fineract.infrastructure.reportmailingjob.service.ReportMailingJobReadPlatformService;
    +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.context.annotation.Scope;
    +import org.springframework.stereotype.Component;
    +
    +@Path("/" + ReportMailingJobConstants.REPORT_MAILING_JOB_RESOURCE_NAME)
    +@Component
    +@Scope("singleton")
    +public class ReportMailingJobApiResource {
    +
    +    private final PlatformSecurityContext platformSecurityContext;
    +    private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
    +    private final ApiRequestParameterHelper apiRequestParameterHelper;
    +    private final DefaultToApiJsonSerializer<ReportMailingJobData> reportMailingToApiJsonSerializer;
    +    private final ReportMailingJobReadPlatformService reportMailingJobReadPlatformService;
    +    
    +    @Autowired
    +    public ReportMailingJobApiResource(final PlatformSecurityContext platformSecurityContext, 
    +            final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, 
    +            final ApiRequestParameterHelper apiRequestParameterHelper, 
    +            final DefaultToApiJsonSerializer<ReportMailingJobData> reportMailingToApiJsonSerializer, 
    +            final ReportMailingJobReadPlatformService reportMailingJobReadPlatformService) {
    +        this.platformSecurityContext = platformSecurityContext;
    +        this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
    +        this.apiRequestParameterHelper = apiRequestParameterHelper;
    +        this.reportMailingToApiJsonSerializer = reportMailingToApiJsonSerializer;
    +        this.reportMailingJobReadPlatformService = reportMailingJobReadPlatformService;
    +    }
    +    
    +    @POST
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String createReportMailingJob(final String apiRequestBodyAsJson) {
    +        final CommandWrapper commandWrapper = new CommandWrapperBuilder().
    +                createReportMailingJob(ReportMailingJobConstants.REPORT_MAILING_JOB_PERMISSION_NAME).
    +                withJson(apiRequestBodyAsJson).build();
    +        
    +        final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
    +        
    +        return this.reportMailingToApiJsonSerializer.serialize(commandProcessingResult);
    +    }
    +    
    +    @PUT
    +    @Path("{entityId}")
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String updateReportMailingJob(@PathParam("entityId") final Long entityId, final String apiRequestBodyAsJson) {
    +        final CommandWrapper commandWrapper = new CommandWrapperBuilder().
    +                updateReportMailingJob(ReportMailingJobConstants.REPORT_MAILING_JOB_PERMISSION_NAME, entityId).
    +                withJson(apiRequestBodyAsJson).build();
    +        
    +        final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
    +        
    +        return this.reportMailingToApiJsonSerializer.serialize(commandProcessingResult);
    +    }
    +    
    +    @DELETE
    +    @Path("{entityId}")
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String deleteReportMailingJob(@PathParam("entityId") final Long entityId, final String apiRequestBodyAsJson) {
    +        final CommandWrapper commandWrapper = new CommandWrapperBuilder().
    +                deleteReportMailingJob(ReportMailingJobConstants.REPORT_MAILING_JOB_PERMISSION_NAME, entityId).
    +                withJson(apiRequestBodyAsJson).build();
    +        
    +        final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
    +        
    +        return this.reportMailingToApiJsonSerializer.serialize(commandProcessingResult);
    +    }
    +    
    +    @GET
    +    @Path("{entityId}")
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String retrieveReportMailingJob(@PathParam("entityId") final Long entityId, @Context final UriInfo uriInfo) {
    +        this.platformSecurityContext.authenticatedUser().validateHasReadPermission(ReportMailingJobConstants.REPORT_MAILING_JOB_PERMISSION_NAME);
    +        
    +        final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    +        ReportMailingJobData reportMailingJobData = this.reportMailingJobReadPlatformService.retrieveReportMailingJob(entityId);
    +        
    +        if (settings.isTemplate()) {
    +            final ReportMailingJobData ReportMailingJobDataOptions = this.reportMailingJobReadPlatformService.retrieveReportMailingJobEnumOptions();
    +            reportMailingJobData = ReportMailingJobData.newInstance(reportMailingJobData, ReportMailingJobDataOptions);
    +        }
    +        
    +        return this.reportMailingToApiJsonSerializer.serialize(settings, reportMailingJobData, ReportMailingJobConstants.REPORT_MAILING_JOB_DATA_PARAMETERS);
    +    }
    +    
    +    @GET
    +    @Path("template")
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String retrieveReportMailingJobTemplate(@Context final UriInfo uriInfo) {
    +        this.platformSecurityContext.authenticatedUser().validateHasReadPermission(ReportMailingJobConstants.REPORT_MAILING_JOB_PERMISSION_NAME);
    +        
    +        final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    +        final ReportMailingJobData ReportMailingJobDataOptions = this.reportMailingJobReadPlatformService.retrieveReportMailingJobEnumOptions();
    +        
    +        return this.reportMailingToApiJsonSerializer.serialize(settings, ReportMailingJobDataOptions, ReportMailingJobConstants.REPORT_MAILING_JOB_DATA_PARAMETERS);
    +    }
    +    
    +    @GET
    +    @Consumes({ MediaType.APPLICATION_JSON })
    +    @Produces({ MediaType.APPLICATION_JSON })
    +    public String retrieveAllReportMailingJobs(@Context final UriInfo uriInfo) {
    --- End diff --
    
    Suggestion: Better to give pagination support to retrieve all report mailing jobs. 


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73291714
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java ---
    @@ -2736,4 +2736,27 @@ public CommandWrapperBuilder deleteSelfServiceBeneficiaryTPT(final Long benefici
             return this;
     	}
     
    -}
    \ No newline at end of file
    +	public CommandWrapperBuilder createReportMailingJob(final String entityName) {
    +        this.actionName = "CREATE";
    +        this.entityName = entityName;
    +        this.entityId = null;
    +        this.href = "/reportmailingjobs";
    +        return this;
    +    }
    +    
    +    public CommandWrapperBuilder updateReportMailingJob(final String entityName, final Long entityId) {
    +        this.actionName = "UPDATE";
    +        this.entityName = entityName;
    +        this.entityId = entityId;
    +        this.href = "/reportmailingjobs/" + entityId;
    +        return this;
    +    }
    +    
    +    public CommandWrapperBuilder deleteReportMailingJob(final String entityName, final Long entityId) {
    --- End diff --
    
    Caller is passing permission name and entity id. But you are assigning permission name to entity name.


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73289816
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadReportingService.java ---
    @@ -44,4 +47,7 @@
         ReportData retrieveReport(final Long id);
     
         Collection<String> getAllowedReportTypes();
    +    
    +    ByteArrayOutputStream generatePentahoReportAsOutputStream(String reportName, String outputTypeParam,
    --- End diff --
    
    I don't see any reference to this method. Is it required as implementation returns just null


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73291621
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java ---
    @@ -2736,4 +2736,27 @@ public CommandWrapperBuilder deleteSelfServiceBeneficiaryTPT(final Long benefici
             return this;
     	}
     
    -}
    \ No newline at end of file
    +	public CommandWrapperBuilder createReportMailingJob(final String entityName) {
    +        this.actionName = "CREATE";
    +        this.entityName = entityName;
    +        this.entityId = null;
    +        this.href = "/reportmailingjobs";
    +        return this;
    +    }
    +    
    +    public CommandWrapperBuilder updateReportMailingJob(final String entityName, final Long entityId) {
    --- End diff --
    
    Caller is passing permission name and entity id. But you are assigning permission name to entity name


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by emmanuelnnaa <gi...@git.apache.org>.
Github user emmanuelnnaa closed the pull request at:

    https://github.com/apache/incubator-fineract/pull/191


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73293456
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJobConfigurationRepositoryWrapper.java ---
    @@ -0,0 +1,56 @@
    +/**
    + * 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.reportmailingjob.domain;
    +
    +import org.apache.fineract.infrastructure.reportmailingjob.exception.ReportMailingJobConfigurationNotFoundException;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.stereotype.Service;
    +
    +@Service
    +public class ReportMailingJobConfigurationRepositoryWrapper {
    +    private final ReportMailingJobConfigurationRepository reportMailingJobConfigurationRepository;
    +    
    +    @Autowired
    +    public ReportMailingJobConfigurationRepositoryWrapper(ReportMailingJobConfigurationRepository reportMailingJobConfigurationRepository) {
    +        this.reportMailingJobConfigurationRepository = reportMailingJobConfigurationRepository;
    +    }
    +    
    +    /** 
    +     * find ReportMailingJobConfiguration by name, throw exception if not found
    +     * 
    +     * @param name -- the name of the configuration
    +     * @return ReportMailingJobConfiguration object
    +     **/
    +    public ReportMailingJobConfiguration findOneThrowExceptionIfNotFound(final String name) {
    +        final ReportMailingJobConfiguration reportMailingJobConfiguration = this.reportMailingJobConfigurationRepository.findByName(name);
    +        
    +        if (reportMailingJobConfiguration == null) {
    +            throw new ReportMailingJobConfigurationNotFoundException(name);
    +        }
    +        
    +        return reportMailingJobConfiguration;
    +    }
    +    
    +    /** 
    +     * @return ReportMailingJobConfigurationRepository JPA repository object
    +     **/
    +    public ReportMailingJobConfigurationRepository getReportMailingJobConfigurationRepository() {
    --- End diff --
    
    Is this method required? 


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73293255
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/domain/ReportMailingJob.java ---
    @@ -0,0 +1,588 @@
    +/**
    + * 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.reportmailingjob.domain;
    +
    +import java.util.Date;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +
    +import javax.persistence.Column;
    +import javax.persistence.Entity;
    +import javax.persistence.JoinColumn;
    +import javax.persistence.ManyToOne;
    +import javax.persistence.Table;
    +import javax.persistence.Temporal;
    +import javax.persistence.TemporalType;
    +import javax.persistence.UniqueConstraint;
    +
    +import org.apache.commons.lang.StringUtils;
    +import org.apache.fineract.infrastructure.core.api.JsonCommand;
    +import org.apache.fineract.infrastructure.dataqueries.domain.Report;
    +import org.apache.fineract.infrastructure.reportmailingjob.ReportMailingJobConstants;
    +import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobEmailAttachmentFileFormat;
    +import org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobPreviousRunStatus;
    +import org.apache.fineract.useradministration.domain.AppUser;
    +import org.joda.time.DateTime;
    +import org.joda.time.LocalDate;
    +import org.joda.time.LocalDateTime;
    +import org.joda.time.format.DateTimeFormat;
    +import org.joda.time.format.DateTimeFormatter;
    +import org.springframework.data.jpa.domain.AbstractPersistable;
    +
    +@Entity
    +@Table(name = "m_report_mailing_job", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "unique_name") })
    +public class ReportMailingJob extends AbstractPersistable<Long> {
    --- End diff --
    
    Updated user and date are missing. Extend this entity from AbstractAuditableCustom


---
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.
---

[GitHub] incubator-fineract pull request #191: commit for FINERACT-65 (Implement abil...

Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:

    https://github.com/apache/incubator-fineract/pull/191#discussion_r73289454
  
    --- Diff: fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportRepositoryWrapper.java ---
    @@ -0,0 +1,61 @@
    +/**
    + * 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.dataqueries.domain;
    +
    +import org.apache.fineract.infrastructure.dataqueries.exception.ReportNotFoundException;
    +import org.springframework.beans.factory.annotation.Autowired;
    +import org.springframework.stereotype.Service;
    +
    +/** 
    + *  A wrapper class for the ReportRepository that provides a method that returns a Report entity if it exists, 
    + *  else throws "ReportNotFoundException" exception if the Report does not exist
    + **/
    +@Service
    +public class ReportRepositoryWrapper {
    +    private final ReportRepository reportRepository;
    +    
    +    @Autowired
    +    public ReportRepositoryWrapper(final ReportRepository reportRepository) {
    +        this.reportRepository = reportRepository;
    +    }
    +    
    +    /**
    +     * Retrieves an entity by its id
    +     * 
    +     * @param id must not be null
    +     * @throws ReportNotFoundException if entity not found
    +     * @return {@link Report} object
    +     */
    +    public Report findOneThrowExceptionIfNotFound(final Long id) {
    +        final Report report = this.reportRepository.findOne(id);
    +        
    +        if (report == null) {
    +            throw new ReportNotFoundException(id);
    +        }
    +        
    +        return report;
    +    }
    +    
    +    /**
    +     * @return {@link ReportRepository} object
    +     */
    +    public ReportRepository getReportRepository() {
    --- End diff --
    
    I don't see any references to this method. Is this method required?


---
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.
---