Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public class LayerAdminMetadataHandler extends RestActionHandler {
private UserService userService = null;
private PermissionService permissionsService = null;

private final static String JSKEY_ID = "id";
private final static String JSKEY_NAME = "name";

private String capabilitiesCron = null;

@Override
Expand Down Expand Up @@ -75,6 +72,7 @@ public void handleGet(ActionParameters params) throws ActionException {
JSONHelper.putValue(root, "permissionTypes", getPermissionTypes(params.getLocale().getLanguage()));
JSONHelper.putValue(root, "layerTypes", getMandatoryFields());
JSONHelper.putValue(root, "capabilitiesCron", getCapabilitiesUpdateCron());
JSONHelper.putValue(root, "systemRoles", Role.getSystemRolesAsMap());
ResponseHelper.writeResponse(params, root);
} catch (Exception e) {
throw new ActionException("Something went wrong getting roles and permission types from the platform", e);
Expand All @@ -86,10 +84,7 @@ private JSONArray getRoles() throws ServiceException, JSONException {
final JSONArray rolesJSON = new JSONArray();
if (roles != null) {
for (Role role : roles) {
JSONObject external = new JSONObject();
external.put(JSKEY_ID, role.getId());
external.put(JSKEY_NAME, role.getName());
rolesJSON.put(external);
rolesJSON.put(role.toJSON());
}
}
return rolesJSON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ private JSONObject roles2JsonArray(Role[] roles) throws JSONException {

final JSONObject response = new JSONObject();
JSONHelper.put(response, "rolelist", roleValues);

final JSONObject systemRoles = new JSONObject();
JSONHelper.putValue(systemRoles, "anonymous", Role.getGuestUserRole().getName());
JSONHelper.putValue(systemRoles, "user", Role.getDefaultUserRole().getName());
JSONHelper.putValue(systemRoles, "admin", Role.getAdminRole().getName());
JSONHelper.putValue(response, "systemRoles", systemRoles);
JSONHelper.putValue(response, "systemRoles", Role.getSystemRolesAsMap());

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@
"name": "DOWNLOAD",
"id": "DOWNLOAD"
}
]
],
"systemRoles": {
"anonymous": "Guest",
"user": "User",
"admin": "Admin"
}
}
11 changes: 8 additions & 3 deletions service-base/src/main/java/fi/nls/oskari/domain/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import org.json.JSONObject;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;

/**
* Internal model for user role.
Expand Down Expand Up @@ -88,6 +86,13 @@ public static List<Role> getSystemRoles () {
getDefaultUserRole(),
getAdminRole());
}
public static Map<String,String> getSystemRolesAsMap () {
final Map<String,String> systemRoles = new HashMap<>();
systemRoles.put("anonymous", getGuestUserRole().getName());
systemRoles.put("user", getDefaultUserRole().getName());
systemRoles.put("admin", getAdminRole().getName());
return systemRoles;
}

private static Role getRoleByName(final String rolename) {
try {
Expand Down
Loading