Merge pull request #416 from goutham-M/mifosx522

In add new group form if activation date field is empty it showing connection fail(fixed)
This commit is contained in:
Keith Woodlock
2013-07-02 09:53:04 -07:00
2 changed files with 21 additions and 19 deletions
@@ -10,9 +10,9 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul
public class InvalidGroupStateTransitionException extends AbstractPlatformDomainRuleException {
public InvalidGroupStateTransitionException(final String action, final String postFix, final String defaultUserMessage,
final Object... defaultUserMessageArgs) {
super("error.msg.group." + action + "." + postFix, defaultUserMessage, defaultUserMessageArgs);
public InvalidGroupStateTransitionException(final String levelName, final String action, final String postFix,
final String defaultUserMessage, final Object... defaultUserMessageArgs) {
super("error.msg." + levelName + "." + action + "." + postFix, defaultUserMessage, defaultUserMessageArgs);
}
}
@@ -106,13 +106,9 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
if (groupOffice == null) { throw new OfficeNotFoundException(officeId); }
final LocalDate activationDate = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName);
if (groupOffice.getOpeningLocalDate().isAfter(activationDate)) {
final String errorMessage = "Group activation date should be greater than or equal to the parent Office's creation date "
+ activationDate.toString();
throw new InvalidGroupStateTransitionException("activate.date", "cannot.be.before.office.activation.date", errorMessage, activationDate,
groupOffice.getOpeningLocalDate());
}
final GroupLevel groupLevel = this.groupLevelRepository.findOne(groupingType.getId());
validateOfficeOpeningDateisAfterGroupOrCenterOpeningDate(groupOffice, groupLevel, activationDate);
Staff staff = null;
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
@@ -125,7 +121,6 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final Set<Group> groupMembers = assembleSetOfChildGroups(officeId, command);
final boolean active = command.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.activeParamName);
final GroupLevel groupLevel = this.groupLevelRepository.findOne(groupingType.getId());
final Group newGroup = Group.newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId, active, activationDate,
clientMembers, groupMembers);
@@ -184,7 +179,8 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final Locale locale = command.extractLocale();
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
final LocalDate activationDate = command.localDateValueOfParameterNamed("activationDate");
validateOfficeOpeningDateisAfterGroupOrCenterOpeningDate(group.getOffice(), group.getGroupLevel(), activationDate);
group.activate(fmt, activationDate);
this.groupRepository.saveAndFlush(group);
@@ -232,13 +228,8 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final LocalDate activationDate = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName);
if (groupOffice.getOpeningLocalDate().isAfter(activationDate)) {
final String errorMessage = "Group activation date should be greater than or equal to the parent Office's creation date "
+ activationDate.toString();
throw new InvalidGroupStateTransitionException("activate.date", "cannot.be.before.office.activation.date", errorMessage, activationDate,
groupOffice.getOpeningLocalDate());
}
validateOfficeOpeningDateisAfterGroupOrCenterOpeningDate(groupOffice, groupForUpdate.getGroupLevel(), activationDate);
final Map<String, Object> actualChanges = groupForUpdate.update(command);
if (actualChanges.containsKey(GroupingTypesApiConstants.staffIdParamName)) {
@@ -530,4 +521,15 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
}
}
public void validateOfficeOpeningDateisAfterGroupOrCenterOpeningDate(final Office groupOffice, final GroupLevel groupLevel,
final LocalDate activationDate) {
if (activationDate != null && groupOffice.getOpeningLocalDate().isAfter(activationDate)) {
final String levelName = groupLevel.getLevelName();
final String errorMessage = levelName
+ " activation date should be greater than or equal to the parent Office's creation date " + activationDate.toString();
throw new InvalidGroupStateTransitionException(levelName.toLowerCase(), "activate.date",
"cannot.be.before.office.activation.date", errorMessage, activationDate, groupOffice.getOpeningLocalDate());
}
}
}