Skip to content

Commit

Permalink
Merge pull request #345 from diadoc/fix-clients
Browse files Browse the repository at this point in the history
Исправление багов и добавление недостающих параметров в методы
  • Loading branch information
korvalanni authored Dec 16, 2024
2 parents e282ce0 + e7e6ced commit 4099e62
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 74 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ru.kontur.diadoc</groupId>
<artifactId>diadocsdk</artifactId>
<version>3.24.2</version>
<version>3.24.3</version>

<packaging>jar</packaging>

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/Diadoc/Api/DiadocApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,27 @@ public EmployeePowerOfAttorneyClient getEmployeePowerOfAttorneyClient() {
return employeePowerOfAttorneyClient;
}

/**
* @deprecated
* Используйте {@link #getDocumentWorkflowClient()}
*/
@Deprecated
public DocumentWorkflowClient gDocumentWorkflowClient() {
return documentWorkflowClient;
}

public TemplateClient getTemplateClient() {
return templateClient;
}

public DocumentWorkflowClient getDocumentWorkflowClient() {
return documentWorkflowClient;
}

public DiadocHttpClient getDiadocHttpClient() {
return diadocHttpClient;
}

public AuthManager getAuthManager() {
return authManager;
}
Expand Down
41 changes: 22 additions & 19 deletions src/main/java/Diadoc/Api/counteragent/CounteragentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Optional;

import static Diadoc.Api.Proto.AcquireCounteragentProtos.*;
import static Diadoc.Api.Proto.AsyncMethodResultProtos.*;
Expand Down Expand Up @@ -55,10 +57,8 @@ public AsyncMethodResult acquireCounteragent(
.setPath("/V2/AcquireCounteragent")
.addParameter("myOrgId", myOrgId);

if (myDepartmentId != null) {
url.addParameter("myDepartmentId", myDepartmentId);
}

Tools.addParameterIfNotNull(url, "myDepartmentId", myDepartmentId);

var request = RequestBuilder
.post(url.build())
.setEntity(new ByteArrayEntity(acquireCounteragentRequest.toByteArray()));
Expand Down Expand Up @@ -86,9 +86,7 @@ public AsyncMethodResult acquireCounteragentV3(
.setPath("/V3/AcquireCounteragent")
.addParameter("myBoxId", myBoxId);

if (myDepartmentId != null) {
url.addParameter("myDepartmentId", myDepartmentId);
}
Tools.addParameterIfNotNull(url, "myDepartmentId", myDepartmentId);

var request = RequestBuilder
.post(url.build())
Expand Down Expand Up @@ -235,33 +233,38 @@ public CounteragentList getCounteragents(String myOrgId, @Nullable String counte
url.addParameter("counteragentStatus", counteragentStatus);
}

if (afterIndexKey != null) {
url.addParameter("afterIndexKey", afterIndexKey);
}
Tools.addParameterIfNotNull(url, "afterIndexKey", afterIndexKey);

var request = RequestBuilder.get(url.build());
return CounteragentList.parseFrom(diadocHttpClient.performRequest(request));
} catch (URISyntaxException | IOException e) {
throw new DiadocSdkException(e);
}
}

public CounteragentList getCounteragentsV3(String myBoxId, @Nullable String counteragentStatus, @Nullable String afterIndexKey) throws DiadocSdkException {
if (Tools.isNullOrEmpty(myBoxId)) {
throw new IllegalArgumentException("myBoxId"); }

var counteragentEnumStatus = CounteragentStatus.fromString(counteragentStatus).orElse(null);

return getCounteragentsV3(myBoxId, counteragentEnumStatus, afterIndexKey, null, null);
}

public CounteragentList getCounteragentsV3(String myBoxId, @Nullable CounteragentStatus counteragentStatus, @Nullable String afterIndexKey, @Nullable String query, @Nullable Integer pageSize) throws DiadocSdkException {
if (Tools.isNullOrEmpty(myBoxId)) {
throw new IllegalArgumentException("myBoxId");
}

try {
var url = new URIBuilder(diadocHttpClient.getBaseUrl())
.setPath("/V3/GetCounteragents")
.addParameter("myBoxId", myBoxId);

if (!Tools.isNullOrEmpty(counteragentStatus)) {
url.addParameter("counteragentStatus", counteragentStatus);
}

if (afterIndexKey != null) {
url.addParameter("afterIndexKey", afterIndexKey);
}
Tools.addParameterIfNotNull(url, "counteragentStatus", counteragentStatus);
Tools.addParameterIfNotNull(url, "afterIndexKey", afterIndexKey);
Tools.addParameterIfNotNull(url, "query", query);
Tools.addParameterIfNotNull(url, "pageSize",pageSize);

var request = RequestBuilder.get(url.build());
return CounteragentList.parseFrom(diadocHttpClient.performRequest(request));
Expand Down Expand Up @@ -362,4 +365,4 @@ public BoxCounteragentEventList getCounteragentEvents(
throw new DiadocSdkException(e);
}
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/Diadoc/Api/counteragent/CounteragentStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Diadoc.Api.counteragent;

import java.util.Arrays;
import java.util.Optional;

public enum CounteragentStatus {
IsMyCounteragent,
InvitesMe,
IsInvitedByMe,
Rejected;

public static Optional<CounteragentStatus> fromString(String value) {
if (value == null) {
return Optional.empty();
}
return Arrays.stream(values())
.filter(status -> status.name().equals(value))
.findFirst();
}
}
76 changes: 55 additions & 21 deletions src/main/java/Diadoc/Api/document/DocumentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ByteArrayEntity;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -19,7 +20,7 @@
import static Diadoc.Api.Proto.SignatureInfoProtos.SignatureInfo;

public class DocumentClient {
private DiadocHttpClient diadocHttpClient;
private final DiadocHttpClient diadocHttpClient;

public DocumentClient(DiadocHttpClient diadocHttpClient) {
this.diadocHttpClient = diadocHttpClient;
Expand Down Expand Up @@ -79,6 +80,9 @@ public DocumentList getDocuments(DocumentsFilter filter) throws DiadocSdkExcepti
url.addParameter("count", filter.getCount().toString());
}

Tools.addParameterIfNotNull(url, "fromDepartmentId", filter.getFromDepartmentId());
Tools.addParameterIfNotNull(url, "toDepartmentId", filter.getToDepartmentId());

var request = RequestBuilder.get(url.build());

return DocumentList.parseFrom(diadocHttpClient.performRequest(request));
Expand All @@ -99,18 +103,19 @@ public DocumentList getDocuments(
boolean excludeSubdepartments,
String afterIndexKey,
Integer count) throws DiadocSdkException {
return getDocuments(new DocumentsFilter()
.setBoxId(boxId)
.setFilterCategory(filterCategory)
.setCounteragentBoxId(counteragentBoxId)
.setTimestampFrom(timestampFrom)
.setTimestampTo(timestampTo)
.setFromDocumentDate(fromDocumentDate)
.setToDocumentDate(toDocumentDate)
.setDepartmentId(departmentId)
.setExcludeSubdepartments(excludeSubdepartments)
.setAfterIndexKey(afterIndexKey)
.setCount(count));
return getDocuments(new DocumentsFilter.Builder()
.boxId(boxId)
.filterCategory(filterCategory)
.counteragentBoxId(counteragentBoxId)
.timestampFrom(timestampFrom)
.timestampTo(timestampTo)
.fromDocumentDate(fromDocumentDate)
.toDocumentDate(toDocumentDate)
.departmentId(departmentId)
.excludeSubdepartments(excludeSubdepartments)
.afterIndexKey(afterIndexKey)
.count(count)
.build());
}

public DocumentList getDocuments(String boxId,
Expand Down Expand Up @@ -148,14 +153,30 @@ public Document getDocument(String boxId, String messageId, String entityId) thr
throw new IllegalArgumentException("entityId");
}

return getDocument(boxId, messageId, entityId, true);
}


public Document getDocument(String boxId, String messageId, String entityId, @Nullable Boolean injectEntityContent) throws DiadocSdkException {
if (boxId == null) {
throw new IllegalArgumentException("boxId");
}
if (messageId == null) {
throw new IllegalArgumentException("messageId");
}
if (entityId == null) {
throw new IllegalArgumentException("entityId");
}

try {
var request = RequestBuilder.get(
new URIBuilder(diadocHttpClient.getBaseUrl())
var url = new URIBuilder(diadocHttpClient.getBaseUrl())
.setPath("/V3/GetDocument")
.addParameter("boxId", boxId)
.addParameter("messageId", messageId)
.addParameter("entityId", entityId)
.build());
.addParameter("entityId", entityId);
Tools.addParameterIfNotNull(url, "injectEntityContent", injectEntityContent);

var request = RequestBuilder.get(url.build());
return Document.parseFrom(diadocHttpClient.performRequest(request));
} catch (URISyntaxException | IOException e) {
throw new DiadocSdkException(e);
Expand Down Expand Up @@ -203,11 +224,24 @@ public PrepareDocumentsToSignResponse prepareDocumentsToSign(PrepareDocumentsToS
throw new IllegalArgumentException("documentsToSignRequest");
}

return prepareDocumentsToSign(documentsToSignRequest, null);
}

public PrepareDocumentsToSignResponse prepareDocumentsToSign(PrepareDocumentsToSignRequest documentsToSignRequest, @Nullable Boolean excludeContent) throws DiadocSdkException {
if (documentsToSignRequest == null) {
throw new IllegalArgumentException("documentsToSignRequest");
}

if (excludeContent == null) {
excludeContent = false;
}

try {
var request = RequestBuilder.post(
new URIBuilder(diadocHttpClient.getBaseUrl())
.setPath("/PrepareDocumentsToSign")
.build())
new URIBuilder(diadocHttpClient.getBaseUrl())
.setPath("/PrepareDocumentsToSign")
.addParameter("excludeContent", excludeContent.toString())
.build())
.setEntity(new ByteArrayEntity(documentsToSignRequest.toByteArray()));
return PrepareDocumentsToSignResponse.parseFrom(diadocHttpClient.performRequest(request));
} catch (URISyntaxException | IOException e) {
Expand Down Expand Up @@ -265,4 +299,4 @@ public SignatureInfo getSignatureInfo(String boxId, String messageId, String ent
}


}
}
Loading

0 comments on commit 4099e62

Please sign in to comment.