From 8822ecea5041ac1007a3047cb8a5c53addff1f56 Mon Sep 17 00:00:00 2001 From: Nayan Ambali Date: Tue, 19 Feb 2013 20:32:25 +0530 Subject: [PATCH] New api to get contextMenus list for creating groups at different levels --- .../group/api/GroupsLevelApiResource.java | 66 +++++++++++++++++ .../portfolio/group/domain/Group.java | 2 +- .../portfolio/group/domain/GroupLevel.java | 74 +++++++++++++++++++ .../group/domain/GroupLevelRepository.java | 13 ++++ .../GroupLevelReadPlatformService.java | 16 ++++ .../GroupLevelReadPlatformServiceImpl.java | 33 +++++++++ 6 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsLevelApiResource.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevelRepository.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformService.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformServiceImpl.java diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsLevelApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsLevelApiResource.java new file mode 100644 index 000000000..3dbf8bc19 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsLevelApiResource.java @@ -0,0 +1,66 @@ +/** + * 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.api; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; +import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; +import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.portfolio.group.domain.GroupLevel; +import org.mifosplatform.portfolio.group.service.GroupLevelReadPlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Path("/grouplevels") +@Component +@Scope("singleton") +public class GroupsLevelApiResource { + + private static final Set GROUPLEVEL_DATA_PARAMETERS = new HashSet(Arrays.asList("parentId", "isSuperParent", "levelId", + "levelName", "recursable", "canHaveClients")); + + private final PlatformSecurityContext context; + private final GroupLevelReadPlatformService groupLevelReadPlatformService; + private final ToApiJsonSerializer toApiJsonSerializer; + private final ApiRequestParameterHelper apiRequestParameterHelper; + + @Autowired + public GroupsLevelApiResource(final PlatformSecurityContext context, final GroupLevelReadPlatformService groupLevelReadPlatformService, + final ToApiJsonSerializer toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper) { + this.context = context; + this.groupLevelReadPlatformService = groupLevelReadPlatformService; + this.toApiJsonSerializer = toApiJsonSerializer; + this.apiRequestParameterHelper = apiRequestParameterHelper; + } + + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String retrieveAllGroups(@Context final UriInfo uriInfo) { + + this.context.authenticatedUser().validateHasReadPermission("GROUP"); + + final Collection groupLevel = this.groupLevelReadPlatformService.retrieveAllLevels(); + final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + + return this.toApiJsonSerializer.serialize(settings, groupLevel, GROUPLEVEL_DATA_PARAMETERS); + + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java index 23a2a1871..ad4240df3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java @@ -32,7 +32,7 @@ public class Group extends AbstractPersistable { private Office office; @ManyToOne - @JoinColumn(name = "loan_officer_id", nullable = true) + @JoinColumn(name = "staff_id", nullable = true) private Staff loanOfficer; @Column(name = "name", length = 100, unique = true) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java new file mode 100644 index 000000000..3f7eba7c9 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevel.java @@ -0,0 +1,74 @@ +/** + * 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.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.springframework.data.jpa.domain.AbstractPersistable; + +@Entity +@Table(name = "m_group_level") +public class GroupLevel extends AbstractPersistable { + + @Column(name = "parent_id") + private final Long parentId; + + @Column(name = "is_super_parent", nullable = false) + private final boolean isSuperParent; + + @Column(name = "level_name", nullable = false, length = 100, unique = true) + private final String levelName; + + @Column(name = "recursable", nullable = false) + private boolean recursable = false; + + @Column(name = "can_have_clients", nullable = false) + private boolean canHaveClients = false; + + public GroupLevel() { + + this.parentId = null; + this.isSuperParent = false; + this.levelName = null; + this.recursable = false; + this.canHaveClients = false; + + } + + public GroupLevel(final Long parentId, final boolean isSuperParent, final String levelName, final boolean recursable, + final boolean canHaveClients) { + + this.isSuperParent = isSuperParent; + this.parentId = parentId; + this.levelName = levelName; + this.recursable = recursable; + this.canHaveClients = canHaveClients; + + } + + public Long getParentId() { + return this.parentId; + } + + public boolean getIsSuperParent() { + return this.isSuperParent; + } + + public String getLevelName() { + return this.levelName; + } + + public boolean getRecursable() { + return this.recursable; + } + + public boolean getCanHaveClients() { + return this.canHaveClients; + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevelRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevelRepository.java new file mode 100644 index 000000000..1fcbc2849 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupLevelRepository.java @@ -0,0 +1,13 @@ +/** + * 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.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface GroupLevelRepository extends JpaRepository, JpaSpecificationExecutor { + // no behaviour added +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformService.java new file mode 100644 index 000000000..abdb11e5a --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformService.java @@ -0,0 +1,16 @@ +/** + * 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 java.util.Collection; + +import org.mifosplatform.portfolio.group.domain.GroupLevel; + +public interface GroupLevelReadPlatformService { + + Collection retrieveAllLevels(); + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformServiceImpl.java new file mode 100644 index 000000000..afe331876 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupLevelReadPlatformServiceImpl.java @@ -0,0 +1,33 @@ +/** + * 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 java.util.Collection; + +import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.portfolio.group.domain.GroupLevel; +import org.mifosplatform.portfolio.group.domain.GroupLevelRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class GroupLevelReadPlatformServiceImpl implements GroupLevelReadPlatformService { + + private final PlatformSecurityContext context; + private final GroupLevelRepository groupLevelRepository; + + @Autowired + public GroupLevelReadPlatformServiceImpl(final PlatformSecurityContext context, final GroupLevelRepository groupRepository) { + this.context = context; + this.groupLevelRepository = groupRepository; + } + + @Override + public Collection retrieveAllLevels() { + this.context.authenticatedUser(); + return this.groupLevelRepository.findAll(); + } +}