use of org.mifos.customers.group.BasicGroupInfo in project head by mifos.
the class CustomerPersistenceIntegrationTest method testGetAllBasicGroupInfo.
@Test
public void testGetAllBasicGroupInfo() throws Exception {
CustomerPersistence customerPersistence = new CustomerPersistence();
center = createCenter("new_center");
group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
GroupBO newGroup = TestObjectFactory.createWeeklyFeeGroupUnderCenter("newGroup", CustomerStatus.GROUP_HOLD, center);
GroupBO newGroup2 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("newGroup2", CustomerStatus.GROUP_CANCELLED, center);
GroupBO newGroup3 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("newGroup3", CustomerStatus.GROUP_CLOSED, center);
GroupBO newGroup4 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("newGroup4", CustomerStatus.GROUP_PARTIAL, center);
GroupBO newGroup5 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("newGroup5", CustomerStatus.GROUP_PENDING, center);
List<BasicGroupInfo> groupInfos = customerPersistence.getAllBasicGroupInfo();
Assert.assertEquals(2, groupInfos.size());
Assert.assertEquals(group.getDisplayName(), groupInfos.get(0).getGroupName());
Assert.assertEquals(group.getSearchId(), groupInfos.get(0).getSearchId());
Assert.assertEquals(group.getOffice().getOfficeId(), groupInfos.get(0).getBranchId());
Assert.assertEquals(group.getCustomerId(), groupInfos.get(0).getGroupId());
Assert.assertEquals(newGroup.getDisplayName(), groupInfos.get(1).getGroupName());
Assert.assertEquals(newGroup.getSearchId(), groupInfos.get(1).getSearchId());
Assert.assertEquals(newGroup.getOffice().getOfficeId(), groupInfos.get(1).getBranchId());
Assert.assertEquals(newGroup.getCustomerId(), groupInfos.get(1).getGroupId());
// TestObjectFactory.cleanUp(newGroup);
// TestObjectFactory.cleanUp(newGroup2);
// TestObjectFactory.cleanUp(newGroup3);
// TestObjectFactory.cleanUp(newGroup4);
// TestObjectFactory.cleanUp(newGroup5);
}
use of org.mifos.customers.group.BasicGroupInfo in project head by mifos.
the class PortfolioAtRiskHelper method execute.
@Override
public void execute(long timeInMillis) throws BatchJobException {
long time1 = new DateTimeService().getCurrentDateTime().getMillis();
List<BasicGroupInfo> groupInfos = null;
List<String> errorList = new ArrayList<String>();
try {
groupInfos = new CustomerPersistence().getAllBasicGroupInfo();
} catch (Exception e) {
throw new BatchJobException(e);
}
if (groupInfos != null && !groupInfos.isEmpty()) {
int groupCount = groupInfos.size();
getLogger().info("PortfolioAtRisk: got " + groupCount + " groups to process.");
long startTime = new DateTimeService().getCurrentDateTime().getMillis();
int i = 1;
Integer groupId = null;
GroupPersistence groupPersistence = new GroupPersistence();
try {
for (BasicGroupInfo groupInfo : groupInfos) {
groupId = groupInfo.getGroupId();
String searchStr = groupInfo.getSearchId() + ".%";
double portfolioAtRisk = PortfolioAtRiskCalculation.generatePortfolioAtRiskForTask(groupId, groupInfo.getBranchId(), searchStr);
// updated_by and updated_date
if (portfolioAtRisk > -1) {
groupPersistence.updateGroupInfoAndGroupPerformanceHistoryForPortfolioAtRisk(portfolioAtRisk, groupId);
}
if (i % 500 == 0) {
long time = new DateTimeService().getCurrentDateTime().getMillis();
getLogger().info("500 groups updated in " + (time - startTime) + " milliseconds. There are " + (groupCount - i) + " more groups to be updated.");
startTime = time;
}
i++;
}
} catch (Exception e) {
getLogger().error("PortfolioAtRiskHelper execute failed with exception " + e.getClass().getName() + ": " + e.getMessage() + " at group " + groupId.toString(), e);
StaticHibernateUtil.rollbackTransaction();
errorList.add(groupId.toString());
} finally {
StaticHibernateUtil.closeSession();
}
}
long time2 = new DateTimeService().getCurrentDateTime().getMillis();
getLogger().info("PortfolioAtRiskTask ran in " + (time2 - time1) + " milliseconds");
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
}
Aggregations