From e7e6ced69773af038386b9d8ade41e3fbbdfa1da Mon Sep 17 00:00:00 2001 From: "Dmitriy.Novikov" <112627421+DmitriyNovikov89@users.noreply.github.com> Date: Thu, 12 Dec 2024 22:33:09 +0700 Subject: [PATCH] fix clients --- .github/workflows/actions.yml | 6 +- pom.xml | 2 +- src/main/java/Diadoc/Api/DiadocApi.java | 17 ++ .../Api/counteragent/CounteragentClient.java | 41 ++-- .../Api/counteragent/CounteragentStatus.java | 20 ++ .../Diadoc/Api/document/DocumentClient.java | 76 ++++++-- .../Diadoc/Api/document/DocumentsFilter.java | 182 +++++++++++++++++- src/main/java/Diadoc/Api/helpers/Tools.java | 13 ++ .../Api/organizations/OrganizationClient.java | 96 ++++++++- .../PowerOfAttorneyClient.java | 2 +- .../Diadoc/Api/print/PrintFormClient.java | 45 +++-- .../Diadoc/Api/template/TemplateClient.java | 21 +- 12 files changed, 444 insertions(+), 77 deletions(-) create mode 100644 src/main/java/Diadoc/Api/counteragent/CounteragentStatus.java diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index f42d0791..05154bda 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -73,7 +73,7 @@ jobs: - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: packages path: | @@ -92,7 +92,7 @@ jobs: fetch-depth: 0 - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: packages @@ -124,4 +124,4 @@ jobs: draft: false prerelease: false files: | - **/*.jar \ No newline at end of file + **/*.jar diff --git a/pom.xml b/pom.xml index 5e1a6bc9..382058a6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 ru.kontur.diadoc diadocsdk - 3.24.2 + 3.24.3 jar diff --git a/src/main/java/Diadoc/Api/DiadocApi.java b/src/main/java/Diadoc/Api/DiadocApi.java index 2da23f9f..5adda51f 100644 --- a/src/main/java/Diadoc/Api/DiadocApi.java +++ b/src/main/java/Diadoc/Api/DiadocApi.java @@ -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; } diff --git a/src/main/java/Diadoc/Api/counteragent/CounteragentClient.java b/src/main/java/Diadoc/Api/counteragent/CounteragentClient.java index b4e1f4f8..70ed7e9d 100644 --- a/src/main/java/Diadoc/Api/counteragent/CounteragentClient.java +++ b/src/main/java/Diadoc/Api/counteragent/CounteragentClient.java @@ -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.*; @@ -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())); @@ -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()) @@ -235,9 +233,7 @@ 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)); @@ -245,23 +241,30 @@ public CounteragentList getCounteragents(String myOrgId, @Nullable String counte 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)); @@ -362,4 +365,4 @@ public BoxCounteragentEventList getCounteragentEvents( throw new DiadocSdkException(e); } } -} +} \ No newline at end of file diff --git a/src/main/java/Diadoc/Api/counteragent/CounteragentStatus.java b/src/main/java/Diadoc/Api/counteragent/CounteragentStatus.java new file mode 100644 index 00000000..676801ca --- /dev/null +++ b/src/main/java/Diadoc/Api/counteragent/CounteragentStatus.java @@ -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 fromString(String value) { + if (value == null) { + return Optional.empty(); + } + return Arrays.stream(values()) + .filter(status -> status.name().equals(value)) + .findFirst(); + } +} diff --git a/src/main/java/Diadoc/Api/document/DocumentClient.java b/src/main/java/Diadoc/Api/document/DocumentClient.java index 23b20e2f..449de38e 100644 --- a/src/main/java/Diadoc/Api/document/DocumentClient.java +++ b/src/main/java/Diadoc/Api/document/DocumentClient.java @@ -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; @@ -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; @@ -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)); @@ -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, @@ -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); @@ -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) { @@ -265,4 +299,4 @@ public SignatureInfo getSignatureInfo(String boxId, String messageId, String ent } -} +} \ No newline at end of file diff --git a/src/main/java/Diadoc/Api/document/DocumentsFilter.java b/src/main/java/Diadoc/Api/document/DocumentsFilter.java index 8de8e6dc..d6936355 100644 --- a/src/main/java/Diadoc/Api/document/DocumentsFilter.java +++ b/src/main/java/Diadoc/Api/document/DocumentsFilter.java @@ -1,12 +1,14 @@ package Diadoc.Api.document; -import javax.swing.text.DocumentFilter; import java.util.Date; public class DocumentsFilter { private String boxId; private String filterCategory; private String counteragentBoxId; + + private String fromDepartmentId; + private String toDepartmentId; private Date timestampFrom; private Date timestampTo; private String fromDocumentDate; @@ -17,8 +19,18 @@ public class DocumentsFilter { private String afterIndexKey; private Integer count; + /** + * @deprecated Конструктор устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ + @Deprecated public DocumentsFilter(){} + /** + * @deprecated Конструктор устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ + @Deprecated public DocumentsFilter( String boxId, String filterCategory, @@ -46,10 +58,124 @@ public DocumentsFilter( this.count = count; } + private DocumentsFilter(Builder builder) { + this.boxId = builder.boxId; + this.filterCategory = builder.filterCategory; + this.counteragentBoxId = builder.counteragentBoxId; + this.timestampFrom = builder.timestampFrom; + this.timestampTo = builder.timestampTo; + this.fromDocumentDate = builder.fromDocumentDate; + this.toDocumentDate = builder.toDocumentDate; + this.departmentId = builder.departmentId; + this.excludeSubdepartments = builder.excludeSubdepartments; + this.sortDirection = builder.sortDirection; + this.afterIndexKey = builder.afterIndexKey; + this.count = builder.count; + this.fromDepartmentId = builder.fromDepartmentId; + this.toDepartmentId = builder.toDepartmentId; + } + + public static class Builder { + private String boxId; + private String filterCategory; + private String counteragentBoxId; + private String fromDepartmentId; + private String toDepartmentId; + private Date timestampFrom; + private Date timestampTo; + private String fromDocumentDate; + private String toDocumentDate; + private String departmentId; + private boolean excludeSubdepartments; + private String sortDirection; + private String afterIndexKey; + private Integer count; + + public Builder() {} + + public Builder boxId(String boxId) { + this.boxId = boxId; + return this; + } + + public Builder filterCategory(String filterCategory) { + this.filterCategory = filterCategory; + return this; + } + + public Builder counteragentBoxId(String counteragentBoxId) { + this.counteragentBoxId = counteragentBoxId; + return this; + } + + public Builder timestampFrom(Date timestampFrom) { + this.timestampFrom = timestampFrom; + return this; + } + + public Builder timestampTo(Date timestampTo) { + this.timestampTo = timestampTo; + return this; + } + + public Builder fromDocumentDate(String fromDocumentDate) { + this.fromDocumentDate = fromDocumentDate; + return this; + } + + public Builder toDocumentDate(String toDocumentDate) { + this.toDocumentDate = toDocumentDate; + return this; + } + + public Builder departmentId(String departmentId) { + this.departmentId = departmentId; + return this; + } + + public Builder excludeSubdepartments(boolean excludeSubdepartments) { + this.excludeSubdepartments = excludeSubdepartments; + return this; + } + + public Builder sortDirection(String sortDirection) { + this.sortDirection = sortDirection; + return this; + } + + public Builder afterIndexKey(String afterIndexKey) { + this.afterIndexKey = afterIndexKey; + return this; + } + + public Builder count(Integer count) { + this.count = count; + return this; + } + + public Builder fromDepartmentId(String fromDepartmentId) { + this.fromDepartmentId = fromDepartmentId; + return this; + } + + public Builder toDepartmentId(String toDepartmentId) { + this.toDepartmentId = toDepartmentId; + return this; + } + + public DocumentsFilter build() { + return new DocumentsFilter(this); + } + } + public String getBoxId() { return boxId; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setBoxId(String boxId) { this.boxId = boxId; return this; @@ -59,6 +185,10 @@ public String getFilterCategory() { return filterCategory; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setFilterCategory(String filterCategory) { this.filterCategory = filterCategory; return this; @@ -68,6 +198,10 @@ public String getCounteragentBoxId() { return counteragentBoxId; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setCounteragentBoxId(String counteragentBoxId) { this.counteragentBoxId = counteragentBoxId; return this; @@ -77,6 +211,10 @@ public Date getTimestampFrom() { return timestampFrom; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setTimestampFrom(Date timestampFrom) { this.timestampFrom = timestampFrom; return this; @@ -86,6 +224,10 @@ public Date getTimestampTo() { return timestampTo; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setTimestampTo(Date timestampTo) { this.timestampTo = timestampTo; return this; @@ -95,6 +237,10 @@ public String getFromDocumentDate() { return fromDocumentDate; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setFromDocumentDate(String fromDocumentDate) { this.fromDocumentDate = fromDocumentDate; return this; @@ -104,6 +250,10 @@ public String getToDocumentDate() { return toDocumentDate; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setToDocumentDate(String toDocumentDate) { this.toDocumentDate = toDocumentDate; return this; @@ -113,6 +263,10 @@ public String getDepartmentId() { return departmentId; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setDepartmentId(String departmentId) { this.departmentId = departmentId; return this; @@ -122,6 +276,10 @@ public boolean isExcludeSubdepartments() { return excludeSubdepartments; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setExcludeSubdepartments(boolean excludeSubdepartments) { this.excludeSubdepartments = excludeSubdepartments; return this; @@ -131,6 +289,10 @@ public String getSortDirection() { return sortDirection; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setSortDirection(String sortDirection) { this.sortDirection = sortDirection; return this; @@ -140,6 +302,10 @@ public String getAfterIndexKey() { return afterIndexKey; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setAfterIndexKey(String afterIndexKey) { this.afterIndexKey = afterIndexKey; return this; @@ -149,8 +315,20 @@ public Integer getCount() { return count; } + /** + * @deprecated Setter устарел + * Рекомендуется использовать {@link #DocumentsFilter(Builder)} + */ public DocumentsFilter setCount(Integer count) { this.count = count; return this; } -} + + public String getFromDepartmentId() { + return fromDepartmentId; + } + + public String getToDepartmentId() { + return toDepartmentId; + } +} \ No newline at end of file diff --git a/src/main/java/Diadoc/Api/helpers/Tools.java b/src/main/java/Diadoc/Api/helpers/Tools.java index 7dd65856..32c3cece 100644 --- a/src/main/java/Diadoc/Api/helpers/Tools.java +++ b/src/main/java/Diadoc/Api/helpers/Tools.java @@ -8,6 +8,7 @@ import java.util.Random; import com.google.protobuf.ByteString; +import org.apache.http.client.utils.URIBuilder; public class Tools { public static String ConsoleReadLine() throws IOException { @@ -52,4 +53,16 @@ public static byte[] GenerateRandomBytes(int size) { public static String concatUriPath(String prefixPath, String postfixPath) { return prefixPath.replaceAll("/*$", "") + postfixPath; } + + public static void addParameterIfNotNull(URIBuilder urlBuilder, String paramName, Object paramValue) { + if (paramValue != null) { + urlBuilder.addParameter(paramName, String.valueOf(paramValue)); + } + } + + public static void addParameterIfNotNull(URIBuilder urlBuilder, String paramName, Enum paramValue) { + if (paramValue != null) { + urlBuilder.addParameter(paramName, paramValue.name()); + } + } } diff --git a/src/main/java/Diadoc/Api/organizations/OrganizationClient.java b/src/main/java/Diadoc/Api/organizations/OrganizationClient.java index 28962371..28e2b700 100644 --- a/src/main/java/Diadoc/Api/organizations/OrganizationClient.java +++ b/src/main/java/Diadoc/Api/organizations/OrganizationClient.java @@ -49,6 +49,13 @@ public Organization getOrganizationById(String orgId) throws DiadocSdkException return getOrganization("orgId", orgId); } + public Organization getOrganizationByBoxId(String boxId) throws DiadocSdkException { + if (Tools.isNullOrEmpty(boxId)) { + throw new IllegalArgumentException("boxId"); + } + return getOrganization("boxId", boxId); + } + public Organization getOrganizationByInn(String inn) throws DiadocSdkException { if (inn == null || inn.isEmpty()) { throw new IllegalArgumentException("inn"); @@ -56,6 +63,24 @@ public Organization getOrganizationByInn(String inn) throws DiadocSdkException { return getOrganization("inn", inn); } + public Organization getOrganizationByInnAndKpp(String inn, @Nullable String kpp) throws DiadocSdkException { + if (inn == null) { + throw new IllegalArgumentException("inn"); + } + + try { + var url = new URIBuilder(diadocHttpClient.getBaseUrl()) + .setPath("/GetOrganization") + .addParameter("inn", inn); + + Tools.addParameterIfNotNull(url, "kpp", kpp); + var request = RequestBuilder.get(url.build()); + return getOrganization(request); + } catch (URISyntaxException e) { + throw new DiadocSdkException(e); + } + } + public Organization getOrganizationByFnsParticipantId(String fnsParticipantId) throws DiadocSdkException { if (fnsParticipantId == null || fnsParticipantId.isEmpty()) { throw new IllegalArgumentException("fnsParticipantId"); @@ -63,6 +88,33 @@ public Organization getOrganizationByFnsParticipantId(String fnsParticipantId) t return getOrganization("fnsParticipantId", fnsParticipantId); } + public Organization getOrganizationByParameters( + @Nullable String orgId, @Nullable String boxId, @Nullable String fnsParticipantId, @Nullable String inn, @Nullable String kpp + ) throws DiadocSdkException { + if (inn == null && kpp != null) { + throw new IllegalArgumentException("inn"); + } + + if (orgId == null && boxId == null && fnsParticipantId == null && inn == null) { + throw new IllegalArgumentException("One argument must not be null"); + } + + try { + var url = new URIBuilder(diadocHttpClient.getBaseUrl()).setPath("/GetOrganization"); + Tools.addParameterIfNotNull(url, "boxId", boxId); + Tools.addParameterIfNotNull(url, "fnsParticipantId", fnsParticipantId); + Tools.addParameterIfNotNull(url, "inn", inn); + Tools.addParameterIfNotNull(url, "kpp", kpp); + Tools.addParameterIfNotNull(url, "orgId", orgId); + var request = RequestBuilder.get(url.build()); + return getOrganization(request); + } catch (URISyntaxException e) { + throw new DiadocSdkException(e); + } + } + + + public OrganizationWithCounteragentStatus[] getOrganizationsByInnList(String myOrgId, Iterable innList) throws DiadocSdkException { var request = GetOrganizationsByInnListRequest.newBuilder(); request.addAllInnList(innList); @@ -135,8 +187,8 @@ public OrganizationList getOrganizationsByInnKpp(String inn, @Nullable String kp url.addParameter("includeRelations", "true"); } var request = RequestBuilder.get(url.build()); - return OrganizationList.parseFrom(diadocHttpClient.performRequest(request)); - } catch (URISyntaxException | IOException e) { + return getOrganizationsList(request); + } catch (URISyntaxException e) { throw new DiadocSdkException(e); } } @@ -154,8 +206,8 @@ public OrganizationList getMyOrganizations(boolean autoRegister) throws DiadocSd url.addParameter("autoRegister", Boolean.toString(false)); } var request = RequestBuilder.get(url.build()); - return OrganizationList.parseFrom(diadocHttpClient.performRequest(request)); - } catch (URISyntaxException | IOException e) { + return getOrganizationsList(request); + } catch (URISyntaxException e) { throw new DiadocSdkException(e); } } @@ -176,8 +228,8 @@ public OrganizationUsersList getOrganizationUsers(String orgId) throws DiadocSdk .setPath("/GetOrganizationUsers") .addParameter("orgId", orgId) .build()); - return OrganizationUsersList.parseFrom(diadocHttpClient.performRequest(request)); - } catch (URISyntaxException | IOException e) { + return getOrganizationUsersList(request); + } catch (URISyntaxException e) { throw new DiadocSdkException(e); } } @@ -189,8 +241,8 @@ public OrganizationUsersList getOrganizationUsersV2(String boxId) throws DiadocS .setPath("/V2/GetOrganizationUsers") .addParameter("boxId", boxId) .build()); - return OrganizationUsersList.parseFrom(diadocHttpClient.performRequest(request)); - } catch (URISyntaxException | IOException e) { + return getOrganizationUsersList(request); + } catch (URISyntaxException e) { throw new DiadocSdkException(e); } } @@ -221,8 +273,32 @@ private Organization getOrganization(String name, String value) throws DiadocSdk .addParameter(name, value) .build()); + return getOrganization(request); + } catch (URISyntaxException e) { + throw new DiadocSdkException(e); + } + } + + private Organization getOrganization(RequestBuilder request) throws DiadocSdkException { + try { return Organization.parseFrom(diadocHttpClient.performRequest(request)); - } catch (URISyntaxException | IOException e) { + } catch (IOException e) { + throw new DiadocSdkException(e); + } + } + + private OrganizationUsersList getOrganizationUsersList(RequestBuilder request) throws DiadocSdkException{ + try { + return OrganizationUsersList.parseFrom(diadocHttpClient.performRequest(request)); + } catch (IOException e) { + throw new DiadocSdkException(e); + } + } + + private OrganizationList getOrganizationsList(RequestBuilder request) throws DiadocSdkException { + try { + return OrganizationList.parseFrom(diadocHttpClient.performRequest(request)); + } catch (IOException e) { throw new DiadocSdkException(e); } } @@ -264,7 +340,7 @@ public void registerConfirm(RegistrationConfirmRequest registrationConfirmReques try { var request = RequestBuilder.post( new URIBuilder(diadocHttpClient.getBaseUrl()) - .setPath("/Register") + .setPath("/RegisterConfirm") .build()) .setEntity(new ByteArrayEntity(registrationConfirmRequest.toByteArray())); diadocHttpClient.performRequest(request); diff --git a/src/main/java/Diadoc/Api/powersOfAttorney/PowerOfAttorneyClient.java b/src/main/java/Diadoc/Api/powersOfAttorney/PowerOfAttorneyClient.java index bcf9a51d..b84e7c7f 100644 --- a/src/main/java/Diadoc/Api/powersOfAttorney/PowerOfAttorneyClient.java +++ b/src/main/java/Diadoc/Api/powersOfAttorney/PowerOfAttorneyClient.java @@ -87,7 +87,7 @@ public PowerOfAttorneyPrevalidateResult prevalidatePowerOfAttorney( try { var request = RequestBuilder.post( new URIBuilder(diadocHttpClient.getBaseUrl()) - .setPath("/RegisterPowerOfAttorneyResult") + .setPath("/PrevalidatePowerOfAttorney") .addParameter("boxId", boxId) .addParameter("registrationNumber", registrationNumber) .addParameter("issuerInn", issuerInn) diff --git a/src/main/java/Diadoc/Api/print/PrintFormClient.java b/src/main/java/Diadoc/Api/print/PrintFormClient.java index e2146523..6cf3685a 100644 --- a/src/main/java/Diadoc/Api/print/PrintFormClient.java +++ b/src/main/java/Diadoc/Api/print/PrintFormClient.java @@ -1,6 +1,7 @@ package Diadoc.Api.print; import Diadoc.Api.exceptions.DiadocSdkException; +import Diadoc.Api.httpClient.DiadocResponseInfo; import Diadoc.Api.print.models.DocumentProtocolResult; import Diadoc.Api.print.models.DocumentZipResult; import Diadoc.Api.print.models.PrintFormContent; @@ -14,6 +15,7 @@ import javax.mail.internet.ParseException; import java.io.IOException; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import static Diadoc.Api.Proto.CustomPrintFormDetectionProtos.*; import static Diadoc.Api.Proto.Documents.DocumentProtocolProtos.*; @@ -145,31 +147,46 @@ public DocumentProtocolResult generateDocumentProtocol(String boxId, String mess } public PrintFormResult generatePrintFormFromAttachment(String fromBoxId, String documentType, byte[] bytes) throws DiadocSdkException { - if (Tools.isNullOrEmpty(fromBoxId)) { - throw new IllegalArgumentException("fromBoxId"); - } + validateInput(documentType, bytes); + + var response = executeGeneratePrintFormRequest(fromBoxId, documentType, bytes); + + return new PrintFormResult( + new PrintFormContent( + response.getContentType(), + response.getFileName() != null ? response.getFileName() : "default", + response.getContent() + ) + ); + } + + public String generatePrintFormFromAttachmentId(String fromBoxId, String documentType, byte[] bytes) throws DiadocSdkException { + validateInput(documentType, bytes); + + var response = executeGeneratePrintFormRequest(fromBoxId, documentType, bytes).getContent(); + + return new String(response, StandardCharsets.UTF_8); + } + + private void validateInput(String documentType, byte[] bytes) { if (Tools.isNullOrEmpty(documentType)) { throw new IllegalArgumentException("documentType"); } if (bytes == null) { throw new IllegalArgumentException("bytes"); } + } + private DiadocResponseInfo executeGeneratePrintFormRequest(String fromBoxId, String documentType, byte[] bytes) throws DiadocSdkException { try { - var request = RequestBuilder.get(new URIBuilder(diadocHttpClient.getBaseUrl()) + var uri = new URIBuilder(diadocHttpClient.getBaseUrl()) .setPath("/GeneratePrintFormFromAttachment") - .addParameter("fromBoxId", fromBoxId) - .addParameter("documentType", documentType) - .build()) - .setEntity(new ByteArrayEntity(bytes)); + .addParameter("documentType", documentType); + Tools.addParameterIfNotNull(uri, "fromBoxId", fromBoxId); - var response = diadocHttpClient.getRawResponse(request); + var request = RequestBuilder.post(uri.build()).setEntity(new ByteArrayEntity(bytes)); - if (response.getRetryAfter() != null) { - return new PrintFormResult(response.getRetryAfter()); - } - - return new PrintFormResult(new PrintFormContent(response.getContentType(), response.getFileName(), response.getContent())); + return diadocHttpClient.getRawResponse(request); } catch (URISyntaxException | ParseException | IOException e) { throw new DiadocSdkException(e); diff --git a/src/main/java/Diadoc/Api/template/TemplateClient.java b/src/main/java/Diadoc/Api/template/TemplateClient.java index 909f2e6e..9408c0bf 100644 --- a/src/main/java/Diadoc/Api/template/TemplateClient.java +++ b/src/main/java/Diadoc/Api/template/TemplateClient.java @@ -93,6 +93,15 @@ public MessagePatch postTemplatePatch( String templateId, DiadocMessage_PostApiProtos.TemplatePatchToPost templatePatchToPost) throws DiadocSdkException { + return postTemplatePatch(boxId, templateId, null, templatePatchToPost); + } + + public MessagePatch postTemplatePatch( + String boxId, + String templateId, + @Nullable String operationId, + DiadocMessage_PostApiProtos.TemplatePatchToPost templatePatchToPost) throws DiadocSdkException { + if (boxId == null) { throw new IllegalArgumentException("boxId"); } @@ -104,12 +113,12 @@ public MessagePatch postTemplatePatch( } try { - var request = RequestBuilder.post( - new URIBuilder(diadocHttpClient.getBaseUrl()) - .setPath("/PostTemplatePatch") - .addParameter("boxId", boxId) - .addParameter("templateId", templateId) - .build()) + var url = new URIBuilder(diadocHttpClient.getBaseUrl()) + .setPath("/PostTemplatePatch") + .addParameter("boxId", boxId) + .addParameter("templateId", templateId); + Tools.addParameterIfNotNull(url, "operationId", operationId); + var request = RequestBuilder.post(url.build()) .setEntity(new ByteArrayEntity(templatePatchToPost.toByteArray())); return MessagePatch.parseFrom(diadocHttpClient.performRequest(request));