Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
RtTeams and JsonTeam + unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed May 4, 2017
1 parent 74c0e5e commit 691c76c
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 4 deletions.
142 changes: 142 additions & 0 deletions src/main/java/com/amihaiemil/versioneye/JsonTeam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* Copyright (c) 2017, Mihai Emil Andronache
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
package com.amihaiemil.versioneye;

import java.util.ArrayList;
import java.util.List;

import javax.json.JsonArray;
import javax.json.JsonObject;

/**
* VersionEye Team backed by a JsonObject.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 1.0.0
*/
final class JsonTeam implements Team {

/**
* Team.
*/
private JsonObject team;

/**
* Ctor.
* @param team Given team.
*/
JsonTeam(final JsonObject team) {
this.team = team;
}

@Override
public String teamId() {
return this.team.getString("ids");
}

@Override
public String name() {
return this.team.getString("name");
}

@Override
public boolean versionNotifications() {
return this.team.getBoolean("version_notifications");
}

@Override
public boolean licenseNotifications() {
return this.team.getBoolean("license_notifications");
}

@Override
public boolean securityNotifications() {
return this.team.getBoolean("security_notifications");
}

@Override
public boolean monday() {
return this.team.getBoolean("monday");
}

@Override
public boolean tuesday() {
return this.team.getBoolean("tuesday");
}

@Override
public boolean wednesday() {
return this.team.getBoolean("wednesday");
}

@Override
public boolean thursday() {
return this.team.getBoolean("thursday");
}

@Override
public boolean friday() {
return this.team.getBoolean("friday");
}

@Override
public boolean saturday() {
return this.team.getBoolean("saturday");
}

@Override
public boolean sunday() {
return this.team.getBoolean("sunday");
}

@Override
public List<UserData> users() {
final JsonArray users = this.team.getJsonArray("users");
final List<UserData> members = new ArrayList<>();
for(int idx = 0; idx < users.size(); idx++) {
members.add(new JsonUserData(users.getJsonObject(idx)));
}
return members;
}

@Override
public String createdAt() {
return this.team.getString("created_at");
}

@Override
public String updatedAt() {
return this.team.getString("updated_at");
}

@Override
public JsonObject json() {
return this.team;
}

}
6 changes: 3 additions & 3 deletions src/main/java/com/amihaiemil/versioneye/RtOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @author Sherif Waly (sheifwaly95@gmail.com)
* @version $Id$
* @since 1.0.0
* @todo #45:30min/DEV implement and test `teams()` and `projects()` methods.
* @todo #37:30min/DEV implement and test `projects()` method.
*/
final class RtOrganization implements Organization {

Expand All @@ -57,12 +57,12 @@ final class RtOrganization implements Organization {
*/
RtOrganization(final JsonObject organization, final Request entry) {
this.organization = organization;
this.req = entry;
this.req = entry.uri().path(organization.getString("name")).back();
}

@Override
public Teams teams() {
return null;
return new RtTeams(this.req, this.organization.getString("api_key"));
}

@Override
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/com/amihaiemil/versioneye/RtTeams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017, Mihai Emil Andronache
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
package com.amihaiemil.versioneye;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
import javax.json.JsonArray;
import com.jcabi.http.Request;
import com.jcabi.http.response.JsonResponse;
import com.jcabi.http.response.RestResponse;

/**
* Real implementation for {@link Teams}.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 1.0.0
*/
final class RtTeams implements Teams {

/**
* HTTP request.
*/
private Request req;

/**
* Ctor.
* @param entry HTTP request.
* @param orgKey The organization's api_key
*/
RtTeams(final Request entry, final String orgKey) {
this.req = entry.uri().queryParam("api_key", orgKey).back();
}

@Override
public List<Team> fetch() throws IOException {
final JsonArray array = this.req.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
.json()
.readArray();
final List<Team> teams = new ArrayList<>();
for(int idx=0; idx<array.size(); idx++) {
teams.add(
new JsonTeam(array.getJsonObject(idx))
);
}
return teams;
}

}
139 changes: 139 additions & 0 deletions src/main/java/com/amihaiemil/versioneye/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* Copyright (c) 2017, Mihai Emil Andronache
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
package com.amihaiemil.versioneye;

import java.util.List;

import javax.json.JsonObject;

/**
* A VersionEye Team.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 1.0.0
*
*/
public interface Team {

/**
* Team id.
* @return String
*/
String teamId();

/**
* Team name.
* @return String
*/
String name();

/**
* Does this team receive versions notifications?
* @return Boolean.
*/
boolean versionNotifications();

/**
* Does this team receive licenses notifications?
* @return Boolean.
*/
boolean licenseNotifications();

/**
* Does this team receive security notifications?
* @return Boolean.
*/
boolean securityNotifications();

/**
* Should notifications be sent on Mondays?
* @return Boolean.
*/
boolean monday();

/**
* Should notifications be sent on Tuesdays?
* @return Boolean.
*/
boolean tuesday();

/**
* Should notifications be sent on Wednesdays?
* @return Boolean.
*/
boolean wednesday();

/**
* Should notifications be sent on Thursdays?
* @return Boolean.
*/
boolean thursday();

/**
* Should notifications be sent on Fridays?
* @return Boolean.
*/
boolean friday();

/**
* Should notifications be sent on Saturdays?
* @return Boolean.
*/
boolean saturday();

/**
* Should notifications be sent on Sundays?
* @return Boolean.
*/
boolean sunday();

/**
* Members of this team.
* @return List of UserData.
*/
List<UserData> users();

/**
* Created at.
* @return String.
*/
String createdAt();

/**
* Updated at.
* @return String.
*/
String updatedAt();

/**
* This Team as JsonObject.
* @return JsonObject.
*/
JsonObject json();

}
Loading

2 comments on commit 691c76c

@0pdd
Copy link

@0pdd 0pdd commented on 691c76c May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 45-46f15e48 disappeared, that's why I closed as #47

@0pdd
Copy link

@0pdd 0pdd commented on 691c76c May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 37-8087fd76 discovered and submitted as #49

Please sign in to comment.