|
| 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 | + |
| 19 | +package com.cloud.api.commands; |
| 20 | + |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +import org.apache.log4j.Logger; |
| 25 | + |
| 26 | +import com.cloud.api.ApiConstants; |
| 27 | +import com.cloud.api.BaseCmd; |
| 28 | +import com.cloud.api.Implementation; |
| 29 | +import com.cloud.api.Parameter; |
| 30 | +import com.cloud.api.ServerApiException; |
| 31 | +import com.cloud.api.response.HostResponse; |
| 32 | +import com.cloud.api.response.ListResponse; |
| 33 | +import com.cloud.api.response.SwiftResponse; |
| 34 | +import com.cloud.storage.Swift; |
| 35 | +import com.cloud.user.Account; |
| 36 | + |
| 37 | +@Implementation(description = "List Swift.", responseObject = HostResponse.class) |
| 38 | +public class ListSwiftCmd extends BaseCmd { |
| 39 | + public static final Logger s_logger = Logger.getLogger(ListSwiftCmd.class.getName()); |
| 40 | + private static final String s_name = "ListSwiftresponse"; |
| 41 | + |
| 42 | + ///////////////////////////////////////////////////// |
| 43 | + //////////////// API parameters ///////////////////// |
| 44 | + ///////////////////////////////////////////////////// |
| 45 | + |
| 46 | + @Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "the id of the swift") |
| 47 | + private Long id; |
| 48 | + |
| 49 | + ///////////////////////////////////////////////////// |
| 50 | + /////////////// API Implementation/////////////////// |
| 51 | + ///////////////////////////////////////////////////// |
| 52 | + |
| 53 | + public Long getId() { |
| 54 | + return id; |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + @Override |
| 59 | + public String getCommandName() { |
| 60 | + return s_name; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public long getEntityOwnerId() { |
| 65 | + return Account.ACCOUNT_ID_SYSTEM; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public void execute(){ |
| 70 | + List<? extends Swift> result = _resourceService.listSwift(this); |
| 71 | + ListResponse<SwiftResponse> response = new ListResponse<SwiftResponse>(); |
| 72 | + List<SwiftResponse> swiftResponses = new ArrayList<SwiftResponse>(); |
| 73 | + |
| 74 | + if (result != null) { |
| 75 | + SwiftResponse swiftResponse = null; |
| 76 | + for (Swift swift : result) { |
| 77 | + swiftResponse = _responseGenerator.createSwiftResponse(swift); |
| 78 | + swiftResponse.setResponseName(getCommandName()); |
| 79 | + swiftResponse.setObjectName("swift"); |
| 80 | + swiftResponses.add(swiftResponse); |
| 81 | + } |
| 82 | + response.setResponses(swiftResponses); |
| 83 | + response.setResponseName(getCommandName()); |
| 84 | + this.setResponseObject(response); |
| 85 | + |
| 86 | + } else { |
| 87 | + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Swift"); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments