diff --git a/pom.xml b/pom.xml index d069ff3c03a3df23146ffcab916a07c4391d8a09..7f3fda1dc30ad23723641a8ce6320e8e964498d9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ br.puc-rio.tecgraf.csbase rest-client-demo-java - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT jar resttest @@ -98,6 +98,11 @@ + + br.puc-rio.tecgraf.csbase + csbase-rest-client-java + 0.1.0 + javax.ws.rs diff --git a/src/main/java/Requests/Algorithms/Algorithm.java b/src/main/java/Requests/Algorithms/Algorithm.java deleted file mode 100644 index c39260c067e865264a1c3221fd163740cf09d35c..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Algorithms/Algorithm.java +++ /dev/null @@ -1,127 +0,0 @@ -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 categories = null; - private User whoCreated = null; - private AlgorithmVersion lastVersion = null; - private List versions = new ArrayList(); - 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 categories) { - this.categories = categories; - return this; - } - - public List getCategories() { - return categories; - } - - public void setCategories(List 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 versions) { - this.versions = versions; - return this; - } - public Algorithm addVersionsItem(AlgorithmVersion versionsItem) { - this.versions.add(versionsItem); - return this; - } - public List getVersions() { - return versions; - } - public void setVersions(List 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 "); - } -} - diff --git a/src/main/java/Requests/Algorithms/AlgorithmExplorer.java b/src/main/java/Requests/Algorithms/AlgorithmExplorer.java deleted file mode 100644 index 1811ebf4bd6b540b3c4b6ad6a2cb37a4961e3c2e..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Algorithms/AlgorithmExplorer.java +++ /dev/null @@ -1,40 +0,0 @@ -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; - } - -} diff --git a/src/main/java/Requests/Algorithms/AlgorithmVersion.java b/src/main/java/Requests/Algorithms/AlgorithmVersion.java deleted file mode 100644 index e8e0c4e95891d923dab3abcd26ac58f8c2c0ebda..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Algorithms/AlgorithmVersion.java +++ /dev/null @@ -1,100 +0,0 @@ -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 requirements = new ArrayList(); - - 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 requirements) { - this.requirements = requirements; - return this; - } - - public AlgorithmVersion addRequirementsItem(Requirement requirementsItem) { - this.requirements.add(requirementsItem); - return this; - } - - public List getRequirements() { - return requirements; - } - - public void setRequirements(List 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 diff --git a/src/main/java/Requests/Algorithms/Requirement.java b/src/main/java/Requests/Algorithms/Requirement.java deleted file mode 100644 index 2a3fcc0f655c40a4c54f7a1aeda9c7ba3d3e8778..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Algorithms/Requirement.java +++ /dev/null @@ -1,150 +0,0 @@ -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 "); - } -} diff --git a/src/main/java/Requests/Authentication/Authentication.java b/src/main/java/Requests/Authentication/Authentication.java deleted file mode 100644 index 8db88098868b1285ef5b86349b6c3c3772632567..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Authentication/Authentication.java +++ /dev/null @@ -1,31 +0,0 @@ -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; - } -} diff --git a/src/main/java/Requests/Authentication/InvalidLoginOrPasswordException.java b/src/main/java/Requests/Authentication/InvalidLoginOrPasswordException.java deleted file mode 100644 index 2469b9f2705e32668a1d2661279f6ce18605d52d..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Authentication/InvalidLoginOrPasswordException.java +++ /dev/null @@ -1,6 +0,0 @@ -package Requests.Authentication; - -@SuppressWarnings("serial") -public class InvalidLoginOrPasswordException extends Exception { - -} diff --git a/src/main/java/Requests/Authentication/LoginOrPasswordNotProvidedException.java b/src/main/java/Requests/Authentication/LoginOrPasswordNotProvidedException.java deleted file mode 100644 index 6d6ed13b535c4ca6e43919bbd65c0848f3d7ecf4..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Authentication/LoginOrPasswordNotProvidedException.java +++ /dev/null @@ -1,6 +0,0 @@ -package Requests.Authentication; - -@SuppressWarnings("serial") -public class LoginOrPasswordNotProvidedException extends Exception { - -} diff --git a/src/main/java/Requests/Authentication/Token.java b/src/main/java/Requests/Authentication/Token.java deleted file mode 100644 index 5ce364c6b8bd281cf9619fa8ecaf43745f8be554..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Authentication/Token.java +++ /dev/null @@ -1,89 +0,0 @@ -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 "); - } -} - diff --git a/src/main/java/Requests/Jobs/JobInfo.java b/src/main/java/Requests/Jobs/JobInfo.java deleted file mode 100644 index 21c1584045df8499efdc876d57cf9afbe165b243..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Jobs/JobInfo.java +++ /dev/null @@ -1,776 +0,0 @@ -package Requests.Jobs; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; -import java.util.Map; - -/** - * JobInfo - */ -public class JobInfo { - private String jobId = null; - - private String groupId = null; - - private String sessionId = null; - - /** - * If the job was submit by the REST service or by RMI service. - */ - public enum SubmitedByEnum { - REST_SERVICE("REST Service"), - RMI_SERVICE("RMI Service"); - private String value; - SubmitedByEnum(String value) { - this.value = value; - } - @Override - public String toString() { - return String.valueOf(value); - } - } - - public enum StatusType { - SCHEDULED("SCHEDULED"), - INIT("INIT"), - UPLOADING("UPLOADING"), - QUEUED("QUEUED"), - EXECUTING("EXECUTING"), - DOWNLOADING("DOWNLOADING"), - FINISHED("FINISHED"), - UNKNOWN("UNKNOWN"); - private String value; - - StatusType(String value) { - this.value = value; - } - @Override - public String toString() { - return String.valueOf(value); - } - } - - private SubmitedByEnum submitedBy = null; - - private String projectId = null; - - private String algorithmId = null; - - private String algorithmVersion = null; - - private String algorithmName = null; - - private String jobOwner = null; - - private String jobOwnerName = null; - - private Boolean automaticallyMachineSelection = null; - - private String submissionMachine = null; - - private String submissionTime = null; - - private String executionMachine = null; - - private String endTime = null; - - private Integer numberOfAttempts = null; - - private String description = null; - - private Integer priority = null; - - private StatusType state = null; - - private Integer exitCode = null; - - /** - * The status describing the end of the execution. It can be empty if the job - * have not already finished. - */ - public enum ExitStatusEnum { - UNKNOWN("unknown"), - - SUCCESS("success"), - - EXECUTION_ERROR("execution_error"), - - JOB_IDENTIFIER_NOT_FOUND("job_identifier_not_found"), - - UNEXPECTED_MACHINE_ERROR("unexpected_machine_error"), - - PROJECT_NOT_FOUND("project_not_found"), - - FAILED_SETUP_EXECUTION_ENVIRONMENT("failed_setup_execution_environment"), - - NO_PERMISSION("no_permission"), - - NO_MACHINE_AVAILABLE("no_machine_available"), - - KILLED("killed"), - - LOST("lost"), - - UNDEFINED("undefined"); - - private String value; - - ExitStatusEnum(String value) { - this.value = value; - } - - @Override - public String toString() { - return String.valueOf(value); - } - } - - private ExitStatusEnum exitStatus = null; - private Double cpuTime = null; - private Integer wallclockTime = null; - private Double ramMemory = null; - private String progressInfo = null; - private List statusHistory = new ArrayList(); - private String lastModifiedTime = null; - private List monitoredFiles = new ArrayList(); - private Map specificData = new HashMap(); - - public JobInfo jobId(String jobId) { - this.jobId = jobId; - return this; - } - - /** - * The job Id. - * - * @return jobId - **/ - public String getJobId() { - return jobId; - } - - public void setJobId(String jobId) { - this.jobId = jobId; - } - - public JobInfo groupId(String groupId) { - this.groupId = groupId; - return this; - } - - /** - * The group Id of the job. - * - * @return groupId - **/ - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public JobInfo sessionId(String sessionId) { - this.sessionId = sessionId; - return this; - } - - /** - * The session Id used for job submission. By default, the sessionId is the - * project Id. - * - * @return sessionId - **/ - public String getSessionId() { - return sessionId; - } - - public void setSessionId(String sessionId) { - this.sessionId = sessionId; - } - - public JobInfo submitedBy(SubmitedByEnum submitedBy) { - this.submitedBy = submitedBy; - return this; - } - - /** - * If the job was submit by the REST service or by RMI service. - * - * @return submitedBy - **/ - public SubmitedByEnum getSubmitedBy() { - return submitedBy; - } - - public void setSubmitedBy(SubmitedByEnum submitedBy) { - this.submitedBy = submitedBy; - } - - public JobInfo projectId(String projectId) { - this.projectId = projectId; - return this; - } - - /** - * The project Id associated with the job. - * - * @return projectId - **/ - public String getProjectId() { - return projectId; - } - - public void setProjectId(String projectId) { - this.projectId = projectId; - } - - public JobInfo algorithmId(String algorithmId) { - this.algorithmId = algorithmId; - return this; - } - - /** - * The algorithm Id associated with the job. - * - * @return algorithmId - **/ - public String getAlgorithmId() { - return algorithmId; - } - - public void setAlgorithmId(String algorithmId) { - this.algorithmId = algorithmId; - } - - public JobInfo algorithmVersion(String algorithmVersion) { - this.algorithmVersion = algorithmVersion; - return this; - } - - /** - * The algoritm version associated with the job. - * - * @return algorithmVersion - **/ - public String getAlgorithmVersion() { - return algorithmVersion; - } - - public void setAlgorithmVersion(String algorithmVersion) { - this.algorithmVersion = algorithmVersion; - } - - public JobInfo algorithmName(String algorithmName) { - this.algorithmName = algorithmName; - return this; - } - - /** - * The algoritm name associated with the job. - * - * @return algorithmName - **/ - public String getAlgorithmName() { - return algorithmName; - } - - public void setAlgorithmName(String algorithmName) { - this.algorithmName = algorithmName; - } - - public JobInfo jobOwner(String jobOwner) { - this.jobOwner = jobOwner; - return this; - } - - /** - * The id of the user who submitted the job. - * - * @return jobOwner - **/ - public String getJobOwner() { - return jobOwner; - } - - public void setJobOwner(String jobOwner) { - this.jobOwner = jobOwner; - } - - public JobInfo jobOwnerName(String jobOwnerName) { - this.jobOwnerName = jobOwnerName; - return this; - } - - /** - * The name of the user who submitted the job. - * - * @return jobOwnerName - **/ - public String getJobOwnerName() { - return jobOwnerName; - } - - public void setJobOwnerName(String jobOwnerName) { - this.jobOwnerName = jobOwnerName; - } - - public JobInfo automaticallyMachineSelection(Boolean automaticallyMachineSelection) { - this.automaticallyMachineSelection = automaticallyMachineSelection; - return this; - } - - /** - * If the user select a machine for execution or not. - * - * @return automaticallyMachineSelection - **/ - public Boolean getAutomaticallyMachineSelection() { - return automaticallyMachineSelection; - } - - public void setAutomaticallyMachineSelection(Boolean automaticallyMachineSelection) { - this.automaticallyMachineSelection = automaticallyMachineSelection; - } - - public JobInfo submissionMachine(String submissionMachine) { - this.submissionMachine = submissionMachine; - return this; - } - - /** - * The machine selected for job execution. If the user choose the - * automatically machine selection, this information is empty. - * - * @return submissionMachine - **/ - public String getSubmissionMachine() { - return submissionMachine; - } - - public void setSubmissionMachine(String submissionMachine) { - this.submissionMachine = submissionMachine; - } - - public JobInfo submissionTime(String submissionTime) { - this.submissionTime = submissionTime; - return this; - } - - /** - * The submission time. - * - * @return submissionTime - **/ - public String getSubmissionTime() { - return submissionTime; - } - - public void setSubmissionTime(String submissionTime) { - this.submissionTime = submissionTime; - } - - public JobInfo executionMachine(String executionMachine) { - this.executionMachine = executionMachine; - return this; - } - - /** - * The machine where the job executed (or was scheduled to execute). - * - * @return executionMachine - **/ - public String getExecutionMachine() { - return executionMachine; - } - - public void setExecutionMachine(String executionMachine) { - this.executionMachine = executionMachine; - } - - public JobInfo endTime(String endTime) { - this.endTime = endTime; - return this; - } - - /** - * The end time of the execution. It can be empty if the job have not already - * finished. - * - * @return endTime - **/ - public String getEndTime() { - return endTime; - } - - public void setEndTime(String endTime) { - this.endTime = endTime; - } - - public JobInfo numberOfAttempts(Integer numberOfAttempts) { - this.numberOfAttempts = numberOfAttempts; - return this; - } - - /** - * The number of times the job has already been scheduled for execution. - * - * @return numberOfAttempts - **/ - public Integer getNumberOfAttempts() { - return numberOfAttempts; - } - - public void setNumberOfAttempts(Integer numberOfAttempts) { - this.numberOfAttempts = numberOfAttempts; - } - - public JobInfo description(String description) { - this.description = description; - return this; - } - - /** - * The description provided by the user at submission. It can be empty. - * - * @return description - **/ - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public JobInfo priority(Integer priority) { - this.priority = priority; - return this; - } - - /** - * The priority of the job. - * - * @return priority - **/ - public Integer getPriority() { - return priority; - } - - public void setPriority(Integer priority) { - this.priority = priority; - } - - public JobInfo state(StatusType state) { - this.state = state; - return this; - } - - /** - * Get state - * - * @return state - **/ - public StatusType getState() { - return state; - } - - public void setState(StatusType state) { - this.state = state; - } - - public JobInfo exitCode(Integer exitCode) { - this.exitCode = exitCode; - return this; - } - - /** - * The code returned by the job execution. It can be empty if the job have not - * already finished or if the system could not gather it. - * - * @return exitCode - **/ - public Integer getExitCode() { - return exitCode; - } - - public void setExitCode(Integer exitCode) { - this.exitCode = exitCode; - } - - public JobInfo exitStatus(ExitStatusEnum exitStatus) { - this.exitStatus = exitStatus; - return this; - } - - /** - * The status describing the end of the execution. It can be empty if the job - * have not already finished. - * - * @return exitStatus - **/ - public ExitStatusEnum getExitStatus() { - return exitStatus; - } - - public void setExitStatus(ExitStatusEnum exitStatus) { - this.exitStatus = exitStatus; - } - - public JobInfo cpuTime(Double cpuTime) { - this.cpuTime = cpuTime; - return this; - } - - /** - * Get cpuTime - * - * @return cpuTime - **/ - public Double getCpuTime() { - return cpuTime; - } - - public void setCpuTime(Double cpuTime) { - this.cpuTime = cpuTime; - } - - public JobInfo wallclockTime(Integer wallclockTime) { - this.wallclockTime = wallclockTime; - return this; - } - - /** - * Get wallclockTime - * - * @return wallclockTime - **/ - public Integer getWallclockTime() { - return wallclockTime; - } - - public void setWallclockTime(Integer wallclockTime) { - this.wallclockTime = wallclockTime; - } - - public JobInfo ramMemory(Double ramMemory) { - this.ramMemory = ramMemory; - return this; - } - - /** - * Get ramMemory - * - * @return ramMemory - **/ - public Double getRamMemory() { - return ramMemory; - } - - public void setRamMemory(Double ramMemory) { - this.ramMemory = ramMemory; - } - - public JobInfo progressInfo(String progressInfo) { - this.progressInfo = progressInfo; - return this; - } - - /** - * The progress info about a job. - * - **/ - public void setProgressInfo(String progressInfo) { - this.progressInfo = progressInfo; - } - - public JobInfo statusHistory(List statusHistory) { - this.statusHistory = statusHistory; - return this; - } - - public JobInfo addStatusHistoryItem(StatusChangeHistory statusHistoryItem) { - this.statusHistory.add(statusHistoryItem); - return this; - } - - /** - * Get statusHistory - * - * @return statusHistory - **/ - public List getStatusHistory() { - return statusHistory; - } - - public void setStatusHistory(List statusHistory) { - this.statusHistory = statusHistory; - } - - public JobInfo lastModifiedTime(String lastModifiedTime) { - this.lastModifiedTime = lastModifiedTime; - return this; - } - - /** - * The time of job last modification. - * - * @return lastModifiedTime - **/ - public String getLastModifiedTime() { - return lastModifiedTime; - } - - public void setLastModifiedTime(String lastModifiedTime) { - this.lastModifiedTime = lastModifiedTime; - } - - public JobInfo monitoredFiles(List monitoredFiles) { - this.monitoredFiles = monitoredFiles; - return this; - } - - public JobInfo addMonitoredFilesItem(MonitoredFile monitoredFilesItem) { - this.monitoredFiles.add(monitoredFilesItem); - return this; - } - - /** - * Monitored files during the job's execution - * - * @return monitoredFiles - **/ - public List getMonitoredFiles() { - return monitoredFiles; - } - - public void setMonitoredFiles(List monitoredFiles) { - this.monitoredFiles = monitoredFiles; - } - - public JobInfo specificData(Map specificData) { - this.specificData = specificData; - return this; - } - - public JobInfo putSpecificDataItem(String key, String specificDataItem) { - this.specificData.put(key, specificDataItem); - return this; - } - - /** - * Specific data monitored during the job's execution - * - * @return specificData - **/ - public Map getSpecificData() { - return specificData; - } - - public void setSpecificData(Map specificData) { - this.specificData = specificData; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - JobInfo job = (JobInfo) o; - return Objects.equals(this.jobId, job.jobId) && - Objects.equals(this.groupId, job.groupId) && - Objects.equals(this.sessionId, job.sessionId) && - Objects.equals(this.submitedBy, job.submitedBy) && - Objects.equals(this.projectId, job.projectId) && - Objects.equals(this.algorithmId, job.algorithmId) && - Objects.equals(this.algorithmVersion, job.algorithmVersion) && - Objects.equals(this.algorithmName, job.algorithmName) && - Objects.equals(this.jobOwner, job.jobOwner) && - Objects.equals(this.jobOwnerName, job.jobOwnerName) && - Objects.equals(this.automaticallyMachineSelection, job.automaticallyMachineSelection) && - Objects.equals(this.submissionMachine, job.submissionMachine) && - Objects.equals(this.submissionTime, job.submissionTime) && - Objects.equals(this.executionMachine, job.executionMachine) && - Objects.equals(this.endTime, job.endTime) && - Objects.equals(this.numberOfAttempts, job.numberOfAttempts) && - Objects.equals(this.description, job.description) && - Objects.equals(this.priority, job.priority) && - Objects.equals(this.state, job.state) && - Objects.equals(this.exitCode, job.exitCode) && - Objects.equals(this.exitStatus, job.exitStatus) && - Objects.equals(this.cpuTime, job.cpuTime) && - Objects.equals(this.wallclockTime, job.wallclockTime) && - Objects.equals(this.ramMemory, job.ramMemory) && - Objects.equals(this.progressInfo, job.progressInfo) && - Objects.equals(this.statusHistory, job.statusHistory) && - Objects.equals(this.lastModifiedTime, job.lastModifiedTime) && - Objects.equals(this.monitoredFiles, job.monitoredFiles) && - Objects.equals(this.specificData, job.specificData); - } - - @Override - public int hashCode() { - return Objects.hash(jobId, groupId, sessionId, submitedBy, projectId, algorithmId, algorithmVersion, algorithmName, - jobOwner, jobOwnerName, automaticallyMachineSelection, submissionMachine, submissionTime, executionMachine, - endTime, numberOfAttempts, description, priority, state, exitCode, exitStatus, cpuTime, wallclockTime, ramMemory, - progressInfo, statusHistory, lastModifiedTime, monitoredFiles, specificData); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class JobInfo {\n"); - - sb.append(" jobId: ").append(toIndentedString(jobId)).append("\n"); - sb.append(" groupId: ").append(toIndentedString(groupId)).append("\n"); - sb.append(" sessionId: ").append(toIndentedString(sessionId)).append("\n"); - sb.append(" submitedBy: ").append(toIndentedString(submitedBy)).append("\n"); - sb.append(" projectId: ").append(toIndentedString(projectId)).append("\n"); - sb.append(" algorithmId: ").append(toIndentedString(algorithmId)).append("\n"); - sb.append(" algorithmVersion: ").append(toIndentedString(algorithmVersion)).append("\n"); - sb.append(" algorithmName: ").append(toIndentedString(algorithmName)).append("\n"); - sb.append(" jobOwner: ").append(toIndentedString(jobOwner)).append("\n"); - sb.append(" jobOwnerName: ").append(toIndentedString(jobOwnerName)).append("\n"); - sb.append(" automaticallyMachineSelection: ").append(toIndentedString(automaticallyMachineSelection)).append( - "\n"); - sb.append(" submissionMachine: ").append(toIndentedString(submissionMachine)).append("\n"); - sb.append(" submissionTime: ").append(toIndentedString(submissionTime)).append("\n"); - sb.append(" executionMachine: ").append(toIndentedString(executionMachine)).append("\n"); - sb.append(" endTime: ").append(toIndentedString(endTime)).append("\n"); - sb.append(" numberOfAttempts: ").append(toIndentedString(numberOfAttempts)).append("\n"); - sb.append(" description: ").append(toIndentedString(description)).append("\n"); - sb.append(" priority: ").append(toIndentedString(priority)).append("\n"); - sb.append(" state: ").append(toIndentedString(state)).append("\n"); - sb.append(" exitCode: ").append(toIndentedString(exitCode)).append("\n"); - sb.append(" exitStatus: ").append(toIndentedString(exitStatus)).append("\n"); - sb.append(" cpuTime: ").append(toIndentedString(cpuTime)).append("\n"); - sb.append(" wallclockTime: ").append(toIndentedString(wallclockTime)).append("\n"); - sb.append(" ramMemory: ").append(toIndentedString(ramMemory)).append("\n"); - sb.append(" progressInfo: ").append(toIndentedString(progressInfo)).append("\n"); - sb.append(" statusHistory: ").append(toIndentedString(statusHistory)).append("\n"); - sb.append(" lastModifiedTime: ").append(toIndentedString(lastModifiedTime)).append("\n"); - sb.append(" monitoredFiles: ").append(toIndentedString(monitoredFiles)).append("\n"); - sb.append(" specificData: ").append(toIndentedString(specificData)).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 "); - } -} - diff --git a/src/main/java/Requests/Jobs/JobPullInfo.java b/src/main/java/Requests/Jobs/JobPullInfo.java deleted file mode 100644 index 37df27f154df98d9c6bf5c15f284179eaa5999f1..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Jobs/JobPullInfo.java +++ /dev/null @@ -1,88 +0,0 @@ -package Requests.Jobs; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class JobPullInfo { - private Long date = null; - - private List jobs = new ArrayList(); - - public JobPullInfo date(Long date) { - this.date = date; - return this; - } - - public Long getDate() { - return date; - } - - public void setDate(Long date) { - this.date = date; - } - - public JobPullInfo jobs(List jobs) { - this.jobs = jobs; - return this; - } - - public JobPullInfo addJobsItem(JobInfo jobsItem) { - this.jobs.add(jobsItem); - return this; - } - - public List getJobs() { - return jobs; - } - - public void setJobs(List jobs) { - this.jobs = jobs; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - JobPullInfo pullInfo = (JobPullInfo) o; - return Objects.equals(this.date, pullInfo.date) && - Objects.equals(this.jobs, pullInfo.jobs); - } - - @Override - public int hashCode() { - return Objects.hash(date, jobs); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class JobPullInfo {\n"); - sb.append(" date: ").append(toIndentedString(date)).append("\n"); - sb.append(" jobs: ").append(toIndentedString(jobs)).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 "); - } - - public JobInfo getJob(String jobId) { - for (JobInfo job : jobs) { - if (job.getJobId().equals(jobId)) { - return job; - } - } - return null; - } -} - diff --git a/src/main/java/Requests/Jobs/JobServices.java b/src/main/java/Requests/Jobs/JobServices.java deleted file mode 100644 index 6850bdd7c8b4be81af7130d463863e1985604f06..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Jobs/JobServices.java +++ /dev/null @@ -1,118 +0,0 @@ -package Requests.Jobs; - -import Requests.Algorithms.Algorithm; -import Requests.Algorithms.AlgorithmVersion; -import Requests.Authentication.Token; -import Requests.Projects.Project; - -import javax.ws.rs.client.*; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -public class JobServices { - - public static String submitJob(String host, Token token, Project project, Algorithm algorithm, - AlgorithmVersion version, String description, int priority, boolean emailOnTerminated, - String[] candidateMachines, Map args) { - - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host).path("jobs"); - - Map postBody = new HashMap<>(); - postBody.put("description", description); - postBody.put("remoteCommand", buildRemoteCommand(project, algorithm, version)); - postBody.put("args", args); - postBody.put("priority", Integer.toString(priority)); - postBody.put("emailOnTerminated", Boolean.toString(emailOnTerminated)); - postBody.put("numberOfJobs", new Integer(1)); - - Invocation.Builder invocationBuilder = webTarget.request("application/json;charset=UTF-8"); - Response response = invocationBuilder - .header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()) - .header(HttpHeaders.CONTENT_TYPE, "application/json").header(HttpHeaders.CACHE_CONTROL, "no-cache") - .post(Entity.entity(postBody, MediaType.APPLICATION_JSON_TYPE), Response.class); - if (response.getStatus() == Response.Status.OK.getStatusCode()) - return response.readEntity(String.class); - return null; - } - - private static Map buildRemoteCommand(Project project, Algorithm algorithm, - AlgorithmVersion version) { - Map remoteCommand = new HashMap<>(); - remoteCommand.put("algorithmId", algorithm.getId()); - remoteCommand.put("versionId", version.getId()); - remoteCommand.put("projectId", project.getId()); - return remoteCommand; - } - - public static JobInfo getJobInfo(String host, Token token, String jobId) { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host).path("jobs").path(jobId); - - Invocation.Builder invocationBuilder = webTarget.request("application/json;charset=UTF-8"); - Response response = invocationBuilder - .header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()) - .header(HttpHeaders.CONTENT_TYPE, "application/json").header(HttpHeaders.CACHE_CONTROL, "no-cache") - .get(Response.class); - if (response.getStatus() == Response.Status.OK.getStatusCode()) - return response.readEntity(JobInfo.class); - return null; - - } - - public static void awaitJobEnd(String host, Token token, JobInfo jinfo) { - String jobId = jinfo.getJobId(); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); - Date date; - try { - date = format.parse(jinfo.getLastModifiedTime()); - } catch (ParseException e) { - e.printStackTrace(); - return; - } - long currDate = date.getTime(); - while (true) - { - JobPullInfo info = getJobPullInfo(host, token, jobId, currDate); - if (info!=null && info.getJob(jobId)!=null) - { - JobInfo.StatusType state = info.getJob(jobId).getState(); - System.out.println ("Job state (" + currDate + "): " + state); - if (state.equals(JobInfo.StatusType.FINISHED)) { - System.out.println("Job " + jobId + " terminou"); - break; - } else { - currDate = info.getDate(); - } - } - } - } - - private static JobPullInfo getJobPullInfo(String host, Token token, String jobId, long date) { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host) - .path("jobs") - .path("pull") - .queryParam("jobId", jobId) - .queryParam("date", date); - - Invocation.Builder invocationBuilder = webTarget.request("application/json;charset=UTF-8"); - Response response = invocationBuilder - .header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()) - .header(HttpHeaders.CONTENT_TYPE, "application/json").header(HttpHeaders.CACHE_CONTROL, "no-cache") - .get(Response.class); - if (response.getStatus() == Response.Status.OK.getStatusCode()) - { - return response.readEntity(JobPullInfo.class); - } - return null; - } - - -} diff --git a/src/main/java/Requests/Jobs/JobSession.java b/src/main/java/Requests/Jobs/JobSession.java deleted file mode 100644 index 8d6044544fce185d6b13ace263a7d59d11cf9f11..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Jobs/JobSession.java +++ /dev/null @@ -1,16 +0,0 @@ -package Requests.Jobs; - -public class JobSession { - - private String contact; - private String sessionName; - private String[] jobCategory; - - public JobSession() { - - } - - public String getName() { - return this.sessionName; - } -} diff --git a/src/main/java/Requests/Jobs/MonitoredFile.java b/src/main/java/Requests/Jobs/MonitoredFile.java deleted file mode 100644 index e7a35a065a54479b78096655df4b4dd93cd2130b..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Jobs/MonitoredFile.java +++ /dev/null @@ -1,117 +0,0 @@ -package Requests.Jobs; - -import java.util.Objects; -import java.util.ArrayList; -import java.util.List; - - -/** - * MonitoredFile - */ -public class MonitoredFile { - private String name = null; - - private String id = null; - - private List formats = new ArrayList(); - - public MonitoredFile name(String name) { - this.name = name; - return this; - } - - /** - * Get name - * @return name - **/ - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public MonitoredFile id(String id) { - this.id = id; - return this; - } - - /** - * Get id - * @return id - **/ - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public MonitoredFile formats(List formats) { - this.formats = formats; - return this; - } - - public MonitoredFile addFormatsItem(String formatsItem) { - this.formats.add(formatsItem); - return this; - } - - /** - * Get formats - * @return formats - **/ - public List getFormats() { - return formats; - } - - public void setFormats(List formats) { - this.formats = formats; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MonitoredFile monitoredFile = (MonitoredFile) o; - return Objects.equals(this.name, monitoredFile.name) && - Objects.equals(this.id, monitoredFile.id) && - Objects.equals(this.formats, monitoredFile.formats); - } - - @Override - public int hashCode() { - return Objects.hash(name, id, formats); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class MonitoredFile {\n"); - - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" formats: ").append(toIndentedString(formats)).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 "); - } -} - diff --git a/src/main/java/Requests/Jobs/StatusChangeHistory.java b/src/main/java/Requests/Jobs/StatusChangeHistory.java deleted file mode 100644 index 4a1e0cf91cf292fb9a4f6622b9775a53977d3c71..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Jobs/StatusChangeHistory.java +++ /dev/null @@ -1,72 +0,0 @@ -package Requests.Jobs; - -import java.util.Objects; - -public class StatusChangeHistory { - private JobInfo.StatusType status = null; - - private String timestamp = null; - - public StatusChangeHistory status(JobInfo.StatusType status) { - this.status = status; - return this; - } - - public JobInfo.StatusType getStatus() { - return status; - } - - public void setStatus(JobInfo.StatusType status) { - this.status = status; - } - - public StatusChangeHistory timestamp(String timestamp) { - this.timestamp = timestamp; - return this; - } - - public String getTimestamp() { - return timestamp; - } - - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - StatusChangeHistory statusChangeHistory = (StatusChangeHistory) o; - return Objects.equals(this.status, statusChangeHistory.status) && - Objects.equals(this.timestamp, statusChangeHistory.timestamp); - } - - @Override - public int hashCode() { - return Objects.hash(status, timestamp); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class StatusChangeHistory {\n"); - - sb.append(" status: ").append(toIndentedString(status)).append("\n"); - sb.append(" timestamp: ").append(toIndentedString(timestamp)).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 "); - } -} diff --git a/src/main/java/Requests/Projects/FileExplorer.java b/src/main/java/Requests/Projects/FileExplorer.java deleted file mode 100644 index 4a581e74db31f5a18a94cee9b0f629a9ac97273f..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/FileExplorer.java +++ /dev/null @@ -1,181 +0,0 @@ -package Requests.Projects; - -import Requests.Authentication.InvalidLoginOrPasswordException; -import Requests.Authentication.Token; -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataMultiPart; -import org.glassfish.jersey.media.multipart.MultiPart; -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; - -import javax.ws.rs.client.*; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; -import java.text.Normalizer; -import java.util.Base64; -import java.util.regex.Pattern; - -public class FileExplorer { - - private static final Pattern DIACRITICS_AND_FRIENDS = Pattern - .compile("[\\p{InCombiningDiacriticalMarks}\\p{IsLm}\\p{IsSk}]+"); - - public static FileUpload uploadFile(String host, Token token, Project project, String projectFolderPath, - String localFilePath, String fileName) throws ProjectOrFileNotFoundException, PermissionException { - FileDataBodyPart filePart = new FileDataBodyPart("file", new File(localFilePath)); - MultiPart multipartEntity = null; - FormDataMultiPart form = null; - try { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host).register(MultiPartFeature.class); - filePart.setContentDisposition(FormDataContentDisposition.name("file") - .fileName(fileName).build()); - form = new FormDataMultiPart(); - form.field("uploadType", "multipart"); - multipartEntity = form.bodyPart(filePart); - Response response = webTarget.path("projects").path(project.getId()).path("files").path - (projectFolderPath).request("application/json;charset=UTF-8").header(HttpHeaders - .AUTHORIZATION, "Bearer " + token.getAccessToken()).post(Entity.entity - (multipartEntity, MediaType.MULTIPART_FORM_DATA)); - return response.readEntity(FileUpload.class); - } finally { - if (multipartEntity != null) { - try { - multipartEntity.close(); - } catch (IOException e) { - } - multipartEntity = null; - } - if (form != null) { - try { - form.close(); - } catch (IOException e) { - } - form = null; - } - } - } - - private static String validateFileName(String fileName) { - return stripDiacritics(fileName.replaceAll("[ \"\'!@#$%¨&*()+`´{}^~:;?/°><,|\\[\\]\\\\]", "")); - - } - - private static String stripDiacritics(String str) { - str = Normalizer.normalize(str, Normalizer.Form.NFD); - str = DIACRITICS_AND_FRIENDS.matcher(str).replaceAll(""); - return str; - } - - public static String downloadTextFile(String host, Token token, Project project, String projectFolderPath, - String fileName) - throws ProjectOrFileNotFoundException, PermissionException, InvalidLoginOrPasswordException { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host); - String fileId = Base64.getEncoder().encodeToString(projectFolderPath.equals("root") ? fileName.getBytes() - : (projectFolderPath + (fileName == null ? "" : "/" + fileName)).getBytes()); - WebTarget uploadTarget = webTarget.path("projects").path(project.getId()).path("files").path(fileId); - - Invocation.Builder invocationBuilder = uploadTarget.request(); - - Response response = invocationBuilder - .header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()).get(); - - int status = response.getStatus(); - - if (status == Response.Status.OK.getStatusCode()) - return response.readEntity(String.class); - else if (status == Response.Status.BAD_REQUEST.getStatusCode()) - throw new InvalidLoginOrPasswordException(); - else if (status == Response.Status.FORBIDDEN.getStatusCode()) - throw new PermissionException(); - else if (status == Response.Status.NOT_FOUND.getStatusCode()) - throw new ProjectOrFileNotFoundException(); - client.close(); - return null; - } - - public static InputStream downloadBinaryFile(String host, Token token, Project project, String projectFolderPath, - String fileName) - throws ProjectOrFileNotFoundException, PermissionException, InvalidLoginOrPasswordException { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host); - String fileId = Base64.getEncoder().encodeToString(projectFolderPath.equals("root") ? fileName.getBytes() - : (projectFolderPath + (fileName == null ? "" : "/" + fileName)).getBytes()); - WebTarget uploadTarget = webTarget.path("projects").path(project.getId()).path("files").path(fileId); - - Invocation.Builder invocationBuilder = uploadTarget.request(); - - Response response = invocationBuilder - .header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()).get(); - - int status = response.getStatus(); - - if (status == Response.Status.OK.getStatusCode()) - return response.readEntity(InputStream.class); - else if (status == Response.Status.BAD_REQUEST.getStatusCode()) - throw new InvalidLoginOrPasswordException(); - else if (status == Response.Status.FORBIDDEN.getStatusCode()) - throw new PermissionException(); - else if (status == Response.Status.NOT_FOUND.getStatusCode()) - throw new ProjectOrFileNotFoundException(); - client.close(); - return null; - } - - public static void downloadLargeFile(String host, Token token, Project project, String projectFolderPath, - String fileName, String destinFileName) - throws ProjectOrFileNotFoundException, PermissionException, InvalidLoginOrPasswordException { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host); - String fileId = Base64.getEncoder().encodeToString(projectFolderPath.equals("root") ? fileName.getBytes() - : (projectFolderPath + (fileName == null ? "" : "/" + fileName)).getBytes()); - WebTarget uploadTarget = webTarget.path("projects").path(project.getId()).path("files").path(fileId) - .path("link"); - - Invocation.Builder invocationBuilder = uploadTarget.request("application/json;charset=UTF-8"); - Response response = invocationBuilder - .header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()).get(); - - int status = response.getStatus(); - - if (status == Response.Status.OK.getStatusCode()) { - FileLink link = response.readEntity(FileLink.class); - URL website; - try { - File file = new File(destinFileName); - if (file.getParentFile() != null) { - file.getParentFile().mkdirs(); - } - file.createNewFile(); - website = new URL(link.getUrl()); - ReadableByteChannel rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destinFileName); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - } else if (status == Response.Status.BAD_REQUEST.getStatusCode()) - throw new InvalidLoginOrPasswordException(); - else if (status == Response.Status.FORBIDDEN.getStatusCode()) - throw new PermissionException(); - else if (status == Response.Status.NOT_FOUND.getStatusCode()) - throw new ProjectOrFileNotFoundException(); - } -} diff --git a/src/main/java/Requests/Projects/FileLink.java b/src/main/java/Requests/Projects/FileLink.java deleted file mode 100644 index 2d51224b35e0aab1b4d5ab886de6d16859f89fc0..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/FileLink.java +++ /dev/null @@ -1,89 +0,0 @@ -package Requests.Projects; - -import java.util.Objects; - -public class FileLink { - private String url = null; - - private String fileName = null; - - private String mimeType = null; - - public FileLink url(String url) { - this.url = url; - return this; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public FileLink fileName(String fileName) { - this.fileName = fileName; - return this; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public FileLink mimeType(String mimeType) { - this.mimeType = mimeType; - return this; - } - - public String getMimeType() { - return mimeType; - } - - public void setMimeType(String mimeType) { - this.mimeType = mimeType; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - FileLink fileLink = (FileLink) o; - return Objects.equals(this.url, fileLink.url) && - Objects.equals(this.fileName, fileLink.fileName) && - Objects.equals(this.mimeType, fileLink.mimeType); - } - - @Override - public int hashCode() { - return Objects.hash(url, fileName, mimeType); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class FileLink {\n"); - - sb.append(" url: ").append(toIndentedString(url)).append("\n"); - sb.append(" fileName: ").append(toIndentedString(fileName)).append("\n"); - sb.append(" mimeType: ").append(toIndentedString(mimeType)).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 "); - } -} diff --git a/src/main/java/Requests/Projects/FileUpload.java b/src/main/java/Requests/Projects/FileUpload.java deleted file mode 100644 index 843d9200e2b4580cd1dc12021dadcf7663b898d1..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/FileUpload.java +++ /dev/null @@ -1,72 +0,0 @@ -package Requests.Projects; - -import java.util.Objects; - -public class FileUpload { - - private String uploadId = null; - private String fileId = null; - public FileUpload uploadId(String uploadId) { - this.uploadId = uploadId; - return this; - } - - public String getUploadId() { - return uploadId; - } - - public void setUploadId(String uploadId) { - this.uploadId = uploadId; - } - - public FileUpload fileId(String fileId) { - this.fileId = fileId; - return this; - } - - public String getFileId() { - return fileId; - } - - public void setFileId(String fileId) { - this.fileId = fileId; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - FileUpload fileUpload = (FileUpload) o; - return Objects.equals(this.uploadId, fileUpload.uploadId) && - Objects.equals(this.fileId, fileUpload.fileId); - } - - @Override - public int hashCode() { - return Objects.hash(uploadId, fileId); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class FileUpload {\n"); - - sb.append(" uploadId: ").append(toIndentedString(uploadId)).append("\n"); - sb.append(" fileId: ").append(toIndentedString(fileId)).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 "); - } - } - diff --git a/src/main/java/Requests/Projects/PermissionException.java b/src/main/java/Requests/Projects/PermissionException.java deleted file mode 100644 index d8786d22cca5e013adfd844d0756f2d3233694be..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/PermissionException.java +++ /dev/null @@ -1,5 +0,0 @@ -package Requests.Projects; - -public class PermissionException extends Exception { - -} diff --git a/src/main/java/Requests/Projects/Project.java b/src/main/java/Requests/Projects/Project.java deleted file mode 100644 index 593f4b1098f2932f84756a1b03b50776e23fb540..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/Project.java +++ /dev/null @@ -1,245 +0,0 @@ -package Requests.Projects; - -import Requests.User.User; - -import javax.ws.rs.Produces; -import javax.xml.bind.annotation.XmlRootElement; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -@Produces("application/json") -@XmlRootElement -public class Project { - private String id = null; - private String name = null; - private String description = null; - private User owner = null; - private Boolean editable = null; - private Boolean isOwner = null; - private Long modified = null; - private Long created = null; - private String type = null; - - public enum VisibilityEnum { - PRIVATE("private"), - PUBLIC_RO("public_ro"), - PUBLIC_RW("public_rw"), - SELECTIVE("selective"); - private String value; - VisibilityEnum(String value) { - this.value = value; - } - @Override - public String toString() { - return String.valueOf(value); - } - } - - private VisibilityEnum visibility = null; - - private List members = new ArrayList(); - - public Project id(String id) { - this.id = id; - return this; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Project name(String name) { - this.name = name; - return this; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Project description(String description) { - this.description = description; - return this; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Project owner(User owner) { - this.owner = owner; - return this; - } - - public User getOwner() { - return owner; - } - - public void setOwner(User owner) { - this.owner = owner; - } - - public Project editable(Boolean editable) { - this.editable = editable; - return this; - } - - public Boolean getEditable() { - return editable; - } - - public void setEditable(Boolean editable) { - this.editable = editable; - } - - public Project isOwner(Boolean isOwner) { - this.isOwner = isOwner; - return this; - } - - public Boolean getIsOwner() { - return isOwner; - } - - public void setIsOwner(Boolean isOwner) { - this.isOwner = isOwner; - } - - public Project modified(Long modified) { - this.modified = modified; - return this; - } - - public Long getModified() { - return modified; - } - - public void setModified(Long modified) { - this.modified = modified; - } - - public Project created(Long created) { - this.created = created; - return this; - } - - public Long getCreated() { - return created; - } - - public void setCreated(Long created) { - this.created = created; - } - - public Project type(String type) { - this.type = type; - return this; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Project visibility(VisibilityEnum visibility) { - this.visibility = visibility; - return this; - } - - public VisibilityEnum getVisibility() { - return visibility; - } - - public void setVisibility(VisibilityEnum visibility) { - this.visibility = visibility; - } - - public Project members(List members) { - this.members = members; - return this; - } - - public Project addMembersItem(TeamMember membersItem) { - this.members.add(membersItem); - return this; - } - - public List getMembers() { - return members; - } - - public void setMembers(List members) { - this.members = members; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Project project = (Project) o; - return Objects.equals(this.id, project.id) && - Objects.equals(this.name, project.name) && - Objects.equals(this.description, project.description) && - Objects.equals(this.owner, project.owner) && - Objects.equals(this.editable, project.editable) && - Objects.equals(this.isOwner, project.isOwner) && - Objects.equals(this.modified, project.modified) && - Objects.equals(this.created, project.created) && - Objects.equals(this.type, project.type) && - Objects.equals(this.visibility, project.visibility) && - Objects.equals(this.members, project.members); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, description, owner, editable, isOwner, modified, created, type, visibility, members); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class Project {\n"); - - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" description: ").append(toIndentedString(description)).append("\n"); - sb.append(" owner: ").append(toIndentedString(owner)).append("\n"); - sb.append(" editable: ").append(toIndentedString(editable)).append("\n"); - sb.append(" isOwner: ").append(toIndentedString(isOwner)).append("\n"); - sb.append(" modified: ").append(toIndentedString(modified)).append("\n"); - sb.append(" created: ").append(toIndentedString(created)).append("\n"); - sb.append(" type: ").append(toIndentedString(type)).append("\n"); - sb.append(" visibility: ").append(toIndentedString(visibility)).append("\n"); - sb.append(" members: ").append(toIndentedString(members)).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 "); - } -} diff --git a/src/main/java/Requests/Projects/ProjectExplorer.java b/src/main/java/Requests/Projects/ProjectExplorer.java deleted file mode 100644 index 76cbdb24c3d5fcb646b95cd2b315ee4eca677116..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/ProjectExplorer.java +++ /dev/null @@ -1,31 +0,0 @@ -package Requests.Projects; - -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; -import java.util.Base64; - -public class ProjectExplorer { - - public static Project findProjectByName(String host, Token token, String projectName) { - - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(host); - - String projectId = Base64.getEncoder().encodeToString(projectName.getBytes()); - Response response = webTarget.path("projects").path(projectId) - .request("application/json;charset=UTF-8") - .header(HttpHeaders.AUTHORIZATION, token.getTokenType() + token.getAccessToken()).get(); - - if (response.getStatus() == Response.Status.OK.getStatusCode()) { - Project project = response.readEntity(Project.class); - return project; - } - return null; - } - -} diff --git a/src/main/java/Requests/Projects/ProjectOrFileNotFoundException.java b/src/main/java/Requests/Projects/ProjectOrFileNotFoundException.java deleted file mode 100644 index d4121ee3abbaa23787b59b9c609dda77809c3721..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/ProjectOrFileNotFoundException.java +++ /dev/null @@ -1,5 +0,0 @@ -package Requests.Projects; - -public class ProjectOrFileNotFoundException extends Exception { - -} diff --git a/src/main/java/Requests/Projects/TeamMember.java b/src/main/java/Requests/Projects/TeamMember.java deleted file mode 100644 index 114220ec40018a9afb9366073f7627c0324667f6..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/Projects/TeamMember.java +++ /dev/null @@ -1,149 +0,0 @@ -package Requests.Projects; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class TeamMember { - private String id = null; - - private String login = null; - - private String name = null; - - private List roles = new ArrayList(); - - private String avatar = null; - - private Boolean editable = null; - - public TeamMember id(String id) { - this.id = id; - return this; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public TeamMember login(String login) { - this.login = login; - return this; - } - - public String getLogin() { - return login; - } - - public void setLogin(String login) { - this.login = login; - } - - public TeamMember name(String name) { - this.name = name; - return this; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public TeamMember roles(List roles) { - this.roles = roles; - return this; - } - - public TeamMember addRolesItem(String rolesItem) { - this.roles.add(rolesItem); - return this; - } - - public List getRoles() { - return roles; - } - - public void setRoles(List roles) { - this.roles = roles; - } - - public TeamMember avatar(String avatar) { - this.avatar = avatar; - return this; - } - - public String getAvatar() { - return avatar; - } - - public void setAvatar(String avatar) { - this.avatar = avatar; - } - - public TeamMember editable(Boolean editable) { - this.editable = editable; - return this; - } - - public Boolean getEditable() { - return editable; - } - - public void setEditable(Boolean editable) { - this.editable = editable; - } - - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TeamMember teamMember = (TeamMember) o; - return Objects.equals(this.id, teamMember.id) && - Objects.equals(this.login, teamMember.login) && - Objects.equals(this.name, teamMember.name) && - Objects.equals(this.roles, teamMember.roles) && - Objects.equals(this.avatar, teamMember.avatar) && - Objects.equals(this.editable, teamMember.editable); - } - - @Override - public int hashCode() { - return Objects.hash(id, login, name, roles, avatar, editable); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class TeamMember {\n"); - - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" login: ").append(toIndentedString(login)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" roles: ").append(toIndentedString(roles)).append("\n"); - sb.append(" avatar: ").append(toIndentedString(avatar)).append("\n"); - sb.append(" editable: ").append(toIndentedString(editable)).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 "); - } -} - - diff --git a/src/main/java/Requests/User/User.java b/src/main/java/Requests/User/User.java deleted file mode 100644 index e3bc61c1e948a9df8d7faa2c0673335b5b1d8218..0000000000000000000000000000000000000000 --- a/src/main/java/Requests/User/User.java +++ /dev/null @@ -1,110 +0,0 @@ -package Requests.User; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class User { - private String id = null; - private String name = null; - private String login = null; - private String avatar = null; - private List roles = new ArrayList(); - public User id(String id) { - this.id = id; - return this; - } - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public User name(String name) { - this.name = name; - return this; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public User login(String login) { - this.login = login; - return this; - } - public String getLogin() { - return login; - } - public void setLogin(String login) { - this.login = login; - } - public User avatar(String avatar) { - this.avatar = avatar; - return this; - } - public String getAvatar() { - return avatar; - } - public void setAvatar(String avatar) { - this.avatar = avatar; - } - public User roles(List roles) { - this.roles = roles; - return this; - } - public User addRolesItem(String rolesItem) { - this.roles.add(rolesItem); - return this; - } - public List getRoles() { - return roles; - } - public void setRoles(List roles) { - this.roles = roles; - } - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - User user = (User) o; - return Objects.equals(this.id, user.id) && - Objects.equals(this.name, user.name) && - Objects.equals(this.login, user.login) && - Objects.equals(this.avatar, user.avatar) && - Objects.equals(this.roles, user.roles); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, login, avatar, roles); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class User {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" login: ").append(toIndentedString(login)).append("\n"); - sb.append(" avatar: ").append(toIndentedString(avatar)).append("\n"); - sb.append(" roles: ").append(toIndentedString(roles)).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 "); - } -} - -