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,9 @@ 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.POST, "/api/*/groups"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_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,6 +85,9 @@
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.GroupCreateCommand;
import org.apache.fineract.portfolio.group.data.GroupCreateRequest;
import org.apache.fineract.portfolio.group.data.GroupCreateResponse;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.fineract.portfolio.group.data.GroupRoleData;
import org.apache.fineract.portfolio.group.service.CenterReadPlatformService;
Expand Down Expand Up @@ -131,6 +135,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 @@ -321,15 +326,11 @@ public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("groupId")
+ "Mandatory Fields: name, officeId, active, activationDate (if active=true)\n\n"
+ "Optional Fields: externalId, staffId, clientMembers")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PostGroupsRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GroupsApiResourceSwagger.PostGroupsResponse.class)))
public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson) {

final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createGroup() //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = commandsSourceWritePlatformService.logCommandSource(commandRequest);
return toApiJsonSerializer.serialize(result);
@ApiResponse(responseCode = "200", description = "OK")
public GroupCreateResponse create(GroupCreateRequest request) {
var command = new GroupCreateCommand();
command.setPayload(request);
return dispatcher.<GroupCreateRequest, GroupCreateResponse>dispatch(command).get();
}

@POST
Expand All @@ -339,7 +340,7 @@ 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)))
@ApiResponse(responseCode = "200", description = "OK")
public String unassignLoanOfficer(@PathParam("groupId") @Parameter(description = "groupId") final Long groupId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {

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.GroupCreateRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class GroupCreateCommand extends Command<GroupCreateRequest> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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.NotBlank;
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 DatatableEntry implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

@NotBlank(message = "{org.apache.fineract.portfolio.group.create.assertion.datatable-registered-table-name-required}")
private String registeredTableName;

private Map<String, Object> data;
}
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.portfolio.group.data;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

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

@Serial
private static final long serialVersionUID = 1L;

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

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

private Long centerId;

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

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

@NotNull(message = "{org.apache.fineract.portfolio.group.create.assertion.active-required}")
private Boolean active;

private String activationDate;

private String submittedOnDate;

private Set<Long> clientMembers;

private String locale;

private String dateFormat;

@Valid
private List<DatatableEntry> datatables;

@JsonIgnore
@AssertTrue(message = "{org.apache.fineract.portfolio.group.create.assertion.activation-date-required-when-active}")
public boolean isActivationDateValidWhenActive() {
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,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 GroupCreateResponse 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
Expand Up @@ -18,31 +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.GroupCreateRequest;
import org.apache.fineract.portfolio.group.data.GroupCreateResponse;
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 = "CREATE")
public class CreateGroupCommandHandler implements NewCommandSourceHandler {
@Slf4j
@Component
@RequiredArgsConstructor
public class GroupCreateCommandHandler implements CommandHandler<GroupCreateRequest, GroupCreateResponse> {

private final GroupingTypesWritePlatformService groupWritePlatformService;
private final GroupingTypesWritePlatformService groupingTypesWritePlatformService;

@Autowired
public CreateGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
this.groupWritePlatformService = groupWritePlatformService;
@Retry(name = "commandGroupCreate", fallbackMethod = "fallback")
@Override
@Transactional
public GroupCreateResponse handle(Command<GroupCreateRequest> command) {
return groupingTypesWritePlatformService.createGroup(command.getPayload());
}

@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {

final Long centerId = command.longValueOfParameterNamed("centerId");
return this.groupWritePlatformService.createGroup(centerId, command);
public GroupCreateResponse fallback(Command<GroupCreateRequest> command, Throwable t) {
return CommandHandler.super.fallback(command, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.group.data.GroupCreateRequest;
import org.apache.fineract.portfolio.group.data.GroupCreateResponse;

public interface GroupingTypesWritePlatformService {

Expand All @@ -29,6 +31,8 @@ public interface GroupingTypesWritePlatformService {

CommandProcessingResult createGroup(Long centerId, JsonCommand command);

GroupCreateResponse createGroup(GroupCreateRequest request);

CommandProcessingResult activateGroupOrCenter(Long entityId, JsonCommand command);

CommandProcessingResult updateGroup(Long groupId, JsonCommand command);
Expand Down
Loading