Merge pull request #823 from lingalamadhukar/MIFOSX-998
Activation permission check for group and center
This commit is contained in:
+18
-1
@@ -17,6 +17,9 @@ import java.util.Set;
|
|||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.joda.time.format.DateTimeFormat;
|
import org.joda.time.format.DateTimeFormat;
|
||||||
import org.joda.time.format.DateTimeFormatter;
|
import org.joda.time.format.DateTimeFormatter;
|
||||||
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
|
import org.mifosplatform.commands.service.CommandProcessingService;
|
||||||
|
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||||
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
|
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
|
||||||
import org.mifosplatform.infrastructure.codes.domain.CodeValueRepositoryWrapper;
|
import org.mifosplatform.infrastructure.codes.domain.CodeValueRepositoryWrapper;
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
@@ -77,6 +80,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
private final LoanRepository loanRepository;
|
private final LoanRepository loanRepository;
|
||||||
private final CodeValueRepositoryWrapper codeValueRepository;
|
private final CodeValueRepositoryWrapper codeValueRepository;
|
||||||
private final SavingsAccountRepository savingsRepository;
|
private final SavingsAccountRepository savingsRepository;
|
||||||
|
private final CommandProcessingService commandProcessingService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||||
@@ -84,7 +88,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
final OfficeRepository officeRepository, final StaffRepositoryWrapper staffRepository, final NoteRepository noteRepository,
|
final OfficeRepository officeRepository, final StaffRepositoryWrapper staffRepository, final NoteRepository noteRepository,
|
||||||
final GroupLevelRepository groupLevelRepository, final GroupingTypesDataValidator fromApiJsonDeserializer,
|
final GroupLevelRepository groupLevelRepository, final GroupingTypesDataValidator fromApiJsonDeserializer,
|
||||||
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository,
|
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository,
|
||||||
final CodeValueRepositoryWrapper codeValueRepository) {
|
final CodeValueRepositoryWrapper codeValueRepository, final CommandProcessingService commandProcessingService) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.groupRepository = groupRepository;
|
this.groupRepository = groupRepository;
|
||||||
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
||||||
@@ -96,6 +100,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
this.loanRepository = loanRepository;
|
this.loanRepository = loanRepository;
|
||||||
this.savingsRepository = savingsRepository;
|
this.savingsRepository = savingsRepository;
|
||||||
this.codeValueRepository = codeValueRepository;
|
this.codeValueRepository = codeValueRepository;
|
||||||
|
this.commandProcessingService = commandProcessingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
|
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
|
||||||
@@ -144,6 +149,17 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
final Group newGroup = Group.newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId, active, activationDate,
|
final Group newGroup = Group.newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId, active, activationDate,
|
||||||
clientMembers, groupMembers, submittedOnDate, currentUser);
|
clientMembers, groupMembers, submittedOnDate, currentUser);
|
||||||
|
|
||||||
|
boolean rollbackTransaction = false;
|
||||||
|
if (newGroup.isActive()) {
|
||||||
|
if (newGroup.isCenter()) {
|
||||||
|
final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateCenter(null).build();
|
||||||
|
rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper, currentUser);
|
||||||
|
} else {
|
||||||
|
final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateGroup(null).build();
|
||||||
|
rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper, currentUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// pre-save to generate id for use in group hierarchy
|
// pre-save to generate id for use in group hierarchy
|
||||||
this.groupRepository.save(newGroup);
|
this.groupRepository.save(newGroup);
|
||||||
|
|
||||||
@@ -156,6 +172,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
.withOfficeId(groupOffice.getId()) //
|
.withOfficeId(groupOffice.getId()) //
|
||||||
.withGroupId(newGroup.getId()) //
|
.withGroupId(newGroup.getId()) //
|
||||||
.withEntityId(newGroup.getId()) //
|
.withEntityId(newGroup.getId()) //
|
||||||
|
.setRollbackTransaction(rollbackTransaction)//
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
} catch (final DataIntegrityViolationException dve) {
|
} catch (final DataIntegrityViolationException dve) {
|
||||||
|
|||||||
Reference in New Issue
Block a user