forked from connaryscott/rundeck-api-java-client
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
696 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/main/java/org/rundeck/api/domain/RundeckJobDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* RundeckJobDelete.java | ||
* | ||
* User: Greg Schueler <a href="mailto:[email protected]">[email protected]</a> | ||
* Created: 10/1/12 3:53 PM | ||
* | ||
*/ | ||
package org.rundeck.api.domain; | ||
|
||
import java.util.*; | ||
|
||
|
||
/** | ||
* RundeckJobDelete represents a result of a job delete request. | ||
* | ||
* @author Greg Schueler <a href="mailto:[email protected]">[email protected]</a> | ||
*/ | ||
public class RundeckJobDelete { | ||
private String id; | ||
private String error; | ||
private boolean successful; | ||
private String errorCode; | ||
private String message; | ||
|
||
/** | ||
* Job ID | ||
*/ | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Error message if the job could not be deleted | ||
*/ | ||
public String getError() { | ||
return error; | ||
} | ||
|
||
public void setError(String error) { | ||
this.error = error; | ||
} | ||
|
||
/** | ||
* True if the job was successfully deleted | ||
*/ | ||
public boolean isSuccessful() { | ||
return successful; | ||
} | ||
|
||
public void setSuccessful(boolean successful) { | ||
this.successful = successful; | ||
} | ||
|
||
/** | ||
* Error code string if there was a failure | ||
*/ | ||
public String getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
public void setErrorCode(String errorCode) { | ||
this.errorCode = errorCode; | ||
} | ||
|
||
/** | ||
* Success message if it was successful | ||
*/ | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { return true; } | ||
if (o == null || getClass() != o.getClass()) { return false; } | ||
|
||
RundeckJobDelete delete = (RundeckJobDelete) o; | ||
|
||
if (successful != delete.successful) { return false; } | ||
if (error != null ? !error.equals(delete.error) : delete.error != null) { return false; } | ||
if (errorCode != null ? !errorCode.equals(delete.errorCode) : delete.errorCode != null) { return false; } | ||
if (id != null ? !id.equals(delete.id) : delete.id != null) { return false; } | ||
if (message != null ? !message.equals(delete.message) : delete.message != null) { return false; } | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = id != null ? id.hashCode() : 0; | ||
result = 31 * result + (error != null ? error.hashCode() : 0); | ||
result = 31 * result + (successful ? 1 : 0); | ||
result = 31 * result + (errorCode != null ? errorCode.hashCode() : 0); | ||
result = 31 * result + (message != null ? message.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RundeckJobDelete{" + | ||
"id='" + id + '\'' + | ||
", error='" + error + '\'' + | ||
", successful=" + successful + | ||
", errorCode='" + errorCode + '\'' + | ||
", message='" + message + '\'' + | ||
'}'; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/org/rundeck/api/domain/RundeckJobDeleteBulk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* RundeckJobDeleteBulk.java | ||
* | ||
* User: Greg Schueler <a href="mailto:[email protected]">[email protected]</a> | ||
* Created: 10/1/12 4:12 PM | ||
* | ||
*/ | ||
package org.rundeck.api.domain; | ||
|
||
import java.util.*; | ||
|
||
|
||
/** | ||
* RundeckJobDeleteBulk represents the result of a bulk job delete request and contains | ||
* a list of {@link RundeckJobDelete} objects. | ||
* | ||
* @author Greg Schueler <a href="mailto:[email protected]">[email protected]</a> | ||
*/ | ||
public class RundeckJobDeleteBulk implements Iterable<RundeckJobDelete> { | ||
private List<RundeckJobDelete> results; | ||
private int requestCount; | ||
private boolean allsuccessful; | ||
|
||
public RundeckJobDeleteBulk(List<RundeckJobDelete> results, int requestCount, boolean allsuccessful) { | ||
this.results = results; | ||
this.requestCount = requestCount; | ||
this.allsuccessful = allsuccessful; | ||
} | ||
|
||
public List<RundeckJobDelete> getResults() { | ||
return results; | ||
} | ||
|
||
/** | ||
* The number of job delete requests processed. | ||
*/ | ||
public int getRequestCount() { | ||
return requestCount; | ||
} | ||
|
||
/** | ||
* True if all job delete requests were successful | ||
*/ | ||
public boolean isAllsuccessful() { | ||
return allsuccessful; | ||
} | ||
|
||
@Override | ||
public Iterator<RundeckJobDelete> iterator() { | ||
if(null!=results){ | ||
return results.iterator(); | ||
}else{ | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RundeckJobDeleteBulk{" + | ||
"results=" + results + | ||
", requestCount=" + requestCount + | ||
", allsuccessful=" + allsuccessful + | ||
'}'; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/org/rundeck/api/parser/BulkDeleteParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* BulkDeleteParser.java | ||
* | ||
* User: Greg Schueler <a href="mailto:[email protected]">[email protected]</a> | ||
* Created: 10/1/12 3:55 PM | ||
* | ||
*/ | ||
package org.rundeck.api.parser; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.dom4j.Element; | ||
import org.dom4j.Node; | ||
import org.rundeck.api.domain.RundeckJobDelete; | ||
import org.rundeck.api.domain.RundeckJobDeleteBulk; | ||
|
||
import java.util.*; | ||
|
||
|
||
/** | ||
* BulkDeleteParser is ... | ||
* | ||
* @author Greg Schueler <a href="mailto:[email protected]">[email protected]</a> | ||
*/ | ||
public class BulkDeleteParser implements XmlNodeParser<RundeckJobDeleteBulk> { | ||
private String xpath; | ||
|
||
public BulkDeleteParser(String xpath) { | ||
this.xpath = xpath; | ||
} | ||
|
||
public BulkDeleteParser() { | ||
} | ||
|
||
@Override | ||
public RundeckJobDeleteBulk parseXmlNode(Node node) { | ||
Node subnode = xpath != null ? node.selectSingleNode(xpath) : node; | ||
final ArrayList<RundeckJobDelete> deletes = new ArrayList<RundeckJobDelete>(); | ||
final List results = subnode.selectNodes("(succeeded|failed)/deleteJobResult"); | ||
final DeleteParser parser = new DeleteParser(); | ||
if (null != results && results.size() > 0) { | ||
for (final Object o : results) { | ||
deletes.add(parser.parseXmlNode((Node) o)); | ||
} | ||
} | ||
|
||
final String requestcount = StringUtils.trimToNull(subnode.valueOf("@requestCount")); | ||
final String allsuccessString = StringUtils.trimToNull(subnode.valueOf("@allsuccessful")); | ||
int count = 0; | ||
boolean allsuccess = false; | ||
if (null != requestcount) { | ||
try { | ||
count = Integer.parseInt(requestcount); | ||
} catch (NumberFormatException e) { | ||
|
||
} | ||
} | ||
if (null != allsuccessString) { | ||
allsuccess = Boolean.parseBoolean(allsuccessString); | ||
} | ||
|
||
return new RundeckJobDeleteBulk(deletes, count, allsuccess); | ||
} | ||
} |
Oops, something went wrong.