New api to get contextMenus list for creating groups at different levels
This commit is contained in:
+66
@@ -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<String> GROUPLEVEL_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("parentId", "isSuperParent", "levelId",
|
||||
"levelName", "recursable", "canHaveClients"));
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final GroupLevelReadPlatformService groupLevelReadPlatformService;
|
||||
private final ToApiJsonSerializer<GroupLevel> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
|
||||
@Autowired
|
||||
public GroupsLevelApiResource(final PlatformSecurityContext context, final GroupLevelReadPlatformService groupLevelReadPlatformService,
|
||||
final ToApiJsonSerializer<GroupLevel> 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> groupLevel = this.groupLevelReadPlatformService.retrieveAllLevels();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
return this.toApiJsonSerializer.serialize(settings, groupLevel, GROUPLEVEL_DATA_PARAMETERS);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class Group extends AbstractPersistable<Long> {
|
||||
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)
|
||||
|
||||
+74
@@ -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<Long> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -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<GroupLevel, Long>, JpaSpecificationExecutor<GroupLevel> {
|
||||
// no behaviour added
|
||||
}
|
||||
+16
@@ -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<GroupLevel> retrieveAllLevels();
|
||||
|
||||
}
|
||||
+33
@@ -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<GroupLevel> retrieveAllLevels() {
|
||||
this.context.authenticatedUser();
|
||||
return this.groupLevelRepository.findAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user