use of org.mifos.dto.domain.ClientCreationDetail in project head by mifos.
the class ImportClientsServiceFacadeWebTier method save.
@Override
public ParsedClientsDto save(ParsedClientsDto parsedClientsDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
DateTimeService dateTimeService = new DateTimeService();
/* Construct ClientBO objects */
List<NewClientDto> newClients = new ArrayList<NewClientDto>();
for (ImportedClientDetail importedClient : parsedClientsDto.getSuccessfullyParsedRows()) {
String secondMiddleName = null;
ClientCreationDetail clientCreationDetail = importedClient.getClientCreationDetail();
PersonnelBO formedBy = null;
/* Client name details */
ClientNameDetailDto clientNameDetails = clientCreationDetail.getClientNameDetailDto();
ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientNameDetails);
ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
String clientFirstName = clientNameDetails.getFirstName();
String clientLastName = clientNameDetails.getLastName();
String secondLastName = clientNameDetails.getSecondLastName();
/* Spouse/father name details */
ClientNameDetailEntity spouseFatherNameDetailEntity = null;
if (clientCreationDetail.getSpouseFatherName() != null) {
spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getSpouseFatherName());
}
/* Data conversion */
DateTime dateOfBirth = new DateTime(clientCreationDetail.getDateOfBirth());
DateTime mfiJoiningDate = new DateTime(clientCreationDetail.getMfiJoiningDate());
DateTime trainedDateTime = null;
if (clientCreationDetail.getTrainedDate() != null) {
trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
}
/* Status */
CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
CustomerStatus finalStatus = clientStatus;
if (clientStatus == CustomerStatus.CLIENT_ACTIVE && clientCreationDetail.getActivationDate() == null) {
clientStatus = CustomerStatus.CLIENT_PENDING;
}
/* Address */
Address address = null;
if (clientCreationDetail.getAddress() != null) {
AddressDto dto = clientCreationDetail.getAddress();
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
// empty list
List<ClientInitialSavingsOfferingEntity> associatedOfferings = new ArrayList<ClientInitialSavingsOfferingEntity>();
// client object
ClientBO client;
if (clientCreationDetail.getGroupFlag() == 1) {
CustomerBO group = customerDao.findCustomerBySystemId(clientCreationDetail.getParentGroupId());
if (clientCreationDetail.getFormedBy() != null) {
formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
} else {
formedBy = group.getPersonnel();
}
client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, group, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
} else {
Short officeId = clientCreationDetail.getOfficeId();
Short officerId = clientCreationDetail.getLoanOfficerId();
PersonnelBO loanOfficer = personnelDao.findPersonnelById(officerId);
OfficeBO office = this.officeDao.findOfficeById(officeId);
if (clientCreationDetail.getFormedBy() != null) {
formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
} else {
formedBy = loanOfficer;
}
int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
/* meeting */
final MeetingDto meetingDto = importedClient.getMeeting();
MeetingBO clientMeeting = null;
if (meetingDto != null) {
clientMeeting = new MeetingFactory().create(meetingDto);
clientMeeting.setUserContext(userContext);
}
client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
if (clientCreationDetail.getActivationDate() != null) {
client.setCustomerActivationDate(clientCreationDetail.getActivationDate().toDateMidnight().toDate());
}
}
// global id
if (importedClient.getClientGlobalNum() != null) {
client.setGlobalCustNum(importedClient.getClientGlobalNum());
}
NewClientDto newClient = new NewClientDto(client, finalStatus);
newClients.add(newClient);
}
/* Validate client data */
for (NewClientDto newClient : newClients) {
ClientBO client = newClient.getClientBO();
try {
client.validate();
customerDao.validateClientForDuplicateNameOrGovtId(client.getDisplayName(), client.getDateOfBirth(), client.getGovernmentId());
} catch (CustomerException ex) {
throw new MifosRuntimeException(ex);
}
}
/* Save clients */
// empty list
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
try {
hibernateTransactionHelper.startTransaction();
for (NewClientDto newClient : newClients) {
ClientBO client = newClient.getClientBO();
CustomerStatus finalStatus = newClient.getCustomerStatus();
// status to pending approval if active
MeetingBO meeting = client.getCustomerMeetingValue();
customerDao.save(client);
hibernateTransactionHelper.flushSession();
CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
CustomerAccountBO customerAccount = customerAccountFactory.create(client, accountFees, meeting, applicableCalendarEvents);
client.addAccount(customerAccount);
customerDao.save(client);
hibernateTransactionHelper.flushSession();
if (client.getParentCustomer() != null) {
customerDao.save(client.getParentCustomer());
}
if (client.getGlobalCustNum() == null) {
client.generateGlobalCustomerNumber();
}
client.generateSearchId();
customerDao.save(client);
hibernateTransactionHelper.flushSession();
if (client.getParentCustomer() != null) {
customerDao.save(client.getParentCustomer());
}
/* activate client */
if (finalStatus == CustomerStatus.CLIENT_ACTIVE) {
hibernateTransactionHelper.flushSession();
hibernateTransactionHelper.beginAuditLoggingFor(client);
client.clearCustomerFlagsIfApplicable(client.getStatus(), finalStatus);
client.updateCustomerStatus(finalStatus);
// changeStatus(client, oldStatus, newStatus);
if (client.getParentCustomer() != null) {
CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
client.addCustomerHierarchy(hierarchy);
}
if (client.getCustomerActivationDate() != null) {
client.setCustomerActivationDate(client.getCustomerActivationDate());
} else {
client.setCustomerActivationDate(dateTimeService.getCurrentJavaDateTime());
}
customerAccount.createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(client, accountFees, meeting, applicableCalendarEvents, new DateTime(client.getCustomerActivationDate()));
customerDao.save(client);
}
}
hibernateTransactionHelper.commitTransaction();
} catch (Exception ex) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(ex);
}
return parsedClientsDto;
}
use of org.mifos.dto.domain.ClientCreationDetail in project head by mifos.
the class XlsClientsImporter method parse.
public ParsedClientsDto parse(final InputStream input) {
final List<ValueListElement> buisnessActivitiesList = customerDao.retrieveBusinessActivities();
final List<ValueListElement> gendersList = customerDao.retrieveGenders();
final List<ValueListElement> citizenshipsList = customerDao.retrieveCitizenship();
final List<ValueListElement> ethinicitiesList = customerDao.retrieveEthnicity();
final List<ValueListElement> educationLevelsList = customerDao.retrieveEducationLevels();
final List<ValueListElement> handicappedList = customerDao.retrieveHandicapped();
final List<ValueListElement> povertyStatusList = customerDao.retrievePoverty();
final List<ValueListElement> maritalStatusList = customerDao.retrieveMaritalStatuses();
final List<ValueListElement> salutationsList = customerDao.retrieveSalutations();
final List<OfficeDto> allOfficess = officeDao.findAllOffices();
final FieldConfig fieldConfig = FieldConfig.getInstance();
final List<String> globalCustNums = new ArrayList<String>();
final List<String> errorsList = new ArrayList<String>();
final List<ImportedClientDetail> parsedClientDetails = new ArrayList<ImportedClientDetail>();
try {
final HSSFWorkbook workbook = new HSSFWorkbook(input);
final HSSFSheet sheet = workbook.getSheetAt(0);
/* test first data row */
HSSFRow row = sheet.getRow(XlsImportConstants.FIRST_CLIENT_ROW.value());
if (row == null) {
errorsList.add(getMessage(XlsMessageConstants.NOT_ENOUGH_INPUT_ROW));
}
@SuppressWarnings("rawtypes") Iterator rowIterator = sheet.rowIterator();
/* Skip first rows */
if (errorsList.isEmpty()) {
for (int i = 0; i < XlsImportConstants.SKIPPED_ROWS.value(); i++) {
if (rowIterator.hasNext()) {
rowIterator.next();
} else {
errorsList.add(getMessage(XlsMessageConstants.NOT_ENOUGH_INPUT_ROW));
break;
}
}
}
XlsImportConstants currentCell = XlsImportConstants.CLIENT_NUM_CELL;
int friendlyRowNumber = 0;
/* Parse client data */
if (errorsList.isEmpty()) {
while (rowIterator.hasNext()) {
try {
row = (HSSFRow) rowIterator.next();
friendlyRowNumber = row.getRowNum() + 1;
/* Get data from sheet */
currentCell = XlsImportConstants.CLIENT_NUM_CELL;
String clientGlobalNum = getCellStringValue(row, currentCell);
if (StringUtils.isBlank(clientGlobalNum)) {
// generate number
clientGlobalNum = null;
} else {
// check for duplicates
validateGlobalCustNum(clientGlobalNum, globalCustNums);
globalCustNums.add(clientGlobalNum);
}
currentCell = XlsImportConstants.BRANCH_SHORT_NAME_CELL;
final String branchShortName = getCellStringValue(row, currentCell);
final Short branchOfficeId = getBranchId(branchShortName, allOfficess);
currentCell = XlsImportConstants.GROUP_GLOBAL_NUM_CELL;
final String groupGlobalNum = getCellStringValue(row, currentCell);
validateGroup(groupGlobalNum);
if (StringUtils.isBlank(groupGlobalNum) && branchOfficeId == null) {
String error = getRowError(friendlyRowNumber) + getMessage(XlsMessageConstants.OFFICE_AND_BRANCH);
errorsList.add(error);
continue;
}
currentCell = XlsImportConstants.SALUTATION_CELL;
final String salutation = getCellStringValue(row, currentCell);
final Integer salutationId = getValueElementId(salutation, salutationsList);
validateMandatoryField(salutationId);
currentCell = XlsImportConstants.FIRST_NAME_CELL;
final String clientFirstName = getCellStringValue(row, currentCell);
validateMandatoryField(clientFirstName);
currentCell = XlsImportConstants.MIDDLE_NAME_CELL;
final String clientMiddleName = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.MIDDLE_NAME)) {
validateMandatoryField(clientMiddleName);
}
currentCell = XlsImportConstants.LAST_NAME_CELL;
final String clientLastName = getCellStringValue(row, currentCell);
validateMandatoryField(clientLastName);
currentCell = XlsImportConstants.SECOND_LAST_NAME_CELL;
final String clientSecondLastName = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.SECOND_LAST_NAME)) {
validateMandatoryField(clientSecondLastName);
}
currentCell = XlsImportConstants.GOVERNMENT_ID_CELL;
String governmentId = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.GOVERNMENT_ID)) {
validateMandatoryField(governmentId);
}
currentCell = XlsImportConstants.DATE_OF_BIRTH_CELL;
final Date dateOfBirth = getCellDateValue(row, currentCell);
validateMandatoryField(dateOfBirth);
validateAge(dateOfBirth);
currentCell = XlsImportConstants.GENDER_CELL;
final String gender = getCellStringValue(row, currentCell);
final Short genderId = intToShort(getValueElementId(gender, gendersList));
validateMandatoryField(genderId);
currentCell = XlsImportConstants.MARITAL_STATUS_CELL;
final String maritalStatus = getCellStringValue(row, currentCell);
final Integer maritalStatusId = getValueElementId(maritalStatus, maritalStatusList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.MARITAL_STATUS)) {
validateMandatoryField(maritalStatusId);
}
currentCell = XlsImportConstants.NUMBER_OF_CHILDREN_CELL;
final Short numberOfChildren = intToShort(getCellIntegerValue(row, currentCell));
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.NUMBER_OF_CHILDREN)) {
validateMandatoryField(numberOfChildren);
}
currentCell = XlsImportConstants.CITIZENSHIP_CELL;
final String citizenship = getCellStringValue(row, currentCell);
final Integer citizenshipId = getValueElementId(citizenship, citizenshipsList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.CITIZENSHIP)) {
validateMandatoryField(citizenshipId);
}
currentCell = XlsImportConstants.ETHINICITY_CELL;
final String ethinicity = getCellStringValue(row, currentCell);
final Integer ethinicityId = getValueElementId(ethinicity, ethinicitiesList);
if (fieldConfig.isFieldHidden(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.ETHNICITY)) {
validateMandatoryField(ethinicityId);
}
currentCell = XlsImportConstants.EDUCATION_LEVEL_CELL;
final String educationLevel = getCellStringValue(row, currentCell);
final Integer educationLevelId = getValueElementId(educationLevel, educationLevelsList);
if (fieldConfig.isFieldHidden(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.EDUCATION_LEVEL)) {
validateMandatoryField(educationLevelId);
}
currentCell = XlsImportConstants.ACTIVITIES_CELL;
final String activites = getCellStringValue(row, currentCell);
final Integer activityId = getValueElementId(activites, buisnessActivitiesList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.BUSINESS_ACTIVITIES)) {
validateMandatoryField(activityId);
}
currentCell = XlsImportConstants.POVERTY_STATUS_CELL;
final String povertyStatus = getCellStringValue(row, currentCell);
final Short povertyStatusId = intToShort(getValueElementId(povertyStatus, povertyStatusList));
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.POVERTY_STATUS)) {
validateMandatoryField(povertyStatusId);
}
currentCell = XlsImportConstants.HANDICAPPED_CELL;
final String handicapped = getCellStringValue(row, currentCell);
final Integer handicappedId = getValueElementId(handicapped, handicappedList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.HANDICAPPED)) {
validateMandatoryField(handicappedId);
}
currentCell = XlsImportConstants.SPOUSE_FATHER_RELATIONSHIP_CELL;
final String spouseOrFather = getCellStringValue(row, currentCell);
final Short spouseFatherNameType = getSpouseNameType(spouseOrFather);
final boolean familyMandatory = fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.FAMILY_DETAILS);
if (familyMandatory) {
validateMandatoryField(spouseFatherNameType);
}
currentCell = XlsImportConstants.SPOUSE_FIRST_NAME_CELL;
final String spouseFirstName = getCellStringValue(row, currentCell);
if (familyMandatory) {
validateMandatoryField(spouseFirstName);
}
currentCell = XlsImportConstants.SPOUSE_MIDDLE_NAME_CELL;
final String spouseMiddleName = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.SPOUSE_SECOND_LAST_NAME_CELL;
final String spouseSecondLastName = getCellStringValue(row, currentCell);
if (familyMandatory && fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.SPOUSE_FATHER_SECOND_LAST_NAME)) {
validateMandatoryField(spouseSecondLastName);
}
currentCell = XlsImportConstants.SPOUSE_LAST_NAME_CELL;
final String spouseLastName = getCellStringValue(row, currentCell);
if (familyMandatory) {
validateMandatoryField(spouseLastName);
}
currentCell = XlsImportConstants.ADDRESS_CELL;
final String address = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.ADDRESS1)) {
validateMandatoryField(address);
}
currentCell = XlsImportConstants.CITY_DISTRICT_CELL;
final String cityDistrict = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.STATE_CELL;
final String state = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.COUNTRY_CELL;
final String country = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.POSTAL_CODE_CELL;
final String postalCode = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.TELEPHONE_CELL;
final String telephone = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.RECRUITED_BY_CELL;
final String recruitedBy = getCellStringValue(row, currentCell);
validateMandatoryField(recruitedBy);
final Short formedBy = getOfficerId(recruitedBy);
currentCell = XlsImportConstants.STATUS_CELL;
final String status = getCellStringValue(row, currentCell);
final Short statusId = statusToShort(status);
currentCell = XlsImportConstants.LOAN_OFFICER_CELL;
final String loanOfficer = getCellStringValue(row, currentCell);
if (!StringUtils.isBlank(groupGlobalNum) && !StringUtils.isBlank(loanOfficer)) {
throw new CellException(getMessage(XlsMessageConstants.LOAN_OFFICER_FOR_GROUP_CLIENT));
}
currentCell = XlsImportConstants.ACTIVATION_DATE_CELL;
final LocalDate activationDate = DateUtils.getLocalDateFromDate(getCellDateValue(row, currentCell));
if (activationDate != null && !status.equals(getMessage(XlsMessageConstants.ACTIVE))) {
throw new CellException(getMessage(XlsMessageConstants.ACTIVE_STATUS_FOR_ACTIVATION_DATE));
}
/* Meeting data */
currentCell = XlsImportConstants.MEETING_FREQUENCY_CELL;
final Integer recurrenceType = getRecurrenceType(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_RECUR_EVERY_WEEK_CELL;
final Integer recurEveryWeek = getCellIntegerValue(row, currentCell);
currentCell = XlsImportConstants.MEETING_ON_WEEK_CELL;
final Integer weeklyMeetingDay = getDayValue(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_OPT1_DAY_CELL;
final Integer opt1Day = getCellIntegerValue(row, currentCell);
validateMonthDay(opt1Day);
currentCell = XlsImportConstants.MEETING_OPT1_EVERY_CELL;
final Integer opt1Every = getCellIntegerValue(row, currentCell);
validatePositive(opt1Every);
currentCell = XlsImportConstants.MEETING_OPT2_THE_CELL;
final Integer opt2The = getDayRankValue(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_OPT2_DAY_CELL;
final Integer opt2Day = getDayValue(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_OPT2_EVERY_CELL;
final Integer opt2Every = getCellIntegerValue(row, currentCell);
validatePositive(opt2Every);
currentCell = XlsImportConstants.MEETING_LOCATION_CELL;
final String meetingLocation = getCellStringValue(row, currentCell);
Integer recurrenceDayNumber = 0;
Integer recurrenceWeekOfMonth = 0;
Integer recurrenceDayOfWeek = 0;
Integer recurEvery = 0;
/*
* Validate meeting data
*/
if (!StringUtils.isBlank(groupGlobalNum) && recurrenceType != null) {
// no meeting allowed for a group
throw new RowException(getMessage(XlsMessageConstants.MEETING_FOR_GROUP));
} else if (recurrenceType == null) {
// make sure everything is empty
if (recurEveryWeek != null || weeklyMeetingDay != null || opt1Day != null || opt1Every != null || opt2Day != null || opt2Every != null || opt2The != null || !StringUtils.isBlank(meetingLocation)) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
} else if (recurrenceType == RecurrenceType.WEEKLY.getValue().intValue()) {
// make sure weekly data is set
if (recurEveryWeek == null || weeklyMeetingDay == null) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
// make sure monthly details are empty
if (opt1Day != null || opt1Every != null || opt2Day != null || opt2Every != null || opt2The != null) {
throw new RowException(getMessage(XlsMessageConstants.MONTHLY_MEETING_DETAILS_NOT_EMPTY));
}
// set data
recurrenceDayOfWeek = weeklyMeetingDay;
recurEvery = recurEveryWeek;
// validate location
validateMandatoryField(meetingLocation);
} else {
// make sure weekly details are empty
if (recurEveryWeek != null || weeklyMeetingDay != null) {
throw new RowException(getMessage(XlsMessageConstants.WEEKLY_MEETING_DETAILS_NOT_EMPTY));
}
if (opt1Day == null) {
// make sure option 2 is set
if (opt2Day == null || opt2Every == null || opt2The == null) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
// make sure option 1 is empty
if (opt1Every != null) {
throw new RowException(getMessage(XlsMessageConstants.OPTIONS_EXCLUSIVE));
}
// set data
recurrenceWeekOfMonth = opt2The;
recurrenceDayOfWeek = opt2Day;
recurEvery = opt2Every;
} else {
// make sure option 1 is set
if (opt1Every == null) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
// make sure option 2 is empty
if (opt2Day != null || opt2Every != null || opt2The != null) {
throw new RowException(getMessage(XlsMessageConstants.OPTIONS_EXCLUSIVE));
}
// set data
recurrenceDayNumber = opt1Day;
recurEvery = opt1Every;
}
// validate location
validateMandatoryField(meetingLocation);
}
/*
* Create meeting data
*/
MeetingDto meetingDto = null;
if (recurrenceType != null) {
final LocalDate meetingStartDate = new LocalDate();
final MeetingRecurrenceDto meetingRecurrenceDto = new MeetingRecurrenceDto(recurrenceDayNumber, recurrenceWeekOfMonth, recurrenceDayOfWeek);
final MeetingDetailsDto meetingDetailsDto = new MeetingDetailsDto(recurrenceType, null, recurEvery, meetingRecurrenceDto);
final MeetingTypeDto meetingTypeDto = new MeetingTypeDto(MeetingType.CUSTOMER_MEETING.getValue().intValue(), null, null);
meetingDto = new MeetingDto(meetingStartDate, meetingLocation, meetingTypeDto, meetingDetailsDto);
} else {
}
String clientName = buildName(clientFirstName, clientMiddleName, clientLastName, clientSecondLastName);
customerDao.validateClientForDuplicateNameOrGovtId(clientName, dateOfBirth, governmentId);
/* Create dto's */
/* address */
final Address addressObject = new Address(address, null, null, cityDistrict, state, country, postalCode, telephone);
final AddressDto addressDto = Address.toDto(addressObject);
/* Personal details */
final ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(CLIENT_NAME_TYPE, salutationId, clientFirstName, clientMiddleName, clientLastName, clientSecondLastName);
final ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(ethinicityId, citizenshipId, handicappedId, activityId, maritalStatusId, educationLevelId, numberOfChildren, genderId, povertyStatusId);
/* Spouse details */
ClientNameDetailDto spouseNameDetailDto = null;
if (spouseFatherNameType == null) {
spouseNameDetailDto = new ClientNameDetailDto();
spouseNameDetailDto.setFirstName("");
spouseNameDetailDto.setLastName("");
} else {
spouseNameDetailDto = new ClientNameDetailDto(spouseFatherNameType, null, spouseFirstName, spouseMiddleName, spouseLastName, spouseSecondLastName);
}
/* branch office */
Short officeId = 0;
Short loanOfficerId = null;
Short groupFlagValue = 1;
if (StringUtils.isBlank(groupGlobalNum)) {
if (statusId == CustomerStatus.CLIENT_ACTIVE.getValue() && meetingDto == null) {
String error = getRowError(friendlyRowNumber) + getMessage(XlsMessageConstants.NO_MEETING_ERROR);
errorsList.add(error);
continue;
}
groupFlagValue = 0;
officeId = branchOfficeId;
List<PersonnelBO> officers = legacyPersonnelDao.getActiveLoanOfficersUnderOffice(officeId);
if (officers.isEmpty()) {
String error = getCellError(friendlyRowNumber, XlsImportConstants.BRANCH_SHORT_NAME_CELL) + getMessage(XlsMessageConstants.NO_OFFICERS_ERROR, branchShortName);
errorsList.add(error);
continue;
}
loanOfficerId = null;
for (PersonnelBO officer : officers) {
if (officer.getDisplayName().equals(loanOfficer)) {
loanOfficerId = officer.getPersonnelId();
break;
}
}
} else {
validateGroupStatus(groupGlobalNum, statusId);
}
/* Not imported values */
final boolean trained = false;
final Date trainedDate = null;
final java.sql.Date mfiJoiningDate = null;
final String externalId = "";
final InputStream picture = null;
final List<ApplicableAccountFeeDto> feesToApply = null;
final List<ClientNameDetailDto> familyNames = null;
final List<ClientFamilyDetailDto> familyDetails = null;
final List<Short> selectedSavingsProducts = null;
/* Final dto */
final ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingsProducts, clientName, statusId, mfiJoiningDate, externalId, addressDto, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlagValue, clientNameDetailDto, clientPersonalDetailDto, spouseNameDetailDto, picture, feesToApply, groupGlobalNum, familyNames, familyDetails, loanOfficerId, officeId, activationDate);
validateDuplicateCustomers(clientCreationDetail, parsedClientDetails);
final ImportedClientDetail importedClientDetail = new ImportedClientDetail(clientCreationDetail, clientGlobalNum, meetingDto);
parsedClientDetails.add(importedClientDetail);
} catch (RowException ex) {
final String error = getRowError(friendlyRowNumber) + ex.getMessage();
errorsList.add(error);
} catch (CustomerException ex) {
final String error = getRowError(friendlyRowNumber) + getMessage(XlsMessageConstants.DUPLICATE_CLIENT_ERROR);
errorsList.add(error);
} catch (Exception ex) {
final String error = getCellError(friendlyRowNumber, currentCell) + ex.getMessage();
errorsList.add(error);
}
}
}
} catch (Exception ex) {
errorsList.add(getMessage(XlsMessageConstants.ERROR_READING_DOCUMENT, ex.getMessage()));
}
return new ParsedClientsDto(errorsList, parsedClientDetails);
}
use of org.mifos.dto.domain.ClientCreationDetail in project head by mifos.
the class PictureFormFile method create.
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
ClientCustActionForm actionForm = (ClientCustActionForm) form;
MeetingBO meeting = (MeetingBO) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_MEETING, request);
List<SavingsDetailDto> allowedSavingProducts = getSavingsOfferingsFromSession(request);
if (ClientRules.isFamilyDetailsRequired()) {
actionForm.setFamilyDateOfBirth();
actionForm.constructFamilyDetails();
}
List<Short> selectedSavingProducts = actionForm.getSelectedOfferings();
String clientName = actionForm.getClientName().getDisplayName();
Short clientStatus = actionForm.getStatusValue().getValue();
java.sql.Date mfiJoiningDate = DateUtils.getDateAsSentFromBrowser(actionForm.getMfiJoiningDate());
String externalId = actionForm.getExternalId();
AddressDto address = null;
if (actionForm.getAddress() != null) {
address = Address.toDto(actionForm.getAddress());
}
Short formedBy = actionForm.getFormedByPersonnelValue();
java.sql.Date dateOfBirth = DateUtils.getDateAsSentFromBrowser(actionForm.getDateOfBirth());
String governmentId = actionForm.getGovernmentId();
boolean trained = isTrained(actionForm.getTrainedValue());
java.sql.Date trainedDate = DateUtils.getDateAsSentFromBrowser(actionForm.getTrainedDate());
Short groupFlagValue = actionForm.getGroupFlagValue();
ClientNameDetailDto clientNameDetailDto = actionForm.getClientName();
ClientPersonalDetailDto clientPersonalDetailDto = actionForm.getClientDetailView();
ClientNameDetailDto spouseFatherName = actionForm.getSpouseName();
InputStream picture = actionForm.getCustomerPicture();
String parentGroupId = actionForm.getParentGroupId();
List<ClientNameDetailDto> familyNames = actionForm.getFamilyNames();
List<ClientFamilyDetailDto> familyDetails = actionForm.getFamilyDetails();
Short loanOfficerId = actionForm.getLoanOfficerIdValue();
Short officeId = actionForm.getOfficeIdValue();
// only applies when status is active
LocalDate activationDateAsToday = new LocalDate();
ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingProducts, clientName, clientStatus, mfiJoiningDate, externalId, address, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlagValue, clientNameDetailDto, clientPersonalDetailDto, spouseFatherName, picture, actionForm.getFeesToApply(), parentGroupId, familyNames, familyDetails, loanOfficerId, officeId, activationDateAsToday);
MeetingDto meetingDto = null;
if (meeting != null) {
meetingDto = meeting.toDto();
}
CustomerDetailsDto clientDetails = this.clientServiceFacade.createNewClient(clientCreationDetail, meetingDto, allowedSavingProducts);
List<FormFile> formFiles = actionForm.getFiles();
List<UploadedFileDto> filesMetadata = actionForm.getFilesMetadata();
for (int i = 0; i < formFiles.size(); i++) {
if (formFiles.get(i).getFileSize() != 0) {
InputStream inputStream = formFiles.get(i).getInputStream();
UploadedFileDto fileMetadata = filesMetadata.get(i);
clientServiceFacade.uploadFile(clientDetails.getId(), inputStream, fileMetadata);
}
}
actionForm.setCustomerId(clientDetails.getId().toString());
actionForm.setGlobalCustNum(clientDetails.getGlobalCustNum());
actionForm.setEditFamily("notEdit");
createClientQuestionnaire.saveResponses(request, actionForm, clientDetails.getId());
return mapping.findForward(ActionForwards.create_success.toString());
}
use of org.mifos.dto.domain.ClientCreationDetail in project head by mifos.
the class GroupServiceFacadeWebTierIntegrationTest method createClient.
private CustomerDetailsDto createClient(String parentGroupId) {
MeetingBO meeting = new MeetingBuilder().withStartDate(new DateTime().minusWeeks(2)).build();
MeetingDto meetingDto = meeting.toDto();
String externalId = null;
AddressDto addressDto = new AddressDto("here", "", "", "", "", "", "", "");
PersonnelBO user = IntegrationTestObjectMother.findPersonnelById(Short.valueOf("1"));
Short loanOfficerId = user.getPersonnelId();
List<ApplicableAccountFeeDto> feesToApply = new ArrayList<ApplicableAccountFeeDto>();
CustomerStatus.CLIENT_ACTIVE.getValue();
boolean trained = false;
// setup
Short officeId = branch1.getOfficeId();
DateTime mfiJoiningDate = new DateTime().minusWeeks(2);
DateTime activationDate = new DateTime().minusWeeks(1);
List<Short> selectedSavingProducts = new ArrayList<Short>();
String clientName = "client";
Short formedBy = loanOfficerId;
Date dateOfBirth = new LocalDate(1990, 1, 1).toDateMidnight().toDate();
String governmentId = "";
Date trainedDate = new LocalDate(2000, 1, 1).toDateMidnight().toDate();
;
// not in a group
Short groupFlag = YesNoFlag.YES.getValue();
Integer salutation = 1;
String firstName = "first";
String middleName = null;
String lastName = "last";
String secondLastName = null;
ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), salutation, firstName, middleName, lastName, secondLastName);
// magic numbers from default data
Integer ethnicity = 218;
Integer citizenship = 130;
Integer handicapped = 138;
Integer businessActivities = 225;
Integer educationLevel = 226;
Short numChildren = 0;
Short gender = 49;
Short povertyStatus = 41;
Integer maritalStatus = ClientPersonalDetailDto.MARRIED;
// active
Short clientStatus = 3;
ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(ethnicity, citizenship, handicapped, businessActivities, maritalStatus, educationLevel, numChildren, gender, povertyStatus);
ClientNameDetailDto spouseFatherName = new ClientNameDetailDto(NameType.SPOUSE.getValue(), salutation, firstName, middleName, lastName, secondLastName);
InputStream picture = null;
List<ClientNameDetailDto> familyNames = null;
List<ClientFamilyDetailDto> familyDetails = null;
ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingProducts, clientName, clientStatus, mfiJoiningDate.toDate(), externalId, addressDto, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlag, clientNameDetailDto, clientPersonalDetailDto, spouseFatherName, picture, feesToApply, parentGroupId, familyNames, familyDetails, loanOfficerId, officeId, activationDate.toLocalDate());
// exercise test
List<SavingsDetailDto> allowedSavingProducts = new ArrayList<SavingsDetailDto>();
CustomerDetailsDto newlyCreatedCustomerDetails = clientServiceFacade.createNewClient(clientCreationDetail, meetingDto, allowedSavingProducts);
return newlyCreatedCustomerDetails;
}
use of org.mifos.dto.domain.ClientCreationDetail in project head by mifos.
the class ClientServiceFacadeWebTierIntegrationTest method shouldCreateGroupWithExpectedSearchId.
@Test
public void shouldCreateGroupWithExpectedSearchId() {
// setup
boolean centerHierarchyExistsOriginal = ClientRules.getCenterHierarchyExists();
MeetingBO meeting = new MeetingBuilder().withStartDate(new DateTime().minusWeeks(2)).build();
MeetingDto meetingDto = meeting.toDto();
String externalId = null;
AddressDto addressDto = new AddressDto("here", "", "", "", "", "", "", "");
PersonnelBO user = IntegrationTestObjectMother.findPersonnelById(Short.valueOf("1"));
Short loanOfficerId = user.getPersonnelId();
List<ApplicableAccountFeeDto> feesToApply = new ArrayList<ApplicableAccountFeeDto>();
CustomerStatus.CLIENT_ACTIVE.getValue();
boolean trained = false;
OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
// setup
createOfficeHierarchyUnderHeadOffice(headOffice);
Short officeId = branch1.getOfficeId();
DateTime mfiJoiningDate = new DateTime().minusWeeks(2);
DateTime activationDate = new DateTime().minusWeeks(1);
List<Short> selectedSavingProducts = new ArrayList<Short>();
String clientName = "client";
Short formedBy = loanOfficerId;
Date dateOfBirth = new LocalDate(1990, 1, 1).toDateMidnight().toDate();
String governmentId = "";
Date trainedDate = new LocalDate(2000, 1, 1).toDateMidnight().toDate();
;
// not in a group
Short groupFlag = YesNoFlag.NO.getValue();
Integer salutation = 1;
String firstName = "first";
String middleName = null;
String lastName = "last";
String secondLastName = null;
ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), salutation, firstName, middleName, lastName, secondLastName);
// magic numbers from default data
Integer ethnicity = 218;
Integer citizenship = 130;
Integer handicapped = 138;
Integer businessActivities = 225;
Integer educationLevel = 226;
Short numChildren = 0;
Short gender = 49;
Short povertyStatus = 41;
Integer maritalStatus = ClientPersonalDetailDto.MARRIED;
// active
Short clientStatus = 3;
ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(ethnicity, citizenship, handicapped, businessActivities, maritalStatus, educationLevel, numChildren, gender, povertyStatus);
ClientNameDetailDto spouseFatherName = new ClientNameDetailDto(NameType.SPOUSE.getValue(), salutation, firstName, middleName, lastName, secondLastName);
InputStream picture = null;
String parentGroupId = null;
List<ClientNameDetailDto> familyNames = null;
List<ClientFamilyDetailDto> familyDetails = null;
ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingProducts, clientName, clientStatus, mfiJoiningDate.toDate(), externalId, addressDto, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlag, clientNameDetailDto, clientPersonalDetailDto, spouseFatherName, picture, feesToApply, parentGroupId, familyNames, familyDetails, loanOfficerId, officeId, activationDate.toLocalDate());
// exercise test
ClientRules.setCenterHierarchyExists(false);
List<SavingsDetailDto> allowedSavingProducts = new ArrayList<SavingsDetailDto>();
CustomerDetailsDto newlyCreatedCustomerDetails = clientServiceFacade.createNewClient(clientCreationDetail, meetingDto, allowedSavingProducts);
// verification
ClientRules.setCenterHierarchyExists(centerHierarchyExistsOriginal);
ClientBO client = customerDao.findClientBySystemId(newlyCreatedCustomerDetails.getGlobalCustNum());
Assert.assertThat(client.getSearchId(), is("1." + client.getCustomerId()));
}
Aggregations