Skip to content

Commit 9f8a958

Browse files
authored
Merge pull request #73 from codebar-ag/feature-intelligent-indexing
Feature Intelligent Indexing
2 parents b6a1e57 + 1147ced commit 9f8a958

File tree

7 files changed

+77
-6
lines changed

7 files changed

+77
-6
lines changed

src/DTO/Dialog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function fake(
3939
?bool $isDefault = null,
4040
?string $fileCabinetId = null,
4141
): self {
42-
return new static(
42+
return new self(
4343
id: $id ?? (string) Str::uuid(),
4444
type: $type ?? Arr::random(['Search', 'Store', 'ResultList', 'InfoDialog']),
4545
label: $label ?? 'Fake Dialog',

src/DTO/Document.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
use Carbon\Carbon;
66
use CodebarAg\DocuWare\Support\ParseValue;
7+
use Illuminate\Support\Arr;
78
use Illuminate\Support\Collection;
89
use Illuminate\Support\Str;
910

1011
final class Document
1112
{
1213
public static function fromJson(array $data): self
1314
{
14-
$fields = self::convertFields(collect($data['Fields']));
15+
$suggestions = Arr::has($data, 'Suggestions')
16+
? self::convertSuggestions(collect(Arr::get($data, 'Suggestions')))
17+
: null;
18+
19+
$fields = Arr::has($data, 'Fields')
20+
? self::convertFields(collect(Arr::get($data, 'Fields')))
21+
: null;
1522

1623
return new self(
1724
id: $data['Id'],
@@ -21,9 +28,11 @@ public static function fromJson(array $data): self
2128
extension: $fields['DWEXTENSION']->value,
2229
content_type: $data['ContentType'],
2330
file_cabinet_id: $data['FileCabinetId'],
31+
intellixTrust: Arr::get($data, 'IntellixTrust'),
2432
created_at: ParseValue::date($data['CreatedAt']),
2533
updated_at: ParseValue::date($data['LastModified']),
2634
fields: $fields,
35+
suggestions: $suggestions,
2736
);
2837
}
2938

@@ -34,6 +43,13 @@ protected static function convertFields(Collection $fields): Collection
3443
});
3544
}
3645

46+
protected static function convertSuggestions(Collection $suggestions): Collection|null
47+
{
48+
return $suggestions->mapWithKeys(function (array $suggestion) {
49+
return [$suggestion['DBName'] => SuggestionField::fromJson($suggestion)];
50+
});
51+
}
52+
3753
public function __construct(
3854
public int $id,
3955
public int $file_size,
@@ -42,9 +58,11 @@ public function __construct(
4258
public string|null $extension,
4359
public string $content_type,
4460
public string $file_cabinet_id,
61+
public string|null $intellixTrust,
4562
public Carbon $created_at,
4663
public Carbon $updated_at,
47-
public Collection $fields,
64+
public Collection|null $fields,
65+
public Collection|null $suggestions,
4866
) {
4967
}
5068

@@ -94,24 +112,28 @@ public static function fake(
94112
?string $extension = null,
95113
?string $content_type = null,
96114
?string $file_cabinet_id = null,
115+
?string $intellixTrust = null,
97116
?Carbon $created_at = null,
98117
?Carbon $updated_at = null,
99118
?Collection $fields = null,
119+
?Collection $suggestions = null,
100120
): self {
101-
return new static(
121+
return new self(
102122
id: $id ?? random_int(1, 999999),
103123
file_size: $file_size ?? random_int(1000, 999999),
104124
total_pages: $total_pages ?? random_int(1, 100),
105125
title: $title ?? 'Fake Title',
106126
extension: $extension ?? '.pdf',
107127
content_type: $content_type ?? 'application/pdf',
108128
file_cabinet_id: $file_cabinet_id ?? (string) Str::uuid(),
129+
intellixTrust: $intellixTrust ?? 'Red',
109130
created_at: $created_at ?? now()->subDay(),
110131
updated_at: $updated_at ?? now(),
111132
fields: $fields ?? collect([
112133
DocumentField::fake(),
113134
DocumentField::fake(),
114135
]),
136+
suggestions: $suggestions ?? null
115137
);
116138
}
117139
}

src/DTO/Field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function fake(
4040
?string $type = null,
4141
?string $scope = null,
4242
): self {
43-
return new static(
43+
return new self(
4444
name: $name ?? 'FAKE_FIELD',
4545
label: $label ?? 'Fake Field',
4646
type: Arr::random(['Text', 'Memo', 'Numeric', 'Decimal', 'Date', 'DateTime', 'Keyword']),

src/DTO/FileCabinet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function fake(
3434
?bool $isBasket = null,
3535
?string $assignedCabinet = null,
3636
): self {
37-
return new static(
37+
return new self(
3838
id: $id ?? (string) Str::uuid(),
3939
name: $name ?? 'Fake File Cabinet',
4040
color: $color ?? Arr::random(['Red', 'Blue', 'Black', 'Green', 'Yellow']),

src/DTO/SuggestionField.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace CodebarAg\DocuWare\DTO;
4+
5+
use Illuminate\Support\Arr;
6+
7+
final class SuggestionField
8+
{
9+
public static function fromJson(array $data): self
10+
{
11+
return new self(
12+
value: Arr::get($data, 'Value', []),
13+
name: Arr::get($data, 'Name'),
14+
db_name: Arr::get($data, 'DBName'),
15+
confidence: Arr::get($data, 'Confidence'),
16+
);
17+
}
18+
19+
public function __construct(
20+
public array $value,
21+
public string|null $name,
22+
public string|null $db_name,
23+
public string|null $confidence,
24+
) {
25+
}
26+
27+
public static function fake(
28+
array $value = [],
29+
?string $name = null,
30+
?string $db_name = null,
31+
?string $confidence = null,
32+
): self {
33+
return new self(
34+
value: $value ?? [],
35+
name: $name ?? 'Fake Name',
36+
db_name: $db_name ?? 'FAKE_NAME',
37+
confidence: $confidence ?? 'Red',
38+
);
39+
}
40+
}

src/DocuWare.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ public function getDocument(string $fileCabinetId, int $documentId): Document
199199

200200
$data = $response->throw()->json();
201201

202+
ray($data, 'getDocument');
203+
202204
return Document::fromJson($data);
203205
}
204206

tests/Feature/DTOTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use CodebarAg\DocuWare\DTO\DocumentPaginator;
99
use CodebarAg\DocuWare\DTO\Field;
1010
use CodebarAg\DocuWare\DTO\FileCabinet;
11+
use CodebarAg\DocuWare\DTO\SuggestionField;
1112
use CodebarAg\DocuWare\DTO\TableRow;
1213

1314
uses()->group('dto');
@@ -35,6 +36,12 @@
3536
$this->assertInstanceOf(DocumentField::class, $fake);
3637
});
3738

39+
it('create a fake suggestion field', function () {
40+
$fake = SuggestionField::fake();
41+
42+
$this->assertInstanceOf(SuggestionField::class, $fake);
43+
});
44+
3845
it('create a fake document', function () {
3946
$fake = Document::fake();
4047

0 commit comments

Comments
 (0)