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 @@ -397,6 +397,13 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_HOOK")
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/hooks/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_HOOK")

// group
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/groups/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_GROUP")
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/groups/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_GROUP")

// template
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/templates/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_TEMPLATE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 +85,14 @@
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.GroupDeleteCommand;
import org.apache.fineract.portfolio.group.command.GroupUpdateCommand;
import org.apache.fineract.portfolio.group.data.GroupDeleteRequest;
import org.apache.fineract.portfolio.group.data.GroupDeleteResponse;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.fineract.portfolio.group.data.GroupRoleData;
import org.apache.fineract.portfolio.group.data.GroupUpdateRequest;
import org.apache.fineract.portfolio.group.data.GroupUpdateResponse;
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 +138,7 @@ public class GroupsApiResource {
private final GLIMAccountInfoReadPlatformService glimAccountInfoReadPlatformService;
private final GSIMReadPlatformService gsimReadPlatformService;
private final SqlValidator sqlValidator;
private final CommandDispatcher dispatcher;

@GET
@Path("template")
Expand Down Expand Up @@ -357,31 +365,22 @@ public String unassignLoanOfficer(@PathParam("groupId") @Parameter(description =
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update a Group", operationId = "updateGroup", description = "Updates a Group")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PutGroupsGroupIdRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PutGroupsGroupIdResponse.class)))
public String update(@PathParam("groupId") @Parameter(description = "groupId") final Long groupId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {

final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.updateGroup(groupId) //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);
public GroupUpdateResponse update(@PathParam("groupId") final Long groupId, GroupUpdateRequest request) {
request.setGroupId(groupId);
var command = new GroupUpdateCommand();
command.setPayload(request);
return dispatcher.<GroupUpdateRequest, GroupUpdateResponse>dispatch(command).get();
}

@DELETE
@Path("{groupId}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Delete a Group", operationId = "deleteGroup", description = "A group can be deleted if it is in pending state and has no associations - clients, loans or savings")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.DeleteGroupsGroupIdResponse.class)))
public String delete(@PathParam("groupId") @Parameter(description = "groupId") final Long groupId) {

final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.deleteGroup(groupId) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);
public GroupDeleteResponse delete(@PathParam("groupId") final Long groupId) {
final GroupDeleteRequest request = GroupDeleteRequest.builder().groupId(groupId).build();
var command = new GroupDeleteCommand();
command.setPayload(request);
return dispatcher.<GroupDeleteRequest, GroupDeleteResponse>dispatch(command).get();
}

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

@Data
@EqualsAndHashCode(callSuper = true)
public class GroupDeleteCommand extends Command<GroupDeleteRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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.GroupUpdateRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class GroupUpdateCommand extends Command<GroupUpdateRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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 java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GroupDeleteRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

@NotNull(message = "{org.apache.fineract.portfolio.group.delete.assertion.group-id-required}")
private Long groupId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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 java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GroupDeleteResponse implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private Long resourceId;
private Long officeId;
private Long groupId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* 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 com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;
import java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public class GroupUpdateRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private Long groupId;

@NotBlank(message = "{org.apache.fineract.portfolio.group.update.assertion.name-required}")
@Size(max = 100, message = "{org.apache.fineract.portfolio.group.update.assertion.name-max-length}")
private String name;

@Size(max = 100, message = "{org.apache.fineract.portfolio.group.update.assertion.external-id-max-length}")
private String externalId;

@Positive(message = "{org.apache.fineract.portfolio.group.update.assertion.office-id-positive}")
private Long officeId;

@Positive(message = "{org.apache.fineract.portfolio.group.update.assertion.staff-id-positive}")
private Long staffId;

private Long centerId;

private Boolean active;

private String activationDate;

private String submittedOnDate;

private String locale;

private String dateFormat;

@JsonIgnore
@AssertTrue(message = "{org.apache.fineract.portfolio.group.update.assertion.activation-date-required-when-active-or-present}")
public boolean isActivationDateValid() {
if (Boolean.TRUE.equals(active)) {
return activationDate != null && !activationDate.isBlank();
}
return true;
}
}
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 java.io.Serial;
import java.io.Serializable;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GroupUpdateResponse implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private Long resourceId;
private Long officeId;
private Long groupId;
private Map<String, Object> changes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,33 @@
*/
package org.apache.fineract.portfolio.group.handler;

import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import io.github.resilience4j.retry.annotation.Retry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.command.core.CommandHandler;
import org.apache.fineract.portfolio.group.data.GroupDeleteRequest;
import org.apache.fineract.portfolio.group.data.GroupDeleteResponse;
import org.apache.fineract.portfolio.group.service.GroupingTypesWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Service
@CommandType(entity = "GROUP", action = "DELETE")
public class DeleteGroupCommandHandler implements NewCommandSourceHandler {
@Slf4j
@Component
@RequiredArgsConstructor
public class GroupDeleteCommandHandler implements CommandHandler<GroupDeleteRequest, GroupDeleteResponse> {

private final GroupingTypesWritePlatformService groupWritePlatformService;
private final GroupingTypesWritePlatformService groupingTypesWritePlatformService;

@Autowired
public DeleteGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
this.groupWritePlatformService = groupWritePlatformService;
@Retry(name = "commandGroupDelete", fallbackMethod = "fallback")
@Override
@Transactional
public GroupDeleteResponse handle(Command<GroupDeleteRequest> command) {
return groupingTypesWritePlatformService.deleteGroup(command.getPayload());
}

@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.groupWritePlatformService.deleteGroup(command.entityId());
public GroupDeleteResponse fallback(Command<GroupDeleteRequest> command, Throwable t) {
return CommandHandler.super.fallback(command, t);
}
}
Loading
Loading