finish off remaining user admin functionality through API, removing client proxy work.

This commit is contained in:
Keith Woodlock
2012-05-15 01:16:57 +01:00
parent 81e04b66d2
commit e96d623a46
27 changed files with 872 additions and 1056 deletions
@@ -13,14 +13,12 @@ import org.mifosng.data.LoanSchedule;
import org.mifosng.data.NewLoanWorkflowStepOneData;
import org.mifosng.data.NoteData;
import org.mifosng.data.PermissionData;
import org.mifosng.data.RoleData;
import org.mifosng.data.command.AdjustLoanTransactionCommand;
import org.mifosng.data.command.CalculateLoanScheduleCommand;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand;
import org.mifosng.data.command.UndoLoanApprovalCommand;
import org.mifosng.data.command.UndoLoanDisbursalCommand;
@@ -33,20 +31,10 @@ public interface CommonRestOperations {
void updateProtectedResource(ProtectedResourceDetails loadProtectedResourceDetailsById);
Collection<RoleData> retrieveAllRoles();
RoleData retrieveRole(Long roleId);
RoleData retrieveNewRoleDetails();
EntityIdentifier updateRole(RoleCommand command);
Collection<PermissionData> retrieveAllPermissions();
Collection<EnumOptionReadModel> retrieveAllPermissionGroups();
EntityIdentifier createRole(RoleCommand command);
Collection<ClientData> retrieveAllIndividualClients();
Collection<LoanProductData> retrieveAllLoanProducts();
@@ -24,15 +24,12 @@ import org.mifosng.data.NoteData;
import org.mifosng.data.NoteDataList;
import org.mifosng.data.PermissionData;
import org.mifosng.data.PermissionList;
import org.mifosng.data.RoleData;
import org.mifosng.data.RoleList;
import org.mifosng.data.command.AdjustLoanTransactionCommand;
import org.mifosng.data.command.CalculateLoanScheduleCommand;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand;
import org.mifosng.data.command.UndoLoanApprovalCommand;
import org.mifosng.data.command.UndoLoanDisbursalCommand;
@@ -556,92 +553,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
return requestEntity;
}
private HttpEntity<RoleCommand> roleRequest(final RoleCommand command) {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("Accept", "application/xml");
requestHeaders.set("Content-Type", "application/xml");
HttpEntity<RoleCommand> requestEntity = new HttpEntity<RoleCommand>(
command, requestHeaders);
return requestEntity;
}
@Override
public Collection<RoleData> retrieveAllRoles() {
try {
URI restUri = URI.create(getBaseServerUrl().concat(
"api/protected/admin/role/all"));
ResponseEntity<RoleList> s = this.oauthRestServiceTemplate
.exchange(restUri, HttpMethod.GET, emptyRequest(),
RoleList.class);
return s.getBody().getRoles();
} catch (HttpStatusCodeException e) {
ErrorResponseList errorList = parseErrors(e);
throw new ClientValidationException(errorList.getErrors());
}
}
@Override
public RoleData retrieveRole(final Long roleId) {
URI restUri = URI.create(getBaseServerUrl().concat(
"api/protected/admin/role/").concat(roleId.toString()));
ResponseEntity<RoleData> s = this.oauthRestServiceTemplate.exchange(
restUri, HttpMethod.GET, emptyRequest(), RoleData.class);
return s.getBody();
}
@Override
public RoleData retrieveNewRoleDetails() {
URI restUri = URI.create(getBaseServerUrl().concat(
"api/protected/admin/role/new"));
ResponseEntity<RoleData> s = this.oauthRestServiceTemplate.exchange(
restUri, HttpMethod.GET, emptyRequest(), RoleData.class);
return s.getBody();
}
@Override
public EntityIdentifier createRole(final RoleCommand command) {
try {
URI restUri = URI.create(getBaseServerUrl().concat(
"api/protected/admin/role/new"));
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
.postForEntity(restUri, roleRequest(command),
EntityIdentifier.class);
return s.getBody();
} catch (HttpStatusCodeException e) {
ErrorResponseList errorList = parseErrors(e);
throw new ClientValidationException(errorList.getErrors());
}
}
@Override
public EntityIdentifier updateRole(RoleCommand command) {
try {
URI restUri = URI.create(getBaseServerUrl().concat(
"api/protected/admin/role/").concat(
command.getId().toString()));
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
.postForEntity(restUri, roleRequest(command),
EntityIdentifier.class);
return s.getBody();
} catch (HttpStatusCodeException e) {
ErrorResponseList errorList = parseErrors(e);
throw new ClientValidationException(errorList.getErrors());
}
}
@Override
public Collection<PermissionData> retrieveAllPermissions() {
@@ -1,92 +0,0 @@
package org.mifosng.ui.user;
import java.util.Collection;
import javax.servlet.http.HttpServletResponse;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.ErrorResponse;
import org.mifosng.data.PermissionData;
import org.mifosng.data.RoleData;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.ui.CommonRestOperations;
import org.mifosng.ui.loanproduct.ClientValidationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
@Controller
public class AppUserController {
private final CommonRestOperations commonRestOperations;
@Autowired
public AppUserController(final CommonRestOperations commonRestOperations) {
this.commonRestOperations = commonRestOperations;
}
@RequestMapping(consumes="application/json", produces="application/json", value = "/admin/permission/all", method = RequestMethod.GET)
public @ResponseBody Collection<PermissionData> viewAllPermission() {
return this.commonRestOperations.retrieveAllPermissions();
}
@RequestMapping(consumes="application/json", produces="application/json", value = "/admin/role/all", method = RequestMethod.GET)
public @ResponseBody Collection<RoleData> viewAllRoles() {
return this.commonRestOperations.retrieveAllRoles();
}
@RequestMapping(consumes="application/json", produces="application/json", value = "/admin/role/new", method = RequestMethod.GET)
public @ResponseBody RoleData newRoleDetails() {
return this.commonRestOperations.retrieveNewRoleDetails();
}
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/admin/role/new", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody EntityIdentifier createNewRole(@RequestParam(value="selectedItems", required=false) String[] selectedRoles,
@RequestParam(value="name") String name,
@RequestParam(value="description") String description) {
RoleCommand command = new RoleCommand(name, description, selectedRoles);
return this.commonRestOperations.createRole(command);
}
@RequestMapping(consumes = "application/json", produces = "application/json", value = "/admin/role/{roleId}", method = RequestMethod.GET)
public @ResponseBody
RoleData retrieveRoleDetails(@PathVariable("roleId") Long roleId) {
return this.commonRestOperations.retrieveRole(roleId);
}
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/admin/role/{roleId}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody EntityIdentifier updateRole(@PathVariable("roleId") Long roleId,
@RequestParam(value="selectedItems", required=false) String[] selectedRoles,
@RequestParam(value="name") String name,
@RequestParam(value="description") String description) {
RoleCommand command = new RoleCommand(name, description, selectedRoles);
command.setId(roleId);
return this.commonRestOperations.updateRole(command);
}
@ExceptionHandler(ClientValidationException.class)
public @ResponseBody Collection<ErrorResponse> validationException(ClientValidationException ex, HttpServletResponse response) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.setContentType("application/json");
return ex.getValidationErrors();
}
}