This is an automated email from the ASF dual-hosted git repository.
arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new f829eaa9d FINERACT-1760: Get office by external id - [x] Add new
resource to update - [x] Integration test
f829eaa9d is described below
commit f829eaa9d62b4bf026589a9714fa1686017301e5
Author: Janos Haber <[email protected]>
AuthorDate: Wed Aug 30 11:17:42 2023 +0200
FINERACT-1760: Get office by external id
- [x] Add new resource to update
- [x] Integration test
---
.../organisation/office/api/OfficeSwaggerMapper.java | 3 +++
.../organisation/office/api/OfficesApiResource.java | 19 +++++++++++++++++++
.../office/api/OfficesApiResourceSwagger.java | 14 ++++++--------
.../integrationtests/OfficeIntegrationTest.java | 20 ++++++++++++++++++++
.../integrationtests/common/OfficeHelper.java | 4 ++++
5 files changed, 52 insertions(+), 8 deletions(-)
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficeSwaggerMapper.java
b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficeSwaggerMapper.java
index f1ca2d58e..93a80caeb 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficeSwaggerMapper.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficeSwaggerMapper.java
@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Optional;
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.organisation.office.data.OfficeData;
import org.mapstruct.Mapper;
@Mapper(config = MapstructMapperConfig.class)
@@ -35,4 +36,6 @@ public interface OfficeSwaggerMapper {
Optional.ofNullable(changes).map(c -> c.get("name")).ifPresent(c ->
response.name = String.valueOf(c));
return response;
}
+
+ OfficesApiResourceSwagger.GetOfficesResponse
toGetOfficesResponse(OfficeData officeData);
}
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java
b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java
index dd16a67b4..5dcdca405 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResource.java
@@ -164,6 +164,25 @@ public class OfficesApiResource {
return toApiJsonSerializer.serialize(settings, office,
RESPONSE_DATA_PARAMETERS);
}
+ @GET
+ @Path("/external-id/{externalId}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Operation(summary = "Retrieve an Office using external id", description =
"Example Requests:\n" + "\n" + "offices/external-id/asd123\n"
+ + "\n" + "\n" + "offices/external-id/asd123?template=true\n" +
"\n" + "\n"
+ + "offices/external-id/asd123?fields=id,name,parentName")
+ public OfficesApiResourceSwagger.GetOfficesResponse
retrieveOfficeByExternalId(
+ @PathParam("externalId") @Parameter(description = "externalId")
final String externalId, @Context final UriInfo uriInfo) {
+
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
+ final ApiRequestJsonSerializationSettings settings =
apiRequestParameterHelper.process(uriInfo.getQueryParameters());
+ OfficeData office =
readPlatformService.retrieveOfficeWithExternalId(ExternalIdFactory.produce(externalId));
+ if (settings.isTemplate()) {
+ final Collection<OfficeData> allowedParents =
readPlatformService.retrieveAllowedParents(office.getId());
+ office = OfficeData.appendedTemplate(office, allowedParents);
+ }
+ return officeSwaggerMapper.toGetOfficesResponse(office);
+ }
+
@PUT
@Path("{officeId}")
@Consumes({ MediaType.APPLICATION_JSON })
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResourceSwagger.java
b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResourceSwagger.java
index 8db531151..ce5c2f0d2 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResourceSwagger.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/api/OfficesApiResourceSwagger.java
@@ -34,10 +34,6 @@ final class OfficesApiResourceSwagger {
@Schema(description = "GetOfficesResponse")
public static final class GetOfficesResponse {
- private GetOfficesResponse() {
-
- }
-
@Schema(example = "1")
public Long id;
@Schema(example = "Head Office")
@@ -50,10 +46,12 @@ final class OfficesApiResourceSwagger {
public LocalDate openingDate;
@Schema(example = ".")
public String hierarchy;
- // @Schema(example = "")
- // public Long parentId;
- // @Schema(example = "")
- // public String parentName;
+ @Schema(example = "dd MMMM yyyy")
+ public String dateFormat;
+ @Schema(example = "en")
+ public String locale;
+
+ public Collection<GetOfficesResponse> allowedParents;
}
@Schema(description = "GetOfficesTemplateResponse")
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/OfficeIntegrationTest.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/OfficeIntegrationTest.java
index 59636a171..39588993e 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/OfficeIntegrationTest.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/OfficeIntegrationTest.java
@@ -24,7 +24,9 @@ import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.io.IOException;
+import java.time.LocalDate;
import java.util.UUID;
+import org.apache.fineract.client.models.GetOfficesResponse;
import org.apache.fineract.client.models.PutOfficesOfficeIdResponse;
import org.apache.fineract.integrationtests.common.OfficeDomain;
import org.apache.fineract.integrationtests.common.OfficeHelper;
@@ -79,4 +81,22 @@ public class OfficeIntegrationTest {
Assertions.assertTrue(name.equals(newOffice.getName()));
Assertions.assertArrayEquals(dateArr, newOffice.getOpeningDate());
}
+
+ @Test
+ public void testOfficeModificationAndFetchWithExternalId() throws
IOException {
+ OfficeHelper oh = new OfficeHelper(requestSpec, responseSpec);
+ String externalId = UUID.randomUUID().toString();
+ int officeId = oh.createOfficeWithExternalId(externalId, "01 July
2007");
+ String name = Utils.uniqueRandomStringGenerator("New_Office_", 4);
+ String date = "02 July 2007";
+ String[] dateArr = { "2007", "7", "2" };
+
+ oh.updateOfficeUsingExternalId(externalId, name, date);
+ Response<GetOfficesResponse> officeResult =
oh.retrieveOfficeByExternalId(externalId);
+
+ GetOfficesResponse newOffice = officeResult.body();
+
+ Assertions.assertTrue(name.equals(newOffice.getName()));
+
Assertions.assertTrue(newOffice.getOpeningDate().isEqual(LocalDate.of(2007, 7,
2)));
+ }
}
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/OfficeHelper.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/OfficeHelper.java
index 650a5cb51..2b611d664 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/OfficeHelper.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/OfficeHelper.java
@@ -92,6 +92,10 @@ public class OfficeHelper extends IntegrationTest {
new Gson().toJson(map), "resourceId");
}
+ public Response<GetOfficesResponse> retrieveOfficeByExternalId(String
externalId) throws IOException {
+ return
fineract().offices.retrieveOfficeByExternalId(externalId).execute();
+ }
+
public Response<PutOfficesOfficeIdResponse>
updateOfficeUsingExternalId(String externalId, String name, String openingDate)
throws IOException {
return fineract().offices