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

View File

@ -31,42 +31,42 @@ import com.cloud.event.EventTypes;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.user.UserContext; 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 class DeleteProjectInvitationCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName()); public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName());
private static final String s_name = "deleteprojectinvitationresponse"; private static final String s_name = "deleteprojectinvitationresponse";
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
//////////////// API parameters ///////////////////// // ////////////// API parameters /////////////////////
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
@IdentityMapper(entityTableName="project_invitations") @IdentityMapper(entityTableName = "project_invitations")
@Parameter(name=ApiConstants.ID, required=true, type=CommandType.LONG, description="id of the invitation") @Parameter(name = ApiConstants.ID, required = true, type = CommandType.LONG, description = "id of the invitation")
private Long id; private Long id;
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
/////////////////// Accessors /////////////////////// // ///////////////// Accessors ///////////////////////
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
public Long getId() { public Long getId() {
return id; return id;
} }
@Override @Override
public String getCommandName() { public String getCommandName() {
return s_name; return s_name;
} }
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
/////////////// API Implementation/////////////////// // ///////////// API Implementation///////////////////
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
@Override @Override
public long getEntityOwnerId() { public long getEntityOwnerId() {
//TODO - return project entity ownerId // TODO - return project entity ownerId
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 @Override
public void execute(){ public void execute() {
UserContext.current().setEventDetails("Project invitation id " + id); UserContext.current().setEventDetails("Project invitation id " + id);
boolean result = _projectService.deleteProjectInvitation(id); boolean result = _projectService.deleteProjectInvitation(id);
if (result) { if (result) {
@ -76,14 +76,15 @@ public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the project invitation"); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the project invitation");
} }
} }
@Override @Override
public String getEventType() { public String getEventType() {
return EventTypes.EVENT_PROJECT_INVITATION_REMOVE; return EventTypes.EVENT_PROJECT_INVITATION_REMOVE;
} }
@Override @Override
public String getEventDescription() { 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.api.response.ProjectInvitationResponse;
import com.cloud.projects.ProjectInvitation; 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 class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName()); public static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName());
private static final String s_name = "listprojectinvitationsresponse"; private static final String s_name = "listprojectinvitationsresponse";
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
//////////////// API parameters ///////////////////// // ////////////// API parameters /////////////////////
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
@IdentityMapper(entityTableName="projects") @IdentityMapper(entityTableName = "projects")
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="list by project id") @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "list by project id")
private Long projectId; 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; 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; private String state;
@IdentityMapper(entityTableName="project_invitations") @IdentityMapper(entityTableName = "project_invitations")
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list invitations by id") @Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "list invitations by id")
private Long id; private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors /////////////////////// // ///////////////////////////////////////////////////
///////////////////////////////////////////////////// // ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getProjectId() { public Long getProjectId() {
return projectId; return projectId;
} }
@ -66,7 +67,7 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
public String getState() { public String getState() {
return state; return state;
} }
public Long getId() { public Long getId() {
return id; return id;
} }
@ -75,14 +76,15 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
public String getCommandName() { public String getCommandName() {
return s_name; return s_name;
} }
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
/////////////// API Implementation/////////////////// // ///////////// API Implementation///////////////////
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
@Override @Override
public void execute(){ 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()); 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>(); ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>();
List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>(); List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>();
for (ProjectInvitation invite : invites) { for (ProjectInvitation invite : invites) {
@ -91,7 +93,8 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd {
} }
response.setResponses(projectInvitationResponses); response.setResponses(projectInvitationResponses);
response.setResponseName(getCommandName()); response.setResponseName(getCommandName());
this.setResponseObject(response); this.setResponseObject(response);
} }
} }

View File

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

View File

@ -31,31 +31,30 @@ import com.cloud.event.EventTypes;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.user.UserContext; 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 class UpdateProjectInvitationCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName()); public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName());
private static final String s_name = "updateprojectinvitationresponse"; private static final String s_name = "updateprojectinvitationresponse";
// ///////////////////////////////////////////////////
///////////////////////////////////////////////////// // ////////////// API parameters /////////////////////
//////////////// API parameters ///////////////////// // ///////////////////////////////////////////////////
///////////////////////////////////////////////////// @IdentityMapper(entityTableName = "projects")
@IdentityMapper(entityTableName="projects") @Parameter(name = ApiConstants.PROJECT_ID, required = true, type = CommandType.LONG, description = "id of the project to join")
@Parameter(name=ApiConstants.PROJECT_ID, required=true, type=CommandType.LONG, description="id of the project to join")
private Long projectId; 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; 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; 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; private Boolean accept;
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
/////////////////// Accessors /////////////////////// // ///////////////// Accessors ///////////////////////
///////////////////////////////////////////////////// // ///////////////////////////////////////////////////
public Long getProjectId() { public Long getProjectId() {
return projectId; return projectId;
} }
@ -63,37 +62,36 @@ public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
public String getAccountName() { public String getAccountName() {
return accountName; return accountName;
} }
@Override @Override
public String getCommandName() { public String getCommandName() {
return s_name; return s_name;
} }
public String getToken() { public String getToken() {
return token; return token;
} }
public Boolean getAccept() { public Boolean getAccept() {
if (accept == null) { if (accept == null) {
return true; return true;
} }
return accept; return accept;
} }
// ///////////////////////////////////////////////////
///////////////////////////////////////////////////// // ///////////// API Implementation///////////////////
/////////////// API Implementation/////////////////// // ///////////////////////////////////////////////////
/////////////////////////////////////////////////////
@Override @Override
public long getEntityOwnerId() { public long getEntityOwnerId() {
//TODO - return project entity ownerId // TODO - return project entity ownerId
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 @Override
public void execute(){ public void execute() {
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName + "; accept " + getAccept()); UserContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName + "; accept " + getAccept());
boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept()); boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept());
if (result) { if (result) {
SuccessResponse response = new SuccessResponse(getCommandName()); 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"); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to join the project");
} }
} }
@Override @Override
public String getEventType() { public String getEventType() {
return EventTypes.EVENT_PROJECT_INVITATION_UPDATE; return EventTypes.EVENT_PROJECT_INVITATION_UPDATE;
} }
@Override @Override
public String getEventDescription() { 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") @SuppressWarnings("unused")
public class ProjectAccountResponse extends BaseResponse implements ControlledEntityResponse { 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"); private IdentityProxy projectId = new IdentityProxy("projects");
@SerializedName(ApiConstants.PROJECT) @Param(description="project name") @SerializedName(ApiConstants.PROJECT)
@Param(description = "project name")
private String projectName; 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"); 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; 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; 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; 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"); 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; 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; private List<UserResponse> users;
public void setProjectId(Long projectId) { public void setProjectId(Long projectId) {

View File

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

View File

@ -335,7 +335,7 @@ public class ApiServer implements HttpRequestHandler {
responseType = paramValue[1]; responseType = paramValue[1];
} else { } else {
// according to the servlet spec, the parameter map should be in the form (name=String, // 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 // parameter values will be stored in an array
parameterMap.put(/* name */paramValue[0], /* value */new String[] { paramValue[1] }); 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 // 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 // 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 // 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 // code to be very specific to our needs
static class ListenerThread extends Thread { static class ListenerThread extends Thread {
private HttpService _httpService = null; private HttpService _httpService = null;

View File

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

View File

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

View File

@ -23,18 +23,20 @@ import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectAccountVO; import com.cloud.projects.ProjectAccountVO;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long>{ public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
ProjectAccountVO getProjectOwner(long projectId); ProjectAccountVO getProjectOwner(long projectId);
List<ProjectAccountVO> listByProjectId(long projectId); List<ProjectAccountVO> listByProjectId(long projectId);
ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId); ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId);
boolean canAccessProjectAccount(long accountId, long projectAccountId); boolean canAccessProjectAccount(long accountId, long projectAccountId);
boolean canModifyProjectAccount(long accountId, long projectAccountId); boolean canModifyProjectAccount(long accountId, long projectAccountId);
List<Long> listPermittedAccountIds(long accountId); List<Long> listPermittedAccountIds(long accountId);
List<Long> listAdministratedProjects(long adminAccountId); List<Long> listAdministratedProjects(long adminAccountId);
Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role); 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.Func;
import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.SearchCriteria.Op;
@Local(value={ProjectAccountDao.class}) @Local(value = { ProjectAccountDao.class })
public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long> implements ProjectAccountDao { public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long> implements ProjectAccountDao {
protected final SearchBuilder<ProjectAccountVO> AllFieldsSearch; protected final SearchBuilder<ProjectAccountVO> AllFieldsSearch;
final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch; final GenericSearchBuilder<ProjectAccountVO, Long> AdminSearch;
final GenericSearchBuilder<ProjectAccountVO, Long> ProjectAccountSearch; final GenericSearchBuilder<ProjectAccountVO, Long> ProjectAccountSearch;
final GenericSearchBuilder<ProjectAccountVO, Long> CountByRoleSearch; final GenericSearchBuilder<ProjectAccountVO, Long> CountByRoleSearch;
protected ProjectAccountDaoImpl() { protected ProjectAccountDaoImpl() {
AllFieldsSearch = createSearchBuilder(); AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("role", AllFieldsSearch.entity().getAccountRole(), SearchCriteria.Op.EQ); 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("accountId", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ);
AllFieldsSearch.done(); AllFieldsSearch.done();
AdminSearch = createSearchBuilder(Long.class); AdminSearch = createSearchBuilder(Long.class);
AdminSearch.selectField(AdminSearch.entity().getProjectId()); AdminSearch.selectField(AdminSearch.entity().getProjectId());
AdminSearch.and("role", AdminSearch.entity().getAccountRole(), Op.EQ); AdminSearch.and("role", AdminSearch.entity().getAccountRole(), Op.EQ);
AdminSearch.and("accountId", AdminSearch.entity().getAccountId(), Op.EQ); AdminSearch.and("accountId", AdminSearch.entity().getAccountId(), Op.EQ);
AdminSearch.done(); AdminSearch.done();
ProjectAccountSearch = createSearchBuilder(Long.class); ProjectAccountSearch = createSearchBuilder(Long.class);
ProjectAccountSearch.selectField(ProjectAccountSearch.entity().getProjectAccountId()); ProjectAccountSearch.selectField(ProjectAccountSearch.entity().getProjectAccountId());
ProjectAccountSearch.and("accountId", ProjectAccountSearch.entity().getAccountId(), Op.EQ); ProjectAccountSearch.and("accountId", ProjectAccountSearch.entity().getAccountId(), Op.EQ);
ProjectAccountSearch.done(); ProjectAccountSearch.done();
CountByRoleSearch = createSearchBuilder(Long.class); CountByRoleSearch = createSearchBuilder(Long.class);
CountByRoleSearch.select(null, Func.COUNT, CountByRoleSearch.entity().getId()); CountByRoleSearch.select(null, Func.COUNT, CountByRoleSearch.entity().getId());
CountByRoleSearch.and("accountId", CountByRoleSearch.entity().getAccountId(), Op.EQ); CountByRoleSearch.and("accountId", CountByRoleSearch.entity().getAccountId(), Op.EQ);
CountByRoleSearch.and("role", CountByRoleSearch.entity().getAccountRole(), Op.EQ); CountByRoleSearch.and("role", CountByRoleSearch.entity().getAccountRole(), Op.EQ);
CountByRoleSearch.done(); CountByRoleSearch.done();
} }
@Override @Override
public ProjectAccountVO getProjectOwner(long projectId) { public ProjectAccountVO getProjectOwner(long projectId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create(); SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("role", ProjectAccount.Role.Admin); sc.setParameters("role", ProjectAccount.Role.Admin);
sc.setParameters("projectId", projectId); sc.setParameters("projectId", projectId);
return findOneBy(sc); return findOneBy(sc);
} }
@Override @Override
public List<ProjectAccountVO> listByProjectId(long projectId) { public List<ProjectAccountVO> listByProjectId(long projectId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create(); SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("projectId", projectId); sc.setParameters("projectId", projectId);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId) { public ProjectAccountVO findByProjectIdAccountId(long projectId, long accountId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create(); SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("projectId", projectId); sc.setParameters("projectId", projectId);
sc.setParameters("accountId", accountId); sc.setParameters("accountId", accountId);
return findOneBy(sc); return findOneBy(sc);
} }
@Override @Override
public boolean canAccessProjectAccount(long accountId, long projectAccountId) { public boolean canAccessProjectAccount(long accountId, long projectAccountId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create(); SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("accountId", accountId); sc.setParameters("accountId", accountId);
sc.setParameters("projectAccountId", projectAccountId); sc.setParameters("projectAccountId", projectAccountId);
if (findOneBy(sc) != null) { if (findOneBy(sc) != null) {
return true; return true;
} else { } else {
@ -108,21 +108,21 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
sc.setParameters("accountId", accountId); sc.setParameters("accountId", accountId);
sc.setParameters("projectAccountId", projectAccountId); sc.setParameters("projectAccountId", projectAccountId);
sc.setParameters("role", ProjectAccount.Role.Admin); sc.setParameters("role", ProjectAccount.Role.Admin);
if (findOneBy(sc) != null) { if (findOneBy(sc) != null) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
@Override @Override
public List<Long> listPermittedAccountIds(long accountId) { public List<Long> listPermittedAccountIds(long accountId) {
SearchCriteria<Long> sc = ProjectAccountSearch.create(); SearchCriteria<Long> sc = ProjectAccountSearch.create();
sc.setParameters("accountId", accountId); sc.setParameters("accountId", accountId);
return customSearch(sc, null); return customSearch(sc, null);
} }
@Override @Override
public List<Long> listAdministratedProjects(long adminAccountId) { public List<Long> listAdministratedProjects(long adminAccountId) {
SearchCriteria<Long> sc = AdminSearch.create(); SearchCriteria<Long> sc = AdminSearch.create();
@ -130,12 +130,13 @@ public class ProjectAccountDaoImpl extends GenericDaoBase<ProjectAccountVO, Long
sc.setParameters("accountId", adminAccountId); sc.setParameters("accountId", adminAccountId);
return customSearch(sc, null); return customSearch(sc, null);
} }
@Override @Override
public Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role) { public Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role) {
SearchCriteria<Long> sc = CountByRoleSearch.create(); SearchCriteria<Long> sc = CountByRoleSearch.create();
sc.setParameters("accountId", accountId); sc.setParameters("accountId", accountId);
sc.setParameters("role", role); sc.setParameters("role", role);
return customSearch(sc, null).get(0); 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.projects.ProjectVO;
import com.cloud.utils.db.GenericDao; 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); ProjectVO findByNameAndDomain(String name, long domainId);
Long countProjectsForDomain(long domainId); Long countProjectsForDomain(long domainId);
ProjectVO findByProjectAccountId(long projectAccountId); ProjectVO findByProjectAccountId(long projectAccountId);
List<ProjectVO> listByState(Project.State state); 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.SearchCriteria.Func;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
@Local(value={ProjectDao.class}) @Local(value = { ProjectDao.class })
public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements ProjectDao { public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements ProjectDao {
private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class); private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class);
protected final SearchBuilder<ProjectVO> AllFieldsSearch; protected final SearchBuilder<ProjectVO> AllFieldsSearch;
protected GenericSearchBuilder<ProjectVO, Long> CountByDomain; protected GenericSearchBuilder<ProjectVO, Long> CountByDomain;
protected GenericSearchBuilder<ProjectVO, Long> ProjectAccountSearch; protected GenericSearchBuilder<ProjectVO, Long> ProjectAccountSearch;
protected ProjectDaoImpl() { protected ProjectDaoImpl() {
AllFieldsSearch = createSearchBuilder(); AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ); 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("projectAccountId", AllFieldsSearch.entity().getProjectAccountId(), SearchCriteria.Op.EQ);
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ); AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
AllFieldsSearch.done(); AllFieldsSearch.done();
CountByDomain = createSearchBuilder(Long.class); CountByDomain = createSearchBuilder(Long.class);
CountByDomain.select(null, Func.COUNT, null); 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(); CountByDomain.done();
} }
@Override @Override
public ProjectVO findByNameAndDomain(String name, long domainId) { public ProjectVO findByNameAndDomain(String name, long domainId) {
SearchCriteria<ProjectVO> sc = AllFieldsSearch.create(); SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
sc.setParameters("name", name); sc.setParameters("name", name);
sc.setParameters("domainId", domainId); sc.setParameters("domainId", domainId);
return findOneBy(sc); return findOneBy(sc);
} }
@Override @DB @Override
@DB
public boolean remove(Long projectId) { public boolean remove(Long projectId) {
boolean result = false; boolean result = false;
Transaction txn = Transaction.currentTxn(); 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"); s_logger.warn("Failed to reset name for the project id=" + projectId + " as a part of project remove");
return false; return false;
} else { } else {
} }
result = super.remove(projectId); result = super.remove(projectId);
txn.commit(); txn.commit();
return result; return result;
} }
@Override @Override
public Long countProjectsForDomain(long domainId) { public Long countProjectsForDomain(long domainId) {
SearchCriteria<Long> sc = CountByDomain.create(); SearchCriteria<Long> sc = CountByDomain.create();
sc.setParameters("domainId", domainId); sc.setParameters("domainId", domainId);
return customSearch(sc, null).get(0); return customSearch(sc, null).get(0);
} }
@Override @Override
public ProjectVO findByProjectAccountId(long projectAccountId) { public ProjectVO findByProjectAccountId(long projectAccountId) {
SearchCriteria<ProjectVO> sc = AllFieldsSearch.create(); SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
sc.setParameters("projectAccountId", projectAccountId); sc.setParameters("projectAccountId", projectAccountId);
return findOneBy(sc); return findOneBy(sc);
} }
@Override @Override
public List<ProjectVO> listByState(Project.State state) { public List<ProjectVO> listByState(Project.State state) {
SearchCriteria<ProjectVO> sc = AllFieldsSearch.create(); SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
sc.setParameters("state", state); sc.setParameters("state", state);
return listBy(sc); return listBy(sc);
} }
} }

View File

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