Commit 7106ff2b authored by Pedro Rocha's avatar Pedro Rocha
Browse files

Merge branch 'task/CSBASE-4118_MoveDependenciesFromDemo' into 'master'

[CSBASE-4918] Remocao de classes que foram movidas para outro projeto.

See merge request !4
parents 1356c1b2 182e8eea
......@@ -4,7 +4,7 @@
<groupId>br.puc-rio.tecgraf.csbase</groupId>
<artifactId>rest-client-demo-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>resttest</name>
......@@ -98,6 +98,11 @@
</build>
<dependencies>
<dependency>
<groupId>br.puc-rio.tecgraf.csbase</groupId>
<artifactId>csbase-rest-client-java</artifactId>
<version>0.1.0</version>
</dependency>
<!-- JAX-RS -->
<dependency>
<groupId>javax.ws.rs</groupId>
......
package Requests.Algorithms;
import Requests.User.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class Algorithm {
private String id = null;
private String name = null;
private List<String> categories = null;
private User whoCreated = null;
private AlgorithmVersion lastVersion = null;
private List<AlgorithmVersion> versions = new ArrayList<AlgorithmVersion>();
public Algorithm id(String id) {
this.id = id;
return this;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Algorithm name(String name) {
this.name = name;
return this;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Algorithm categories(List<String> categories) {
this.categories = categories;
return this;
}
public List<String> getCategories() {
return categories;
}
public void setCategories(List<String> categories) {
this.categories = categories;
}
public Algorithm whoCreated(User whoCreated) {
this.whoCreated = whoCreated;
return this;
}
public User getWhoCreated() {
return whoCreated;
}
public void setWhoCreated(User whoCreated) {
this.whoCreated = whoCreated;
}
public Algorithm lastVersion(AlgorithmVersion lastVersion) {
this.lastVersion = lastVersion;
return this;
}
public AlgorithmVersion getLastVersion() {
return lastVersion;
}
public void setLastVersion(AlgorithmVersion lastVersion) {
this.lastVersion = lastVersion;
}
public Algorithm versions(List<AlgorithmVersion> versions) {
this.versions = versions;
return this;
}
public Algorithm addVersionsItem(AlgorithmVersion versionsItem) {
this.versions.add(versionsItem);
return this;
}
public List<AlgorithmVersion> getVersions() {
return versions;
}
public void setVersions(List<AlgorithmVersion> versions) {
this.versions = versions;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Algorithm algorithm = (Algorithm) o;
return Objects.equals(this.id, algorithm.id) &&
Objects.equals(this.name, algorithm.name) &&
Objects.equals(this.categories, algorithm.categories) &&
Objects.equals(this.whoCreated, algorithm.whoCreated) &&
Objects.equals(this.lastVersion, algorithm.lastVersion) &&
Objects.equals(this.versions, algorithm.versions);
}
@Override
public int hashCode() {
return Objects.hash(id, name, categories, whoCreated, lastVersion, versions);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Algorithm {\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" categories: ").append(toIndentedString(categories)).append("\n");
sb.append(" whoCreated: ").append(toIndentedString(whoCreated)).append("\n");
sb.append(" lastVersion: ").append(toIndentedString(lastVersion)).append("\n");
sb.append(" versions: ").append(toIndentedString(versions)).append("\n");
sb.append("}");
return sb.toString();
}
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
package Requests.Algorithms;
import Requests.Authentication.Token;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
public class AlgorithmExplorer {
public static Algorithm findAlgorithmByName(String host, Token token, String algorithmName) {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(host);
Response response = webTarget.path("algorithms").path(algorithmName)
.request("application/json;charset=UTF-8")
.header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()).get();
if (response.getStatus() == Response.Status.OK.getStatusCode())
{
return response.readEntity(Algorithm.class);
}
return null;
}
public static Algorithm[] getAlgorithms(String host, Token token) {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(host);
Response response = webTarget.path("algorithms")
.request("application/json;charset=UTF-8")
.header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()).get();
if (response.getStatus() == Response.Status.OK.getStatusCode())
return response.readEntity(Algorithm[].class);
return null;
}
}
package Requests.Algorithms;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class AlgorithmVersion {
private String id = null;
private String description = null;
private List<Requirement> requirements = new ArrayList<Requirement>();
public AlgorithmVersion id(String id) {
this.id = id;
return this;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public AlgorithmVersion description(String description) {
this.description = description;
return this;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public AlgorithmVersion requirements(List<Requirement> requirements) {
this.requirements = requirements;
return this;
}
public AlgorithmVersion addRequirementsItem(Requirement requirementsItem) {
this.requirements.add(requirementsItem);
return this;
}
public List<Requirement> getRequirements() {
return requirements;
}
public void setRequirements(List<Requirement> requirements) {
this.requirements = requirements;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AlgorithmVersion algorithmVersion = (AlgorithmVersion) o;
return Objects.equals(this.id, algorithmVersion.id) &&
Objects.equals(this.description, algorithmVersion.description) &&
Objects.equals(this.requirements, algorithmVersion.requirements);
}
@Override
public int hashCode() {
return Objects.hash(id, description, requirements);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AlgorithmVersion {\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" description: ").append(toIndentedString(description)).append("\n");
sb.append(" requirements: ").append(toIndentedString(requirements)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
\ No newline at end of file
package Requests.Algorithms;
import java.util.Objects;
public class Requirement {
private String key = null;
private String name = null;
public enum TypeEnum {
INTEGER("integer"),
DOUBLE("double"),
BOOLEAN("boolean"),
STRING("string"),
ENUMERATION("enumeration");
private String value;
TypeEnum(String value) {
this.value = value;
}
@Override
public String toString() {
return String.valueOf(value);
}
}
private TypeEnum type = null;
private Boolean editable = null;
private Object value = null;
public Requirement key(String key) {
this.key = key;
return this;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Requirement name(String name) {
this.name = name;
return this;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Requirement type(TypeEnum type) {
this.type = type;
return this;
}
public TypeEnum getType() {
return type;
}
public void setType(TypeEnum type) {
this.type = type;
}
public Requirement editable(Boolean editable) {
this.editable = editable;
return this;
}
public Boolean getEditable() {
return editable;
}
public void setEditable(Boolean editable) {
this.editable = editable;
}
public Requirement value(Object value) {
this.value = value;
return this;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Requirement requirement = (Requirement) o;
return Objects.equals(this.key, requirement.key) &&
Objects.equals(this.name, requirement.name) &&
Objects.equals(this.type, requirement.type) &&
Objects.equals(this.editable, requirement.editable) &&
Objects.equals(this.value, requirement.value);
}
@Override
public int hashCode() {
return Objects.hash(key, name, type, editable, value);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Requirement {\n");
sb.append(" key: ").append(toIndentedString(key)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" editable: ").append(toIndentedString(editable)).append("\n");
sb.append(" value: ").append(toIndentedString(value)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
package Requests.Authentication;
import javax.ws.rs.client.*;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
public class Authentication {
public static Token authenticate(String host, String username, String password)
throws LoginOrPasswordNotProvidedException, InvalidLoginOrPasswordException {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(host).path("authentication");
Form form = new Form();
form.param("login", username);
form.param("password", password);
Invocation.Builder invocationBuilder = webTarget.request("application/json;charset=UTF-8");
Response response = invocationBuilder.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE),
Response.class);
if (response.getStatus() == Response.Status.OK.getStatusCode()) {
return response.readEntity(Token.class);
} else if (response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode())
throw new LoginOrPasswordNotProvidedException();
else if (response.getStatus() == Response.Status.UNAUTHORIZED.getStatusCode())
throw new InvalidLoginOrPasswordException();
return null;
}
}
package Requests.Authentication;
@SuppressWarnings("serial")
public class InvalidLoginOrPasswordException extends Exception {
}
package Requests.Authentication;
@SuppressWarnings("serial")
public class LoginOrPasswordNotProvidedException extends Exception {
}
package Requests.Authentication;
import Requests.User.User;
import java.util.Objects;
public class Token {
private String accessToken = null;
private String tokenType = null;
private User user = null;
public Token accessToken(String accessToken) {
this.accessToken = accessToken;
return this;
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public Token tokenType(String tokenType) {
this.tokenType = tokenType;
return this;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
public Token user(User user) {
this.user = user;
return this;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Token token = (Token) o;
return Objects.equals(this.accessToken, token.accessToken) &&
Objects.equals(this.tokenType, token.tokenType) &&
Objects.equals(this.user, token.user);
}
@Override
public int hashCode() {
return Objects.hash(accessToken, tokenType, user);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Token {\n");
sb.append(" accessToken: ").append(toIndentedString(accessToken)).append("\n");
sb.append(" tokenType: ").append(toIndentedString(tokenType)).append("\n");
sb.append(" user: ").append(toIndentedString(user)).append("\n");
sb.append("}");
return sb.toString();
}
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
This diff is collapsed.
package Requests.Jobs;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;