This commit is contained in:
Keith Woodlock
2012-11-26 13:09:42 +00:00
parent 8f74873408
commit e4e285d943
6 changed files with 33 additions and 62 deletions
@@ -16,6 +16,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.accounting.api.commands.RolePermissionCommand;
import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.data.CommandSourceData;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.PermissionUsageData;
@@ -87,14 +88,6 @@ public class RolesApiResource {
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
// TODO - General thing to fix about REST API is if use partial response
// approach of fields=id,name,selectedPermissions
// It will return just id,name parameters of RoleData and ignore
// description, however as PermissionData used in selectedPermissions
// collection
// also has a field called description it gets ignored also. This is because
// of the implementation of ParameterListExclusionStrategy which doesnt take
// into account the Object its looking at.
@GET
@Path("{roleId}")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -110,13 +103,23 @@ public class RolesApiResource {
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
if (commandId != null) {
// currentChanges =
// handleRequestToIntegrateProposedChangesFromCommand(roleId,
// commandId);
RoleData currentChanges = handleRequestToIntegrateProposedChangesFromRoleCommand(roleId, commandId);
role = RoleData.integrateChanges(role, currentChanges);
}
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, role);
}
private RoleData handleRequestToIntegrateProposedChangesFromRoleCommand(final Long roleId, final Long commandId) {
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(commandId);
return assembleRoleChanges(roleId, entry);
}
private RoleData assembleRoleChanges(final Long roleId, final CommandSourceData entry) {
final RoleCommand changesOnly = this.commandDeserializerService.deserializeRoleCommand(roleId, entry.json(), false);
return RoleData.changes(changesOnly.getName(), changesOnly.getDescription());
}
@PUT
@Path("{roleId}")
@@ -149,9 +152,7 @@ public class RolesApiResource {
currentChanges = handleRequestToIntegrateProposedChangesFromCommand(roleId, commandId);
}
Collection<Collection<PermissionUsageData>> allChanges = retrieveAllUnprocessedDataChanges(roleId);
final RolePermissionsData permissionsData = role.toRolePermissionData(permissionUsageData, currentChanges, allChanges);
final RolePermissionsData permissionsData = role.toRolePermissionData(permissionUsageData, currentChanges);
return this.apiJsonSerializerService.serializeRolePermissionDataToJson(prettyPrint, responseParameters, permissionsData);
}
@@ -177,27 +178,6 @@ public class RolesApiResource {
return proposedChanges;
}
private Collection<Collection<PermissionUsageData>> retrieveAllUnprocessedDataChanges(final Long roleId) {
Collection<Collection<PermissionUsageData>> allChanges = new ArrayList<Collection<PermissionUsageData>>();
final Collection<CommandSourceData> unprocessedChanges = this.commandSourceReadPlatformService
.retrieveUnprocessChangesByResourceId("roles", roleId);
for (CommandSourceData commandSourceData : unprocessedChanges) {
if (commandSourceData.isRoleResource() && commandSourceData.isUpdateRolePermissions()) {
Collection<PermissionUsageData> dataChanges = assemblePermissionChanges(roleId, commandSourceData);
allChanges.add(dataChanges);
}
}
if (allChanges.isEmpty()) {
allChanges = null;
}
return allChanges;
}
@PUT
@Path("{roleId}/permissions")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -10,26 +10,22 @@ public class RoleData {
private final Long id;
private final String name;
private final String description;
@SuppressWarnings("unused")
private final RoleData currentChanges;
public static RoleData changes(final String name, final String description) {
return new RoleData(null, name, description, null);
}
public static RoleData integrateChanges(final RoleData role, final RoleData currentChanges) {
return new RoleData(role.id, role.name, role.description, currentChanges);
}
// @SuppressWarnings("unused")
// private final Collection<RoleData> currentChanges;
public RoleData(final Long id, final String name, final String description) {
public RoleData(final Long id, final String name, final String description, final RoleData currentChanges) {
this.id = id;
this.name = name;
this.description = description;
}
public RoleData() {
this.id = null;
this.name = null;
this.description = null;
}
public RoleData(final RoleData role) {
this.id = role.id;
this.name = role.name;
this.description = role.description;
this.currentChanges = currentChanges;
}
@Override
@@ -43,8 +39,7 @@ public class RoleData {
return this.id.hashCode();
}
public RolePermissionsData toRolePermissionData(final Collection<PermissionUsageData> permissionUsageData,
final Collection<PermissionUsageData> currentChanges, final Collection<Collection<PermissionUsageData>> allChanges) {
return new RolePermissionsData(id, name, description, permissionUsageData, currentChanges, allChanges);
public RolePermissionsData toRolePermissionData(final Collection<PermissionUsageData> permissionUsageData, final Collection<PermissionUsageData> currentChanges) {
return new RolePermissionsData(id, name, description, permissionUsageData, currentChanges);
}
}
@@ -18,17 +18,13 @@ public class RolePermissionsData {
private final Collection<PermissionUsageData> permissionUsageData;
@SuppressWarnings("unused")
private final Collection<PermissionUsageData> currentChanges;
@SuppressWarnings("unused")
private final Collection<Collection<PermissionUsageData>> allChanges;
public RolePermissionsData(final Long id, final String name, final String description,
final Collection<PermissionUsageData> permissionUsageData, final Collection<PermissionUsageData> currentChanges,
final Collection<Collection<PermissionUsageData>> allChanges) {
final Collection<PermissionUsageData> permissionUsageData, final Collection<PermissionUsageData> currentChanges) {
this.id = id;
this.name = name;
this.description = description;
this.permissionUsageData = permissionUsageData;
this.currentChanges = currentChanges;
this.allChanges = allChanges;
}
}
@@ -73,6 +73,6 @@ public class Role extends AbstractAuditableCustom<AppUser, Long> {
}
public RoleData toData() {
return new RoleData(this.getId(), this.name, this.description);
return new RoleData(this.getId(), this.name, this.description, null);
}
}
@@ -60,7 +60,7 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
final String name = rs.getString("name");
final String description = rs.getString("description");
return new RoleData(id, name, description);
return new RoleData(id, name, description, null);
}
public String schema() {
@@ -26,7 +26,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
// FIXME - kw - this value is hardcoded for now but will be retrieved from
// configuration
private boolean makerCheckerEnabledForTask = false;
private boolean makerCheckerEnabledForTask = true;
@Autowired
public RoleWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final RoleRepository roleRepository,