Groups api for centers/groups

This commit is contained in:
Nayan Ambali
2013-04-10 16:30:10 +05:30
parent 9ee3280b7a
commit efe0379258
20 changed files with 327 additions and 101 deletions
@@ -0,0 +1,7 @@
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'READ_CENTER', 'CENTER', 'READ', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'CREATE_CENTER', 'CENTER', 'CREATE', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'CREATE_CENTER_CHECKER', 'CENTER', 'CREATE', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'UPDATE_CENTER', 'CENTER', 'UPDATE', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'UPDATE_CENTER_CHECKER', 'CENTER', 'UPDATE', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'DELETE_CENTER', 'CENTER', 'DELETE', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'DELETE_CENTER_CHECKER', 'CENTER', 'DELETE', 0);
@@ -476,4 +476,8 @@ public class CommandWrapper {
return this.entityName.equals("COLLECTIONSHEET");
}
public boolean isCenterResource() {
return this.entityName.equalsIgnoreCase("CENTER");
}
}
@@ -853,4 +853,27 @@ public class CommandWrapperBuilder {
this.href = "/groups/" + groupId + "/collectionsheet";
return this;
}
public CommandWrapperBuilder createCenter() {
this.actionName = "CREATE";
this.entityName = "CENTER";
this.href = "/centers/template";
return this;
}
public CommandWrapperBuilder updateCenter(Long centerId) {
this.actionName = "UPDATE";
this.entityName = "CENTER";
this.entityId = centerId;
this.href = "/centers/" + centerId;
return this;
}
public CommandWrapperBuilder deleteCenter(Long centerId) {
this.actionName = "DELETE";
this.entityName = "CENTER";
this.entityId = centerId;
this.href = "/centers/" + centerId;
return this;
}
}
@@ -397,7 +397,16 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}
} else if (wrapper.isCenterResource()) {
if (wrapper.isCreate()) {
handler = applicationContext.getBean("createCenterCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateCenterCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteCenterCommandHandler", NewCommandSourceHandler.class);
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}
} else if (wrapper.isCollectionSheetResource()) {
if (wrapper.isUpdate()) {
@@ -20,6 +20,7 @@ import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetData;
import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetFlatData;
import org.mifosplatform.portfolio.collectionsheet.data.LoanDueData;
import org.mifosplatform.portfolio.group.data.GroupData;
import org.mifosplatform.portfolio.group.data.GroupTypes;
import org.mifosplatform.portfolio.group.exception.GroupNotFoundException;
import org.mifosplatform.portfolio.group.service.GroupReadPlatformServiceImpl;
import org.mifosplatform.portfolio.loanproduct.data.LoanProductData;
@@ -53,7 +54,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe
final String hierarchy = currentUser.getOffice().getHierarchy();
final String officeHierarchy = hierarchy + "%";
final GroupData groupData = this.groupReadPlatformServiceImpl.retrieveGroup(groupId);
final GroupData groupData = this.groupReadPlatformServiceImpl.retrieveGroup(groupId , GroupTypes.CENTER.getId());
if (groupData == null) { throw new GroupNotFoundException(groupId); }
final String groupHierarchy = groupData.getHierarchy() + "%";
@@ -35,20 +35,21 @@ import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
import org.mifosplatform.portfolio.group.data.GroupData;
import org.mifosplatform.portfolio.group.data.GroupTypes;
import org.mifosplatform.portfolio.group.service.GroupReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Path("/groups")
@Path("/centers")
@Component
@Scope("singleton")
public class CenterApiResource {
public class CentersApiResource {
/*
* GROUP_DATA_PARAMETERS is used by ToApiJsonSerializer<E>, make sure E's properties and E_PARAMETERS are in same
*/
private static final Set<String> GROUP_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "externalId", "officeId",
private static final Set<String> CENTER_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "externalId", "officeId",
"officeName", "staffId", "staffName", "parentId", "parentName", "hierarchy", "groupSummaryData", "groupLevelData",
"clientMembers", "allowedClients", "allowedOffices", "allowedParentGroups", "allowedStaffs", "childGroups"));
@@ -58,9 +59,11 @@ public class CenterApiResource {
private final ToApiJsonSerializer<GroupAccountSummaryCollectionData> groupSummaryToApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private static final Long LEVEL_ID = GroupTypes.CENTER.getId();
@Autowired
public CenterApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService,
public CentersApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService,
final ToApiJsonSerializer<GroupData> toApiJsonSerializer,
final ToApiJsonSerializer<GroupAccountSummaryCollectionData> groupSummaryToApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper,
@@ -76,80 +79,62 @@ public class CenterApiResource {
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllGroups(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
public String retrieveAllCenters(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("officeId") final Long officeId, @QueryParam("externalId") final String externalId,
@QueryParam("name") final String name, @QueryParam("underHierarchy") final String hierarchy,
@QueryParam("levelId") final Long levelId) {
@QueryParam("name") final String name , @QueryParam("underHierarchy") final String hierarchy) {
this.context.authenticatedUser().validateHasReadPermission("GROUP");
this.context.authenticatedUser().validateHasReadPermission("CENTER");
final String extraCriteria = getGroupExtraCriteria(sqlSearch, officeId, externalId, name, hierarchy, levelId);
final Collection<GroupData> groups = this.groupReadPlatformService.retrieveAllGroups(extraCriteria);
final String extraCriteria = getCenterExtraCriteria(sqlSearch, officeId, externalId, name , LEVEL_ID , hierarchy);
final Collection<GroupData> centers = this.groupReadPlatformService.retrieveAllGroups(extraCriteria);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, groups, GROUP_DATA_PARAMETERS);
return this.toApiJsonSerializer.serialize(settings, centers, CENTER_DATA_PARAMETERS);
}
@GET
@Path("{groupId}")
@Path("{centerId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveGroupData(@Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId) {
public String retrieveCenterData(@Context final UriInfo uriInfo, @PathParam("centerId") final Long centerId) {
this.context.authenticatedUser().validateHasReadPermission("GROUP");
this.context.authenticatedUser().validateHasReadPermission("CENTER");
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
final GroupData group = this.groupReadPlatformService.retrieveGroupDetails(groupId, template);
final GroupData group = this.groupReadPlatformService.retrieveGroupDetails(centerId, LEVEL_ID, template);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, group, GROUP_DATA_PARAMETERS);
return this.toApiJsonSerializer.serialize(settings, group, CENTER_DATA_PARAMETERS);
}
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String newGroupDetails(@Context final UriInfo uriInfo, @QueryParam("officeId") final Long officeId,
@QueryParam("levelId") final Long levelId, @QueryParam("parentGroupId") final Long parentGroupId) {
public String newGroupDetails(@Context final UriInfo uriInfo, @QueryParam("officeId") final Long officeId) {
this.context.authenticatedUser().validateHasReadPermission("GROUP");
this.context.authenticatedUser().validateHasReadPermission("CENTER");
GroupData groupTemplateData = null;
if (levelId != null && parentGroupId != null) {
groupTemplateData = this.groupReadPlatformService.retrieveNewChildGroupDetails(officeId, levelId, parentGroupId);
} else if (officeId != null && levelId != null) {
groupTemplateData = this.groupReadPlatformService.retrieveNewGroupDetails(officeId, levelId);
} else if (levelId != null) {
groupTemplateData = this.groupReadPlatformService.retrieveNewGroupDetails(this.context.authenticatedUser().getOffice().getId(),
levelId);
GroupData centerTemplateData = null;
if (officeId != null) {
centerTemplateData = this.groupReadPlatformService.retrieveNewGroupDetails(officeId, LEVEL_ID);
} else {
centerTemplateData = this.groupReadPlatformService.retrieveNewGroupDetails(this.context.authenticatedUser().getOffice().getId(),
LEVEL_ID);
}
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, groupTemplateData, GROUP_DATA_PARAMETERS);
return this.toApiJsonSerializer.serialize(settings, centerTemplateData, CENTER_DATA_PARAMETERS);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String createGroup(final String apiRequestBodyAsJson) {
public String createCenter(final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.createGroup() //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
@POST
@Path("{groupId}/command/unassign_staff")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String unassignLoanOfficer(@PathParam("groupId") final Long groupId, final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.unassignStaff(groupId) //
.createCenter() //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -158,13 +143,13 @@ public class CenterApiResource {
}
@PUT
@Path("{groupId}")
@Path("{centerId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String updateGroup(@PathParam("groupId") final Long groupId, final String apiRequestBodyAsJson) {
public String updateGroup(@PathParam("centerId") final Long centerId, final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.updateGroup(groupId) //
.updateCenter(centerId) //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -172,13 +157,13 @@ public class CenterApiResource {
}
@DELETE
@Path("{groupId}")
@Path("{centerId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String deleteGroup(@PathParam("groupId") final Long groupId) {
public String deleteGroup(@PathParam("centerId") final Long centerId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.deleteGroup(groupId) //
.deleteCenter(centerId) //
.build(); //
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
@@ -206,10 +191,9 @@ public class CenterApiResource {
// 'g.' preffix because of ERROR 1052 (23000): Column 'column_name' in where
// clause is ambiguous
// caused by the same name of columns in m_office and m_group tables
private String getGroupExtraCriteria(String sqlSearch, final Long officeId, final String externalId, final String name,
final String hierarchy, final Long levelId) {
private String getCenterExtraCriteria(String sqlSearch, final Long officeId, final String externalId, final String name , final Long levelId ,final String hierarchy) {
String extraCriteria = "";
String extraCriteria = " and g.level_id = " + LEVEL_ID + " ";
if (sqlSearch != null) {
sqlSearch = sqlSearch.replaceAll(" name ", " g.name ");
@@ -233,10 +217,11 @@ public class CenterApiResource {
extraCriteria += " and g.name like " + ApiParameterHelper.sqlEncodeString(name + "%");
}
if (hierarchy != null) {
extraCriteria += " and o.hierarchy like " + ApiParameterHelper.sqlEncodeString(hierarchy + "%");
}
if (StringUtils.isNotBlank(extraCriteria)) {
extraCriteria = extraCriteria.substring(4);
}
@@ -35,6 +35,7 @@ import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
import org.mifosplatform.portfolio.group.data.GroupData;
import org.mifosplatform.portfolio.group.data.GroupTypes;
import org.mifosplatform.portfolio.group.service.GroupReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -59,7 +60,7 @@ public class GroupsApiResource {
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private static final Long LEVEL_ID = (long) 2;
private static final Long LEVEL_ID = GroupTypes.GROUP.getId();
@Autowired
public GroupsApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService,
@@ -80,11 +81,11 @@ public class GroupsApiResource {
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllGroups(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("officeId") final Long officeId, @QueryParam("externalId") final String externalId,
@QueryParam("name") final String name) {
@QueryParam("name") final String name , @QueryParam("underHierarchy") final String hierarchy) {
this.context.authenticatedUser().validateHasReadPermission("GROUP");
final String extraCriteria = getGroupExtraCriteria(sqlSearch, officeId, externalId, name , LEVEL_ID);
final String extraCriteria = getGroupExtraCriteria(sqlSearch, officeId, externalId, name , LEVEL_ID , hierarchy);
final Collection<GroupData> groups = this.groupReadPlatformService.retrieveAllGroups(extraCriteria);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -100,7 +101,7 @@ public class GroupsApiResource {
this.context.authenticatedUser().validateHasReadPermission("GROUP");
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
final GroupData group = this.groupReadPlatformService.retrieveGroupDetails(groupId, template);
final GroupData group = this.groupReadPlatformService.retrieveGroupDetails(groupId, LEVEL_ID, template);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, group, GROUP_DATA_PARAMETERS);
@@ -208,10 +209,10 @@ public class GroupsApiResource {
// clause is ambiguous
// caused by the same name of columns in m_office and m_group tables
private String getGroupExtraCriteria(String sqlSearch, final Long officeId, final String externalId, final String name,
final Long levelId) {
final Long levelId , final String hierarchy) {
String extraCriteria = "";
if (sqlSearch != null) {
sqlSearch = sqlSearch.replaceAll(" name ", " g.name ");
sqlSearch = sqlSearch.replaceAll("name ", "g.name ");
@@ -234,6 +235,11 @@ public class GroupsApiResource {
extraCriteria += " and g.name like " + ApiParameterHelper.sqlEncodeString(name + "%");
}
if (hierarchy != null) {
extraCriteria += " and o.hierarchy like " + ApiParameterHelper.sqlEncodeString(hierarchy + "%");
}
if (StringUtils.isNotBlank(extraCriteria)) {
extraCriteria = extraCriteria.substring(4);
}
@@ -0,0 +1,72 @@
package org.mifosplatform.portfolio.group.data;
import java.util.HashMap;
import java.util.Map;
public enum GroupTypes {
CENTER(new Long(1), "groupTypes.center", "center"), //
GROUP(new Long(2), "groupTypes.group", "group"), //
INVALID(new Long(99), "lendingStrategy.invalid", "invalid");
private Long id;
private String code;
private String value;
GroupTypes(final Long id, final String code, final String value) {
this.id = id;
this.code = code;
this.value = value;
}
private static final Map<Long, GroupTypes> intToEnumMap = new HashMap<Long, GroupTypes>();
private static long minValue;
private static long maxValue;
static {
int i = 0;
for (final GroupTypes type : GroupTypes.values()) {
if (i == 0) {
minValue = type.id;
}
intToEnumMap.put(type.id, type);
if (minValue >= type.id) {
minValue = type.id;
}
if (maxValue < type.id) {
maxValue = type.id;
}
i = i + 1;
}
}
public static GroupTypes fromInt(final int i) {
final GroupTypes type = intToEnumMap.get(Integer.valueOf(i));
return type;
}
public static long getMinValue() {
return minValue;
}
public static long getMaxValue() {
return maxValue;
}
@Override
public String toString() {
return name().toString();
}
public Long getId() {
return this.id;
}
public String getCode() {
return this.code;
}
public String getValue() {
return this.value;
}
}
@@ -0,0 +1,32 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.portfolio.group.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class CreateCenterCommandHandler implements NewCommandSourceHandler {
private final GroupWritePlatformService groupWritePlatformService;
private static final Long LEVEL_ID = (long) 1;
@Autowired
public CreateCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
this.groupWritePlatformService = groupWritePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.groupWritePlatformService.createGroup(null , LEVEL_ID , command);
}
}
@@ -8,6 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.portfolio.group.data.GroupTypes;
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -17,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
public class CreateGroupCommandHandler implements NewCommandSourceHandler {
private final GroupWritePlatformService groupWritePlatformService;
private static final Long LEVEL_ID = GroupTypes.GROUP.getId();;
@Autowired
public CreateGroupCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
@@ -27,6 +29,7 @@ public class CreateGroupCommandHandler implements NewCommandSourceHandler {
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.groupWritePlatformService.createGroup(command);
final Long centerId = command.longValueOfParameterNamed("centerId");
return this.groupWritePlatformService.createGroup(centerId , LEVEL_ID , command);
}
}
@@ -0,0 +1,31 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.portfolio.group.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class DeleteCenterCommandHandler implements NewCommandSourceHandler {
private final GroupWritePlatformService groupWritePlatformService;
@Autowired
public DeleteCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
this.groupWritePlatformService = groupWritePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.groupWritePlatformService.deleteGroup(command.entityId());
}
}
@@ -0,0 +1,32 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.portfolio.group.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UpdateCenterCommandHandler implements NewCommandSourceHandler {
private final GroupWritePlatformService groupWritePlatformService;
@Autowired
public UpdateCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
this.groupWritePlatformService = groupWritePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.groupWritePlatformService.updateGroup(command.entityId(), command);
}
}
@@ -40,7 +40,7 @@ public final class GroupCommandFromApiJsonDeserializer extends AbstractFromApiJs
* The parameters supported for this command.
*/
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "externalId", "name", "officeId", "staffId",
"parentId", "clientMembers", "childGroups"));
"centerId", "clientMembers", "childGroups"));
private final FromJsonHelper fromApiJsonHelper;
@@ -98,10 +98,10 @@ public final class GroupCommandFromApiJsonDeserializer extends AbstractFromApiJs
* Either OfficeId or ParentId is mandatory to have value
*/
final String parentIdParameterName = "parentId";
if (this.fromApiJsonHelper.parameterExists(parentIdParameterName, element)) {
final Long parentId = this.fromApiJsonHelper.extractLongNamed(parentIdParameterName, element);
baseDataValidator.reset().parameter(parentIdParameterName).value(parentId).notNull().integerGreaterThanZero();
final String centerIdParameterName = "centerId";
if (this.fromApiJsonHelper.parameterExists(centerIdParameterName, element)) {
final Long centerId = this.fromApiJsonHelper.extractLongNamed(centerIdParameterName, element);
baseDataValidator.reset().parameter(centerIdParameterName).value(centerId).notNull().integerGreaterThanZero();
}else{
final String officeIdParameterName = "officeId";
final Long officeId = this.fromApiJsonHelper.extractLongNamed(officeIdParameterName, element);
@@ -20,7 +20,7 @@ public interface GroupReadPlatformService {
Collection<GroupData> retrieveAllGroups(String extraCriteria);
GroupData retrieveGroup(Long groupId);
GroupData retrieveGroup(Long groupId, Long levelId);
GroupData retrieveNewGroupDetails(Long officeId, Long levelId);
@@ -36,7 +36,7 @@ public interface GroupReadPlatformService {
Collection<StaffData> retrieveStaffsbyOfficeId(Long officeId);
GroupData retrieveGroupDetails(Long groupId, boolean template);
GroupData retrieveGroupDetails(Long groupId, Long levelId, boolean template);
Collection<GroupLookup> retrieveChildGroupsbyGroupId(Long groupId);
@@ -51,4 +51,5 @@ public interface GroupReadPlatformService {
StaffData retrieveStaffsbyId(Long staffId);
Long getLevelIdByGroupId(final Long groupId);
}
@@ -72,7 +72,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
final GroupDataMapper rm = new GroupDataMapper();
String sql = "select " + rm.groupSchema() + " where o.hierarchy like ? and g.is_deleted=0";
String sql = "select " + rm.groupSchema() + " where o.hierarchy like ? and g.is_deleted=0 ";
if (StringUtils.isNotBlank(extraCriteria)) {
sql += " and (" + extraCriteria + ")";
@@ -84,14 +84,14 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
}
@Override
public GroupData retrieveGroup(final Long groupId) {
public GroupData retrieveGroup(final Long groupId , final Long levelId) {
try {
this.context.authenticatedUser();
final GroupDataMapper rm = new GroupDataMapper();
final String sql = "select " + rm.groupSchema() + " where g.id = ? and g.is_deleted=0";
final String sql = "select " + rm.groupSchema() + " where g.id = ? and g.is_deleted=0 and g.level_id = " + levelId;
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { groupId });
} catch (final EmptyResultDataAccessException e) {
@@ -207,9 +207,9 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
}
@Override
public GroupData retrieveGroupDetails(final Long groupId, final boolean template) {
public GroupData retrieveGroupDetails(final Long groupId, final Long levelId , final boolean template) {
GroupData group = retrieveGroup(groupId);
GroupData group = retrieveGroup(groupId, levelId);
final Collection<ClientLookup> clientMembers = retrieveClientMembers(groupId);
Collection<ClientLookup> availableClients = null;
Collection<OfficeData> allowedOffices = null;
@@ -467,7 +467,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
this.context.authenticatedUser();
// Check if group exists
retrieveGroup(groupId);
//retrieveGroup(groupId);
final List<GroupAccountSummaryData> pendingApprovalLoans = new ArrayList<GroupAccountSummaryData>();
final List<GroupAccountSummaryData> awaitingDisbursalLoans = new ArrayList<GroupAccountSummaryData>();
@@ -534,7 +534,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
this.context.authenticatedUser();
// Check if group exists
retrieveGroup(groupId);
//retrieveGroup(groupId);
final GroupLoanAccountSummaryDataMapper rm = new GroupLoanAccountSummaryDataMapper();
@@ -0,0 +1,34 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.portfolio.group.service;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.portfolio.group.data.GroupTypes;
public class GroupTypeEnumerations {
public static EnumOptionData groupType(final Integer id) {
return groupType(GroupTypes.fromInt(id));
}
public static EnumOptionData groupType(final GroupTypes type) {
EnumOptionData optionData = null;
switch (type) {
case CENTER:
optionData = new EnumOptionData(type.getId().longValue(), type.getCode(), "Individual loan");
break;
case GROUP:
optionData = new EnumOptionData(type.getId().longValue(), type.getCode(), "Group loan");
break;
default:
optionData = new EnumOptionData(GroupTypes.INVALID.getId().longValue(), GroupTypes.INVALID.getCode() , "Invalid");
break;
}
return optionData;
}
}
@@ -10,7 +10,8 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
public interface GroupWritePlatformService {
CommandProcessingResult createGroup(JsonCommand command);
CommandProcessingResult createGroup(Long parentId, Long levelId,
JsonCommand command);
CommandProcessingResult updateGroup(Long grouptId, JsonCommand command);
@@ -72,9 +72,9 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
@Transactional
@Override
public CommandProcessingResult createGroup(final JsonCommand command) {
public CommandProcessingResult createGroup(final Long parentId , final Long levelId , final JsonCommand command) {
GroupLevel groupLevel = null;
GroupLevel groupLevel = this.groupLevelRepository.findOne(levelId);
try {
this.context.authenticatedUser();
@@ -83,33 +83,16 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
final String name = command.stringValueOfParameterNamed("name");
final String externalId = command.stringValueOfParameterNamed("externalId");
final Long parentId = command.longValueOfParameterNamed("parentId");
Long officeId = null;
Group parentGroup = null;
if (parentId == null) {
/*
* Scenario: Creating parent group [group with highest level]
* In-case of Centre/Groups, parent group with highest level is
* Centre. In-case of Federation/Cluster/SHG, parent group with
* highest level is Federation. In-case of
* Village/Centre/Groups, parent group with highest level is
* Village.
*/
officeId = command.longValueOfParameterNamed("officeId");
groupLevel = this.groupLevelRepository.findBySuperParent(true);
} else {
parentGroup = this.groupRepository.findOne(parentId);
if (parentGroup == null || parentGroup.isDeleted()) { throw new GroupNotFoundException(parentId); }
officeId = parentGroup.getOfficeId();
groupLevel = this.groupLevelRepository.findByParentId(parentGroup.getGroupLevel().getId());
}
final Office groupOffice = this.officeRepository.findOne(officeId);
@@ -27,6 +27,7 @@ import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundExcepti
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
import org.mifosplatform.portfolio.group.data.GroupData;
import org.mifosplatform.portfolio.group.data.GroupTypes;
import org.mifosplatform.portfolio.group.service.GroupReadPlatformService;
import org.mifosplatform.portfolio.loanaccount.data.DisbursementData;
import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData;
@@ -161,7 +162,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
context.authenticatedUser();
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroupDetails(groupId, false);
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroupDetails(groupId , GroupTypes.GROUP.getId() , false);
final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant();
LoanAccountData loanDetails = LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate);
@@ -178,7 +179,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
context.authenticatedUser();
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroup(groupId);
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroup(groupId , GroupTypes.GROUP.getId() );
final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant();
LoanAccountData loanDetails = LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate);
@@ -20,6 +20,7 @@ import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
import org.mifosplatform.portfolio.group.data.GroupData;
import org.mifosplatform.portfolio.group.data.GroupTypes;
import org.mifosplatform.portfolio.group.service.GroupReadPlatformService;
import org.mifosplatform.portfolio.savings.data.SavingsAccountData;
import org.mifosplatform.portfolio.savings.data.SavingsAccountStatusEnumData;
@@ -212,7 +213,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
GroupData group = null;
if (groupId != null) {
group = this.groupReadPlatformService.retrieveGroup(groupId);
group = this.groupReadPlatformService.retrieveGroup(groupId , GroupTypes.GROUP.getId());
}
final Collection<SavingsProductData> productOptions = this.savingsProductReadPlatformService.retrieveAllForLookup();