forked from apache/fineract
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'FINERACT-65' into develop
- Loading branch information
Showing
43 changed files
with
4,765 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...n/java/org/apache/fineract/infrastructure/dataqueries/domain/ReportRepositoryWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...n/java/org/apache/fineract/infrastructure/reportmailingjob/ReportMailingJobConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
162 changes: 162 additions & 0 deletions
162
.../org/apache/fineract/infrastructure/reportmailingjob/api/ReportMailingJobApiResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.