Skip to content

Commit

Permalink
Merge branch 'FINERACT-65' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nazeer1100126 committed Aug 12, 2016
2 parents f8f3f74 + b30976b commit 1d51258
Show file tree
Hide file tree
Showing 43 changed files with 4,765 additions and 5 deletions.
444 changes: 444 additions & 0 deletions api-docs/apiLive.htm

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2755,4 +2755,27 @@ public CommandWrapperBuilder deleteSelfServiceBeneficiaryTPT(final Long benefici
return this;
}

}
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) {
this.actionName = "DELETE";
this.entityName = entityName;
this.entityId = entityId;
this.href = "/reportmailingjobs/" + entityId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,33 @@ public boolean isSelfUser() {
return this.isSelfUser;
}

}
/**
* creates an instance of the SearchParameters from a request for the report mailing job run history
*
* @return SearchParameters object
**/
public static SearchParameters fromReportMailingJobRunHistory(final Integer offset,
final Integer limit, final String orderBy, final String sortOrder) {
final Integer maxLimitAllowed = getCheckedLimit(limit);

return new SearchParameters(null, null, null, null, null, null, null, offset, maxLimitAllowed, orderBy,
sortOrder, null, null, null, null, null, false);
}

/**
* creates an instance of the {@link SearchParameters} from a request for the report mailing job
*
* @param offset
* @param limit
* @param orderBy
* @param sortOrder
* @return {@link SearchParameters} object
*/
public static SearchParameters fromReportMailingJob(final Integer offset,
final Integer limit, final String orderBy, final String sortOrder) {
final Integer maxLimitAllowed = getCheckedLimit(limit);

return new SearchParameters(null, null, null, null, null, null, null, offset, maxLimitAllowed, orderBy,
sortOrder, null, null, null, null, null, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,4 @@ public ReportParameterData mapRow(final ResultSet rs, @SuppressWarnings("unused"
return new ReportParameterData(id, null, null, parameterName);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public enum JobName {
GENERATE_LOANLOSS_PROVISIONING("Generate Loan Loss Provisioning"), //
POST_DIVIDENTS_FOR_SHARES("Post Dividends For Shares"), //
UPDATE_SAVINGS_DORMANT_ACCOUNTS("Update Savings Dormant Accounts"), //
ADD_PERIODIC_ACCRUAL_ENTRIES_FOR_LOANS_WITH_INCOME_POSTED_AS_TRANSACTIONS("Add Accrual Transactions For Loans With Income Posted As Transactions");
ADD_PERIODIC_ACCRUAL_ENTRIES_FOR_LOANS_WITH_INCOME_POSTED_AS_TRANSACTIONS("Add Accrual Transactions For Loans With Income Posted As Transactions"),
EXECUTE_REPORT_MAILING_JOBS("Execute Report Mailing Jobs");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ReportMailingJobConstants {

// define the API resource entity name
public static final String REPORT_MAILING_JOB_ENTITY_NAME = "REPORTMAILINGJOB";

// define the API resource name for the report mailing job resource
public static final String REPORT_MAILING_JOB_RESOURCE_NAME = "reportmailingjobs";

// define the API resource name for the report mailing job history resource
public static final String REPORT_MAILING_JOB_RUN_HISTORY_RESOURCE_NAME = "reportmailingjobrunhistory";

// general API resource request parameter constants
public static final String LOCALE_PARAM_NAME = "locale";
public static final String DATE_FORMAT_PARAM_NAME = "dateFormat";

// parameter constants for create/update entity API request
public static final String NAME_PARAM_NAME = "name";
public static final String DESCRIPTION_PARAM_NAME = "description";
public static final String START_DATE_TIME_PARAM_NAME = "startDateTime";
public static final String RECURRENCE_PARAM_NAME = "recurrence";
public static final String EMAIL_RECIPIENTS_PARAM_NAME = "emailRecipients";
public static final String EMAIL_SUBJECT_PARAM_NAME = "emailSubject";
public static final String EMAIL_MESSAGE_PARAM_NAME = "emailMessage";
public static final String EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME = "emailAttachmentFileFormatId";
public static final String STRETCHY_REPORT_ID_PARAM_NAME = "stretchyReportId";
public static final String STRETCHY_REPORT_PARAM_MAP_PARAM_NAME = "stretchyReportParamMap";
public static final String IS_ACTIVE_PARAM_NAME = "isActive";

// other parameter constants
public static final String ID_PARAM_NAME = "id";
public static final String EMAIL_ATTACHMENT_FILE_FORMAT_PARAM_NAME = "emailAttachmentFileFormat";
public static final String PREVIOUS_RUN_DATE_TIME_PARAM_NAME = "previousRunDateTime";
public static final String NEXT_RUN_DATE_TIME_PARAM_NAME = "nextRunDateTime";
public static final String PREVIOUS_RUN_STATUS = "previousRunStatus";
public static final String PREVIOUS_RUN_ERROR_LOG = "previousRunErrorLog";
public static final String PREVIOUS_RUN_ERROR_MESSAGE = "previousRunErrorMessage";
public static final String NUMBER_OF_RUNS = "numberOfRuns";
public static final String STRETCHY_REPORT_PARAM_NAME = "stretchyReport";

// list of permitted parameters for the create report mailing job request
public static final Set<String> CREATE_REQUEST_PARAMETERS = new HashSet<>(Arrays.asList(LOCALE_PARAM_NAME, DATE_FORMAT_PARAM_NAME,
NAME_PARAM_NAME, DESCRIPTION_PARAM_NAME, RECURRENCE_PARAM_NAME, EMAIL_RECIPIENTS_PARAM_NAME, EMAIL_SUBJECT_PARAM_NAME,
EMAIL_MESSAGE_PARAM_NAME, EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, STRETCHY_REPORT_ID_PARAM_NAME,
STRETCHY_REPORT_PARAM_MAP_PARAM_NAME, IS_ACTIVE_PARAM_NAME, START_DATE_TIME_PARAM_NAME));

// list of permitted parameters for the update report mailing job request
public static final Set<String> UPDATE_REQUEST_PARAMETERS = new HashSet<>(Arrays.asList(LOCALE_PARAM_NAME, DATE_FORMAT_PARAM_NAME,
NAME_PARAM_NAME, DESCRIPTION_PARAM_NAME, RECURRENCE_PARAM_NAME, EMAIL_RECIPIENTS_PARAM_NAME, EMAIL_SUBJECT_PARAM_NAME,
EMAIL_MESSAGE_PARAM_NAME, EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, STRETCHY_REPORT_ID_PARAM_NAME,
STRETCHY_REPORT_PARAM_MAP_PARAM_NAME, IS_ACTIVE_PARAM_NAME, START_DATE_TIME_PARAM_NAME));

// list of parameters that represent the properties of a report mailing job
public static final Set<String> REPORT_MAILING_JOB_DATA_PARAMETERS = new HashSet<>(Arrays.asList(ID_PARAM_NAME, NAME_PARAM_NAME,
DESCRIPTION_PARAM_NAME, RECURRENCE_PARAM_NAME, EMAIL_RECIPIENTS_PARAM_NAME, EMAIL_SUBJECT_PARAM_NAME, EMAIL_MESSAGE_PARAM_NAME,
EMAIL_ATTACHMENT_FILE_FORMAT_PARAM_NAME, STRETCHY_REPORT_PARAM_NAME, STRETCHY_REPORT_PARAM_MAP_PARAM_NAME, IS_ACTIVE_PARAM_NAME,
START_DATE_TIME_PARAM_NAME, PREVIOUS_RUN_DATE_TIME_PARAM_NAME, NEXT_RUN_DATE_TIME_PARAM_NAME, PREVIOUS_RUN_STATUS,
PREVIOUS_RUN_ERROR_LOG, PREVIOUS_RUN_ERROR_MESSAGE, NUMBER_OF_RUNS));

// report mailing job configuration names
public static final String GMAIL_SMTP_SERVER = "GMAIL_SMTP_SERVER";
public static final String GMAIL_SMTP_PORT = "GMAIL_SMTP_PORT";
public static final String GMAIL_SMTP_USERNAME = "GMAIL_SMTP_USERNAME";
public static final String GMAIL_SMTP_PASSWORD = "GMAIL_SMTP_PASSWORD";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* 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 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.QueryParam;
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.core.service.Page;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
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_ENTITY_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_ENTITY_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_ENTITY_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_ENTITY_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_ENTITY_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,
@QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder) {
this.platformSecurityContext.authenticatedUser().validateHasReadPermission(ReportMailingJobConstants.REPORT_MAILING_JOB_ENTITY_NAME);

final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final SearchParameters searchParameters = SearchParameters.fromReportMailingJob(offset, limit, orderBy, sortOrder);
final Page<ReportMailingJobData> reportMailingJobData = this.reportMailingJobReadPlatformService.retrieveAllReportMailingJobs(searchParameters);

return this.reportMailingToApiJsonSerializer.serialize(settings, reportMailingJobData, ReportMailingJobConstants.REPORT_MAILING_JOB_DATA_PARAMETERS);
}
}
Loading

0 comments on commit 1d51258

Please sign in to comment.