Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/nulabinc/backlog4j/BacklogClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author nulab-inc
*/
public interface BacklogClient extends ProjectMethods, IssueMethods, SpaceMethods,
WikiMethods, ResolutionMethods, StatusMethods, PriorityMethods, UserMethods,
WikiMethods, DocumentMethods, ResolutionMethods, StatusMethods, PriorityMethods, UserMethods,
StarMethods, NotificationMethods, GitMethods, PullRequestMethods, GroupMethods, WebhookMethods, WatchingMethods,
BacklogUrlSupport {

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/nulabinc/backlog4j/BacklogClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1105,4 +1105,22 @@ public void markAsCheckedUserWatches(Object numericUserId) throws BacklogExcepti
post(buildEndpoint("users/" + numericUserId + "/watchings/markAsChecked"));
}

@Override
public ResponseList<Document> getDocuments(GetDocumentsParams params) {
ResponseList<Document> documents = factory.createDocumentList(get(buildEndpoint("documents"), params));
return documents;
}

@Override
public Document getDocument(String documentId) {
return factory.createDocument(get(buildEndpoint("documents/" + documentId)));
}

@Override
public AttachmentData downloadDocumentAttachment(String documentId, long attachmentId) {
BacklogHttpResponse backlogHttpResponse = get(backlogEndPointSupport.getDocumentAttachmentEndpoint(documentId, attachmentId));
String filename = backlogHttpResponse.getFileNameFromContentDisposition();
InputStream inputStream = backlogHttpResponse.asInputStream();
return new AttachmentDataImpl(filename, inputStream);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/nulabinc/backlog4j/BacklogEndPointSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,16 @@ public String getPullRequestAttachmentEndpoint(Object projectIdOrKey, Object rep
protected String buildEndpoint(String connection) {
return configure.getRestBaseURL() + "/" + connection;
}

/**
* Returns the endpoint of Document page's attachment file.
*
* @param documentId the Document page identifier
* @param attachmentId the attachment identifier
* @return the endpoint
* @throws BacklogException
*/
public String getDocumentAttachmentEndpoint(String documentId, long attachmentId) throws BacklogException {
return buildEndpoint("documents/" + documentId + "/attachments/" + attachmentId);
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/nulabinc/backlog4j/Document.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.nulabinc.backlog4j;

import java.util.Date;
import java.util.List;

/**
* The interface for Backlog Document page data.
*
* @author nulab-inc
*/
public interface Document {

String getId();

long getProjectId();

String getProjectIdAsString();

String getTitle();

String getJson();

String getPlain();

long getStatusId();

String getEmoji();

List<DocumentTag> getTags();

List<Attachment> getAttachments();

User getCreatedUser();

Date getCreated();

User getUpdatedUser();

Date getUpdated();
}
15 changes: 15 additions & 0 deletions src/main/java/com/nulabinc/backlog4j/DocumentTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nulabinc.backlog4j;

/**
* The interface for Backlog Document page's tag data.
*
* @author nulab-inc
*/
public interface DocumentTag {

long getId();

String getIdAsString();

String getName();
}
41 changes: 41 additions & 0 deletions src/main/java/com/nulabinc/backlog4j/api/DocumentMethods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nulabinc.backlog4j.api;

import com.nulabinc.backlog4j.AttachmentData;
import com.nulabinc.backlog4j.Document;
import com.nulabinc.backlog4j.ResponseList;
import com.nulabinc.backlog4j.api.option.GetDocumentsParams;

/**
* Executes Backlog Document APIs.
*
* @author nulab-inc
*/
public interface DocumentMethods {

/**
* Returns Document pages in the project.
*
* @param params the finding document parameters
* @return the document pages in a list
*/
ResponseList<Document> getDocuments(GetDocumentsParams params);


/**
* Returns the Document page.
*
* @param documentId the Document page identifier
* @return the Document page
*/
Document getDocument(String documentId);

/**
* Downloads the Document page's attachment file.
*
* @param documentId the Document page identifier
* @param attachmentId the attachment file identifier
* @return downloaded file data
*/
AttachmentData downloadDocumentAttachment(String documentId, long attachmentId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.nulabinc.backlog4j.api.option;

import com.nulabinc.backlog4j.BacklogException;
import com.nulabinc.backlog4j.http.NameValuePair;

import java.util.List;

/**
* Parameters for get document page API.
*
* @author nulab-inc
*/
public class GetDocumentsParams extends GetParams {

private SortKey sort;
private Order order;

public enum SortKey {
Created("created"),
Updated("updated");

SortKey(String value) {
this.value = value;
}

public String getStrValue() {
return value;
}

private final String value;
}

public enum Order {
Asc("asc"),
Desc("desc");

Order(String value) {
this.value = value;
}

public String getStrValue() {
return value;
}

private final String value;
}

public GetDocumentsParams(List<Long> projectIds, long offset) {
parameters.add(new NameValuePair("offset", String.valueOf(offset)));
for (Long projectId : projectIds) {
parameters.add(new NameValuePair("projectId[]", projectId.toString()));
}
}

public GetDocumentsParams keyword(String keyword) throws BacklogException {
parameters.add(new NameValuePair("keyword", keyword));
return this;
}

public GetDocumentsParams sort(SortKey sort) {
parameters.add(new NameValuePair("sort", sort.getStrValue()));
this.sort = sort;
return this;
}

public GetDocumentsParams order(Order order) {
parameters.add(new NameValuePair("order", order.getStrValue()));
this.order = order;
return this;
}

public GetDocumentsParams offset(long offset) {
parameters.add(new NameValuePair("offset", String.valueOf(offset)));
return this;
}

public GetDocumentsParams count(long count) {
parameters.add(new NameValuePair("count", String.valueOf(count)));
return this;
}

public SortKey getSort() {
return sort;
}

public Order getOrder() {
return order;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ public interface InternalFactory {

ResponseList<Watch> createWatchList(BacklogHttpResponse res) throws BacklogException;

ResponseList<Document> createDocumentList(BacklogHttpResponse res) throws BacklogException;

Document createDocument(BacklogHttpResponse res) throws BacklogException;

}
Loading