1- /**
2- * Licensed to the Apache Software Foundation (ASF) under one
3- * or more contributor license agreements. See the NOTICE file
4- * distributed with this work for additional information
5- * regarding copyright ownership. The ASF licenses this file
6- * to you under the Apache License, Version 2.0 (the
7- * "License"); you may not use this file except in compliance
8- * with the License. You may obtain a copy of the License at
9- *
10- * http://www.apache.org/licenses/LICENSE-2.0
11- *
12- * Unless required by applicable law or agreed to in writing,
13- * software distributed under the License is distributed on an
14- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15- * KIND, either express or implied. See the License for the
16- * specific language governing permissions and limitations
17- * under the License.
18- */
191package org .apache .fineract .integrationtests .useradministration .roles ;
202
21- import com .google .gson .Gson ;
22- import com .google .gson .reflect .TypeToken ;
233import io .restassured .specification .RequestSpecification ;
244import io .restassured .specification .ResponseSpecification ;
25- import java .lang .reflect .Type ;
26- import java .util .HashMap ;
275import java .util .List ;
286import java .util .Map ;
29- import org .apache .fineract .client .models .CommandProcessingResult ;
30- import org .apache .fineract .client .models .PutPermissionsRequest ;
7+ import lombok .extern .slf4j .Slf4j ;
8+ import org .apache .fineract .client .models .PostRolesRequest ;
9+ import org .apache .fineract .client .models .PostRolesResponse ;
10+ import org .apache .fineract .client .models .GetRolesRoleIdResponse ;
11+ import org .apache .fineract .client .models .PostRolesRoleIdPermissionsRequest ;
12+ import org .apache .fineract .client .models .PostRolesRoleIdPermissionsResponse ;
3113import org .apache .fineract .client .util .Calls ;
32- import org .apache .fineract .client .util .JSON ;
3314import org .apache .fineract .integrationtests .common .FineractClientHelper ;
3415import org .apache .fineract .integrationtests .common .Utils ;
35- import org .apache .fineract .useradministration .data .PermissionData ;
3616
17+ @ Slf4j
3718public final class RolesHelper {
3819
39- public static final long SUPER_USER_ROLE_ID = 1L ; // This is hardcoded into the initial Liquibase migration
20+ public static final long SUPER_USER_ROLE_ID = 1L ;
4021
41- public RolesHelper () {
22+ private RolesHelper () {}
4223
43- }
44-
45- private static final String CREATE_ROLE_URL = "/fineract-provider/api/v1/roles?" + Utils .TENANT_IDENTIFIER ;
46- private static final String ROLE_URL = "/fineract-provider/api/v1/roles" ;
47- private static final String PERMISSIONS_URL = "/fineract-provider/api/v1/permissions" ;
48- private static final String DISABLE_ROLE_COMMAND = "disable" ;
49- private static final String ENABLE_ROLE_COMMAND = "enable" ;
50-
51- private static final Gson GSON = new JSON ().getGson ();
52-
53- // TODO: Rewrite to use fineract-client instead!
54- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
55- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
56- @ Deprecated (forRemoval = true )
24+
5725 public static Integer createRole (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ) {
58- return Utils .performServerPost (requestSpec , responseSpec , CREATE_ROLE_URL , getTestCreateRoleAsJSON (), "resourceId" );
26+ log .info ("---------------------------------CREATING A ROLE (COMPATIBILITY)---------------------------------------------" );
27+ PostRolesRequest request = new PostRolesRequest ()
28+ .name (Utils .uniqueRandomStringGenerator ("Role_" , 4 ))
29+ .description ("New Role" );
30+
31+
32+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .createRole (request )).getResourceId ().intValue ();
5933 }
6034
61- // TODO: Rewrite to use fineract-client instead!
62- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
63- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
64- @ Deprecated (forRemoval = true )
65- public static String getTestCreateRoleAsJSON () {
66- final HashMap <String , String > map = new HashMap <>();
67- map .put ("name" , Utils .uniqueRandomStringGenerator ("Role_Name_" , 5 ));
68- map .put ("description" , Utils .randomStringGenerator ("Role_Description_" , 10 ));
69- return new Gson ().toJson (map );
70- }
7135
72- // TODO: Rewrite to use fineract-client instead!
73- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
74- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
75- @ Deprecated (forRemoval = true )
76- public static HashMap <String , Object > getRoleDetails (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ,
77- final Integer roleId ) {
78- final String GET_ROLE_URL = "/fineract-provider/api/v1/roles/" + roleId + "?" + Utils .TENANT_IDENTIFIER ;
79- return Utils .performServerGet (requestSpec , responseSpec , GET_ROLE_URL , "" );
36+ public static Long createRole () {
37+ PostRolesRequest request = new PostRolesRequest ()
38+ .name (Utils .uniqueRandomStringGenerator ("Role_" , 4 ))
39+ .description ("New Role" );
40+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .createRole (request )).getResourceId ();
8041 }
8142
82- // TODO: Rewrite to use fineract-client instead!
83- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
84- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
85- @ Deprecated (forRemoval = true )
86- public static Integer disableRole (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ,
87- final Integer roleId ) {
88- return Utils .performServerPost (requestSpec , responseSpec , createRoleOperationURL (DISABLE_ROLE_COMMAND , roleId ), "" , "resourceId" );
43+
44+ public static GetRolesRoleIdResponse getRoleDetails (final Long roleId ) {
45+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .retrieveRole (roleId ));
8946 }
9047
91- // TODO: Rewrite to use fineract-client instead!
92- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
93- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
94- @ Deprecated (forRemoval = true )
95- public static Integer enableRole (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ,
96- final Integer roleId ) {
97- return Utils .performServerPost (requestSpec , responseSpec , createRoleOperationURL (ENABLE_ROLE_COMMAND , roleId ), "" , "resourceId" );
98- }
99-
100- // TODO: Rewrite to use fineract-client instead!
101- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
102- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
103- @ Deprecated (forRemoval = true )
104- public static Integer deleteRole (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ,
105- final Integer roleId ) {
106- return Utils .performServerDelete (requestSpec , responseSpec , createRoleOperationURL (ENABLE_ROLE_COMMAND , roleId ), "resourceId" );
107- }
108-
109- // TODO: Rewrite to use fineract-client instead!
110- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
111- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
112- @ Deprecated (forRemoval = true )
48+
11349 public static String addPermissionsToRole (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ,
11450 final Integer roleId , final Map <String , Boolean > permissionMap ) {
115- return Utils .performServerPut (requestSpec , responseSpec , ROLE_URL + "/" + roleId + "/permissions?" + Utils .TENANT_IDENTIFIER ,
116- getAddPermissionsToRoleJSON (permissionMap ));
117- }
118-
119- // TODO: Rewrite to use fineract-client instead!
120- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
121- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
122- @ Deprecated (forRemoval = true )
123- public static List <PermissionData > getPermissions (final RequestSpecification requestSpec , final ResponseSpecification responseSpec ,
124- boolean makerCheckerable ) {
125- String response = Utils .performServerGet (requestSpec , responseSpec ,
126- PERMISSIONS_URL + "?" + makerCheckerable + "=" + makerCheckerable );
127- final Type listType = new TypeToken <List <PermissionData >>() {}.getType ();
128- return GSON .fromJson (response , listType );
51+ PostRolesRoleIdPermissionsRequest request = new PostRolesRoleIdPermissionsRequest ().permissions (permissionMap );
52+ Calls .ok (FineractClientHelper .getFineractClient ().roles .updateRolePermissions (roleId .longValue (), request ));
53+ return "" ;
12954 }
13055
131- public CommandProcessingResult updatePermissions (PutPermissionsRequest request ) {
132- return Calls .ok (FineractClientHelper .getFineractClient ().permissions .updatePermissionsDetails (request ));
56+
57+ public static Integer disableRole (final Long roleId ) {
58+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .disableRole (roleId )).getResourceId ().intValue ();
13359 }
13460
135- // TODO: Rewrite to use fineract-client instead!
136- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
137- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
138- @ Deprecated (forRemoval = true )
139- private static String getAddPermissionsToRoleJSON (Map <String , Boolean > permissionMap ) {
140- final HashMap <String , Map <String , Boolean >> map = new HashMap <>();
141- map .put ("permissions" , permissionMap );
142- return new Gson ().toJson (map );
61+ public static Integer enableRole (final Long roleId ) {
62+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .enableRole (roleId )).getResourceId ().intValue ();
14363 }
14464
145- // TODO: Rewrite to use fineract-client instead!
146- // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
147- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
148- @ Deprecated (forRemoval = true )
149- private static String createRoleOperationURL (final String command , final Integer roleId ) {
150- return ROLE_URL + "/" + roleId + "?command=" + command + "&" + Utils .TENANT_IDENTIFIER ;
65+ public static Integer deleteRole (final Long roleId ) {
66+ return Calls .ok (FineractClientHelper .getFineractClient ().roles .deleteRole (roleId )).getResourceId ().intValue ();
15167 }
152- }
68+ }
0 commit comments