Skip to content

Commit 2e46af5

Browse files
authored
Merge pull request #152 from codebar-ag/feature-l11
Feature l11
2 parents 44fb052 + 9d597a8 commit 2e46af5

File tree

15 files changed

+302
-188
lines changed

15 files changed

+302
-188
lines changed

.phpunit.cache/test-results

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

README.md

Lines changed: 101 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ $connector = new DocuWareConnector(
214214
);
215215
```
216216

217-
### Extending the connector
217+
### Extending the connector (EXAMPLE)
218218

219219
We understand it may be repetitive to pass the configuration every time you create a new connector.
220220

@@ -230,7 +230,7 @@ namespace App\Connectors;
230230
use CodebarAg\DocuWare\Connectors\DocuWareConnector;
231231
use CodebarAg\DocuWare\DTO\Config\ConfigWithCredentials;
232232

233-
class CustomDocuWareConnector extends DocuWareConnector
233+
class YourOwnDocuWareConnector extends DocuWareConnector
234234
{
235235
public function __construct() {
236236
$configuration = new ConfigWithCredentials(
@@ -249,7 +249,7 @@ class CustomDocuWareConnector extends DocuWareConnector
249249
use App\Connectors\CustomDocuWareConnector;
250250
use CodebarAg\DocuWare\DTO\Config\ConfigWithCredentials;
251251

252-
$connector = new CustomDocuWareConnector();
252+
$connector = new YourOwnDocuWareConnector();
253253
```
254254

255255

@@ -461,6 +461,7 @@ $image = $connector->send(new GetDocumentPreviewRequest($fileCabinetId, $documen
461461
#### Create Data Record
462462
```php
463463
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
464+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO;
464465

465466
$document = $connector->send(new CreateDataRecord(
466467
$fileCabinetId,
@@ -472,9 +473,48 @@ $document = $connector->send(new CreateDataRecord(
472473
))->dto();
473474
```
474475

476+
#### Create Table Data Record
477+
```php
478+
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
479+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO;
480+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateTimeDTO;
481+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO;
482+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO;
483+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTableDTO;
484+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO;
485+
486+
$tableRows = collect([
487+
collect([
488+
IndexTextDTO::make('TEXT', 'project_1'),
489+
IndexNumericDTO::make('INT', 1),
490+
IndexDecimalDTO::make('DECIMAL', 1.1),
491+
IndexDateDTO::make('DATE', $now),
492+
IndexDateTimeDTO::make('DATETIME', $now),
493+
]),
494+
collect([
495+
IndexTextDTO::make('TEXT', 'project_2'),
496+
IndexNumericDTO::make('INT', 2),
497+
IndexDecimalDTO::make('DECIMAL', 2.2),
498+
IndexDateDTO::make('DATE', $now),
499+
IndexDateTimeDTO::make('DATETIME', $now),
500+
]),
501+
]);
502+
503+
504+
$document = $connector->send(new CreateDataRecord(
505+
$fileCabinetId,
506+
null,
507+
null,
508+
collect([
509+
IndexTableDTO::make('TABLE_NAME', $tableRows)
510+
]),
511+
))->dto();
512+
```
513+
475514
#### Update Index Values
476515
```php
477516
use CodebarAg\DocuWare\Requests\Documents\UpdateIndexValues\UpdateIndexValues;
517+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO;
478518

479519
$response = $connector->send(new UpdateIndexValues(
480520
$fileCabinetId,
@@ -484,6 +524,44 @@ $response = $connector->send(new UpdateIndexValues(
484524
])
485525
))->dto();
486526
```
527+
528+
#### Update Table Data Record
529+
```php
530+
use CodebarAg\DocuWare\Requests\Documents\UpdateIndexValues\UpdateIndexValues;
531+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO;
532+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateTimeDTO;
533+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO;
534+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO;
535+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTableDTO;
536+
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO;
537+
538+
$tableRows = collect([
539+
collect([
540+
IndexTextDTO::make('TEXT', 'project_1'),
541+
IndexNumericDTO::make('INT', 1),
542+
IndexDecimalDTO::make('DECIMAL', 1.1),
543+
IndexDateDTO::make('DATE', $now),
544+
IndexDateTimeDTO::make('DATETIME', $now),
545+
]),
546+
collect([
547+
IndexTextDTO::make('TEXT', 'project_2'),
548+
IndexNumericDTO::make('INT', 2),
549+
IndexDecimalDTO::make('DECIMAL', 2.2),
550+
IndexDateDTO::make('DATE', $now),
551+
IndexDateTimeDTO::make('DATETIME', $now),
552+
]),
553+
]);
554+
555+
556+
$document = $connector->send(new UpdateIndexValues(
557+
$fileCabinetId,
558+
null,
559+
null,
560+
collect([
561+
IndexTableDTO::make('TABLE_NAME', $tableRows)
562+
]),
563+
))->dto();
564+
```
487565
</details>
488566

489567

@@ -1017,51 +1095,43 @@ CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO {
10171095

10181096
```php
10191097
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO {
1020-
+name: "FIELD_NUMERIC" // string
1021-
+value: 1 // null|int
1098+
+name: "FIELD_NUMERIC" // string
1099+
+value: 1 // null|int
10221100
}
10231101
```
10241102

10251103
```php
10261104
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO {
1027-
+name: "FIELD_DECIMAL" // string
1028-
+value: 1.00 // null|int|float
1105+
+name: "FIELD_DECIMAL" // string
1106+
+value: 1.00 // null|int|float
10291107
}
10301108
```
10311109

10321110
```php
1033-
{
1034-
+name: "FIELD_DATE" // string
1035-
+value: now(), // null|Carbon
1111+
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO {
1112+
+name: "FIELD_DATE" // string
1113+
+value: now(), // null|Carbon
10361114
}
10371115
```
10381116

10391117
```php
1040-
{
1041-
+name: "FIELD_DATETIME" // string
1042-
+value: now(), // null|Carbon
1118+
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateTimeDTO {
1119+
+name: "FIELD_DATETIME" // string
1120+
+value: now(), // null|Carbon
10431121
}
10441122
```
10451123

10461124
```php
1047-
{
1048-
+name: "FIELD_TABLE" // string
1049-
+value: collect([
1050-
0 => [
1051-
[
1052-
'NAME' => 'TABLE_ID',
1053-
'VALUE' => '1',
1054-
],
1055-
[
1056-
'NAME' => 'TABLE_DATE',
1057-
'VALUE' => Carbon::class
1058-
],
1059-
[
1060-
'NAME' => 'TABLE_DECIMALE',
1061-
'VALUE' => 1.00,
1062-
],
1063-
]
1064-
]) // null|Collection|array
1125+
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexKeywordDTO {
1126+
+name: "FIELD_KEYWORD" // string
1127+
+value: "Value" // null|string
1128+
}
1129+
```
1130+
1131+
```php
1132+
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexMemoDTO {
1133+
+name: "FIELD_MEMO" // string
1134+
+value: "Value" // null|string
10651135
}
10661136
```
10671137

src/Connectors/DocuWareConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function getOrCreateNewOAuthToken()
8989

9090
protected function getAuthenticationTokenEndpoint(): IdentityServiceConfiguration
9191
{
92-
$responsibleIdentityServiceResponse = (new GetResponsibleIdentityService)->send();
92+
$responsibleIdentityServiceResponse = (new GetResponsibleIdentityService($this->configuration->url))->send();
9393

9494
$identityServiceConfigurationResponse = (new GetIdentityServiceConfiguration(
9595
identityServiceUrl: $responsibleIdentityServiceResponse->dto()->identityServiceUrl
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace CodebarAg\DocuWare\DTO\Documents\DocumentIndex;
4+
5+
class IndexKeywordDTO
6+
{
7+
public function __construct(
8+
public string $name,
9+
public ?string $value,
10+
) {}
11+
12+
public static function make(string $name, ?string $value): self
13+
{
14+
return new self($name, $value);
15+
}
16+
17+
public function values(): array
18+
{
19+
return [
20+
'FieldName' => $this->name,
21+
'Item' => $this->value,
22+
'ItemElementName' => 'Keyword',
23+
];
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace CodebarAg\DocuWare\DTO\Documents\DocumentIndex;
4+
5+
class IndexMemoDTO
6+
{
7+
public function __construct(
8+
public string $name,
9+
public ?string $value,
10+
) {}
11+
12+
public static function make(string $name, ?string $value): self
13+
{
14+
return new self($name, $value);
15+
}
16+
17+
public function values(): array
18+
{
19+
return [
20+
'FieldName' => $this->name,
21+
'Item' => $this->value,
22+
'ItemElementName' => 'Memo',
23+
];
24+
}
25+
}

src/DTO/Documents/DocumentIndex/IndexTableDTO.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace CodebarAg\DocuWare\DTO\Documents\DocumentIndex;
44

5-
use Illuminate\Support\Arr;
65
use Illuminate\Support\Collection;
76

87
class IndexTableDTO
@@ -12,7 +11,7 @@ public function __construct(
1211
public null|Collection|array $rows,
1312
) {}
1413

15-
public static function make(string $name, null|Collection|array $rows): self
14+
public static function make(string $name, Collection|array $rows): self
1615
{
1716
return new self($name, $rows);
1817
}
@@ -32,40 +31,18 @@ public function values(): array
3231
protected function rowsCollection(): array
3332
{
3433
return collect($this->rows ?? [])->map(function ($row) {
35-
36-
$indexes = collect($row)->map(function ($column) {
37-
38-
if (! Arr::has($column, ['NAME', 'VALUE'])) {
39-
return null;
40-
}
41-
42-
$name = Arr::get($column, 'NAME');
43-
$value = Arr::get($column, 'VALUE');
44-
45-
return PrepareTableDTO::make($name, $value);
46-
47-
})
48-
->filter()
49-
->values();
50-
51-
if ($indexes->isEmpty()) {
52-
return null;
53-
}
54-
55-
return self::makeRowContent($indexes);
56-
34+
return self::makeRowContent(collect($row));
5735
})
5836
->filter()
5937
->values()
6038
->toArray();
61-
6239
}
6340

6441
public static function makeRowContent(Collection $indexes): array
6542
{
6643
return [
6744
'ColumnValue' => $indexes
68-
->map(fn (IndexTextDTO|IndexDateDTO|IndexDecimalDTO $index) => $index->values())
45+
->map(fn (IndexTextDTO|IndexNumericDTO|IndexDecimalDTO|IndexDateDTO|IndexDateTimeDTO|IndexKeywordDTO|IndexMemoDTO $index) => $index->values())
6946
->filter()
7047
->values()
7148
->toArray(),

src/DTO/Documents/DocumentIndex/PrepareDTO.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,11 @@
66

77
class PrepareDTO
88
{
9-
public static function guess(string $name, mixed $value): mixed
10-
{
11-
$type = gettype($value);
12-
13-
return match ($type) {
14-
'integer' => IndexNumericDTO::make($name, $value),
15-
'string' => IndexTextDTO::make($name, $value),
16-
'double' => IndexDecimalDTO::make($name, $value),
17-
'object' => IndexDateDTO::makeWithFallback($name, $value),
18-
default => null,
19-
};
20-
}
21-
229
public static function makeFields(Collection $indexes): array
2310
{
2411
return [
2512
'Fields' => $indexes
26-
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO $index) => $index->values())
13+
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO|IndexKeywordDTO|IndexMemoDTO $index) => $index->values())
2714
->filter()
2815
->values(),
2916
];
@@ -33,7 +20,7 @@ public static function makeField(Collection $indexes, bool $forceUpdate = false)
3320
{
3421
return [
3522
'Field' => $indexes
36-
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO $index) => $index->values())
23+
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO|IndexKeywordDTO|IndexMemoDTO $index) => $index->values())
3724
->filter()
3825
->values(),
3926
'ForceUpdate' => $forceUpdate,

src/DTO/Documents/DocumentIndex/PrepareTableDTO.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Requests/Authentication/OAuth/GetResponsibleIdentityService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class GetResponsibleIdentityService extends SoloRequest implements Cacheable
1818

1919
protected Method $method = Method::GET;
2020

21+
public function __construct(
22+
protected ?string $url = null
23+
) {}
24+
2125
public function resolveEndpoint(): string
2226
{
2327
$base = config('laravel-docuware.credentials.url').'/DocuWare/Platform';

tests/Feature/Requests/FileCabinets/Search/GetDocumentsFromAFileCabinetTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@
2323
config('laravel-docuware.tests.file_cabinet_id')
2424
))->dto();
2525

26+
ray($documents);
27+
2628
Event::assertDispatched(DocuWareResponseLog::class);
2729
});

0 commit comments

Comments
 (0)