Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.group.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonElement;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand Down Expand Up @@ -50,6 +51,7 @@
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.command.core.CommandDispatcher;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
Expand Down Expand Up @@ -84,8 +86,20 @@
import org.apache.fineract.portfolio.client.service.ClientReadPlatformService;
import org.apache.fineract.portfolio.collectionsheet.data.JLGCollectionSheetData;
import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetReadPlatformService;
import org.apache.fineract.portfolio.group.command.GroupActivateCommand;
import org.apache.fineract.portfolio.group.command.GroupAssignStaffCommand;
import org.apache.fineract.portfolio.group.command.GroupCloseCommand;
import org.apache.fineract.portfolio.group.command.GroupUnassignStaffCommand;
import org.apache.fineract.portfolio.group.data.GroupActivateRequest;
import org.apache.fineract.portfolio.group.data.GroupActivateResponse;
import org.apache.fineract.portfolio.group.data.GroupAssignStaffRequest;
import org.apache.fineract.portfolio.group.data.GroupAssignStaffResponse;
import org.apache.fineract.portfolio.group.data.GroupCloseRequest;
import org.apache.fineract.portfolio.group.data.GroupCloseResponse;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.fineract.portfolio.group.data.GroupRoleData;
import org.apache.fineract.portfolio.group.data.GroupUnassignStaffRequest;
import org.apache.fineract.portfolio.group.data.GroupUnassignStaffResponse;
import org.apache.fineract.portfolio.group.service.CenterReadPlatformService;
import org.apache.fineract.portfolio.group.service.GroupReadPlatformService;
import org.apache.fineract.portfolio.group.service.GroupRolesReadPlatformService;
Expand Down Expand Up @@ -131,6 +145,8 @@ public class GroupsApiResource {
private final GLIMAccountInfoReadPlatformService glimAccountInfoReadPlatformService;
private final GSIMReadPlatformService gsimReadPlatformService;
private final SqlValidator sqlValidator;
private final CommandDispatcher commandDispatcher;
private final ObjectMapper objectMapper;

@GET
@Path("template")
Expand Down Expand Up @@ -339,17 +355,15 @@ public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson
@Operation(summary = "Unassign a Staff", operationId = "unassignLoanOfficerGroup", description = "Allows you to unassign the Staff.\n\n"
+ "Mandatory Fields: staffId")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PostGroupsGroupIdCommandUnassignStaffRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PostGroupsGroupIdCommandUnassignStaffResponse.class)))
public String unassignLoanOfficer(@PathParam("groupId") @Parameter(description = "groupId") final Long groupId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {

final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.unassignGroupStaff(groupId) //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

@Parameter(hidden = true) final String apiRequestBodyAsJson) throws java.io.IOException {

final GroupUnassignStaffRequest request = objectMapper.readValue(apiRequestBodyAsJson, GroupUnassignStaffRequest.class);
request.setGroupId(groupId);
final var command = new GroupUnassignStaffCommand();
command.setPayload(request);
final java.util.function.Supplier<GroupUnassignStaffResponse> response = commandDispatcher.dispatch(command);
return toApiJsonSerializer.serialize(response.get());
}

@PUT
Expand Down Expand Up @@ -420,69 +434,92 @@ public String delete(@PathParam("groupId") @Parameter(description = "groupId") f
+ "Allows you to update the member Role.\n\n" + "Mandatory Fields: role\n\n"
+ "Showing request/response for Transfer Clients across groups")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PostGroupsGroupIdRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PostGroupsGroupIdResponse.class)))
public String activateOrGenerateCollectionSheet(@PathParam("groupId") @Parameter(description = "groupId") final Long groupId,
@QueryParam("command") @Parameter(description = "command") final String commandParam,
@QueryParam("roleId") @Parameter(description = "roleId") final Long roleId,
@Parameter(hidden = true) final String apiRequestBodyAsJson, @Context final UriInfo uriInfo) {
final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
@Parameter(hidden = true) final String apiRequestBodyAsJson, @Context final UriInfo uriInfo) throws java.io.IOException {

final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
CommandProcessingResult result = null;

if (is(commandParam, "activate")) {
final CommandWrapper commandRequest = builder.activateGroup(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);
final GroupActivateRequest request = objectMapper.readValue(apiRequestBodyAsJson, GroupActivateRequest.class);
request.setGroupId(groupId);
final var command = new GroupActivateCommand();
command.setPayload(request);
final java.util.function.Supplier<GroupActivateResponse> response = commandDispatcher.dispatch(command);
return toApiJsonSerializer.serialize(response.get());

} else if (is(commandParam, "associateClients")) {
final CommandWrapper commandRequest = builder.associateClientsToGroup(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

} else if (is(commandParam, "disassociateClients")) {
final CommandWrapper commandRequest = builder.disassociateClientsFromGroup(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

} else if (is(commandParam, "generateCollectionSheet")) {
final JsonElement parsedQuery = fromJsonHelper.parse(apiRequestBodyAsJson);
final JsonQuery query = JsonQuery.from(apiRequestBodyAsJson, parsedQuery, fromJsonHelper);
final JLGCollectionSheetData collectionSheet = collectionSheetReadPlatformService.generateGroupCollectionSheet(groupId, query);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return toApiJsonSerializer.serialize(settings, collectionSheet, GroupingTypesApiConstants.COLLECTIONSHEET_DATA_PARAMETERS);

} else if (is(commandParam, "saveCollectionSheet")) {
final CommandWrapper commandRequest = builder.saveGroupCollectionSheet(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

} else if (is(commandParam, "unassignStaff")) {
final CommandWrapper commandRequest = builder.unassignGroupStaff(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);
final GroupUnassignStaffRequest request = objectMapper.readValue(apiRequestBodyAsJson, GroupUnassignStaffRequest.class);
request.setGroupId(groupId);
final var command = new GroupUnassignStaffCommand();
command.setPayload(request);
final java.util.function.Supplier<GroupUnassignStaffResponse> response = commandDispatcher.dispatch(command);
return toApiJsonSerializer.serialize(response.get());

} else if (is(commandParam, "assignStaff")) {
final CommandWrapper commandRequest = builder.assignGroupStaff(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);
final GroupAssignStaffRequest request = objectMapper.readValue(apiRequestBodyAsJson, GroupAssignStaffRequest.class);
request.setGroupId(groupId);
final var command = new GroupAssignStaffCommand();
command.setPayload(request);
final java.util.function.Supplier<GroupAssignStaffResponse> response = commandDispatcher.dispatch(command);
return toApiJsonSerializer.serialize(response.get());

} else if (is(commandParam, "assignRole")) {
final CommandWrapper commandRequest = builder.assignRole(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

} else if (is(commandParam, "unassignRole")) {
final CommandWrapper commandRequest = builder.unassignRole(groupId, roleId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

} else if (is(commandParam, "updateRole")) {
final CommandWrapper commandRequest = builder.updateRole(groupId, roleId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

} else if (is(commandParam, "transferClients")) {
final CommandWrapper commandRequest = builder.transferClientsBetweenGroups(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);

} else if (is(commandParam, "close")) {
final CommandWrapper commandRequest = builder.closeGroup(groupId).build();
result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);
final GroupCloseRequest request = objectMapper.readValue(apiRequestBodyAsJson, GroupCloseRequest.class);
request.setGroupId(groupId);
final var command = new GroupCloseCommand();
command.setPayload(request);
final java.util.function.Supplier<GroupCloseResponse> response = commandDispatcher.dispatch(command);
return toApiJsonSerializer.serialize(response.get());

} else {
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet",
"saveCollectionSheet", "unassignStaff", "assignRole", "unassignRole", "updateassignRole" });
}

}

private boolean is(final String commandParam, final String commandValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.portfolio.group.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.group.data.GroupActivateRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class GroupActivateCommand extends Command<GroupActivateRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.portfolio.group.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.group.data.GroupAssignStaffRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class GroupAssignStaffCommand extends Command<GroupAssignStaffRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.portfolio.group.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.group.data.GroupCloseRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class GroupCloseCommand extends Command<GroupCloseRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.portfolio.group.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.group.data.GroupUnassignStaffRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class GroupUnassignStaffCommand extends Command<GroupUnassignStaffRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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.portfolio.group.data;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GroupActivateRequest {

@NotNull
private Long groupId;

@NotNull
private String activationDate;

private String locale;
private String dateFormat;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.portfolio.group.data;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GroupActivateResponse {

private Long resourceId;
private Long officeId;
private Long groupId;
}
Loading