Role Functionality with test cases
This commit is contained in:
+34
-33
@@ -10,38 +10,39 @@ import static org.junit.Assert.assertEquals;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ClientStatusChecker {
|
||||
public static void verifyClientIsActive(final HashMap<String,Object> clientStatusHashMap) {
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 300);
|
||||
}
|
||||
|
||||
|
||||
public static void verifyClientClosed(final HashMap<String,Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS CLOSED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 600);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
public static void verifyClientPending(final HashMap<String,Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS PENDING ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 100);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
public static void verifyClientRejected(final HashMap<String,Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS REJECTED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 700);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientActiavted(final HashMap<String,Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS ACTIVATED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 300);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientWithdrawn(final HashMap<String,Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS WITHDRAWN ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 800);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
|
||||
public static void verifyClientIsActive(final HashMap<String, Object> clientStatusHashMap) {
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 300);
|
||||
}
|
||||
|
||||
public static void verifyClientClosed(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS CLOSED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 600);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientPending(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS PENDING ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 100);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientRejected(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS REJECTED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 700);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientActiavted(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS ACTIVATED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 300);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientWithdrawn(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS WITHDRAWN ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 800);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -40,10 +40,10 @@ public class ClientTest {
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientId);
|
||||
|
||||
HashMap<String,Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientIsActive(status);
|
||||
|
||||
HashMap<String,Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
HashMap<String, Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* 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.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
import org.mifosplatform.integrationtests.useradministration.roles.RolesHelper;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class RolesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testCreateRolesStatus() {
|
||||
|
||||
System.out.println("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testDisableRolesStatus() {
|
||||
|
||||
System.out.println("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
System.out.println("--------------------------------- DISABLING ROLE -------------------------------");
|
||||
final Integer disableRoleId = RolesHelper.disableRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(disableRoleId, roleId);
|
||||
role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
assertEquals((Boolean) role.get("disabled"), true);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testEnableRolesStatus() {
|
||||
|
||||
System.out.println("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
System.out.println("--------------------------------- DISABLING ROLE -------------------------------");
|
||||
final Integer disableRoleId = RolesHelper.disableRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(disableRoleId, roleId);
|
||||
role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
assertEquals((Boolean) role.get("disabled"), true);
|
||||
|
||||
System.out.println("--------------------------------- ENABLING ROLE -------------------------------");
|
||||
final Integer enableRoleId = RolesHelper.enableRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(enableRoleId, roleId);
|
||||
role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
assertEquals((Boolean) role.get("disabled"), false);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testDeleteRoleStatus() {
|
||||
|
||||
System.out.println("-------------------------------- CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
System.out.println("--------------------------------- DELETE ROLE -------------------------------");
|
||||
final Integer deleteRoleId = RolesHelper.deleteRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(deleteRoleId, roleId);
|
||||
}
|
||||
}
|
||||
+24
-22
@@ -133,7 +133,7 @@ public class ClientHelper {
|
||||
|
||||
/* Client status is a map.So adding SuppressWarnings */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static HashMap<String,Object> getClientStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
public static HashMap<String, Object> getClientStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String clientId) {
|
||||
return (HashMap<String, Object>) getClient(requestSpec, responseSpec, clientId, "status");
|
||||
}
|
||||
@@ -151,9 +151,9 @@ public class ClientHelper {
|
||||
Integer clientClosureCodeId = (Integer) code.get("id");
|
||||
|
||||
/* Retrieve/Create Code Values for the Code "ClientClosureReason" */
|
||||
HashMap<String,Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientClosureCodeId,this.requestSpec,this.responseSpec);
|
||||
Integer closureReasonId = (Integer)codeValue.get("id");
|
||||
|
||||
HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientClosureCodeId, this.requestSpec, this.responseSpec);
|
||||
Integer closureReasonId = (Integer) codeValue.get("id");
|
||||
|
||||
map.put("closureReasonId", closureReasonId.toString());
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
@@ -180,12 +180,13 @@ public class ClientHelper {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
/* Retrieve Code id for the Code "ClientRejectReason" */
|
||||
String codeName = "ClientRejectReason";
|
||||
HashMap<String,Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||
Integer clientRejectionReasonCodeId = (Integer)code.get("id");
|
||||
|
||||
HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||
Integer clientRejectionReasonCodeId = (Integer) code.get("id");
|
||||
|
||||
/* Retrieve/Create Code Values for the Code "ClientRejectReason" */
|
||||
HashMap<String,Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientRejectionReasonCodeId,this.requestSpec,this.responseSpec);
|
||||
Integer rejectionReasonId = (Integer)codeValue.get("id");
|
||||
HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientRejectionReasonCodeId, this.requestSpec,
|
||||
this.responseSpec);
|
||||
Integer rejectionReasonId = (Integer) codeValue.get("id");
|
||||
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
@@ -212,13 +213,14 @@ public class ClientHelper {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
/* Retrieve Code id for the Code "ClientWithdrawReason" */
|
||||
String codeName = "ClientWithdrawReason";
|
||||
HashMap<String,Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||
Integer clientWithdrawReasonCodeId = (Integer)code.get("id");
|
||||
|
||||
HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||
Integer clientWithdrawReasonCodeId = (Integer) code.get("id");
|
||||
|
||||
/* Retrieve/Create Code Values for the Code "ClientWithdrawReason" */
|
||||
HashMap<String,Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientWithdrawReasonCodeId,this.requestSpec,this.responseSpec);
|
||||
Integer withdrawalReasonId = (Integer)codeValue.get("id");
|
||||
|
||||
HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientWithdrawReasonCodeId, this.requestSpec,
|
||||
this.responseSpec);
|
||||
Integer withdrawalReasonId = (Integer) codeValue.get("id");
|
||||
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("withdrawalDate", CREATED_DATE_PLUS_ONE);
|
||||
@@ -229,27 +231,27 @@ public class ClientHelper {
|
||||
|
||||
}
|
||||
|
||||
public HashMap<String,Object> closeClient(final Integer clientId) {
|
||||
public HashMap<String, Object> closeClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- CLOSE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(CLOSE_CLIENT_COMMAND, clientId), getCloseClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String,Object> reactivateClient(final Integer clientId) {
|
||||
public HashMap<String, Object> reactivateClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- REACTIVATE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(REACTIVATE_CLIENT_COMMAND, clientId), getReactivateClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String,Object> rejectClient(final Integer clientId) {
|
||||
public HashMap<String, Object> rejectClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- REJECT CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(REJECT_CLIENT_COMMAND, clientId), getRejectClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String,Object> activateClient(final Integer clientId) {
|
||||
public HashMap<String, Object> activateClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- ACTIVATE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId), getActivateClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String,Object> withdrawClient(final Integer clientId) {
|
||||
public HashMap<String, Object> withdrawClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- WITHDRAWN CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(WITHDRAW_CLIENT_COMMAND, clientId), getWithdrawClientAsJSON(), clientId);
|
||||
}
|
||||
@@ -258,9 +260,9 @@ public class ClientHelper {
|
||||
return CLIENT_URL + "/" + clientId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private HashMap<String,Object> performClientActions(final String postURLForClient, final String jsonToBeSent, final Integer clientId) {
|
||||
private HashMap<String, Object> performClientActions(final String postURLForClient, final String jsonToBeSent, final Integer clientId) {
|
||||
Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForClient, jsonToBeSent, CommonConstants.RESPONSE_STATUS);
|
||||
HashMap<String,Object> response = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
HashMap<String, Object> response = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
+3
-4
@@ -25,10 +25,9 @@ import com.jayway.restassured.path.json.JsonPath;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
|
||||
/**
|
||||
* Util for RestAssured tests.
|
||||
* This class here in src/integrationTest is copy/pasted to src/test; please keep them in sync.
|
||||
* Util for RestAssured tests. This class here in src/integrationTest is
|
||||
* copy/pasted to src/test; please keep them in sync.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Utils {
|
||||
@@ -116,7 +115,7 @@ public class Utils {
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
|
||||
public static String convertDateToURLFormat(final Calendar dateToBeConvert) {
|
||||
return new SimpleDateFormat("dd MMMMMM yyyy").format(dateToBeConvert.getTime());
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 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.integrationtests.useradministration.roles;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class RolesHelper {
|
||||
|
||||
private static final String CREATE_ROLE_URL = "/mifosng-provider/api/v1/roles?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String ROLE_URL = "/mifosng-provider/api/v1/roles";
|
||||
private static final String DISABLE_ROLE_COMMAND = "disable";
|
||||
private static final String ENABLE_ROLE_COMMAND = "enable";
|
||||
|
||||
public static Integer createRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_ROLE_URL, getTestCreaRoleAsJSON(), "resourceId");
|
||||
}
|
||||
|
||||
public static String getTestCreaRoleAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("name", Utils.randomNameGenerator("Role_Name_", 5));
|
||||
map.put("description", Utils.randomNameGenerator("Role_Description_", 10));
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> getRoleDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer roleId) {
|
||||
final String GET_ROLE_URL = "/mifosng-provider/api/v1/roles/" + roleId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
HashMap<String, Object> role = Utils.performServerGet(requestSpec, responseSpec, GET_ROLE_URL, "");
|
||||
return role;
|
||||
}
|
||||
|
||||
public static Integer disableRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer roleId) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, createRoleOperationURL(DISABLE_ROLE_COMMAND, roleId), "", "resourceId");
|
||||
}
|
||||
|
||||
public static Integer enableRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer roleId) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, createRoleOperationURL(ENABLE_ROLE_COMMAND, roleId), "", "resourceId");
|
||||
}
|
||||
|
||||
public static Integer deleteRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer roleId) {
|
||||
return Utils.performServerDelete(requestSpec, responseSpec, createRoleOperationURL(ENABLE_ROLE_COMMAND, roleId), "resourceId");
|
||||
}
|
||||
|
||||
private static String createRoleOperationURL(final String command, final Integer roleId) {
|
||||
return ROLE_URL + "/" + roleId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
}
|
||||
+18
-3
@@ -967,17 +967,32 @@ public class CommandWrapper {
|
||||
public boolean isInactivateSavingsAccountCharge() {
|
||||
return this.actionName.equalsIgnoreCase("INACTIVATE") && this.entityName.equalsIgnoreCase("SAVINGSACCOUNTCHARGE");
|
||||
}
|
||||
|
||||
|
||||
public boolean isRefundByTransfer() {
|
||||
return this.actionName.equalsIgnoreCase("REFUNDBYTRANSFER");
|
||||
}
|
||||
|
||||
|
||||
public boolean isLoanRefundByCash() {
|
||||
return this.actionName.equalsIgnoreCase("REFUNDBYCASH") && this.entityName.equalsIgnoreCase("LOAN");
|
||||
}
|
||||
|
||||
|
||||
public boolean isUndoLoanRefund() {
|
||||
return this.actionName.equalsIgnoreCase("UNDOREFUND") && this.entityName.equalsIgnoreCase("LOAN");
|
||||
}
|
||||
|
||||
public boolean isDisable() {
|
||||
return isDisableOperation() && this.entityId != null;
|
||||
}
|
||||
|
||||
public boolean isDisableOperation() {
|
||||
return this.actionName.equalsIgnoreCase("DISABLE");
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
return isEnableOperation() && this.entityId != null;
|
||||
}
|
||||
|
||||
public boolean isEnableOperation() {
|
||||
return this.actionName.equalsIgnoreCase("ENABLE");
|
||||
}
|
||||
}
|
||||
+33
-6
@@ -61,7 +61,7 @@ public class CommandWrapperBuilder {
|
||||
this.subentityId = withSubEntityId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder withTellerId(final Long withTellerId) {
|
||||
this.tellerId = withTellerId;
|
||||
return this;
|
||||
@@ -703,7 +703,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/loans/" + loanId + "/transactions/" + transactionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder refundLoanTransactionByCash(final Long loanId) {
|
||||
this.actionName = "REFUNDBYCASH";
|
||||
this.entityName = "LOAN";
|
||||
@@ -2200,7 +2200,7 @@ public class CommandWrapperBuilder {
|
||||
this.json = "{}";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder refundByTransfer() {
|
||||
this.actionName = "REFUNDBYTRANSFER";
|
||||
this.entityName = "ACCOUNTTRANSFER";
|
||||
@@ -2208,7 +2208,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/refundByTransfer";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder createTeller() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "TELLER";
|
||||
@@ -2258,7 +2258,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/tellers/" + tellerId + "/cashiers/" + cashierId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder allocateCashToCashier(final Long tellerId, final Long cashierId) {
|
||||
this.actionName = "ALLOCATECASHTOCASHIER";
|
||||
this.entityName = "TELLER";
|
||||
@@ -2267,7 +2267,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/tellers/" + tellerId + "/cashiers/" + cashierId + "/allocate";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder settleCashFromCashier(final Long tellerId, final Long cashierId) {
|
||||
this.actionName = "SETTLECASHFROMCASHIER";
|
||||
this.entityName = "TELLER";
|
||||
@@ -2277,4 +2277,31 @@ public class CommandWrapperBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder deleteRole(Long roleId) {
|
||||
this.actionName = "DELETE";
|
||||
this.entityName = "ROLE";
|
||||
this.entityId = roleId;
|
||||
this.href = "/roles/" + roleId;
|
||||
this.json = "{}";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder disableRole(Long roleId) {
|
||||
this.actionName = "DISABLE";
|
||||
this.entityName = "ROLE";
|
||||
this.entityId = roleId;
|
||||
this.href = "/roles/" + roleId + "/disbales";
|
||||
this.json = "{}";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder enableRole(Long roleId) {
|
||||
this.actionName = "ENABLE";
|
||||
this.entityName = "ROLE";
|
||||
this.entityId = roleId;
|
||||
this.href = "/roles/" + roleId + "/enable";
|
||||
this.json = "{}";
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -136,6 +136,6 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
|
||||
final AppUser maker = this.context.authenticatedUser();
|
||||
commandSourceInput.markAsRejected(maker, DateTime.now());
|
||||
this.commandSourceRepository.save(commandSourceInput);
|
||||
return makerCheckerId ;
|
||||
return makerCheckerId;
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -221,15 +221,19 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
} else if (wrapper.isPermissionResource()) {
|
||||
handler = this.applicationContext.getBean("updateMakerCheckerPermissionsCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isRoleResource()) {
|
||||
|
||||
if (wrapper.isCreate()) {
|
||||
handler = this.applicationContext.getBean("createRoleCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isUpdate()) {
|
||||
handler = this.applicationContext.getBean("updateRoleCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isDelete()) {
|
||||
handler = this.applicationContext.getBean("deleteRoleCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isDisable()) {
|
||||
handler = this.applicationContext.getBean("disableRoleCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isEnable()) {
|
||||
handler = this.applicationContext.getBean("enableRoleCommandHandler", NewCommandSourceHandler.class);
|
||||
} else {
|
||||
throw new UnsupportedCommandException(wrapper.commandName());
|
||||
}
|
||||
|
||||
} else if (wrapper.isUserResource()) {
|
||||
if (wrapper.isCreate()) {
|
||||
handler = this.applicationContext.getBean("createUserCommandHandler", NewCommandSourceHandler.class);
|
||||
|
||||
+60
-2
@@ -11,16 +11,19 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
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.UriInfo;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
@@ -46,8 +49,8 @@ public class RolesApiResource {
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link RoleData}
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "name", "description",
|
||||
"availablePermissions", "selectedPermissions"));
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "name", "description", "availablePermissions",
|
||||
"selectedPermissions"));
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link RoleData}
|
||||
@@ -124,6 +127,35 @@ public class RolesApiResource {
|
||||
return this.toApiJsonSerializer.serialize(settings, role, this.RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Roles enable or disable
|
||||
*
|
||||
* @param roleId
|
||||
* @param commandParam
|
||||
* @param apiRequestBodyAsJson
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Path("{roleId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String actionsOnRoles(@PathParam("roleId") final Long roleId, @QueryParam("command") final String commandParam,
|
||||
final String apiRequestBodyAsJson) {
|
||||
|
||||
final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
|
||||
|
||||
CommandProcessingResult result = null;
|
||||
|
||||
if (is(commandParam, "disable")) {
|
||||
final CommandWrapper commandRequest = builder.disableRole(roleId).build();
|
||||
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
} else if (is(commandParam, "enable")) {
|
||||
final CommandWrapper commandRequest = builder.enableRole(roleId).build();
|
||||
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{roleId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@@ -171,4 +203,30 @@ public class RolesApiResource {
|
||||
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Role
|
||||
*
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
@DELETE
|
||||
@Path("{roleId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String deleteRole(@PathParam("roleId") final Long roleId) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
||||
.deleteRole(roleId) //
|
||||
.build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
private boolean is(final String commandParam, final String commandValue) {
|
||||
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-2
@@ -16,15 +16,17 @@ public class RoleData implements Serializable {
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final Boolean disabled;
|
||||
|
||||
public RolePermissionsData toRolePermissionData(final Collection<PermissionData> permissionUsageData) {
|
||||
return new RolePermissionsData(this.id, this.name, this.description, permissionUsageData);
|
||||
return new RolePermissionsData(this.id, this.name, this.description, this.disabled, permissionUsageData);
|
||||
}
|
||||
|
||||
public RoleData(final Long id, final String name, final String description) {
|
||||
public RoleData(final Long id, final String name, final String description, final Boolean disabled) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-1
@@ -18,15 +18,18 @@ public class RolePermissionsData {
|
||||
private final String name;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean disabled;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<PermissionData> permissionUsageData;
|
||||
|
||||
public RolePermissionsData(final Long id, final String name, final String description,
|
||||
public RolePermissionsData(final Long id, final String name, final String description, final Boolean disabled,
|
||||
final Collection<PermissionData> permissionUsageData) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.disabled = disabled;
|
||||
this.permissionUsageData = permissionUsageData;
|
||||
}
|
||||
}
|
||||
-1
@@ -494,7 +494,6 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
}
|
||||
|
||||
public void validateHasCheckerPermissionTo(final String function) {
|
||||
|
||||
final String checkerPermissionName = function.toUpperCase() + "_CHECKER";
|
||||
if (hasNotPermissionTo("CHECKER_SUPER_USER") && hasNotPermissionTo(checkerPermissionName)) {
|
||||
final String authorizationMessage = "User has no authority to be a checker for: " + function;
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface AppUserRepository extends JpaRepository<AppUser, Long>, JpaSpecificationExecutor<AppUser>, PlatformUserRepository {
|
||||
// no behaviour added
|
||||
|
||||
}
|
||||
|
||||
+21
-1
@@ -34,6 +34,9 @@ public class Role extends AbstractPersistable<Long> {
|
||||
@Column(name = "description", nullable = false, length = 500)
|
||||
private String description;
|
||||
|
||||
@Column(name = "is_disabled", nullable = false)
|
||||
private Boolean disabled;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "m_role_permission", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "permission_id"))
|
||||
private final Set<Permission> permissions = new HashSet<>();
|
||||
@@ -51,6 +54,7 @@ public class Role extends AbstractPersistable<Long> {
|
||||
public Role(final String name, final String description) {
|
||||
this.name = name.trim();
|
||||
this.description = description.trim();
|
||||
this.disabled = false;
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
@@ -109,6 +113,22 @@ public class Role extends AbstractPersistable<Long> {
|
||||
}
|
||||
|
||||
public RoleData toData() {
|
||||
return new RoleData(getId(), this.name, this.description);
|
||||
return new RoleData(getId(), this.name, this.description, this.disabled);
|
||||
}
|
||||
|
||||
public void disableRole() {
|
||||
this.disabled = true;
|
||||
}
|
||||
|
||||
public Boolean isDisabled() {
|
||||
return this.disabled;
|
||||
}
|
||||
|
||||
public void enableRole() {
|
||||
this.disabled = false;
|
||||
}
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return this.disabled;
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -7,7 +7,12 @@ package org.mifosplatform.useradministration.domain;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {
|
||||
// no added behaviour
|
||||
|
||||
@Query("SELECT COUNT(*) FROM AppUser a JOIN a.roles r WHERE r.id = :roleId")
|
||||
Integer getCountOfRolesAssociatedWithUsers(@Param("roleId") Long roleId);
|
||||
|
||||
}
|
||||
+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.useradministration.exception;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
|
||||
public class RoleAssociatedException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public RoleAssociatedException(final String errorcode, final Long id) {
|
||||
super(errorcode, "Role with identifier " + id + " associated with users", id);
|
||||
}
|
||||
}
|
||||
+32
@@ -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.useradministration.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.useradministration.service.RoleWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class DeleteRoleCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final RoleWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public DeleteRoleCommandHandler(final RoleWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
return this.writePlatformService.deleteRole(command.entityId());
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.useradministration.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.useradministration.service.RoleWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DisableRoleCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final RoleWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public DisableRoleCommandHandler(final RoleWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||
return this.writePlatformService.disableRole(command.entityId());
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -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.useradministration.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.useradministration.service.RoleWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class EnableRoleCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final RoleWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public EnableRoleCommandHandler(final RoleWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(JsonCommand command) {
|
||||
return this.writePlatformService.enableRole(command.entityId());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -89,7 +89,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
public AppUserData retrieveNewUserDetails() {
|
||||
|
||||
final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
|
||||
final Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAll();
|
||||
final Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAllActiveRoles();
|
||||
|
||||
return AppUserData.template(offices, availableRoles);
|
||||
}
|
||||
|
||||
+2
@@ -13,6 +13,8 @@ public interface RoleReadPlatformService {
|
||||
|
||||
Collection<RoleData> retrieveAll();
|
||||
|
||||
Collection<RoleData> retrieveAllActiveRoles();
|
||||
|
||||
RoleData retrieveOne(Long roleId);
|
||||
|
||||
Collection<RoleData> retrieveAppUserRoles(Long appUserId);
|
||||
|
||||
+12
-4
@@ -38,6 +38,13 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||
return this.jdbcTemplate.query(sql, this.roleRowMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RoleData> retrieveAllActiveRoles() {
|
||||
final String sql = "select " + this.roleRowMapper.schema() + " where r.is_disabled = 0 order by r.id";
|
||||
|
||||
return this.jdbcTemplate.query(sql, this.roleRowMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleData retrieveOne(final Long id) {
|
||||
|
||||
@@ -58,12 +65,13 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final String name = rs.getString("name");
|
||||
final String description = rs.getString("description");
|
||||
|
||||
return new RoleData(id, name, description);
|
||||
final Boolean disabled = rs.getBoolean("disabled");
|
||||
|
||||
return new RoleData(id, name, description, disabled);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " r.id as id, r.name as name, r.description as description from m_role r";
|
||||
return " r.id as id, r.name as name, r.description as description, r.is_disabled as disabled from m_role r";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +80,6 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||
final String sql = "select " + this.roleRowMapper.schema() + " inner join m_appuser_role"
|
||||
+ " ar on ar.role_id = r.id where ar.appuser_id= ?";
|
||||
|
||||
return this.jdbcTemplate.query(sql,this.roleRowMapper,new Object[]{appUserId});
|
||||
return this.jdbcTemplate.query(sql, this.roleRowMapper, new Object[] { appUserId });
|
||||
}
|
||||
}
|
||||
+6
@@ -15,4 +15,10 @@ public interface RoleWritePlatformService {
|
||||
CommandProcessingResult updateRole(Long roleId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult updateRolePermissions(Long roleId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult deleteRole(Long roleId);
|
||||
|
||||
CommandProcessingResult disableRole(Long roleId);
|
||||
|
||||
CommandProcessingResult enableRole(Long roleId);
|
||||
}
|
||||
+86
-2
@@ -20,6 +20,7 @@ import org.mifosplatform.useradministration.domain.PermissionRepository;
|
||||
import org.mifosplatform.useradministration.domain.Role;
|
||||
import org.mifosplatform.useradministration.domain.RoleRepository;
|
||||
import org.mifosplatform.useradministration.exception.PermissionNotFoundException;
|
||||
import org.mifosplatform.useradministration.exception.RoleAssociatedException;
|
||||
import org.mifosplatform.useradministration.exception.RoleNotFoundException;
|
||||
import org.mifosplatform.useradministration.serialization.PermissionsCommandFromApiJsonDeserializer;
|
||||
import org.slf4j.Logger;
|
||||
@@ -62,7 +63,6 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
||||
this.roleCommandFromApiJsonDeserializer.validateForCreate(command.json());
|
||||
|
||||
final Role entity = Role.fromJson(command);
|
||||
|
||||
this.roleRepository.save(entity);
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).build();
|
||||
@@ -172,7 +172,91 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
||||
if (permission.hasCode(permissionCode)) { return permission; }
|
||||
}
|
||||
}
|
||||
|
||||
throw new PermissionNotFoundException(permissionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for Delete Role
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult deleteRole(Long roleId) {
|
||||
|
||||
try {
|
||||
/**
|
||||
* Checking the role present in DB or not using role_id
|
||||
*/
|
||||
final Role role = this.roleRepository.findOne(roleId);
|
||||
if (role == null) { throw new RoleNotFoundException(roleId); }
|
||||
|
||||
/**
|
||||
* Roles associated with users can't be deleted
|
||||
*/
|
||||
final Integer count = this.roleRepository.getCountOfRolesAssociatedWithUsers(roleId);
|
||||
if (count > 0) { throw new RoleAssociatedException("error.msg.role.associated.with.users.deleted", roleId); }
|
||||
|
||||
this.roleRepository.delete(role);
|
||||
return new CommandProcessingResultBuilder().withEntityId(roleId).build();
|
||||
} catch (final DataIntegrityViolationException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource: " + e.getMostSpecificCause());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for disabling the role
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult disableRole(Long roleId) {
|
||||
try {
|
||||
/**
|
||||
* Checking the role present in DB or not using role_id
|
||||
*/
|
||||
final Role role = this.roleRepository.findOne(roleId);
|
||||
if (role == null) { throw new RoleNotFoundException(roleId); }
|
||||
//if(role.isDisabled()){throw new RoleNotFoundException(roleId);}
|
||||
|
||||
/**
|
||||
* Roles associated with users can't be disable
|
||||
*/
|
||||
final Integer count = this.roleRepository.getCountOfRolesAssociatedWithUsers(roleId);
|
||||
if (count > 0) { throw new RoleAssociatedException("error.msg.role.associated.with.users.disabled", roleId); }
|
||||
|
||||
/**
|
||||
* Disabling the role
|
||||
*/
|
||||
role.disableRole();
|
||||
this.roleRepository.save(role);
|
||||
return new CommandProcessingResultBuilder().withEntityId(roleId).build();
|
||||
|
||||
} catch (final DataIntegrityViolationException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource: " + e.getMostSpecificCause());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for Enabling the role
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult enableRole(Long roleId) {
|
||||
try {
|
||||
/**
|
||||
* Checking the role present in DB or not using role_id
|
||||
*/
|
||||
final Role role = this.roleRepository.findOne(roleId);
|
||||
if (role == null) { throw new RoleNotFoundException(roleId); }
|
||||
//if(!role.isEnabled()){throw new RoleNotFoundException(roleId);}
|
||||
|
||||
role.enableRole();
|
||||
this.roleRepository.save(role);
|
||||
return new CommandProcessingResultBuilder().withEntityId(roleId).build();
|
||||
|
||||
} catch (final DataIntegrityViolationException e) {
|
||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource: " + e.getMostSpecificCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE `m_role` ADD COLUMN `is_disabled` BIT NULL DEFAULT b'0' AFTER `description`;
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('authorisation', 'DISABLE_ROLE', 'ROLE', 'DISABLE', 0);
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('authorisation', 'DISABLE_ROLE_CHECKER', 'ROLE', 'DISABLE_CHECKER', 0);
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('authorisation', 'ENABLE_ROLE', 'ROLE', 'ENABLE', 0);
|
||||
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('authorisation', 'ENABLE_ROLE_CHECKER', 'ROLE', 'ENABLE_CHECKER', 0);
|
||||
Reference in New Issue
Block a user