forked from avniproject/avni-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avniproject#733 | Some refactoring changes,and fixed the permissions …
…group error which was caused due to wrong code being pushed in my last commit
- Loading branch information
1 parent
98b4545
commit cb4abda
Showing
23 changed files
with
450 additions
and
209 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...erver-api/src/main/java/org/avni/server/dao/metabase/CollectionPermissionsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.avni.server.dao.metabase; | ||
|
||
import org.avni.server.domain.metabase.CollectionPermissions; | ||
import org.avni.server.domain.metabase.CollectionPermissionsGraphResponse; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Repository | ||
public class CollectionPermissionsRepository extends MetabaseConnector { | ||
|
||
public CollectionPermissionsRepository(RestTemplateBuilder restTemplateBuilder) { | ||
super(restTemplateBuilder); | ||
} | ||
|
||
public CollectionPermissionsGraphResponse getCollectionPermissionsGraph() { | ||
String url = metabaseApiUrl + "/collection/graph"; | ||
return getForObject(url, CollectionPermissionsGraphResponse.class); | ||
} | ||
|
||
public void updateCollectionPermissions(CollectionPermissions collectionPermissions, int groupId, int collectionId) { | ||
collectionPermissions.updatePermissionsGraph(groupId, collectionId); | ||
String url = metabaseApiUrl + "/collection/graph"; | ||
sendPutRequest(url, convertToMap(collectionPermissions.getPermissionsGraph())); | ||
} | ||
|
||
private Map<String, Object> convertToMap(CollectionPermissionsGraphResponse collectionPermissionsGraphResponse) { | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("revision", collectionPermissionsGraphResponse.getRevision()); | ||
map.put("groups", collectionPermissionsGraphResponse.getGroups()); | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
avni-server-api/src/main/java/org/avni/server/dao/metabase/MetabaseRepository.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
avni-server-api/src/main/java/org/avni/server/dao/metabase/PermissionsGroupRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.avni.server.dao.metabase; | ||
|
||
import org.avni.server.domain.metabase.GroupPermissionsService; | ||
import org.avni.server.domain.metabase.GroupPermissionsGraphResponse; | ||
import org.avni.server.domain.metabase.Group; | ||
import org.avni.server.domain.metabase.GroupPermissionsBody; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Map; | ||
|
||
@Repository | ||
public class PermissionsGroupRepository extends MetabaseConnector { | ||
|
||
public PermissionsGroupRepository(RestTemplateBuilder restTemplateBuilder) { | ||
super(restTemplateBuilder); | ||
} | ||
|
||
public Group save(Group permissionsGroup) { | ||
String url = metabaseApiUrl + "/permissions/group"; | ||
GroupPermissionsBody body = new GroupPermissionsBody(permissionsGroup.getName()); | ||
HttpEntity<Map<String, Object>> entity = createJsonEntity(body); | ||
|
||
Group response = restTemplate.postForObject(url, entity, Group.class); | ||
return response; | ||
} | ||
|
||
public GroupPermissionsGraphResponse getPermissionsGraph() { | ||
String url = metabaseApiUrl + "/permissions/graph"; | ||
return getForObject(url, GroupPermissionsGraphResponse.class); | ||
} | ||
|
||
public void updatePermissionsGraph(GroupPermissionsService permissions, int groupId, int databaseId) { | ||
String url = metabaseApiUrl + "/permissions/graph"; | ||
Map<String, Object> requestBody = permissions.getUpdatedPermissionsGraph(); | ||
sendPutRequest(url, requestBody); | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
avni-server-api/src/main/java/org/avni/server/dao/metabase/PermissionsRepository.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...api/src/main/java/org/avni/server/domain/metabase/CollectionPermissionsGraphResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.avni.server.domain.metabase; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CollectionPermissionsGraphResponse { | ||
private int revision; | ||
private Map<String, Map<String, String>> groups; | ||
|
||
public int getRevision() { | ||
return revision; | ||
} | ||
|
||
public void setRevision(int revision) { | ||
this.revision = revision; | ||
} | ||
|
||
public Map<String, Map<String, String>> getGroups() { | ||
return groups; | ||
} | ||
|
||
public void setGroups(Map<String, Map<String, String>> groups) { | ||
this.groups = groups; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
avni-server-api/src/main/java/org/avni/server/domain/metabase/CollectionResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.