From 56d83f2aa390098fc8f3077194bdcba5c1c90090 Mon Sep 17 00:00:00 2001 From: Bharat saraswal Date: Fri, 22 Sep 2017 19:47:16 +0530 Subject: Resolved below sonar issues. removed redundant code. added method for resuablity of string builder. rename variable to follow camelCase. removed tab char and changed them with spaces. Issue-ID:SO-98 Change-Id: Ib081df5cbfdb4d2183ac51cb6779177ec2009bc6 Signed-off-by: Bharat saraswal --- .../openstack/keystone/api/TenantsResource.java | 401 +++++++++++---------- .../openstack/keystone/api/TokensResource.java | 112 +++--- .../openstack/keystone/api/UsersResource.java | 146 ++++---- 3 files changed, 331 insertions(+), 328 deletions(-) (limited to 'keystone-client/src') diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java index a073241..c521a61 100644 --- a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java +++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java @@ -8,205 +8,214 @@ import com.woorea.openstack.base.client.Entity; import com.woorea.openstack.base.client.HttpMethod; import com.woorea.openstack.base.client.OpenStackClient; import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.keystone.model.Metadata; import com.woorea.openstack.keystone.model.Roles; import com.woorea.openstack.keystone.model.Tenant; import com.woorea.openstack.keystone.model.Tenants; import com.woorea.openstack.keystone.model.Users; -import com.woorea.openstack.keystone.model.Metadata; public class TenantsResource { - - private OpenStackClient client; - - public TenantsResource(OpenStackClient client) { - this.client = client; - } - - public List list() { - return new List(); - } - - public Create create(Tenant tenant) { - return new Create(tenant); - } - - public Show show(String id) { - return new Show(id); - } - - public Update update(String id, Tenant tenant) { - return new Update(id, tenant); - } - - public Delete delete(String id) { - return new Delete(id); - } - - public ListUsers listUsers(String tenantId) { - return new ListUsers(tenantId); - } - - public AddUser addUser(String tenantId, String userId, String roleId) { - return new AddUser(tenantId, userId, roleId); - } - - public RemoveUser removeUser(String tenantId, String userId, String roleId) { - return new RemoveUser(tenantId, userId, roleId); - } - - public ListUserRoles listUserRoles(String tenantId, String userId) { - return new ListUserRoles(tenantId, userId); - } - - public ShowMetadata showMetadata(String id) { - return new ShowMetadata(id); - } - - public CreateOrUpdateMetadata createOrUpdateMetadata(String id,Metadata metadata) { - return new CreateOrUpdateMetadata(id,metadata); - } - - public ReplaceMetadata replaceMetadata(String id,Metadata metadata) { - return new ReplaceMetadata(id,metadata); - } - - public ShowMetadataItem showMetadataItem(String id,String key) { - return new ShowMetadataItem(id,key); - } - - public CreateOrUpdateMetadataItem createOrUpdateMetadataItem(String id,String key,Metadata metadata) { - return new CreateOrUpdateMetadataItem(id,key,metadata); - } - - public DeleteMetadataItem deleteMetadataItem(String id, String key) { - return new DeleteMetadataItem(id,key); - } - - public class List extends OpenStackRequest { - - public List() { - super(client, HttpMethod.GET, "/tenants", null, Tenants.class); - } - - } - - public class Create extends OpenStackRequest { - - private Tenant tenant; - - public Create(Tenant tenant) { - super(client, HttpMethod.POST, "/tenants", Entity.json(tenant), Tenant.class); - this.tenant = tenant; - } - - } - - public class Show extends OpenStackRequest { - - public Show(String id) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(id).toString(), null, Tenant.class); - } - - } - - public class Update extends OpenStackRequest { - - private Tenant tenant; - - public Update(String id, Tenant tenant) { - super(client, HttpMethod.PUT, new StringBuilder("/tenants/").append(id).toString(), Entity.json(tenant), Tenant.class); - this.tenant = tenant; - } - - } - - public class Delete extends OpenStackRequest { - - public Delete(String id) { - super(client, HttpMethod.DELETE, new StringBuilder("/tenants/").append(id).toString(), null, Void.class); - } - - } - - public class ListUsers extends OpenStackRequest { - - public ListUsers(String tenantId) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/users").toString(), null, Users.class); - } - - } - - public class AddUser extends OpenStackRequest { - - public AddUser(String tenantId, String userId, String roleId) { - super(client, HttpMethod.PUT, new StringBuilder("/tenants/").append(tenantId).append("/users/").append(userId).append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); - } - - } - - public class RemoveUser extends OpenStackRequest { - - public RemoveUser(String tenantId, String userId, String roleId) { - super(client, HttpMethod.DELETE, new StringBuilder("/tenants/").append(tenantId).append("/users/").append(userId).append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); - } - - } - - public class ListUserRoles extends OpenStackRequest { - - public ListUserRoles(String tenantId, String userId) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/users/").append(userId).append("/roles").toString(), null, Roles.class); - } - - } - - /** - * The following APIs support Tenant-level metadata. This is a feature supported - * by the DCP/LCP (i.e. AIC cloud), but not native Openstack. The full API as - * documented by AIC is implemented below. - */ - public class ShowMetadata extends OpenStackRequest { - - public ShowMetadata(String tenantId) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/metadata"), null, Metadata.class); - } - - } - - public class CreateOrUpdateMetadata extends OpenStackRequest { - - public CreateOrUpdateMetadata(String tenantId,Metadata metadata) { - super(client, HttpMethod.POST, new StringBuilder("/tenants/").append(tenantId).append("/metadata"), Entity.json(metadata), Metadata.class); - } - - } - public class ReplaceMetadata extends OpenStackRequest { - - public ReplaceMetadata(String tenantId,Metadata metadata) { - super(client, HttpMethod.PUT, new StringBuilder("/tenants/").append(tenantId).append("/metadata"), Entity.json(metadata), Metadata.class); - } - - } - - public class ShowMetadataItem extends OpenStackRequest { - - public ShowMetadataItem(String tenantId, String key) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/metadata").append(key), null, Metadata.class); - } - - } - public class CreateOrUpdateMetadataItem extends OpenStackRequest { - - public CreateOrUpdateMetadataItem(String tenantId,String key,Metadata metadata) { - super(client, HttpMethod.POST, new StringBuilder("/tenants/").append(tenantId).append("/metadata").append(key), Entity.json(metadata), Metadata.class); - } - - } - public class DeleteMetadataItem extends OpenStackRequest { - - public DeleteMetadataItem(String tenantId,String key) { - super(client, HttpMethod.DELETE, new StringBuilder("/tenants/").append(tenantId).append("/metadata/").append(key), null, Void.class); - } - - } - } + + private static final String TENANTS = "/tenants/"; + private static final String USERS = "/users/"; + private static final String METADATA = "/metadata"; + private final OpenStackClient client; + + public TenantsResource(OpenStackClient client) { + this.client = client; + } + + public List list() { + return new List(); + } + + public Create create(Tenant tenant) { + return new Create(tenant); + } + + public Show show(String id) { + return new Show(id); + } + + public Update update(String id, Tenant tenant) { + return new Update(id, tenant); + } + + public Delete delete(String id) { + return new Delete(id); + } + + public ListUsers listUsers(String tenantId) { + return new ListUsers(tenantId); + } + + public AddUser addUser(String tenantId, String userId, String roleId) { + return new AddUser(tenantId, userId, roleId); + } + + public RemoveUser removeUser(String tenantId, String userId, String roleId) { + return new RemoveUser(tenantId, userId, roleId); + } + + public ListUserRoles listUserRoles(String tenantId, String userId) { + return new ListUserRoles(tenantId, userId); + } + + public ShowMetadata showMetadata(String id) { + return new ShowMetadata(id); + } + + public CreateOrUpdateMetadata createOrUpdateMetadata(String id, Metadata metadata) { + return new CreateOrUpdateMetadata(id, metadata); + } + + public ReplaceMetadata replaceMetadata(String id, Metadata metadata) { + return new ReplaceMetadata(id, metadata); + } + + public ShowMetadataItem showMetadataItem(String id, String key) { + return new ShowMetadataItem(id, key); + } + + public CreateOrUpdateMetadataItem createOrUpdateMetadataItem(String id, String key, Metadata metadata) { + return new CreateOrUpdateMetadataItem(id, key, metadata); + } + + public DeleteMetadataItem deleteMetadataItem(String id, String key) { + return new DeleteMetadataItem(id, key); + } + + public class List extends OpenStackRequest { + + public List() { + super(client, HttpMethod.GET, "/tenants", null, Tenants.class); + } + } + + public class Create extends OpenStackRequest { + + private Tenant tenant; + + public Create(Tenant tenant) { + super(client, HttpMethod.POST, "/tenants", Entity.json(tenant), Tenant.class); + this.tenant = tenant; + } + } + + public class Show extends OpenStackRequest { + + public Show(String id) { + super(client, HttpMethod.GET, getTenantsString(id).toString(), null, Tenant.class); + } + } + + public class Update extends OpenStackRequest { + + private Tenant tenant; + + public Update(String id, Tenant tenant) { + super(client, HttpMethod.PUT, getTenantsString(id).toString(), Entity.json(tenant), + Tenant.class); + this.tenant = tenant; + } + } + + public class Delete extends OpenStackRequest { + + public Delete(String id) { + super(client, HttpMethod.DELETE, getTenantsString(id).toString(), null, Void.class); + } + } + + public class ListUsers extends OpenStackRequest { + + public ListUsers(String tenantId) { + super(client, HttpMethod.GET,getTenantsString(tenantId).append("/users").toString(), + null, Users.class); + } + } + + public class AddUser extends OpenStackRequest { + + public AddUser(String tenantId, String userId, String roleId) { + super(client, HttpMethod.PUT, + getTenantsString(tenantId).append(USERS).append(userId) + .append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); + } + } + + public class RemoveUser extends OpenStackRequest { + + public RemoveUser(String tenantId, String userId, String roleId) { + super(client, HttpMethod.DELETE, + getTenantsString(tenantId).append(USERS).append(userId) + .append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); + } + } + + public class ListUserRoles extends OpenStackRequest { + + public ListUserRoles(String tenantId, String userId) { + super(client, HttpMethod.GET, + getTenantsString(tenantId).append(USERS).append(userId).append("/roles") + .toString(), null, Roles.class); + } + } + + /** + * The following APIs support Tenant-level metadata. This is a feature supported + * by the DCP/LCP (i.e. AIC cloud), but not native Openstack. The full API as + * documented by AIC is implemented below. + */ + public class ShowMetadata extends OpenStackRequest { + + public ShowMetadata(String tenantId) { + super(client, HttpMethod.GET, getTenantsString(tenantId).append(METADATA), null, Metadata.class); + } + } + + public class CreateOrUpdateMetadata extends OpenStackRequest { + + public CreateOrUpdateMetadata(String tenantId, Metadata metadata) { + super(client, HttpMethod.POST, getTenantsString(tenantId).append(METADATA), Entity.json(metadata), + Metadata.class); + } + } + + public class ReplaceMetadata extends OpenStackRequest { + + public ReplaceMetadata(String tenantId, Metadata metadata) { + super(client, HttpMethod.PUT, getTenantsString(tenantId).append(METADATA), Entity.json(metadata), + Metadata.class); + } + } + + public class ShowMetadataItem extends OpenStackRequest { + + public ShowMetadataItem(String tenantId, String key) { + super(client, HttpMethod.GET, + getTenantsString(tenantId).append(METADATA).append(key), null, Metadata.class); + } + } + + public class CreateOrUpdateMetadataItem extends OpenStackRequest { + + public CreateOrUpdateMetadataItem(String tenantId, String key, Metadata metadata) { + super(client, HttpMethod.POST, + getTenantsString(tenantId).append(METADATA).append(key), Entity.json(metadata), + Metadata.class); + } + } + + public class DeleteMetadataItem extends OpenStackRequest { + + public DeleteMetadataItem(String tenantId, String key) { + super(client, HttpMethod.DELETE, + getTenantsString(tenantId).append("/metadata/").append(key), null, Void.class); + } + } + + private StringBuilder getTenantsString(String tenantId) { + return new StringBuilder(TENANTS).append(tenantId); + } +} diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java index 06da8ca..d5bfe22 100644 --- a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java +++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java @@ -15,63 +15,57 @@ import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; import com.woorea.openstack.keystone.model.authentication.UsernamePassword; public class TokensResource { - - private final OpenStackClient CLIENT; - - public TokensResource(OpenStackClient client) { - CLIENT = client; - } - - public Authenticate.Builder authenticate() { - return new Authenticate().new Builder(); - } - - public Authenticate authenticate(Authentication authentication) { - return new Authenticate(authentication); - } - - public class Authenticate extends OpenStackRequest { - - private Authentication authentication; - - public Authenticate() { - - } - - public Authenticate(Authentication authentication) { - super(CLIENT, HttpMethod.POST, "/tokens", Entity.json(authentication), Access.class); - this.authentication = authentication; - } - - public Authenticate withTenantId(String tenantId) { - authentication.setTenantId(tenantId); - return this; - } - - public Authenticate withTenantName(String tenantName) { - authentication.setTenantName(tenantName); - return this; - } - - public class Builder { - - public Authenticate withUsernamePassword(String username, String password) { - Authentication authentication = new UsernamePassword(username, password); - return new Authenticate(authentication); - } - - public Authenticate withToken(String token) { - Authentication authentication = new TokenAuthentication(token); - return new Authenticate(authentication); - } - - public Authenticate withAccessKey(String accessKey, String secretKey) { - Authentication authentication = new AccessKey(accessKey, secretKey); - return new Authenticate(authentication); - } - - } - - } - + + private final OpenStackClient client; + + public TokensResource(OpenStackClient client) { + this.client = client; + } + + public Authenticate.Builder authenticate() { + return new Authenticate().new Builder(); + } + + public Authenticate authenticate(Authentication authentication) { + return new Authenticate(authentication); + } + + public class Authenticate extends OpenStackRequest { + + private Authentication authentication; + + public Authenticate() { + + } + + public Authenticate(Authentication authentication) { + super(client, HttpMethod.POST, "/tokens", Entity.json(authentication), Access.class); + this.authentication = authentication; + } + + public Authenticate withTenantId(String tenantId) { + authentication.setTenantId(tenantId); + return this; + } + + public Authenticate withTenantName(String tenantName) { + authentication.setTenantName(tenantName); + return this; + } + + public class Builder { + + public Authenticate withUsernamePassword(String username, String password) { + return new Authenticate(new UsernamePassword(username, password)); + } + + public Authenticate withToken(String token) { + return new Authenticate(new TokenAuthentication(token)); + } + + public Authenticate withAccessKey(String accessKey, String secretKey) { + return new Authenticate(new AccessKey(accessKey, secretKey)); + } + } + } } diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java index dbb897c..94a5b68 100644 --- a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java +++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java @@ -9,77 +9,77 @@ import com.woorea.openstack.keystone.model.User; import com.woorea.openstack.keystone.model.Users; public class UsersResource { - - private OpenStackClient client; - - public UsersResource(OpenStackClient client) { - this.client = client; - } - - public List list() { - return new List(); - } - - public Create create(User user) { - return new Create(user); - } - - public Show show(String id) { - return new Show(id); - } - - public Update update(String id, User user) { - return new Update(id, user); - } - - public Delete delete(String id) { - return new Delete(id); - } - - public class List extends OpenStackRequest { - - public List() { - super(client, HttpMethod.GET, "/users", null, Users.class); - } - - } - - public class Create extends OpenStackRequest { - - private User user; - - public Create(User user) { - super(client, HttpMethod.POST, "/users", Entity.json(user), User.class); - this.user = user; - } - - } - - public class Show extends OpenStackRequest { - - public Show(String id) { - super(client, HttpMethod.GET, new StringBuilder("/users/").append(id).toString(), null, User.class); - } - - } - - public class Update extends OpenStackRequest { - - private User user; - - public Update(String id, User user) { - super(client, HttpMethod.PUT, new StringBuilder("/users/").append(id).toString(), Entity.json(user), User.class); - this.user = user; - } - - } - - public class Delete extends OpenStackRequest { - - public Delete(String id) { - super(client, HttpMethod.DELETE, new StringBuilder("/users/").append(id).toString(), null, Void.class); - } - - } - + + private static final String USERS = "/users/"; + private OpenStackClient client; + + public UsersResource(OpenStackClient client) { + this.client = client; + } + + public List list() { + return new List(); + } + + public Create create(User user) { + return new Create(user); + } + + public Show show(String id) { + return new Show(id); + } + + public Update update(String id, User user) { + return new Update(id, user); + } + + public Delete delete(String id) { + return new Delete(id); + } + + public class List extends OpenStackRequest { + + public List() { + super(client, HttpMethod.GET, "/users", null, Users.class); + } + } + + public class Create extends OpenStackRequest { + + private User user; + + public Create(User user) { + super(client, HttpMethod.POST, "/users", Entity.json(user), User.class); + this.user = user; + } + } + + public class Show extends OpenStackRequest { + + public Show(String id) { + super(client, HttpMethod.GET, getUserString(id), null, User.class); + } + } + + public class Update extends OpenStackRequest { + + private User user; + + public Update(String id, User user) { + super(client, HttpMethod.PUT, getUserString(id), Entity.json(user), + User.class); + this.user = user; + } + } + + public class Delete extends OpenStackRequest { + + public Delete(String id) { + super(client, HttpMethod.DELETE, getUserString(id), null, Void.class); + } + } + + private String getUserString(String id) { + return USERS + id; + } } -- cgit 1.2.3-korg