Code format fixes

This commit is contained in:
Alena Prokharchyk 2012-02-10 15:10:02 -08:00
parent 4c05adaac0
commit 294d3a2fda
19 changed files with 1499 additions and 1472 deletions

View File

@ -35,37 +35,37 @@ import com.cloud.projects.Project;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(description="Creates a project", responseObject=ProjectResponse.class, since="3.0.0")
@Implementation(description = "Creates a project", responseObject = ProjectResponse.class, since = "3.0.0")
public class CreateProjectCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName());
private static final String s_name = "createprojectresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will be Admin for the project")
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will be Admin for the project")
private String accountName;
@IdentityMapper(entityTableName="domain")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a project")
@IdentityMapper(entityTableName = "domain")
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "domain ID of the account owning a project")
private Long domainId;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="name of the project")
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the project")
private String name;
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="display text of the project")
@Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "display text of the project")
private String displayText;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public String getEntityTable() {
return "projects";
return "projects";
}
public String getAccountName() {
if (accountName != null) {
return accountName;
@ -80,7 +80,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
} else {
return UserContext.current().getCaller().getDomainId();
}
}
public String getName() {
@ -95,29 +95,28 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Account caller = UserContext.current().getCaller();
if ((accountName != null && domainId == null) || (domainId != null && accountName == null)) {
throw new InvalidParameterValueException("Account name and domain id must be specified together");
}
if (accountName != null) {
return _accountService.finalizeOwner(caller, accountName, domainId, null).getId();
}
return caller.getId();
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute(){
public void execute() {
Project project = _projectService.enableProject(this.getEntityId());
if (project != null) {
ProjectResponse response = _responseGenerator.createProjectResponse(project);
@ -127,10 +126,10 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
}
}
@Override
public void create() throws ResourceAllocationException{
UserContext.current().setEventDetails("Project Name: "+ getName());
public void create() throws ResourceAllocationException {
UserContext.current().setEventDetails("Project Name: " + getName());
Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
if (project != null) {
this.setEntityId(project.getId());
@ -138,14 +137,15 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_CREATE;
}
@Override
public String getEventDescription() {
return "creating project";
}
}

View File

@ -31,42 +31,42 @@ import com.cloud.event.EventTypes;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class, since="3.0.0")
@Implementation(description = "Accepts or declines project invitation", responseObject = SuccessResponse.class, since = "3.0.0")
public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName());
private static final String s_name = "deleteprojectinvitationresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="project_invitations")
@Parameter(name=ApiConstants.ID, required=true, type=CommandType.LONG, description="id of the invitation")
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName = "project_invitations")
@Parameter(name = ApiConstants.ID, required = true, type = CommandType.LONG, description = "id of the invitation")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
@Override
public String getCommandName() {
return s_name;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public long getEntityOwnerId() {
//TODO - return project entity ownerId
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
// TODO - return project entity ownerId
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
// tracked
}
@Override
public void execute(){
public void execute() {
UserContext.current().setEventDetails("Project invitation id " + id);
boolean result = _projectService.deleteProjectInvitation(id);
if (result) {
@ -76,14 +76,15 @@ public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the project invitation");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_INVITATION_REMOVE;
}
@Override
public String getEventDescription() {
return "Project invitatino id " + id + " is being removed";
return "Project invitatino id " + id + " is being removed";
}
}

View File

@ -31,30 +31,31 @@ import com.cloud.api.response.ListResponse;
import com.cloud.api.response.ProjectInvitationResponse;
import com.cloud.projects.ProjectInvitation;
@Implementation(description="Lists projects and provides detailed information for listed projects", responseObject=ProjectInvitationResponse.class, since="3.0.0")
@Implementation(description = "Lists projects and provides detailed information for listed projects", responseObject = ProjectInvitationResponse.class, since = "3.0.0")
public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName());
private static final String s_name = "listprojectinvitationsresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="list by project id")
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName = "projects")
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "list by project id")
private Long projectId;
@Parameter(name=ApiConstants.ACTIVE_ONLY, type=CommandType.BOOLEAN, description="if true, list only active invitations - having Pending state and ones that are not timed out yet")
@Parameter(name = ApiConstants.ACTIVE_ONLY, type = CommandType.BOOLEAN, description = "if true, list only active invitations - having Pending state and ones that are not timed out yet")
private boolean activeOnly;
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list invitations by state")
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "list invitations by state")
private String state;
@IdentityMapper(entityTableName="project_invitations")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list invitations by id")
@IdentityMapper(entityTableName = "project_invitations")
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "list invitations by id")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getProjectId() {
return projectId;
}
@ -66,7 +67,7 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
public String getState() {
return state;
}
public Long getId() {
return id;
}
@ -75,14 +76,15 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
public String getCommandName() {
return s_name;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute(){
List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(id, projectId, this.getAccountName(), this.getDomainId(), state, activeOnly, this.getStartIndex(), this.getPageSizeVal(), this.isRecursive(), this.listAll());
public void execute() {
List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(id, projectId, this.getAccountName(), this.getDomainId(), state, activeOnly, this.getStartIndex(), this.getPageSizeVal(),
this.isRecursive(), this.listAll());
ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>();
List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>();
for (ProjectInvitation invite : invites) {
@ -91,7 +93,8 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
}
response.setResponses(projectInvitationResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
@ -40,40 +40,40 @@ import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
import com.cloud.utils.exception.ExecutionException;
@Implementation(responseObject=UserVmResponse.class, description="Starts a virtual machine.")
public class StartVMCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
private static final String s_name = "startvirtualmachineresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Implementation(responseObject = UserVmResponse.class, description = "Starts a virtual machine.")
public class StartVMCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
@IdentityMapper(entityTableName="vm_instance")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
private static final String s_name = "startvirtualmachineresponse";
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName = "vm_instance")
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "The ID of the virtual machine")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
public String getCommandName() {
return s_name;
}
public static String getResultObjectName() {
return "virtualmachine";
}
public static String getResultObjectName() {
return "virtualmachine";
}
@Override
public long getEntityOwnerId() {
@ -82,7 +82,8 @@ public class StartVMCmd extends BaseAsyncCmd {
return vm.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
// tracked
}
@Override
@ -92,44 +93,45 @@ public class StartVMCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "starting user vm: " + getId();
return "starting user vm: " + getId();
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.VirtualMachine;
return AsyncJob.Type.VirtualMachine;
}
public Long getInstanceId() {
return getId();
return getId();
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException{
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
try {
UserContext.current().setEventDetails("Vm Id: "+getId());
UserContext.current().setEventDetails("Vm Id: " + getId());
UserVm result;
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
result = _bareMetalVmService.startVirtualMachine(this);
result = _bareMetalVmService.startVirtualMachine(this);
} else {
result = _userVmService.startVirtualMachine(this);
result = _userVmService.startVirtualMachine(this);
}
if (result != null){
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
}
}catch (ConcurrentOperationException ex) {
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}catch (StorageUnavailableException ex) {
} catch (StorageUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
}catch (ExecutionException ex) {
} catch (ExecutionException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
}
}
}
}
}

View File

@ -35,41 +35,40 @@ import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
@Implementation(responseObject=UserVmResponse.class, description="Stops a virtual machine.")
@Implementation(responseObject = UserVmResponse.class, description = "Stops a virtual machine.")
public class StopVMCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName());
private static final String s_name = "stopvirtualmachineresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName="vm_instance")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
@IdentityMapper(entityTableName = "vm_instance")
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "The ID of the virtual machine")
private Long id;
@Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.")
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force stop the VM. The caller knows the VM is stopped.")
private Boolean forced;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
public static String getResultObjectName() {
return "virtualmachine";
}
@ -81,7 +80,8 @@ public class StopVMCmd extends BaseAsyncCmd {
return vm.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
// tracked
}
@Override
@ -91,34 +91,34 @@ public class StopVMCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "stopping user vm: " + getId();
return "stopping user vm: " + getId();
}
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.VirtualMachine;
return AsyncJob.Type.VirtualMachine;
}
@Override
public Long getInstanceId() {
return getId();
return getId();
}
public boolean isForced() {
return (forced != null) ? forced : false;
}
@Override
public void execute() throws ServerApiException, ConcurrentOperationException{
UserContext.current().setEventDetails("Vm Id: "+getId());
public void execute() throws ServerApiException, ConcurrentOperationException {
UserContext.current().setEventDetails("Vm Id: " + getId());
UserVm result;
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
result = _bareMetalVmService.stopVirtualMachine(getId(), isForced());
result = _bareMetalVmService.stopVirtualMachine(getId(), isForced());
} else {
result = _userVmService.stopVirtualMachine(getId(), isForced());
result = _userVmService.stopVirtualMachine(getId(), isForced());
}
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
response.setResponseName(getCommandName());

View File

@ -31,31 +31,30 @@ import com.cloud.event.EventTypes;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class, since="3.0.0")
@Implementation(description = "Accepts or declines project invitation", responseObject = SuccessResponse.class, since = "3.0.0")
public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName());
private static final String s_name = "updateprojectinvitationresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="projects")
@Parameter(name=ApiConstants.PROJECT_ID, required=true, type=CommandType.LONG, description="id of the project to join")
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@IdentityMapper(entityTableName = "projects")
@Parameter(name = ApiConstants.PROJECT_ID, required = true, type = CommandType.LONG, description = "id of the project to join")
private Long projectId;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account that is joining the project")
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account that is joining the project")
private String accountName;
@Parameter(name=ApiConstants.TOKEN, type=CommandType.STRING, description="list invitations for specified account; this parameter has to be specified with domainId")
@Parameter(name = ApiConstants.TOKEN, type = CommandType.STRING, description = "list invitations for specified account; this parameter has to be specified with domainId")
private String token;
@Parameter(name=ApiConstants.ACCEPT, type=CommandType.BOOLEAN, description="if true, accept the invitation, decline if false. True by default")
@Parameter(name = ApiConstants.ACCEPT, type = CommandType.BOOLEAN, description = "if true, accept the invitation, decline if false. True by default")
private Boolean accept;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getProjectId() {
return projectId;
}
@ -63,37 +62,36 @@ public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
public String getAccountName() {
return accountName;
}
@Override
public String getCommandName() {
return s_name;
}
public String getToken() {
return token;
}
public Boolean getAccept() {
if (accept == null) {
return true;
}
return accept;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public long getEntityOwnerId() {
//TODO - return project entity ownerId
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
// TODO - return project entity ownerId
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are
// tracked
}
@Override
public void execute(){
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName + "; accept " + getAccept());
public void execute() {
UserContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName + "; accept " + getAccept());
boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
@ -102,14 +100,14 @@ public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to join the project");
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_PROJECT_INVITATION_UPDATE;
}
@Override
public String getEventDescription() {
return "Updating project invitation for projectId " + projectId;
return "Updating project invitation for projectId " + projectId;
}
}

View File

@ -26,31 +26,40 @@ import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
public class ProjectAccountResponse extends BaseResponse implements ControlledEntityResponse {
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="project id")
@SerializedName(ApiConstants.PROJECT_ID)
@Param(description = "project id")
private IdentityProxy projectId = new IdentityProxy("projects");
@SerializedName(ApiConstants.PROJECT) @Param(description="project name")
@SerializedName(ApiConstants.PROJECT)
@Param(description = "project name")
private String projectName;
@SerializedName(ApiConstants.ACCOUNT_ID) @Param(description="the id of the account")
@SerializedName(ApiConstants.ACCOUNT_ID)
@Param(description = "the id of the account")
private IdentityProxy id = new IdentityProxy("account");
@SerializedName(ApiConstants.ACCOUNT) @Param(description="the name of the account")
@SerializedName(ApiConstants.ACCOUNT)
@Param(description = "the name of the account")
private String accountName;
@SerializedName(ApiConstants.ACCOUNT_TYPE) @Param(description="account type (admin, domain-admin, user)")
@SerializedName(ApiConstants.ACCOUNT_TYPE)
@Param(description = "account type (admin, domain-admin, user)")
private Short accountType;
@SerializedName(ApiConstants.ROLE) @Param(description="account role in the project (regular,owner)")
@SerializedName(ApiConstants.ROLE)
@Param(description = "account role in the project (regular,owner)")
private String role;
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="id of the Domain the account belongs too")
@SerializedName(ApiConstants.DOMAIN_ID)
@Param(description = "id of the Domain the account belongs too")
private IdentityProxy domainId = new IdentityProxy("domain");
@SerializedName(ApiConstants.DOMAIN) @Param(description="name of the Domain the account belongs too")
@SerializedName(ApiConstants.DOMAIN)
@Param(description = "name of the Domain the account belongs too")
private String domainName;
@SerializedName(ApiConstants.USER) @Param(description="the list of users associated with account", responseObject = UserResponse.class)
@SerializedName(ApiConstants.USER)
@Param(description = "the list of users associated with account", responseObject = UserResponse.class)
private List<UserResponse> users;
public void setProjectId(Long projectId) {

View File

@ -175,12 +175,12 @@ public class ApiDispatcher {
Map<String, Object> unpackedParams = cmd.unpackParams(params);
if (cmd instanceof BaseListCmd) {
Object pageSizeObj = unpackedParams.get(ApiConstants.PAGE_SIZE);
Long pageSize = null;
if (pageSizeObj != null) {
pageSize = Long.valueOf((String)pageSizeObj);
}
Object pageSizeObj = unpackedParams.get(ApiConstants.PAGE_SIZE);
Long pageSize = null;
if (pageSizeObj != null) {
pageSize = Long.valueOf((String) pageSizeObj);
}
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
} else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) {
@ -206,13 +206,14 @@ public class ApiDispatcher {
if ((parameterAnnotation == null) || !parameterAnnotation.expose()) {
continue;
}
IdentityMapper identityMapper = field.getAnnotation(IdentityMapper.class);
Object paramObj = unpackedParams.get(parameterAnnotation.name());
if (paramObj == null) {
if (parameterAnnotation.required()) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + " due to missing parameter " + parameterAnnotation.name());
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to missing parameter "
+ parameterAnnotation.name());
}
continue;
}
@ -224,20 +225,23 @@ public class ApiDispatcher {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " + parameterAnnotation.name());
}
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + " due to invalid value " + paramObj + " for parameter "
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj
+ " for parameter "
+ parameterAnnotation.name());
} catch (ParseException parseEx) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8));
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
}
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + ", please pass dates in the format mentioned in the api documentation");
} catch (InvalidParameterValueException invEx){
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8) + " due to invalid value. " + invEx.getMessage());
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8)
+ ", please pass dates in the format mentioned in the api documentation");
} catch (InvalidParameterValueException invEx) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
} catch (CloudRuntimeException cloudEx) {
// FIXME: Better error message? This only happens if the API command is not executable, which typically means
// FIXME: Better error message? This only happens if the API command is not executable, which typically
// means
// there was
// and IllegalAccessException setting one of the parameters.
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length()-8));
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
}
}
}
@ -252,28 +256,29 @@ public class ApiDispatcher {
field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
break;
case DATE:
// This piece of code is for maintaining backward compatibility and support both the date formats(Bug 9724)
// This piece of code is for maintaining backward compatibility and support both the date formats(Bug
// 9724)
// Do the date massaging for ListEventsCmd only
if(cmdObj instanceof ListEventsCmd){
if (cmdObj instanceof ListEventsCmd) {
boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
if (isObjInNewDateFormat){
if (isObjInNewDateFormat) {
DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
synchronized (newFormat) {
field.set(cmdObj, newFormat.parse(paramObj.toString()));
field.set(cmdObj, newFormat.parse(paramObj.toString()));
}
}else{
} else {
DateFormat format = BaseCmd.INPUT_FORMAT;
synchronized (format) {
Date date = format.parse(paramObj.toString());
if (field.getName().equals("startDate")){
Date date = format.parse(paramObj.toString());
if (field.getName().equals("startDate")) {
date = massageDate(date, 0, 0, 0);
}else if (field.getName().equals("endDate")){
} else if (field.getName().equals("endDate")) {
date = massageDate(date, 23, 59, 59);
}
field.set(cmdObj, date);
}
}
}else{
}
} else {
DateFormat format = BaseCmd.INPUT_FORMAT;
format.setLenient(false);
synchronized (format) {
@ -297,16 +302,15 @@ public class ApiDispatcher {
case INTEGER:
listParam.add(Integer.valueOf(token));
break;
case LONG:
{
Long val = null;
if(identityMapper != null)
val = s_instance._identityDao.getIdentityId(identityMapper, token);
else
val = Long.valueOf(token);
listParam.add(val);
}
case LONG: {
Long val = null;
if (identityMapper != null)
val = s_instance._identityDao.getIdentityId(identityMapper, token);
else
val = Long.valueOf(token);
listParam.add(val);
}
break;
case SHORT:
listParam.add(Short.valueOf(token));
@ -318,19 +322,19 @@ public class ApiDispatcher {
field.set(cmdObj, listParam);
break;
case LONG:
if(identityMapper != null)
field.set(cmdObj, s_instance._identityDao.getIdentityId(identityMapper, paramObj.toString()));
else
field.set(cmdObj, Long.valueOf(paramObj.toString()));
if (identityMapper != null)
field.set(cmdObj, s_instance._identityDao.getIdentityId(identityMapper, paramObj.toString()));
else
field.set(cmdObj, Long.valueOf(paramObj.toString()));
break;
case SHORT:
field.set(cmdObj, Short.valueOf(paramObj.toString()));
break;
case STRING:
if((paramObj != null) && paramObj.toString().length() > annotation.length()){
s_logger.error("Value greater than max allowed length "+annotation.length()+" for param: "+field.getName());
throw new InvalidParameterValueException("Value greater than max allowed length "+annotation.length()+" for param: "+field.getName());
}
if ((paramObj != null) && paramObj.toString().length() > annotation.length()) {
s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
}
field.set(cmdObj, paramObj.toString());
break;
case TZDATE:
@ -346,12 +350,12 @@ public class ApiDispatcher {
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() + " is not accessible]");
}
}
private static boolean isObjInNewDateFormat(String string) {
Matcher matcher = BaseCmd.newInputDateFormat.matcher(string);
return matcher.matches();
}
private static Date massageDate(Date date, int hourOfDay, int minute, int second) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
@ -360,10 +364,10 @@ public class ApiDispatcher {
cal.set(Calendar.SECOND, second);
return cal.getTime();
}
public static void plugService(BaseCmd cmd) {
if(!ApiServer.isPluggableServiceCommand(cmd.getClass().getName())){
if (!ApiServer.isPluggableServiceCommand(cmd.getClass().getName())) {
return;
}
Class<?> clazz = cmd.getClass();
@ -379,12 +383,12 @@ public class ApiDispatcher {
Object instance = null;
if (PluggableService.class.isAssignableFrom(fc)) {
instance = locator.getPluggableService(fc);
}
}
if (instance == null) {
throw new CloudRuntimeException("Unable to plug service " + fc.getSimpleName() + " in command " + clazz.getSimpleName());
}
try {
field.setAccessible(true);
field.set(cmd, instance);

View File

@ -335,7 +335,7 @@ public class ApiServer implements HttpRequestHandler {
responseType = paramValue[1];
} else {
// according to the servlet spec, the parameter map should be in the form (name=String,
// value=String[]), so
// value=String[]), so
// parameter values will be stored in an array
parameterMap.put(/* name */paramValue[0], /* value */new String[] { paramValue[1] });
}
@ -867,7 +867,7 @@ public class ApiServer implements HttpRequestHandler {
// FIXME: the following two threads are copied from
// http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
// we have to cite a license if we are using this code directly, so we need to add the appropriate citation or
// modify the
// modify the
// code to be very specific to our needs
static class ListenerThread extends Thread {
private HttpService _httpService = null;

View File

@ -16,49 +16,49 @@ import com.cloud.api.Identity;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="project_invitations")
@Table(name = "project_invitations")
public class ProjectInvitationVO implements ProjectInvitation, Identity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name="project_id")
@Column(name = "project_id")
private long projectId;
@Column(name="account_id")
@Column(name = "account_id")
private Long forAccountId;
@Column(name="domain_id")
@Column(name = "domain_id")
private Long inDomainId;
@Column(name="token")
@Column(name = "token")
private String token;
@Column(name="email")
@Column(name = "email")
private String email;
@Column(name="state")
@Enumerated(value=EnumType.STRING)
@Column(name = "state")
@Enumerated(value = EnumType.STRING)
private State state = State.Pending;
@Column(name=GenericDao.CREATED_COLUMN)
@Column(name = GenericDao.CREATED_COLUMN)
private Date created;
@Column(name="uuid")
@Column(name = "uuid")
private String uuid;
protected ProjectInvitationVO(){
this.uuid = UUID.randomUUID().toString();
protected ProjectInvitationVO() {
this.uuid = UUID.randomUUID().toString();
}
public ProjectInvitationVO(long projectId, Long accountId, Long domainId, String email, String token) {
this.forAccountId = accountId;
this.inDomainId = domainId;
this.projectId = projectId;
this.email = email;
this.token = token;
this.uuid = UUID.randomUUID().toString();
this.forAccountId = accountId;
this.inDomainId = domainId;
this.projectId = projectId;
this.email = email;
this.token = token;
this.uuid = UUID.randomUUID().toString();
}
@Override
@ -89,8 +89,8 @@ public class ProjectInvitationVO implements ProjectInvitation, Identity {
@Override
public Date getCreated() {
return created;
}
}
@Override
public State getState() {
return state;
@ -99,7 +99,7 @@ public class ProjectInvitationVO implements ProjectInvitation, Identity {
public void setState(State state) {
this.state = state;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder("ProjectInvitation[");
@ -111,21 +111,21 @@ public class ProjectInvitationVO implements ProjectInvitation, Identity {
public Long getInDomainId() {
return inDomainId;
}
@Override
public String getUuid() {
return this.uuid;
return this.uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
this.uuid = uuid;
}
@Override
public long getDomainId() {
return inDomainId == null ? -1 : inDomainId;
}
@Override
public long getAccountId() {
return forAccountId == null ? -1 : forAccountId;

View File

@ -1,4 +1,3 @@
package com.cloud.projects;
import java.util.List;
@ -11,10 +10,11 @@ public interface ProjectManager extends ProjectService {
boolean canModifyProjectAccount(Account caller, long accountId);
boolean deleteAccountFromProject(long projectId, long accountId);
List<Long> listPermittedProjectAccounts(long accountId);
boolean projectInviteRequired();
boolean allowUserToCreateProject();
boolean projectInviteRequired();
boolean allowUserToCreateProject();
}

View File

@ -23,18 +23,20 @@ import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectAccountVO;
import com.cloud.utils.db.GenericDao;
public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long>{
public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
ProjectAccountVO getProjectOwner(long projectId);
List<ProjectAccountVO> listByProjectId(long projectId);
ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId);
boolean canAccessProjectAccount(long accountId, long projectAccountId);
boolean canModifyProjectAccount(long accountId, long projectAccountId);
List<Long> listPermittedAccountIds(long accountId);
List<Long> listAdministratedProjects(long adminAccountId);
Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role);
}

View File

@ -30,13 +30,13 @@ import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
@Local(value={ProjectAccountDao.class})
@Local(value = { ProjectAccountDao.class })
public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long> implements ProjectAccountDao {
protected final SearchBuilder<ProjectAccountVO> AllFieldsSearch;
final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch;
final GenericSearchBuilder<ProjectAccountVO, Long> ProjectAccountSearch;
final GenericSearchBuilder<ProjectAccountVO, Long> CountByRoleSearch;
protected ProjectAccountDaoImpl() {
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("role", AllFieldsSearch.entity().getAccountRole(), SearchCriteria.Op.EQ);
@ -44,57 +44,57 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ);
AllFieldsSearch.done();
AdminSearch = createSearchBuilder(Long.class);
AdminSearch.selectField(AdminSearch.entity().getProjectId());
AdminSearch.and("role", AdminSearch.entity().getAccountRole(), Op.EQ);
AdminSearch.and("accountId", AdminSearch.entity().getAccountId(), Op.EQ);
AdminSearch.done();
ProjectAccountSearch = createSearchBuilder(Long.class);
ProjectAccountSearch.selectField(ProjectAccountSearch.entity().getProjectAccountId());
ProjectAccountSearch.and("accountId", ProjectAccountSearch.entity().getAccountId(), Op.EQ);
ProjectAccountSearch.done();
CountByRoleSearch = createSearchBuilder(Long.class);
CountByRoleSearch.select(null, Func.COUNT, CountByRoleSearch.entity().getId());
CountByRoleSearch.and("accountId", CountByRoleSearch.entity().getAccountId(), Op.EQ);
CountByRoleSearch.and("role", CountByRoleSearch.entity().getAccountRole(), Op.EQ);
CountByRoleSearch.done();
}
@Override
public ProjectAccountVO getProjectOwner(long projectId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("role", ProjectAccount.Role.Admin);
sc.setParameters("projectId", projectId);
return findOneBy(sc);
}
@Override
public List<ProjectAccountVO> listByProjectId(long projectId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("projectId", projectId);
return listBy(sc);
}
@Override
public ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("projectId", projectId);
sc.setParameters("accountId", accountId);
return findOneBy(sc);
}
@Override
public boolean canAccessProjectAccount(long accountId, long projectAccountId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("accountId", accountId);
sc.setParameters("projectAccountId", projectAccountId);
if (findOneBy(sc) != null) {
return true;
} else {
@ -108,21 +108,21 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
sc.setParameters("accountId", accountId);
sc.setParameters("projectAccountId", projectAccountId);
sc.setParameters("role", ProjectAccount.Role.Admin);
if (findOneBy(sc) != null) {
return true;
} else {
return false;
}
}
@Override
public List<Long> listPermittedAccountIds(long accountId) {
SearchCriteria<Long> sc = ProjectAccountSearch.create();
sc.setParameters("accountId", accountId);
return customSearch(sc, null);
}
@Override
public List<Long> listAdministratedProjects(long adminAccountId) {
SearchCriteria<Long> sc = AdminSearch.create();
@ -130,12 +130,13 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
sc.setParameters("accountId", adminAccountId);
return customSearch(sc, null);
}
@Override
public Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role) {
SearchCriteria<Long> sc = CountByRoleSearch.create();
SearchCriteria<Long> sc = CountByRoleSearch.create();
sc.setParameters("accountId", accountId);
sc.setParameters("role", role);
return customSearch(sc, null).get(0);
}
}

View File

@ -23,13 +23,14 @@ import com.cloud.projects.Project;
import com.cloud.projects.ProjectVO;
import com.cloud.utils.db.GenericDao;
public interface ProjectDao extends GenericDao<ProjectVO, Long>{
public interface ProjectDao extends GenericDao<ProjectVO, Long> {
ProjectVO findByNameAndDomain(String name, long domainId);
Long countProjectsForDomain(long domainId);
ProjectVO findByProjectAccountId(long projectAccountId);
List<ProjectVO> listByState(Project.State state);
}

View File

@ -16,13 +16,13 @@ import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.Transaction;
@Local(value={ProjectDao.class})
@Local(value = { ProjectDao.class })
public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements ProjectDao {
private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class);
protected final SearchBuilder<ProjectVO> AllFieldsSearch;
protected GenericSearchBuilder<ProjectVO, Long> CountByDomain;
protected GenericSearchBuilder<ProjectVO, Long> ProjectAccountSearch;
protected ProjectDaoImpl() {
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ);
@ -30,23 +30,24 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
AllFieldsSearch.done();
CountByDomain = createSearchBuilder(Long.class);
CountByDomain.select(null, Func.COUNT, null);
CountByDomain.and("domainId", CountByDomain.entity().getDomainId(), SearchCriteria.Op.EQ);
CountByDomain.and("domainId", CountByDomain.entity().getDomainId(), SearchCriteria.Op.EQ);
CountByDomain.done();
}
@Override
public ProjectVO findByNameAndDomain(String name, long domainId) {
SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
sc.setParameters("name", name);
sc.setParameters("domainId", domainId);
return findOneBy(sc);
}
@Override @DB
@Override
@DB
public boolean remove(Long projectId) {
boolean result = false;
Transaction txn = Transaction.currentTxn();
@ -57,34 +58,35 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
s_logger.warn("Failed to reset name for the project id=" + projectId + " as a part of project remove");
return false;
} else {
}
result = super.remove(projectId);
txn.commit();
return result;
}
@Override
public Long countProjectsForDomain(long domainId) {
SearchCriteria<Long> sc = CountByDomain.create();
sc.setParameters("domainId", domainId);
return customSearch(sc, null).get(0);
return customSearch(sc, null).get(0);
}
@Override
public ProjectVO findByProjectAccountId(long projectAccountId) {
public ProjectVO findByProjectAccountId(long projectAccountId) {
SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
sc.setParameters("projectAccountId", projectAccountId);
return findOneBy(sc);
}
@Override
public List<ProjectVO> listByState(Project.State state) {
SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
sc.setParameters("state", state);
return listBy(sc);
}
}

View File

@ -23,14 +23,23 @@ import com.cloud.projects.ProjectInvitation.State;
import com.cloud.projects.ProjectInvitationVO;
import com.cloud.utils.db.GenericDao;
public interface ProjectInvitationDao extends GenericDao<ProjectInvitationVO, Long>{
public interface ProjectInvitationDao extends GenericDao<ProjectInvitationVO, Long> {
ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState);
List<ProjectInvitationVO> listExpiredInvitations();
boolean expirePendingInvitations(long timeOut);
boolean isActive(long id, long timeout);
ProjectInvitationVO findByEmailAndProjectId(String email, long projectId, State... inviteState);
ProjectInvitationVO findPendingByTokenAndProjectId(String token, long projectId, State... inviteState);
void cleanupInvitations(long projectId);
void cleanupInvitations(long projectId);
ProjectInvitationVO findPendingById(long id);
List<ProjectInvitationVO> listInvitationsToExpire(long timeOut);
}

View File

@ -14,12 +14,12 @@ import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@Local(value={ProjectInvitationDao.class})
@Local(value = { ProjectInvitationDao.class })
public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO, Long> implements ProjectInvitationDao {
private static final Logger s_logger = Logger.getLogger(ProjectInvitationDaoImpl.class);
protected final SearchBuilder<ProjectInvitationVO> AllFieldsSearch;
protected final SearchBuilder<ProjectInvitationVO> InactiveSearch;
protected ProjectInvitationDaoImpl() {
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getForAccountId(), SearchCriteria.Op.EQ);
@ -31,7 +31,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
AllFieldsSearch.and("token", AllFieldsSearch.entity().getToken(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
AllFieldsSearch.done();
InactiveSearch = createSearchBuilder();
InactiveSearch.and("id", InactiveSearch.entity().getId(), SearchCriteria.Op.EQ);
InactiveSearch.and("accountId", InactiveSearch.entity().getForAccountId(), SearchCriteria.Op.EQ);
@ -40,36 +40,35 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
InactiveSearch.and("state", InactiveSearch.entity().getState(), SearchCriteria.Op.EQ);
InactiveSearch.done();
}
@Override
public ProjectInvitationVO findByAccountIdProjectId(long accountId, long projectId, State... inviteState) {
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
sc.setParameters("accountId", accountId);
sc.setParameters("projectId", projectId);
if (inviteState != null && inviteState.length > 0) {
sc.setParameters("state", (Object[])inviteState);
sc.setParameters("state", (Object[]) inviteState);
}
return findOneBy(sc);
}
@Override
public List<ProjectInvitationVO> listExpiredInvitations() {
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
sc.setParameters("state", State.Expired);
return listBy(sc);
}
@Override
public boolean expirePendingInvitations(long timeout) {
boolean success = true;
SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime() >> 10) - timeout));
sc.setParameters("state", State.Pending);
List<ProjectInvitationVO> invitationsToExpire = listBy(sc);
for (ProjectInvitationVO invitationToExpire : invitationsToExpire) {
invitationToExpire.setState(State.Expired);
@ -80,74 +79,75 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase<ProjectInvitationVO
}
return success;
}
@Override
public List<ProjectInvitationVO> listInvitationsToExpire (long timeOut) {
SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
public List<ProjectInvitationVO> listInvitationsToExpire(long timeOut) {
SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - timeOut));
sc.setParameters("state", State.Pending);
return listBy(sc);
}
@Override
public boolean isActive(long id, long timeout) {
SearchCriteria<ProjectInvitationVO> sc = InactiveSearch.create();
sc.setParameters("id", id);
if (findOneBy(sc) == null) {
s_logger.warn("Unable to find project invitation by id " + id);
return false;
}
sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - timeout));
if (findOneBy(sc) == null) {
return true;
} else {
return false;
}
}
@Override
public ProjectInvitationVO findByEmailAndProjectId(String email, long projectId, State... inviteState) {
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
sc.setParameters("email", email);
sc.setParameters("projectId", projectId);
if (inviteState != null && inviteState.length > 0) {
sc.setParameters("state", (Object[])inviteState);
sc.setParameters("state", (Object[]) inviteState);
}
return findOneBy(sc);
}
@Override
public ProjectInvitationVO findPendingByTokenAndProjectId(String token, long projectId, State... inviteState) {
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
sc.setParameters("token", token);
sc.setParameters("projectId", projectId);
if (inviteState != null && inviteState.length > 0) {
sc.setParameters("state", (Object[])inviteState);
sc.setParameters("state", (Object[]) inviteState);
}
return findOneBy(sc);
}
@Override
public ProjectInvitationVO findPendingById(long id) {
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
sc.setParameters("id", id);
sc.setParameters("state", State.Pending);
return findOneBy(sc);
}
@Override
public void cleanupInvitations(long projectId) {
SearchCriteria<ProjectInvitationVO> sc = AllFieldsSearch.create();
sc.setParameters("projectId", projectId);
int numberRemoved = remove(sc);
s_logger.debug("Removed " + numberRemoved + " invitations for project id=" + projectId);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff