Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
name: jacoco-it-exec
path: target/jacoco-it.exec
retention-days: 1
if-no-files-found: ignore
Comment thread
IOhacker marked this conversation as resolved.

# ── Job 3: Coverage Gate — merges both .exec files before enforcing ───────
coverage-gate:
Expand Down Expand Up @@ -107,6 +108,7 @@ jobs:

- name: Download Integration Test Coverage Data
uses: actions/download-artifact@v8
continue-on-error: true
with:
name: jacoco-it-exec
path: target/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/**
* 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
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>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.savings.office.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.savings.office.data.OfficeGeolocationData;
import org.apache.fineract.savings.office.data.OfficeServiceData;
import org.apache.fineract.savings.office.service.OfficeExtensionReadPlatformService;
import org.apache.fineract.savings.office.service.OfficeExtensionWritePlatformService;
import org.springframework.stereotype.Component;

/**
* JAX-RS resource exposing admin CRUD endpoints for office services and geolocation under {@code
* /v2/offices/{officeId}/services} and {@code /v2/offices/{officeId}/geolocation}.
*/
@Path("/v2/offices")
@Component
@Tag(
name = "Office Extensions",
description =
"Admin endpoints for managing office services and geolocation data. These endpoints populate"
+ " the data consumed by the self-service office endpoints in the selfservice-plugin.")
@RequiredArgsConstructor
public class OfficeExtensionApiResource {

private static final String RESOURCE_NAME_FOR_PERMISSIONS = "OFFICE";

private final PlatformSecurityContext context;
private final OfficeExtensionReadPlatformService readService;
private final OfficeExtensionWritePlatformService writeService;
private final DefaultToApiJsonSerializer<OfficeServiceData> serviceSerializer;
private final DefaultToApiJsonSerializer<OfficeGeolocationData> geolocationSerializer;

/**
* Lists all services associated with the given office.
*
* @param officeId the office identifier
* @return JSON array of office service data
*/
@GET
@Path("{officeId}/services")
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "List Office Services",
description = "Returns all services configured for the specified office.")
@ApiResponse(
responseCode = "200",
description = "OK",
content =
@Content(
array = @ArraySchema(schema = @Schema(implementation = OfficeServiceData.class))))
public String retrieveOfficeServices(
@PathParam("officeId") @Parameter(description = "officeId") final Long officeId) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final Collection<OfficeServiceData> data = readService.retrieveOfficeServices(officeId);
return serviceSerializer.serializeResult(data);
}

/**
* Creates a new service for the given office.
*
* @param officeId the office identifier
* @param jsonBody the JSON request body
* @return JSON with the created service id
*/
@POST
@Path("{officeId}/services")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "Create Office Service",
description = "Adds a new service to the specified office.")
@ApiResponse(responseCode = "200", description = "OK")
public String createOfficeService(
@PathParam("officeId") @Parameter(description = "officeId") final Long officeId,
@Parameter(hidden = true) final String jsonBody) {
this.context.authenticatedUser().validateHasCreatePermission(RESOURCE_NAME_FOR_PERMISSIONS);
final CommandProcessingResult result = writeService.createOfficeService(officeId, jsonBody);
return serviceSerializer.serializeResult(result);
}

/**
* Updates an existing office service.
*
* @param officeId the office identifier
* @param serviceId the service identifier
* @param jsonBody the JSON request body
* @return JSON with the changes applied
*/
@PUT
@Path("{officeId}/services/{serviceId}")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "Update Office Service",
description = "Updates a specific service for the office.")
@ApiResponse(responseCode = "200", description = "OK")
public String updateOfficeService(
@PathParam("officeId") @Parameter(description = "officeId") final Long officeId,
@PathParam("serviceId") @Parameter(description = "serviceId") final Long serviceId,
@Parameter(hidden = true) final String jsonBody) {
this.context.authenticatedUser().validateHasUpdatePermission(RESOURCE_NAME_FOR_PERMISSIONS);
final CommandProcessingResult result =
writeService.updateOfficeService(officeId, serviceId, jsonBody);
return serviceSerializer.serializeResult(result);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/**
* Deletes an office service.
*
* @param officeId the office identifier
* @param serviceId the service identifier
* @return JSON with the deleted service id
*/
@DELETE
@Path("{officeId}/services/{serviceId}")
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "Delete Office Service",
description = "Removes a specific service from the office.")
@ApiResponse(responseCode = "200", description = "OK")
public String deleteOfficeService(
@PathParam("officeId") @Parameter(description = "officeId") final Long officeId,
@PathParam("serviceId") @Parameter(description = "serviceId") final Long serviceId) {
this.context.authenticatedUser().validateHasDeletePermission(RESOURCE_NAME_FOR_PERMISSIONS);
final CommandProcessingResult result = writeService.deleteOfficeService(officeId, serviceId);
return serviceSerializer.serializeResult(result);
}

/**
* Retrieves the geolocation for the given office.
*
* @param officeId the office identifier
* @return JSON representation of geolocation data
*/
@GET
@Path("{officeId}/geolocation")
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "Retrieve Office Geolocation",
description = "Returns the latitude and longitude of the specified office.")
@ApiResponse(
responseCode = "200",
description = "OK",
content = @Content(schema = @Schema(implementation = OfficeGeolocationData.class)))
public String retrieveOfficeGeolocation(
@PathParam("officeId") @Parameter(description = "officeId") final Long officeId) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final OfficeGeolocationData data = readService.retrieveOfficeGeolocation(officeId);
return geolocationSerializer.serializeResult(data);
}

/**
* Creates or updates the geolocation for the given office.
*
* @param officeId the office identifier
* @param jsonBody the JSON request body containing latitude and longitude
* @return JSON with the geolocation record id
*/
@PUT
@Path("{officeId}/geolocation")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "Save Office Geolocation",
description = "Creates or updates the geolocation for the office (1:1 relationship).")
@ApiResponse(responseCode = "200", description = "OK")
public String saveOfficeGeolocation(
@PathParam("officeId") @Parameter(description = "officeId") final Long officeId,
@Parameter(hidden = true) final String jsonBody) {
this.context.authenticatedUser().validateHasUpdatePermission(RESOURCE_NAME_FOR_PERMISSIONS);
final CommandProcessingResult result = writeService.saveOfficeGeolocation(officeId, jsonBody);
return geolocationSerializer.serializeResult(result);
}

/**
* Deletes the geolocation for the given office.
*
* @param officeId the office identifier
* @return JSON with the deleted office id
*/
@DELETE
@Path("{officeId}/geolocation")
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "Delete Office Geolocation",
description = "Removes the geolocation data for the office.")
@ApiResponse(responseCode = "200", description = "OK")
public String deleteOfficeGeolocation(
@PathParam("officeId") @Parameter(description = "officeId") final Long officeId) {
this.context.authenticatedUser().validateHasDeletePermission(RESOURCE_NAME_FOR_PERMISSIONS);
final CommandProcessingResult result = writeService.deleteOfficeGeolocation(officeId);
return geolocationSerializer.serializeResult(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>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.savings.office.data;

import java.math.BigDecimal;

/** Immutable data transfer object representing an office's geographic coordinates. */
public final class OfficeGeolocationData {

private final Long id;
private final Long officeId;
private final BigDecimal latitude;
private final BigDecimal longitude;

private OfficeGeolocationData(
final Long id, final Long officeId, final BigDecimal latitude, final BigDecimal longitude) {
this.id = id;
this.officeId = officeId;
this.latitude = latitude;
this.longitude = longitude;
}

/**
* Creates a new instance.
*
* @param id the geolocation record identifier
* @param officeId the parent office identifier
* @param latitude the latitude in decimal degrees (-90 to 90)
* @param longitude the longitude in decimal degrees (-180 to 180)
* @return a new {@code OfficeGeolocationData}
*/
public static OfficeGeolocationData instance(
final Long id, final Long officeId, final BigDecimal latitude, final BigDecimal longitude) {
return new OfficeGeolocationData(id, officeId, latitude, longitude);
}

/**
* Returns the geolocation record identifier.
*
* @return the record id, never {@code null}
*/
public Long getId() {
return id;
}

/**
* Returns the associated office identifier.
*
* @return the office id, never {@code null}
*/
public Long getOfficeId() {
return officeId;
}

/**
* Returns the latitude in decimal degrees.
*
* @return the latitude value (-90 to 90), never {@code null}
*/
public BigDecimal getLatitude() {
return latitude;
}

/**
* Returns the longitude in decimal degrees.
*
* @return the longitude value (-180 to 180), never {@code null}
*/
public BigDecimal getLongitude() {
return longitude;
}
}
Loading
Loading