code formatting police.

This commit is contained in:
Keith Woodlock
2012-11-26 21:38:54 +00:00
parent 0549858dea
commit 65206daf30
6 changed files with 124 additions and 148 deletions
@@ -61,13 +61,15 @@ public class PermissionsApiResource {
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
Collection<PermissionUsageData> permissions = null; Collection<PermissionUsageData> permissions = null;
if (makerCheckerable) permissions = this.permissionReadPlatformService.retrieveAllMakerCheckerablePermissions(); if (makerCheckerable) {
else permissions = this.permissionReadPlatformService.retrieveAllPermissions(); permissions = this.permissionReadPlatformService.retrieveAllMakerCheckerablePermissions();
} else {
permissions = this.permissionReadPlatformService.retrieveAllPermissions();
}
return this.apiJsonSerializerService.serializePermissionDataToJson(prettyPrint, responseParameters, permissions); return this.apiJsonSerializerService.serializePermissionDataToJson(prettyPrint, responseParameters, permissions);
} }
@PUT @PUT
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@@ -79,5 +81,4 @@ public class PermissionsApiResource {
return Response.ok().entity(new EntityIdentifier(entityId)).build(); return Response.ok().entity(new EntityIdentifier(entityId)).build();
} }
} }
@@ -24,7 +24,6 @@ public class Permission extends AbstractPersistable<Long> {
@Column(name = "action_name", nullable = true, length = 100) @Column(name = "action_name", nullable = true, length = 100)
private final String actionName; private final String actionName;
@SuppressWarnings("unused")
@Column(name = "can_maker_checker", nullable = false) @Column(name = "can_maker_checker", nullable = false)
private boolean canMakerChecker; private boolean canMakerChecker;
@@ -48,12 +47,11 @@ public class Permission extends AbstractPersistable<Long> {
return this.canMakerChecker; return this.canMakerChecker;
} }
public void setCanMakerChecker(Boolean canMakerChecker) {
this.canMakerChecker = canMakerChecker;
}
public String getGrouping() { public String getGrouping() {
return this.grouping; return this.grouping;
} }
public void enableMakerChecker(final boolean canMakerChecker) {
this.canMakerChecker = canMakerChecker;
}
} }
@@ -15,19 +15,15 @@ import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class PermissionReadPlatformServiceImpl implements public class PermissionReadPlatformServiceImpl implements PermissionReadPlatformService {
PermissionReadPlatformService {
private final static Logger logger = LoggerFactory private final static Logger logger = LoggerFactory.getLogger(PermissionReadPlatformService.class);
.getLogger(PermissionReadPlatformService.class);
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
@Autowired @Autowired
public PermissionReadPlatformServiceImpl( public PermissionReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource) {
final PlatformSecurityContext context,
final TenantAwareRoutingDataSource dataSource) {
this.context = context; this.context = context;
this.jdbcTemplate = new JdbcTemplate(dataSource); this.jdbcTemplate = new JdbcTemplate(dataSource);
} }
@@ -56,8 +52,7 @@ public class PermissionReadPlatformServiceImpl implements
} }
@Override @Override
public Collection<PermissionUsageData> retrieveAllRolePermissions( public Collection<PermissionUsageData> retrieveAllRolePermissions(final Long roleId) {
final Long roleId) {
final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper(); final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper();
final String sql = mapper.rolePermissionSchema(); final String sql = mapper.rolePermissionSchema();
@@ -66,13 +61,10 @@ public class PermissionReadPlatformServiceImpl implements
return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId }); return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId });
} }
private static final class PermissionUsageDataMapper implements private static final class PermissionUsageDataMapper implements RowMapper<PermissionUsageData> {
RowMapper<PermissionUsageData> {
@Override @Override
public PermissionUsageData mapRow(final ResultSet rs, public PermissionUsageData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
@SuppressWarnings("unused") final int rowNum)
throws SQLException {
final String grouping = rs.getString("grouping"); final String grouping = rs.getString("grouping");
final String code = rs.getString("code"); final String code = rs.getString("code");
@@ -80,15 +72,13 @@ public class PermissionReadPlatformServiceImpl implements
final String actionName = rs.getString("actionName"); final String actionName = rs.getString("actionName");
final Boolean selected = rs.getBoolean("selected"); final Boolean selected = rs.getBoolean("selected");
return new PermissionUsageData(grouping, code, entityName, return new PermissionUsageData(grouping, code, entityName, actionName, selected);
actionName, selected);
} }
public String permissionSchema() { public String permissionSchema() {
/* get all non-CHECKER permissions */ /* get all non-CHECKER permissions */
return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, true as selected" return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, true as selected"
+ " from m_permission p " + " from m_permission p " + " where code not like '%\\_CHECKER'"
+ " where code not like '%\\_CHECKER'"
+ " order by p.grouping, ifnull(entity_name, ''), p.code"; + " order by p.grouping, ifnull(entity_name, ''), p.code";
} }
@@ -100,8 +90,7 @@ public class PermissionReadPlatformServiceImpl implements
*/ */
return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, p.can_maker_checker as selected" return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, p.can_maker_checker as selected"
+ " from m_permission p " + " from m_permission p " + " where grouping != 'special' and code not like 'READ_%' and code not like '%\\_CHECKER'"
+ " where grouping != 'special' and code not like 'READ_%' and code not like '%\\_CHECKER'"
+ " order by p.grouping, ifnull(entity_name, ''), p.code"; + " order by p.grouping, ifnull(entity_name, ''), p.code";
} }
@@ -13,15 +13,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
public class PermissionWritePlatformServiceJpaRepositoryImpl implements public class PermissionWritePlatformServiceJpaRepositoryImpl implements PermissionWritePlatformService {
PermissionWritePlatformService {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final PermissionRepository permissionRepository; private final PermissionRepository permissionRepository;
@Autowired @Autowired
public PermissionWritePlatformServiceJpaRepositoryImpl( public PermissionWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final PlatformSecurityContext context,
final PermissionRepository permissionRepository) { final PermissionRepository permissionRepository) {
this.context = context; this.context = context;
this.permissionRepository = permissionRepository; this.permissionRepository = permissionRepository;
@@ -32,25 +30,18 @@ public class PermissionWritePlatformServiceJpaRepositoryImpl implements
public Long updateMakerCheckerPermissions(final PermissionsCommand command) { public Long updateMakerCheckerPermissions(final PermissionsCommand command) {
context.authenticatedUser(); context.authenticatedUser();
final Collection<Permission> allPermissions = this.permissionRepository final Collection<Permission> allPermissions = this.permissionRepository.findAll();
.findAll();
final Map<String, Boolean> commandPermissions = command final Map<String, Boolean> commandPermissions = command.getPermissions();
.getPermissions();
for (final String permissionCode : commandPermissions.keySet()) { for (final String permissionCode : commandPermissions.keySet()) {
final Permission permission = findPermissionByCode(allPermissions, final Permission permission = findPermissionByCode(allPermissions, permissionCode);
permissionCode);
if (permission.getCode().endsWith("_CHECKER") if (permission.getCode().endsWith("_CHECKER") || permission.getCode().startsWith("READ_")
|| permission.getCode().startsWith("READ_") || permission.getGrouping().equalsIgnoreCase("special")) { throw new PermissionNotFoundException(permissionCode); }
|| permission.getGrouping().equalsIgnoreCase("special")) {
throw new PermissionNotFoundException(permissionCode);
}
final boolean isSelected = commandPermissions.get(permissionCode) final boolean isSelected = commandPermissions.get(permissionCode).booleanValue();
.booleanValue(); permission.enableMakerChecker(isSelected);
permission.setCanMakerChecker(isSelected);
this.permissionRepository.save(permission); this.permissionRepository.save(permission);
} }
@@ -58,14 +49,11 @@ public class PermissionWritePlatformServiceJpaRepositoryImpl implements
return new Long(0); return new Long(0);
} }
private Permission findPermissionByCode( private Permission findPermissionByCode(Collection<Permission> allPermissions, String permissionCode) {
Collection<Permission> allPermissions, String permissionCode) {
if (allPermissions != null) { if (allPermissions != null) {
for (Permission permission : allPermissions) { for (Permission permission : allPermissions) {
if (permission.hasCode(permissionCode)) { if (permission.hasCode(permissionCode)) { return permission; }
return permission;
}
} }
} }