| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eb0fdc2 commit b413a62
23 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -268,5 +268,6 @@ public class ApiConstants { | |||
| 268 | 268 | public static final String USER = "user"; | |
| 269 | 269 | public static final String ACTIVE_ONLY = "activeonly"; | |
| 270 | 270 | public static final String TOKEN = "token"; | |
| 271 | + public static final String ACCEPT = "accept"; | ||
| 271 | 272 | ||
| 272 | 273 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,87 @@ | |||
| 1 | + /** | ||
| 2 | + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. | ||
| 3 | + * | ||
| 4 | + * This software is licensed under the GNU General Public License v3 or later. | ||
| 5 | + * | ||
| 6 | + * It is free software: you can redistribute it and/or modify | ||
| 7 | + * it under the terms of the GNU General Public License as published by | ||
| 8 | + * the Free Software Foundation, either version 3 of the License, or any later version. | ||
| 9 | + * This program is distributed in the hope that it will be useful, | ||
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | + * GNU General Public License for more details. | ||
| 13 | + * | ||
| 14 | + * You should have received a copy of the GNU General Public License | ||
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | + * | ||
| 17 | + */ | ||
| 18 | + package com.cloud.api.commands; | ||
| 19 | + | ||
| 20 | + import org.apache.log4j.Logger; | ||
| 21 | + | ||
| 22 | + import com.cloud.api.ApiConstants; | ||
| 23 | + import com.cloud.api.BaseAsyncCmd; | ||
| 24 | + import com.cloud.api.BaseCmd; | ||
| 25 | + import com.cloud.api.Implementation; | ||
| 26 | + import com.cloud.api.Parameter; | ||
| 27 | + import com.cloud.api.ServerApiException; | ||
| 28 | + import com.cloud.api.response.SuccessResponse; | ||
| 29 | + import com.cloud.event.EventTypes; | ||
| 30 | + import com.cloud.user.Account; | ||
| 31 | + import com.cloud.user.UserContext; | ||
| 32 | + | ||
| 33 | + @Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class) | ||
| 34 | + public class DeleteProjectInvitationCmd extends BaseAsyncCmd { | ||
| 35 | + public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName()); | ||
| 36 | + private static final String s_name = "deleteprojectinvitationresponse"; | ||
| 37 | + | ||
| 38 | + ///////////////////////////////////////////////////// | ||
| 39 | + //////////////// API parameters ///////////////////// | ||
| 40 | + ///////////////////////////////////////////////////// | ||
| 41 | + @Parameter(name=ApiConstants.ID, required=true, type=CommandType.LONG, description="id of the invitation") | ||
| 42 | + private Long id; | ||
| 43 | + | ||
| 44 | + ///////////////////////////////////////////////////// | ||
| 45 | + /////////////////// Accessors /////////////////////// | ||
| 46 | + ///////////////////////////////////////////////////// | ||
| 47 | + public Long getId() { | ||
| 48 | + return id; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public String getCommandName() { | ||
| 53 | + return s_name; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + ///////////////////////////////////////////////////// | ||
| 57 | + /////////////// API Implementation/////////////////// | ||
| 58 | + ///////////////////////////////////////////////////// | ||
| 59 | + @Override | ||
| 60 | + public long getEntityOwnerId() { | ||
| 61 | + //TODO - return project entity ownerId | ||
| 62 | + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public void execute(){ | ||
| 68 | + UserContext.current().setEventDetails("Project invitation id " + id); | ||
| 69 | + boolean result = _projectService.deleteProjectInvitation(id); | ||
| 70 | + if (result) { | ||
| 71 | + SuccessResponse response = new SuccessResponse(getCommandName()); | ||
| 72 | + this.setResponseObject(response); | ||
| 73 | + } else { | ||
| 74 | + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the project invitation"); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Override | ||
| 79 | + public String getEventType() { | ||
| 80 | + return EventTypes.EVENT_PROJECT_INVITATION_REMOVE; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public String getEventDescription() { | ||
| 85 | + return "Project invitatino id " + id + " is being removed"; | ||
| 86 | + } | ||
| 87 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,6 +52,9 @@ public class ListProjectInvitationsCmd extends BaseListCmd { | |||
| 52 | 52 | ||
| 53 | 53 | @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list invitations by state") | |
| 54 | 54 | private String state; | |
| 55 | + | ||
| 56 | + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list invitations by id") | ||
| 57 | + private Long id; | ||
| 55 | 58 | ///////////////////////////////////////////////////// | |
| 56 | 59 | /////////////////// Accessors /////////////////////// | |
| 57 | 60 | ///////////////////////////////////////////////////// | |
@@ -75,6 +78,10 @@ public String getState() { | |||
| 75 | 78 | return state; | |
| 76 | 79 | } | |
| 77 | 80 | ||
| 81 | + public Long getId() { | ||
| 82 | + return id; | ||
| 83 | + } | ||
| 84 | + | ||
| 78 | 85 | @Override | |
| 79 | 86 | public String getCommandName() { | |
| 80 | 87 | return s_name; | |
@@ -86,7 +93,7 @@ public String getCommandName() { | |||
| 86 | 93 | ||
| 87 | 94 | @Override | |
| 88 | 95 | public void execute(){ | |
| 89 | - List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(projectId, accountName, domainId, state, activeOnly, this.getStartIndex(), this.getPageSizeVal()); | ||
| 96 | + List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(id, projectId, accountName, domainId, state, activeOnly, this.getStartIndex(), this.getPageSizeVal()); | ||
| 90 | 97 | ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>(); | |
| 91 | 98 | List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>(); | |
| 92 | 99 | for (ProjectInvitation invite : invites) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,22 +30,26 @@ | |||
| 30 | 30 | import com.cloud.user.Account; | |
| 31 | 31 | import com.cloud.user.UserContext; | |
| 32 | 32 | ||
| 33 | - @Implementation(description="Makes account to join the project", responseObject=SuccessResponse.class) | ||
| 34 | - public class JoinProjectCmd extends BaseAsyncCmd { | ||
| 35 | - public static final Logger s_logger = Logger.getLogger(JoinProjectCmd.class.getName()); | ||
| 36 | - private static final String s_name = "joinprojectresponse"; | ||
| 33 | + @Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class) | ||
| 34 | + public class UpdateProjectInvitationCmd extends BaseAsyncCmd { | ||
| 35 | + public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName()); | ||
| 36 | + private static final String s_name = "updateprojectinvitationresponse"; | ||
| 37 | + | ||
| 37 | 38 | ||
| 38 | 39 | ///////////////////////////////////////////////////// | |
| 39 | 40 | //////////////// API parameters ///////////////////// | |
| 40 | 41 | ///////////////////////////////////////////////////// | |
| 41 | 42 | @Parameter(name=ApiConstants.PROJECT_ID, required=true, type=CommandType.LONG, description="id of the project to join") | |
| 42 | 43 | private Long projectId; | |
| 43 | 44 | ||
| 44 | - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="account that is joining the project") | ||
| 45 | + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account that is joining the project") | ||
| 45 | 46 | private String accountName; | |
| 46 | 47 | ||
| 47 | 48 | @Parameter(name=ApiConstants.TOKEN, type=CommandType.STRING, description="list invitations for specified account; this parameter has to be specified with domainId") | |
| 48 | 49 | private String token; | |
| 50 | + | ||
| 51 | + @Parameter(name=ApiConstants.ACCEPT, type=CommandType.BOOLEAN, description="if true, accept the invitation, decline if false. True by default") | ||
| 52 | + private Boolean accept; | ||
| 49 | 53 | ||
| 50 | 54 | ///////////////////////////////////////////////////// | |
| 51 | 55 | /////////////////// Accessors /////////////////////// | |
@@ -67,10 +71,17 @@ public String getToken() { | |||
| 67 | 71 | return token; | |
| 68 | 72 | } | |
| 69 | 73 | ||
| 74 | + public Boolean getAccept() { | ||
| 75 | + if (accept == null) { | ||
| 76 | + return true; | ||
| 77 | + } | ||
| 78 | + return accept; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + | ||
| 70 | 82 | ///////////////////////////////////////////////////// | |
| 71 | 83 | /////////////// API Implementation/////////////////// | |
| 72 | 84 | ///////////////////////////////////////////////////// | |
| 73 | - | ||
| 74 | 85 | @Override | |
| 75 | 86 | public long getEntityOwnerId() { | |
| 76 | 87 | //TODO - return project entity ownerId | |
@@ -80,8 +91,8 @@ public long getEntityOwnerId() { | |||
| 80 | 91 | ||
| 81 | 92 | @Override | |
| 82 | 93 | public void execute(){ | |
| 83 | - UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName); | ||
| 84 | - boolean result = _projectService.joinProject(projectId, accountName, token); | ||
| 94 | + UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName + "; accept " + getAccept()); | ||
| 95 | + boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept()); | ||
| 85 | 96 | if (result) { | |
| 86 | 97 | SuccessResponse response = new SuccessResponse(getCommandName()); | |
| 87 | 98 | this.setResponseObject(response); | |
@@ -92,11 +103,11 @@ public void execute(){ | |||
| 92 | 103 | ||
| 93 | 104 | @Override | |
| 94 | 105 | public String getEventType() { | |
| 95 | - return EventTypes.EVENT_PROJECT_JOIN; | ||
| 106 | + return EventTypes.EVENT_PROJECT_INVITATION_UPDATE; | ||
| 96 | 107 | } | |
| 97 | 108 | ||
| 98 | 109 | @Override | |
| 99 | 110 | public String getEventDescription() { | |
| 100 | - return "Account " + accountName + " joining the project: " + projectId; | ||
| 111 | + return "Updating project invitation for projectId " + projectId; | ||
| 101 | 112 | } | |
| 102 | 113 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | 7 | @SuppressWarnings("unused") | |
| 8 | 8 | public class ProjectInvitationResponse extends BaseResponse implements ControlledEntityResponse{ | |
| 9 | + @SerializedName(ApiConstants.ID) @Param(description="the id of the invitation") | ||
| 10 | + private Long id; | ||
| 11 | + | ||
| 9 | 12 | @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the id of the project") | |
| 10 | 13 | private Long projectId; | |
| 11 | 14 | ||
@@ -26,6 +29,10 @@ public class ProjectInvitationResponse extends BaseResponse implements Controlle | |||
| 26 | 29 | ||
| 27 | 30 | @SerializedName(ApiConstants.STATE) @Param(description="the invitation state") | |
| 28 | 31 | private String invitationState; | |
| 32 | + | ||
| 33 | + public void setId(Long id) { | ||
| 34 | + this.id = id; | ||
| 35 | + } | ||
| 29 | 36 | ||
| 30 | 37 | public void setProjectId(Long projectId) { | |
| 31 | 38 | this.projectId = projectId; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -212,6 +212,7 @@ public class EventTypes { | |||
| 212 | 212 | public static final String EVENT_PROJECT_ACTIVATE = "PROJECT.ACTIVATE"; | |
| 213 | 213 | public static final String EVENT_PROJECT_SUSPEND = "PROJECT.SUSPEND"; | |
| 214 | 214 | public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD"; | |
| 215 | - public static final String EVENT_PROJECT_JOIN = "PROJECT.JOIN"; | ||
| 215 | + public static final String EVENT_PROJECT_INVITATION_UPDATE = "PROJECT.INVITATION.UPDATE"; | ||
| 216 | + public static final String EVENT_PROJECT_INVITATION_REMOVE = "PROJECT.INVITATION.REMOVE"; | ||
| 216 | 217 | public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE"; | |
| 217 | 218 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | import java.util.Date; | |
| 4 | 4 | ||
| 5 | 5 | public interface ProjectInvitation { | |
| 6 | - public enum State {Pending, Completed, Expired} | ||
| 6 | + public enum State {Pending, Completed, Expired, Declined} | ||
| 7 | 7 | ||
| 8 | 8 | long getId(); | |
| 9 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,13 +58,15 @@ public interface ProjectService { | |||
| 58 | 58 | ||
| 59 | 59 | List<? extends ProjectAccount> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal); | |
| 60 | 60 | ||
| 61 | - List<? extends ProjectInvitation> listProjectInvitations(Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal); | ||
| 61 | + List<? extends ProjectInvitation> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal); | ||
| 62 | 62 | ||
| 63 | - boolean joinProject(long projectId, String accountName, String token); | ||
| 63 | + boolean updateInvitation(long projectId, String accountName, String token, boolean accept); | ||
| 64 | 64 | ||
| 65 | 65 | Project activateProject(long projectId); | |
| 66 | 66 | ||
| 67 | 67 | Project suspendProject(long projectId) throws ConcurrentOperationException, ResourceUnavailableException; | |
| 68 | 68 | ||
| 69 | 69 | Project enableProject(long projectId); | |
| 70 | + | ||
| 71 | + boolean deleteProjectInvitation(long invitationId); | ||
| 70 | 72 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -278,7 +278,8 @@ addAccountToProject=com.cloud.api.commands.AddAccountToProjectCmd;15 | |||
| 278 | 278 | deleteAccountFromProject=com.cloud.api.commands.DeleteAccountFromProjectCmd;15 | |
| 279 | 279 | listProjectAccounts=com.cloud.api.commands.ListProjectAccountsCmd;15 | |
| 280 | 280 | listProjectInvitations=com.cloud.api.commands.ListProjectInvitationsCmd;15 | |
| 281 | - joinProject=com.cloud.api.commands.JoinProjectCmd;15 | ||
| 281 | + updateProjectInvitation=com.cloud.api.commands.UpdateProjectInvitationCmd;15 | ||
| 282 | + deleteProjectInvitation=com.cloud.api.commands.DeleteProjectInvitationCmd;15 | ||
| 282 | 283 | ||
| 283 | 284 | #### | |
| 284 | 285 | createFirewallRule=com.cloud.api.commands.CreateFirewallRuleCmd;15 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2540,6 +2540,7 @@ public ProjectAccountResponse createProjectAccountResponse(ProjectAccount projec | |||
| 2540 | 2540 | @Override | |
| 2541 | 2541 | public ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite) { | |
| 2542 | 2542 | ProjectInvitationResponse response = new ProjectInvitationResponse(); | |
| 2543 | + response.setId(invite.getId()); | ||
| 2543 | 2544 | response.setProjectId(invite.getProjectId()); | |
| 2544 | 2545 | response.setProjectName(ApiDBUtils.findProjectById(invite.getProjectId()).getName()); | |
| 2545 | 2546 | response.setInvitationState(invite.getState().toString()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments