Skip to content

Commit

Permalink
Merge pull request #152 from codebar-ag/feature-l11
Browse files Browse the repository at this point in the history
Feature l11
  • Loading branch information
StanBarrows authored Jul 31, 2024
2 parents 44fb052 + 9d597a8 commit 2e46af5
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

132 changes: 101 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ $connector = new DocuWareConnector(
);
```

### Extending the connector
### Extending the connector (EXAMPLE)

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

Expand All @@ -230,7 +230,7 @@ namespace App\Connectors;
use CodebarAg\DocuWare\Connectors\DocuWareConnector;
use CodebarAg\DocuWare\DTO\Config\ConfigWithCredentials;

class CustomDocuWareConnector extends DocuWareConnector
class YourOwnDocuWareConnector extends DocuWareConnector
{
public function __construct() {
$configuration = new ConfigWithCredentials(
Expand All @@ -249,7 +249,7 @@ class CustomDocuWareConnector extends DocuWareConnector
use App\Connectors\CustomDocuWareConnector;
use CodebarAg\DocuWare\DTO\Config\ConfigWithCredentials;

$connector = new CustomDocuWareConnector();
$connector = new YourOwnDocuWareConnector();
```


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

$document = $connector->send(new CreateDataRecord(
$fileCabinetId,
Expand All @@ -472,9 +473,48 @@ $document = $connector->send(new CreateDataRecord(
))->dto();
```

#### Create Table Data Record
```php
use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateTimeDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTableDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO;

$tableRows = collect([
collect([
IndexTextDTO::make('TEXT', 'project_1'),
IndexNumericDTO::make('INT', 1),
IndexDecimalDTO::make('DECIMAL', 1.1),
IndexDateDTO::make('DATE', $now),
IndexDateTimeDTO::make('DATETIME', $now),
]),
collect([
IndexTextDTO::make('TEXT', 'project_2'),
IndexNumericDTO::make('INT', 2),
IndexDecimalDTO::make('DECIMAL', 2.2),
IndexDateDTO::make('DATE', $now),
IndexDateTimeDTO::make('DATETIME', $now),
]),
]);


$document = $connector->send(new CreateDataRecord(
$fileCabinetId,
null,
null,
collect([
IndexTableDTO::make('TABLE_NAME', $tableRows)
]),
))->dto();
```

#### Update Index Values
```php
use CodebarAg\DocuWare\Requests\Documents\UpdateIndexValues\UpdateIndexValues;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO;

$response = $connector->send(new UpdateIndexValues(
$fileCabinetId,
Expand All @@ -484,6 +524,44 @@ $response = $connector->send(new UpdateIndexValues(
])
))->dto();
```

#### Update Table Data Record
```php
use CodebarAg\DocuWare\Requests\Documents\UpdateIndexValues\UpdateIndexValues;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateTimeDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTableDTO;
use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO;

$tableRows = collect([
collect([
IndexTextDTO::make('TEXT', 'project_1'),
IndexNumericDTO::make('INT', 1),
IndexDecimalDTO::make('DECIMAL', 1.1),
IndexDateDTO::make('DATE', $now),
IndexDateTimeDTO::make('DATETIME', $now),
]),
collect([
IndexTextDTO::make('TEXT', 'project_2'),
IndexNumericDTO::make('INT', 2),
IndexDecimalDTO::make('DECIMAL', 2.2),
IndexDateDTO::make('DATE', $now),
IndexDateTimeDTO::make('DATETIME', $now),
]),
]);


$document = $connector->send(new UpdateIndexValues(
$fileCabinetId,
null,
null,
collect([
IndexTableDTO::make('TABLE_NAME', $tableRows)
]),
))->dto();
```
</details>


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

```php
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO {
+name: "FIELD_NUMERIC" // string
+value: 1 // null|int
+name: "FIELD_NUMERIC" // string
+value: 1 // null|int
}
```

```php
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO {
+name: "FIELD_DECIMAL" // string
+value: 1.00 // null|int|float
+name: "FIELD_DECIMAL" // string
+value: 1.00 // null|int|float
}
```

```php
{
+name: "FIELD_DATE" // string
+value: now(), // null|Carbon
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO {
+name: "FIELD_DATE" // string
+value: now(), // null|Carbon
}
```

```php
{
+name: "FIELD_DATETIME" // string
+value: now(), // null|Carbon
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateTimeDTO {
+name: "FIELD_DATETIME" // string
+value: now(), // null|Carbon
}
```

```php
{
+name: "FIELD_TABLE" // string
+value: collect([
0 => [
[
'NAME' => 'TABLE_ID',
'VALUE' => '1',
],
[
'NAME' => 'TABLE_DATE',
'VALUE' => Carbon::class
],
[
'NAME' => 'TABLE_DECIMALE',
'VALUE' => 1.00,
],
]
]) // null|Collection|array
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexKeywordDTO {
+name: "FIELD_KEYWORD" // string
+value: "Value" // null|string
}
```

```php
CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexMemoDTO {
+name: "FIELD_MEMO" // string
+value: "Value" // null|string
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/Connectors/DocuWareConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function getOrCreateNewOAuthToken()

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

$identityServiceConfigurationResponse = (new GetIdentityServiceConfiguration(
identityServiceUrl: $responsibleIdentityServiceResponse->dto()->identityServiceUrl
Expand Down
25 changes: 25 additions & 0 deletions src/DTO/Documents/DocumentIndex/IndexKeywordDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace CodebarAg\DocuWare\DTO\Documents\DocumentIndex;

class IndexKeywordDTO
{
public function __construct(
public string $name,
public ?string $value,
) {}

public static function make(string $name, ?string $value): self
{
return new self($name, $value);
}

public function values(): array
{
return [
'FieldName' => $this->name,
'Item' => $this->value,
'ItemElementName' => 'Keyword',
];
}
}
25 changes: 25 additions & 0 deletions src/DTO/Documents/DocumentIndex/IndexMemoDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace CodebarAg\DocuWare\DTO\Documents\DocumentIndex;

class IndexMemoDTO
{
public function __construct(
public string $name,
public ?string $value,
) {}

public static function make(string $name, ?string $value): self
{
return new self($name, $value);
}

public function values(): array
{
return [
'FieldName' => $this->name,
'Item' => $this->value,
'ItemElementName' => 'Memo',
];
}
}
29 changes: 3 additions & 26 deletions src/DTO/Documents/DocumentIndex/IndexTableDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace CodebarAg\DocuWare\DTO\Documents\DocumentIndex;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class IndexTableDTO
Expand All @@ -12,7 +11,7 @@ public function __construct(
public null|Collection|array $rows,
) {}

public static function make(string $name, null|Collection|array $rows): self
public static function make(string $name, Collection|array $rows): self
{
return new self($name, $rows);
}
Expand All @@ -32,40 +31,18 @@ public function values(): array
protected function rowsCollection(): array
{
return collect($this->rows ?? [])->map(function ($row) {

$indexes = collect($row)->map(function ($column) {

if (! Arr::has($column, ['NAME', 'VALUE'])) {
return null;
}

$name = Arr::get($column, 'NAME');
$value = Arr::get($column, 'VALUE');

return PrepareTableDTO::make($name, $value);

})
->filter()
->values();

if ($indexes->isEmpty()) {
return null;
}

return self::makeRowContent($indexes);

return self::makeRowContent(collect($row));
})
->filter()
->values()
->toArray();

}

public static function makeRowContent(Collection $indexes): array
{
return [
'ColumnValue' => $indexes
->map(fn (IndexTextDTO|IndexDateDTO|IndexDecimalDTO $index) => $index->values())
->map(fn (IndexTextDTO|IndexNumericDTO|IndexDecimalDTO|IndexDateDTO|IndexDateTimeDTO|IndexKeywordDTO|IndexMemoDTO $index) => $index->values())
->filter()
->values()
->toArray(),
Expand Down
17 changes: 2 additions & 15 deletions src/DTO/Documents/DocumentIndex/PrepareDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@

class PrepareDTO
{
public static function guess(string $name, mixed $value): mixed
{
$type = gettype($value);

return match ($type) {
'integer' => IndexNumericDTO::make($name, $value),
'string' => IndexTextDTO::make($name, $value),
'double' => IndexDecimalDTO::make($name, $value),
'object' => IndexDateDTO::makeWithFallback($name, $value),
default => null,
};
}

public static function makeFields(Collection $indexes): array
{
return [
'Fields' => $indexes
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO $index) => $index->values())
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO|IndexKeywordDTO|IndexMemoDTO $index) => $index->values())
->filter()
->values(),
];
Expand All @@ -33,7 +20,7 @@ public static function makeField(Collection $indexes, bool $forceUpdate = false)
{
return [
'Field' => $indexes
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO $index) => $index->values())
->map(fn (IndexTextDTO|IndexDateDTO|IndexDateTimeDTO|IndexNumericDTO|IndexDecimalDTO|IndexTableDTO|IndexKeywordDTO|IndexMemoDTO $index) => $index->values())
->filter()
->values(),
'ForceUpdate' => $forceUpdate,
Expand Down
19 changes: 0 additions & 19 deletions src/DTO/Documents/DocumentIndex/PrepareTableDTO.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class GetResponsibleIdentityService extends SoloRequest implements Cacheable

protected Method $method = Method::GET;

public function __construct(
protected ?string $url = null
) {}

public function resolveEndpoint(): string
{
$base = config('laravel-docuware.credentials.url').'/DocuWare/Platform';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
config('laravel-docuware.tests.file_cabinet_id')
))->dto();

ray($documents);

Event::assertDispatched(DocuWareResponseLog::class);
});
Loading

0 comments on commit 2e46af5

Please sign in to comment.