Skip to content

Commit

Permalink
Release 99 (#8)
Browse files Browse the repository at this point in the history
# Patch notes for 99.0.2541

These patch notes summarize the changes from version 98.0.2363.

Added 2 new APIs:
* TaskField.QueryTaskFields (GET /api/data/projects/tasks/fields)
* TaskField.QueryTaskFieldValues (GET /api/data/tasks/fields/values)

Renamed 2 old APIs:
* Renamed 'ProjectField.UpdateProjectField' to 'ProjectField.UpdateProjectFieldValue'
* Renamed 'ProjectMembers.RetrieveUserProjectMemberShip' to 'ProjectMembers.RetrieveUserProjectMembership'
  • Loading branch information
tspence authored Dec 11, 2023
1 parent 463f908 commit b79a937
Show file tree
Hide file tree
Showing 58 changed files with 1,047 additions and 605 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.projectmanager</groupId>
<artifactId>projectmanagersdk</artifactId>
<version>98.0.2363</version>
<version>99.0.2550</version>

<name>ProjectManagerSDK</name>
<description>Software development kit for the ProjectManager.com API. for Java</description>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/projectmanager/AstroResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,14 @@ public void Parse(Type classReference, String content, int code, long serverDura
this.error = ((AstroResult<T>)gson.fromJson(content, new TypeToken<AstroError>() {}.getType())).getError();
}
}

/**
* Parse response from the server - only works for success
*/
public void ParseBlob(Type classReference, T blobContent, int code, long serverDuration, long roundTripTime)
{
this.statusCode = Integer.toString(code);
this.success = true;
this.data = blobContent;
}
};
207 changes: 207 additions & 0 deletions src/main/java/com/projectmanager/BlobRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/**
* ProjectManager API for Java
*
* (c) 2023-2023 ProjectManager.com
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author ProjectManager.com <[email protected]>
* @copyright 2023-2023 ProjectManager.com
* @link https://github.com/projectmgr/projectmanager-sdk-java
*/

package com.projectmanager;

import java.lang.reflect.Type;
import java.io.ByteArrayOutputStream;
import java.net.InetAddress;
import java.net.URI;
import java.time.Duration;
import java.time.Instant;
import java.util.Hashtable;
import java.util.Map.Entry;
import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPatch;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.net.URIBuilder;
import org.jetbrains.annotations.NotNull;

import com.google.gson.Gson;

/**
* Represents a request to a remote web server
*/
public class BlobRequest {
private Hashtable<String, String> queryParams;
private Hashtable<String, String> pathReplacements;
private String method;
private String path;
private Object body;
private ProjectManagerClient client;

/**
* <p>
* Constructor for BlobRequest.
* </p>
*
* @param client a {@link com.projectmanager.ProjectManagerClient} object.
* @param method a {@link java.lang.String} object.
* @param path a {@link java.lang.String} object.
*/
public BlobRequest(@NotNull ProjectManagerClient client, @NotNull String method, @NotNull String path) {
this.client = client;
this.method = method;
this.path = path;
queryParams = new Hashtable<String, String>();
pathReplacements = new Hashtable<String, String>();
}

/**
* <p>
* AddQuery.
* </p>
*
* @param name a {@link java.lang.String} object.
* @param value a {@link java.lang.String} object.
*/
public void AddQuery(@NotNull String name, @NotNull String value) {
this.queryParams.put(name, value);
}

/**
* <p>
* AddPath.
* </p>
*
* @param name a {@link java.lang.String} object.
* @param value a {@link java.lang.String} object.
*/
public void AddPath(@NotNull String name, @NotNull String value) {
this.pathReplacements.put(name, value);
}

/**
* <p>
* AddBody.
* </p>
*
* @param body a {@link java.lang.Object} object.
*/
public void AddBody(Object body) {
this.body = body;
}

/**
* Adapted from Apache simple request client example
*
* @return a {@link com.projectmanager.AstroResult} object.
*/
public @NotNull AstroResult<byte[]> Call(Type classReference) {
Instant start = Instant.now();
AstroResult<byte[]> result = new AstroResult<byte[]>();
try {

CloseableHttpClient httpclient = HttpClients.createDefault();

// Add query parameters
URIBuilder builder = new URIBuilder(this.client.getServerUri());
for (Entry<String, String> entry : this.queryParams.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue());
}

// Set the path and execute replacements
String filledPath = this.path;
for (Entry<String, String> entry : this.pathReplacements.entrySet()) {
filledPath = filledPath.replaceAll(entry.getKey(), entry.getValue());
}
builder.setPath(filledPath);
URI uri = builder.build();

// Create the appropriate request
ClassicHttpRequest request;
switch (this.method) {
case "PATCH":
request = new HttpPatch(uri);
break;
case "PUT":
request = new HttpPut(uri);
break;
case "POST":
request = new HttpPost(uri);
break;
case "DELETE":
request = new HttpDelete(uri);
break;
case "GET":
default:
request = new HttpGet(uri);
break;
}

request.addHeader("SdkName", "Java");
request.addHeader("SdkVersion", "99.0.2550.0");

String applicationName = this.client.getAppName();

if (applicationName != null) {
request.addHeader("ApplicationName", applicationName);
}

String machineName = InetAddress.getLocalHost().getHostName();

if (machineName != null) {
request.addHeader("MachineName", machineName);
}

String bearerToken = this.client.getBearerToken();
if (bearerToken != null) {
request.addHeader("Authorization", "Bearer " + bearerToken);
}

// If we have a request body
Gson gson = new Gson();
if (body != null) {
StringEntity stringEntity = new StringEntity(gson.toJson(body));
request.setEntity(stringEntity);
}
// Execute and parse results
final CloseableHttpResponse rawResponse = httpclient.execute(request);

// get round trip time
long roundTripTime = Duration.between(start, Instant.now()).toMillis();

// Did we succeed?
int code = rawResponse.getCode();
long serverDuration = 0;

if (rawResponse.getHeader("ServerDuration") != null) {
serverDuration = Long.parseLong(rawResponse.getHeader("ServerDuration").getValue());
}

// Detect success or failure
result.Parse(getClass(), bearerToken, code, serverDuration, roundTripTime);

if (code >= 200 && code < 300) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
rawResponse.getEntity().writeTo(baos);
result.ParseBlob(getClass(), baos.toByteArray(), code, serverDuration, roundTripTime);
} else {
String content = EntityUtils.toString(rawResponse.getEntity());
result.Parse(getClass(), content, code, serverDuration, roundTripTime);
}
return result;
} catch (Exception e) {
result.Parse(getClass(), e.toString(), -1, -1, -1);
}
return result;
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/projectmanager/ProjectManagerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author ProjectManager.com <[email protected]>
*
* @copyright 2023-2023 ProjectManager.com, Inc.
* @version 98.0.2363
* @version 99.0.2550
* @link https://github.com/projectmgr/projectmanager-sdk-java
*/

Expand Down Expand Up @@ -47,6 +47,7 @@
import com.projectmanager.clients.TaskFileClient;
import com.projectmanager.clients.TaskStatusClient;
import com.projectmanager.clients.TaskTagClient;
import com.projectmanager.clients.TeamsClient;
import com.projectmanager.clients.TimesheetClient;
import com.projectmanager.clients.UserRoleClient;
import com.projectmanager.clients.WorkSpaceClient;
Expand Down Expand Up @@ -93,6 +94,7 @@ public class ProjectManagerClient {
private TaskFileClient taskFile;
private TaskStatusClient taskStatus;
private TaskTagClient taskTag;
private TeamsClient teams;
private TimesheetClient timesheet;
private UserRoleClient userRole;
private WorkSpaceClient workSpace;
Expand Down Expand Up @@ -132,6 +134,7 @@ private ProjectManagerClient(@NotNull String serverUri)
this.taskFile = new TaskFileClient(this);
this.taskStatus = new TaskStatusClient(this);
this.taskTag = new TaskTagClient(this);
this.teams = new TeamsClient(this);
this.timesheet = new TimesheetClient(this);
this.userRole = new UserRoleClient(this);
this.workSpace = new WorkSpaceClient(this);
Expand Down Expand Up @@ -323,6 +326,12 @@ private ProjectManagerClient(@NotNull String serverUri)
* @return A collection containing the {@link com.projectmanager.clients.TaskTagClient client} methods in the API.
*/
public @NotNull TaskTagClient getTaskTagClient() { return this.taskTag; }
/**
* A collection of API methods relating to Teams
*
* @return A collection containing the {@link com.projectmanager.clients.TeamsClient client} methods in the API.
*/
public @NotNull TeamsClient getTeamsClient() { return this.teams; }
/**
* A collection of API methods relating to Timesheet
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/projectmanager/RestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void AddBody(Object body) {
}

request.addHeader("SdkName", "Java");
request.addHeader("SdkVersion", "98.0.2363.0");
request.addHeader("SdkVersion", "99.0.2550.0");

String applicationName = this.client.getAppName();

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/projectmanager/clients/ApiKeyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/projectmanager/clients/FileClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -60,6 +61,26 @@ public FileClient(@NotNull ProjectManagerClient client) {
return r.Call(new TypeToken<AstroResult<Object>>() {}.getType());
}

/**
* Downloads a thumbnail image associated with a document that was previously uploaded to ProjectManager.com.
*
* ProjectManager allows you to store files linked to various elements within your Workspace,
* such as Projects, Tasks, or your Home. Files are organized based on their storage location.
*
* When uploading a file, please allow some time for the file to undergo processing and verification.
* ProjectManager may reject file uploads containing issues such as malware. Once a file has
* completed the upload process, you can retrieve its associated thumbnail using the DownloadThumbnail API.
*
* @param documentId The unique identifier of the document for which to download the thumbnail.
* @return A {@link com.projectmanager.AstroResult} containing the results
*/
public @NotNull AstroResult<byte[]> downloadaThumbnailImage(@NotNull String documentId)
{
BlobRequest r = new BlobRequest(this.client, "GET", "/api/data/files/{documentId}/thumbnail");
r.AddPath("{documentId}", documentId == null ? "" : documentId.toString());
return r.Call(new TypeToken<AstroResult<byte[]>>() {}.getType());
}

/**
* Updates information about a File uploaded to your Workspace.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.projectmanager.ProjectManagerClient;
import com.projectmanager.RestRequest;
import com.projectmanager.BlobRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.google.gson.reflect.TypeToken;
Expand Down
Loading

0 comments on commit b79a937

Please sign in to comment.