Skip to content

Commit

Permalink
feat(new-rocket-api): first basic implementation (see #JENKINS-40595)
Browse files Browse the repository at this point in the history
  • Loading branch information
hypery2k committed Dec 26, 2016
1 parent bedf804 commit ebb346e
Show file tree
Hide file tree
Showing 14 changed files with 789 additions and 158 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ node('docker') {
}

stage('Test') {
sh "mvn -Pdocker clean verify"
}

junit testResults: 'target/surefire-reports/TEST-*.xml'
Expand Down
18 changes: 16 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jenkins.version>1.653</jenkins.version>
<java.level>7</java.level>
<failsafeArgLine></failsafeArgLine>
<skipITs>false</skipITs>
<jenkins-test-harness.version>2.13</jenkins-test-harness.version>
<workflow.version>1.11</workflow.version>
<!-- Project Libs-->
Expand Down Expand Up @@ -154,9 +156,19 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${failsafeArgLine}</argLine>
<skipTests>${skipITs}</skipTests>
<includes>
<include>**/*IT.class</include>
</includes>
<systemPropertyVariables>
<ldap.url>ldap://127.0.0.1:${rocket.port}</ldap.url>
<rocket.url>http://127.0.0.1:${rocket.port}</rocket.url>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down Expand Up @@ -342,7 +354,9 @@

<issueManagement>
<system>JIRA</system>
<url>https://issues.jenkins-ci.org/browse/JENKINS-40595?jql=project%20%3D%20JENKINS%20AND%20component%20%3D%20rocket-chat-notifier-plugin</url>
<url>
https://issues.jenkins-ci.org/browse/JENKINS-40595?jql=project%20%3D%20JENKINS%20AND%20component%20%3D%20rocket-chat-notifier-plugin
</url>
</issueManagement>

<ciManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import hudson.util.FormValidation;
import jenkins.model.JenkinsLocationConfiguration;
import jenkins.plugins.rocketchatnotifier.rocket.RocketChatClient;
import jenkins.plugins.rocketchatnotifier.rocket.RocketChatClientImpl;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -298,7 +299,7 @@ public boolean configure(StaplerRequest sr, JSONObject formData) throws FormExce
}

RocketChatClient getRocketChatClient(final String rocketServerURL, final String username, final String password) {
return new RocketChatClient(rocketServerURL, username, password);
return new RocketChatClientImpl(rocketServerURL, username, password);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import jenkins.plugins.rocketchatnotifier.rocket.RocketChatClient;
import jenkins.plugins.rocketchatnotifier.rocket.RocketChatClientImpl;
import sun.security.validator.ValidatorException;

import java.io.IOException;
Expand All @@ -22,7 +23,7 @@ public class RocketClientImpl implements RocketClient {


public RocketClientImpl(String serverUrl, String user, String password, String channel) {
this.client = new RocketChatClient(serverUrl + API_PATH, user, password);
this.client = new RocketChatClientImpl(serverUrl + API_PATH, user, password);
this.channel = channel;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package jenkins.plugins.rocketchatnotifier.model;


public class Response {
private boolean success;
private Message[] messages;
private Message message;
private User[] users;
private User user;
private Room[] channels;
private Room channel;

public void setSuccess(boolean result) {
this.success = result;
}

public boolean isSuccessful() {
return this.success;
}

public void setMessages(final Message[] messages) {
this.messages = messages.clone();
}

public Message[] getMessages() {
return this.messages.clone();
}

public boolean isMessages() {
return this.messages != null;
}

public void setMessage(final Message message) {
this.message = message;
}

public Message getMessage() {
return this.message;
}

public boolean isMessage() {
return this.message != null;
}

public void setUsers(final User[] users) {
this.users = users.clone();
}

public User[] getUsers() {
return this.users.clone();
}

public Room[] getChannels() {
return this.channels.clone();
}

public boolean isUsers() {
return this.users != null;
}

public void setUser(final User user) {
this.user = user;
}

public User getUser() {
return this.user;
}

public boolean isUser() {
return this.user != null;
}
}
139 changes: 139 additions & 0 deletions src/main/java/jenkins/plugins/rocketchatnotifier/model/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package jenkins.plugins.rocketchatnotifier.model;

import java.util.Date;

/**
* Represents a Rocket.Chat user.
*
* @author Bradley Hilton (graywolf336)
* @version 0.0.1
* @since 0.1.0
*/
public class User extends Identified {
private String username, name;
private Date createdAt, lastLogin;
private boolean active;
private int utcOffset;

/**
* Sets the username of this user.
*
* @param username of this user
*/
public void setUsername(String username) {
this.username = username;
}

/**
* Gets the username of this user.
*
* @return user of this user
*/
public String getUsername() {
return this.username;
}

/**
* Sets the display name of this user.
*
* @param name of this user
*/
public void setName(String name) {
this.name = name;
}

/**
* Gets the display name of this user.
*
* @return the name of this user
*/
public String getName() {
return this.name;
}

/**
* Sets the created date of this user.
*
* @param date this user was created
*/
public void setCreatedAt(Date date) {
this.createdAt = new Date(date.getTime());
}

/**
* Gets the date this user was created
*
* @return creation date of this user
*/
public Date getCreatedAt() {
return new Date(this.createdAt.getTime());
}

/**
* Sets the last login date of this user.
*
* @param date this user last logged in
*/
public void setLastLogin(Date date) {
this.lastLogin = new Date(date.getTime());
}

/**
* Gets the date this user last logged in
*
* @return last logged in date
*/
public Date getLastLogin() {
return new Date(this.lastLogin.getTime());
}

/**
* Sets whether this user is active or not
*
* @param active whether this user is active or not
*/
public void setActive(boolean active) {
this.active = active;
}

/**
* Gets whether this user is active or not, non-active users can not log in.
*
* @return whether this user is logged in or not
*/
public boolean getActive() {
return this.active;
}

/**
* Checks whether this user is active or not, non-active users can not log in.
*
* @return whether this user is logged in or not
*/
public boolean isActive() {
return this.active;
}

/**
* Sets the UTC Offset of this user.
*
* @param offset of this user
*/
public void setUtcOffset(int offset) {
this.utcOffset = offset;
}

/**
* Gets the UTC Offset of this user
*
* @return utc offset for this user
*/
public int getUtcOffset() {
return this.utcOffset;
}
}

/*
* "type": "user",//TODO: Convert to ENUM "status": "offline",//TODO: Convert to ENUM "roles": [
* "user" ], "statusConnection": "offline",//TODO: Convert to ENUM
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package jenkins.plugins.rocketchatnotifier.rocket;


/**
* Represents the http methods.
*
* @author Bradley Hilton (graywolf336)
* @version 1.0.0
* @since 0.1.0
*/
public enum HttpMethods {
GET, POST, PUT, DELETE, PATCH
}
Loading

0 comments on commit ebb346e

Please sign in to comment.