filtering permissions/roles (not working yet)
This commit is contained in:
@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import org.codehaus.jackson.map.annotate.JsonFilter;
|
||||
|
||||
@XmlRootElement(name = "permission")
|
||||
@JsonFilter("myFilter")
|
||||
@JsonFilter("permissionFilter")
|
||||
public class PermissionData implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
@@ -5,7 +5,10 @@ import java.util.Collection;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.codehaus.jackson.map.annotate.JsonFilter;
|
||||
|
||||
@XmlRootElement(name = "role")
|
||||
@JsonFilter("roleFilter")
|
||||
public class RoleData {
|
||||
|
||||
private Long id;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.mifosng.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class RoleList {
|
||||
|
||||
private Collection<RoleData> roles = new ArrayList<RoleData>();
|
||||
|
||||
protected RoleList() {
|
||||
//
|
||||
}
|
||||
|
||||
public RoleList(final Collection<RoleData> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public Collection<RoleData> getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public void setRoles(final Collection<RoleData> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -45,6 +45,7 @@ public class AdditionalFieldsApiResource {
|
||||
.getLogger(AdditionalFieldsApiResource.class);
|
||||
|
||||
private String allowedFieldList = "";
|
||||
private String filterName = "myFilter";
|
||||
|
||||
@Autowired
|
||||
private ReadExtraDataAndReportingService readExtraDataAndReportingService;
|
||||
@@ -62,7 +63,7 @@ public class AdditionalFieldsApiResource {
|
||||
.retrieveExtraDatasetNames(type);
|
||||
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(result,
|
||||
return this.jsonFormattingService.convertRequest(result, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@@ -79,7 +80,8 @@ public class AdditionalFieldsApiResource {
|
||||
.retrieveExtraData(type, set, id);
|
||||
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(result,
|
||||
//Note that GenericResultSet doesn't have a filter so all fields are returned (this is correct)
|
||||
return this.jsonFormattingService.convertRequest(result, filterName,
|
||||
allowedFieldList, selectedFields,
|
||||
uriInfo.getQueryParameters());
|
||||
} catch (InvalidSqlException e) {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class LoanProductApiResource {
|
||||
|
||||
private String defaultFieldList = "principalMoney,inArrearsTolerance,amortizationMethod,interestMethod,repaymentPeriodFrequency,interestRatePeriod,interestRateCalculatedInPeriod,repaidEvery,numberOfRepayments,interestRatePerPeriod,annualInterestRate,numberOfInterestFreePeriods,flexible,interestRebateAllowed";
|
||||
private String allowedFieldList = "possibleCurrencies,possibleAmortizationOptions,possibleInterestOptions,possibleInterestRateCalculatedInPeriodOptions,repaymentFrequencyOptions,interestFrequencyOptions";
|
||||
private String filterName = "myFilter";
|
||||
|
||||
@Autowired
|
||||
private LoanProductReadPlatformService loanProductReadPlatformService;
|
||||
@@ -67,7 +68,7 @@ public class LoanProductApiResource {
|
||||
.retrieveAllLoanProducts();
|
||||
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(products,
|
||||
return this.jsonFormattingService.convertRequest(products, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@@ -87,7 +88,8 @@ public class LoanProductApiResource {
|
||||
|
||||
String selectedFields = defaultFieldList + "," + allowedFieldList;
|
||||
return this.jsonFormattingService.convertRequest(loanProduct,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
filterName, allowedFieldList, selectedFields,
|
||||
uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -103,7 +105,8 @@ public class LoanProductApiResource {
|
||||
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(loanProduct,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
filterName, allowedFieldList, selectedFields,
|
||||
uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@PUT
|
||||
|
||||
@@ -34,6 +34,7 @@ public class OfficeApiResource {
|
||||
|
||||
private String defaultFieldList = "openingDate";
|
||||
private String allowedFieldList = "allowedParents";
|
||||
private String filterName = "myFilter";
|
||||
|
||||
@Autowired
|
||||
private OfficeReadPlatformService readPlatformService;
|
||||
@@ -55,7 +56,7 @@ public class OfficeApiResource {
|
||||
Collection<OfficeData> offices = this.readPlatformService
|
||||
.retrieveAllOffices();
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(offices,
|
||||
return this.jsonFormattingService.convertRequest(offices, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@@ -70,7 +71,8 @@ public class OfficeApiResource {
|
||||
|
||||
String selectedFields = defaultFieldList + "," + allowedFieldList;
|
||||
return this.jsonFormattingService.convertRequest(officeData,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
filterName, allowedFieldList, selectedFields,
|
||||
uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -102,7 +104,7 @@ public class OfficeApiResource {
|
||||
}
|
||||
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(office,
|
||||
return this.jsonFormattingService.convertRequest(office, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class PermissionApiResource {
|
||||
private String allowedFieldList = "";
|
||||
|
||||
private String filterName = "permissionFilter";
|
||||
|
||||
@Autowired
|
||||
private PermissionReadPlatformService permissionReadPlatformService;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class PermissionApiResource {
|
||||
|
||||
//TODO - setting selectedFields just to not show org_id, can be set be to "" after org_id is removed
|
||||
String selectedFields = "id,name,description,code,groupType";
|
||||
return this.jsonFormattingService.convertRequest(permissions,
|
||||
return this.jsonFormattingService.convertRequest(permissions, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,17 @@ import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.PermissionData;
|
||||
import org.mifosng.data.RoleData;
|
||||
import org.mifosng.data.RoleList;
|
||||
import org.mifosng.data.command.RoleCommand;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
||||
import org.mifosng.platform.user.service.PermissionReadPlatformService;
|
||||
import org.mifosng.platform.user.service.RoleReadPlatformService;
|
||||
import org.mifosng.platform.user.service.RoleWritePlatformService;
|
||||
@@ -28,69 +31,91 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class RoleApiResource {
|
||||
|
||||
@Autowired
|
||||
|
||||
private String allowedFieldList = "availablePermissions";
|
||||
private String filterName = "roleFilter";
|
||||
|
||||
@Autowired
|
||||
private RoleReadPlatformService roleReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private PermissionReadPlatformService permissionReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private PermissionReadPlatformService permissionReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private RoleWritePlatformService roleWritePlatformService;
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response retrieveAllRoles() {
|
||||
@Autowired
|
||||
private ApiJSONFormattingService jsonFormattingService;
|
||||
|
||||
Collection<RoleData> roles = this.roleReadPlatformService.retrieveAllRoles();
|
||||
return Response.ok().entity(new RoleList(roles)).build();
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllRoles(@Context UriInfo uriInfo) {
|
||||
|
||||
Collection<RoleData> roles = this.roleReadPlatformService
|
||||
.retrieveAllRoles();
|
||||
|
||||
String selectedFields = "id,name,description";
|
||||
return this.jsonFormattingService.convertRequest(roles, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response retrieveNewRoleDetails() {
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveNewRoleDetails(@Context UriInfo uriInfo) {
|
||||
|
||||
Collection<PermissionData> allPermissions = this.permissionReadPlatformService
|
||||
.retrieveAllPermissions();
|
||||
|
||||
Collection<PermissionData> allPermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
|
||||
RoleData role = new RoleData();
|
||||
role.setAvailablePermissions(allPermissions);
|
||||
|
||||
return Response.ok().entity(role).build();
|
||||
String selectedFields = "allowedFieldList";
|
||||
return this.jsonFormattingService.convertRequest(role, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response createRole(final RoleCommand command) {
|
||||
|
||||
Long roleId = this.roleWritePlatformService.createRole(command);
|
||||
return Response.ok().entity(new EntityIdentifier(roleId)).build();
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{roleId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response retrieveRole(@PathParam("roleId") final Long roleId) {
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveRole(@PathParam("roleId") final Long roleId,
|
||||
@QueryParam("template") String template, @Context UriInfo uriInfo) {
|
||||
|
||||
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||
|
||||
Collection<PermissionData> availablePermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
availablePermissions.removeAll(role.getSelectedPermissions());
|
||||
role.setAvailablePermissions(availablePermissions);
|
||||
|
||||
return Response.ok().entity(role).build();
|
||||
if (template != null && template.equalsIgnoreCase("true")) {
|
||||
Collection<PermissionData> availablePermissions = this.permissionReadPlatformService
|
||||
.retrieveAllPermissions();
|
||||
availablePermissions.removeAll(role.getSelectedPermissions());
|
||||
role.setAvailablePermissions(availablePermissions);
|
||||
}
|
||||
|
||||
// TODO - setting selectedFields just to not show org_id, can be set be
|
||||
// to "" after org_id is removed
|
||||
String selectedFields = "id,name,description,selectedPermissions";
|
||||
return this.jsonFormattingService.convertRequest(role, filterName,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{roleId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response updateRole(@PathParam("roleId") final Long roleId, final RoleCommand command) {
|
||||
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response updateRole(@PathParam("roleId") final Long roleId,
|
||||
final RoleCommand command) {
|
||||
|
||||
command.setId(roleId);
|
||||
this.roleWritePlatformService.updateRole(command);
|
||||
return Response.ok().entity(new EntityIdentifier(roleId)).build();
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
public interface ApiJSONFormattingService {
|
||||
|
||||
String convertRequest(Object dataObject, String allowedFieldList,
|
||||
String convertRequest(Object dataObject, String filterName, String allowedFieldList,
|
||||
String selectedFields, MultivaluedMap<String, String> queryParams);
|
||||
|
||||
}
|
||||
|
||||
+18
-10
@@ -14,15 +14,21 @@ import org.codehaus.jackson.map.ObjectWriter;
|
||||
import org.codehaus.jackson.map.ser.FilterProvider;
|
||||
import org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter;
|
||||
import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider;
|
||||
import org.mifosng.platform.api.ReportingApiResource;
|
||||
import org.mifosng.platform.exceptions.PlatformInternalServerException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ApiJSONFormattingServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public String convertRequest(Object dataObject, String allowedFieldList,
|
||||
String selectedFields, MultivaluedMap<String, String> queryParams) {
|
||||
public String convertRequest(Object dataObject, String filterName,
|
||||
String allowedFieldList, String selectedFields,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
|
||||
String filterType = "E";
|
||||
String fieldList = "";
|
||||
@@ -52,10 +58,12 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
if (first) {
|
||||
fieldList = paramField;
|
||||
first = false;
|
||||
} else
|
||||
} else {
|
||||
fieldList += "," + paramField;
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("passed fields and is selected fields - Fieldlist: " + fieldList);
|
||||
|
||||
}
|
||||
} else {
|
||||
@@ -72,16 +80,16 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
fieldList = allowedFieldList;
|
||||
}
|
||||
|
||||
return convertDataObjectJSON(dataObject, filterType, fieldList,
|
||||
isTrue(queryParams.getFirst("pretty")));
|
||||
return convertDataObjectJSON(dataObject, filterName, filterType,
|
||||
fieldList, isTrue(queryParams.getFirst("pretty")));
|
||||
}
|
||||
|
||||
private String convertDataObjectJSON(Object dataObject, String filterType,
|
||||
String fields, boolean prettyOutput) {
|
||||
private String convertDataObjectJSON(Object dataObject, String filterName,
|
||||
String filterType, String fields, boolean prettyOutput) {
|
||||
|
||||
try {
|
||||
String json = "";
|
||||
String myFilter = "myFilter";
|
||||
// String myFilter = "myFilter";
|
||||
FilterProvider filters = null;
|
||||
Set<String> filterFields = new HashSet<String>();
|
||||
|
||||
@@ -91,12 +99,12 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
}
|
||||
|
||||
if (filterType.equals("I")) {
|
||||
filters = new SimpleFilterProvider().addFilter(myFilter,
|
||||
filters = new SimpleFilterProvider().addFilter(filterName,
|
||||
SimpleBeanPropertyFilter
|
||||
.filterOutAllExcept(filterFields));
|
||||
|
||||
} else {
|
||||
filters = new SimpleFilterProvider().addFilter(myFilter,
|
||||
filters = new SimpleFilterProvider().addFilter(filterName,
|
||||
SimpleBeanPropertyFilter
|
||||
.serializeAllExcept(filterFields));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user