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 @@ -2245,13 +2245,6 @@ public CommandWrapperBuilder deleteCalendar(final String supportedEntityType, fi
return this;
}

public CommandWrapperBuilder createGroup() {
this.actionName = ACTION_CREATE;
this.entityName = ENTITY_GROUP;
this.href = "/groups/template";
return this;
}

public CommandWrapperBuilder updateGroup(final Long groupId) {
this.actionName = ACTION_UPDATE;
this.entityName = ENTITY_GROUP;
Expand Down Expand Up @@ -2340,15 +2333,6 @@ public CommandWrapperBuilder assignGroupStaff(final Long groupId) {
return this;
}

public CommandWrapperBuilder closeGroup(final Long groupId) {
this.actionName = ACTION_CLOSE;
this.entityName = ENTITY_GROUP;
this.entityId = groupId;
this.groupId = groupId;
this.href = "/groups/" + groupId + "?command=close";
return this;
}

public CommandWrapperBuilder createCollateral(final Long loanId) {
this.actionName = ACTION_CREATE;
this.entityName = ENTITY_COLLATERAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
*/
package org.apache.fineract.infrastructure.bulkimport.importhandler.group;

import com.google.common.reflect.TypeToken;
import com.google.gson.GsonBuilder;
import java.lang.reflect.Type;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
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.IdempotencyKeyGenerator;
Expand All @@ -35,14 +36,17 @@
import org.apache.fineract.infrastructure.bulkimport.data.Count;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.ClientIdSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.DateSerializer;
import org.apache.fineract.infrastructure.bulkimport.importhandler.helper.EnumOptionDataValueSerializer;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
import org.apache.fineract.portfolio.calendar.data.CalendarData;
import org.apache.fineract.portfolio.client.data.ClientData;
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.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.IndexedColors;
Expand All @@ -61,12 +65,14 @@ public class GroupImportHandler implements ImportHandler {

private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final IdempotencyKeyGenerator idempotencyKeyGenerator;
private final CommandDispatcher dispatcher;

@Autowired
public GroupImportHandler(final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
IdempotencyKeyGenerator idempotencyKeyGenerator) {
final IdempotencyKeyGenerator idempotencyKeyGenerator, final CommandDispatcher dispatcher) {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.idempotencyKeyGenerator = idempotencyKeyGenerator;
this.dispatcher = dispatcher;
}

@Override
Expand Down Expand Up @@ -271,18 +277,51 @@ private Integer importGroupMeeting(final List<CalendarData> meetings, CommandPro
}

private CommandProcessingResult importGroup(final List<GroupGeneralData> groups, final int rowIndex, final String dateFormat) {
GsonBuilder gsonBuilder = GoogleGsonSerializerHelper.createGsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat, groups.get(rowIndex).getLocale()));
Type clientCollectionType = new TypeToken<Collection<ClientData>>() {
GroupGeneralData groupData = groups.get(rowIndex);

}.getType();
gsonBuilder.registerTypeAdapter(clientCollectionType, new ClientIdSerializer());
String payload = gsonBuilder.create().toJson(groups.get(rowIndex));
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createGroup() //
.withJson(payload) //
.build(); //
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
Set<Long> clientMemberIds = new HashSet<>();
if (groupData.getClientMembers() != null) {
for (ClientData client : groupData.getClientMembers()) {
if (client.getId() != null) {
clientMemberIds.add(client.getId());
}
}
}

String activationDateStr = formatDate(groupData.getActivationDate(), dateFormat);
String submittedOnDateStr = formatDate(groupData.getSubmittedOnDate(), dateFormat);

GroupCreateRequest request = GroupCreateRequest.builder() //
.name(groupData.getName()) //
.officeId(groupData.getOfficeId()) //
.staffId(groupData.getStaffId()) //
.centerId(groupData.getCenterId()) //
.externalId(groupData.getExternalId()) //
.active(groupData.getActive()) //
.activationDate(activationDateStr) //
.submittedOnDate(submittedOnDateStr) //
.clientMembers(clientMemberIds.isEmpty() ? null : clientMemberIds) //
.locale(groupData.getLocale()) //
.dateFormat(dateFormat) //
.build();

GroupCreateCommand command = new GroupCreateCommand();
command.setPayload(request);
GroupCreateResponse response = dispatcher.<GroupCreateRequest, GroupCreateResponse>dispatch(command).get();

return new CommandProcessingResultBuilder() //
.withOfficeId(response.getOfficeId()) //
.withGroupId(response.getGroupId()) //
.withEntityId(response.getResourceId()) //
.build();
}

private String formatDate(final LocalDate date, final String dateFormat) {
if (date == null) {
return null;
}
String pattern = (dateFormat != null && !dateFormat.isBlank()) ? dateFormat : "yyyy-MM-dd";
return date.format(DateTimeFormatter.ofPattern(pattern));
}

private int getProgressLevel(String status) {
Expand All @@ -293,5 +332,4 @@ private int getProgressLevel(String status) {
}
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ 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")

Comment thread
nidhiii128 marked this conversation as resolved.
// template
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/templates/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_TEMPLATE")
Expand All @@ -386,6 +387,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/standinginstructionrunhistory"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_STANDINGINSTRUCTION")

// group
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/groups"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_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")

.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated()
.requestMatchers(API_MATCHER.matcher("/api/*/twofactor")).fullyAuthenticated()
.requestMatchers(API_MATCHER.matcher("/api/**")).access(allOfRequestManagers(authorizationManagers));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public interface EntityDatatableChecksWritePlatformService {

boolean saveDatatables(Integer status, String entity, Long entityId, Long productId, JsonArray data);

boolean saveDatatables(Integer status, String entity, Long entityId, Long productId,
java.util.List<org.apache.fineract.portfolio.group.data.DatatableEntry> datatableEntries);

}
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,43 @@ public boolean saveDatatables(final Integer status, final String entity, final L
return isMakerCheckerEnabled;
}

@Transactional
@Override
public boolean saveDatatables(final Integer status, final String entity, final Long entityId, final Long productId,
final java.util.List<org.apache.fineract.portfolio.group.data.DatatableEntry> datatableEntries) {
if (datatableEntries == null || datatableEntries.isEmpty()) {
return false;
}
final AppUser user = this.context.authenticatedUser();
boolean isMakerCheckerEnabled = false;
for (org.apache.fineract.portfolio.group.data.DatatableEntry entry : datatableEntries) {
final String datatableName = entry.getRegisteredTableName();
if (datatableName == null || entry.getData() == null) {
final ApiParameterError error = ApiParameterError.generalError(
"registeredTableName.and.data.parameters.must.be.present.in.each.list.items.in.datatables",
"registeredTableName and data parameters must be present in each list items in datatables");
List<ApiParameterError> errors = new ArrayList<>();
errors.add(error);
throw new PlatformApiDataValidationException(errors);
}
final String taskPermissionName = "CREATE_" + datatableName;
user.validateHasPermissionTo(taskPermissionName);
if (this.configurationDomainService.isMakerCheckerEnabledForTask(taskPermissionName)) {
isMakerCheckerEnabled = true;
}
try {
final String dataAsJson = new com.google.gson.Gson().toJson(entry.getData());
datatableWriteService.createNewDatatableEntry(datatableName, entityId, dataAsJson);
} catch (PlatformApiDataValidationException e) {
for (ApiParameterError error : e.getErrors()) {
error.setParameterName("datatables." + datatableName + "." + error.getParameterName());
}
throw e;
}
}
return isMakerCheckerEnabled;
}

@Transactional
@Override
public CommandProcessingResult deleteCheck(final Long entityDatatableCheckId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@
*/
package org.apache.fineract.infrastructure.event.business.domain.group;

import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.domain.AbstractBusinessEvent;
import org.apache.fineract.portfolio.group.domain.Group;

public class GroupsCreateBusinessEvent extends GroupsBusinessEvent {
public class GroupsCreateBusinessEvent extends AbstractBusinessEvent<Group> {

private static final String CATEGORY = "Group";
private static final String TYPE = "GroupsCreateBusinessEvent";

public GroupsCreateBusinessEvent(CommandProcessingResult value) {
public GroupsCreateBusinessEvent(Group value) {
super(value);
}

@Override
public String getCategory() {
return CATEGORY;
}

@Override
public String getType() {
return TYPE;
}

@Override
public Long getAggregateRootId() {
return get().getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.client.domain.Client;
import org.apache.fineract.portfolio.group.domain.Group;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct;
Expand Down Expand Up @@ -120,9 +121,9 @@ private final class GroupCreatedListener implements BusinessEventListener<Groups

@Override
public void onBusinessEvent(GroupsCreateBusinessEvent event) {
CommandProcessingResult commandProcessingResult = event.get();
buildNotification("ACTIVATE_GROUP", "group", commandProcessingResult.getGroupId(), "New group created", "created",
context.authenticatedUser().getId(), commandProcessingResult.getOfficeId());
Group group = event.get();
buildNotification("ACTIVATE_GROUP", "group", group.getId(), "New group created", "created", context.authenticatedUser().getId(),
group.getOffice().getId());
}
}

Expand Down
Loading