diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index c1a2fa82..d9306d60 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -16,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.3' coverage: none - name: Install composer dependencies diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e8981eeb..53e6252c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,7 +15,7 @@ jobs: matrix: os: [ ubuntu-latest, windows-latest ] php: [ 8.2, 8.3 ] - laravel: [ 10.* ] + laravel: [ 11.* ] stability: [ prefer-lowest, prefer-stable ] name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -55,7 +55,9 @@ jobs: DOCUWARE_PASSWORD: ${{ secrets.DOCUWARE_PASSWORD }} DOCUWARE_COOKIES: ${{ secrets.DOCUWARE_COOKIES }} - DOCUWARE_TESTS_FILE_CABINET_ID: ${{ secrets.DOCUWARE_TESTS_FILE_CABINET_ID }} - DOCUWARE_TESTS_DIALOG_ID: ${{ secrets.DOCUWARE_TESTS_DIALOG_ID }} - DOCUWARE_TESTS_BASKET_ID: ${{ secrets.DOCUWARE_TESTS_BASKET_ID }} - DOCUWARE_TESTS_ORGANIZATION_ID: ${{ secrets.DOCUWARE_TESTS_ORGANIZATION_ID }} + - name: Store Log Artifacts + if: failure() + uses: actions/upload-artifact@v4 + with: + name: Store report artifacts + path: ./vendor/orchestra/testbench-core/laravel/storage/logs diff --git a/.gitignore b/.gitignore index 83c9b9fc..2a6a14c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea .phpunit.result.cache +.phpunit.cache build composer.lock coverage @@ -9,3 +10,13 @@ phpstan.neon testbench.yaml vendor node_modules +.phpactor.json + + + +## Annotations + +src/DTO/Documents/AnnotationsStamps/* +src/Requests/Documents/AnnotationsStamps/* +src/Responses/Documents/AnnotationsStamps/* +tests/Feature/Requests/Documents/AnnotationsStamps/* diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results index 726f8fdf..64b648f9 100644 --- a/.phpunit.cache/test-results +++ b/.phpunit.cache/test-results @@ -1 +1 @@ -{"version":"pest_2.34.7","defects":[],"times":{"P\\Tests\\Local\\UpdateNichtHandelsrechnungenTest::__pest_evaluable_it_can_update_a_document_value":7.343}} \ No newline at end of file +{"version":"pest_2.34.9","defects":[],"times":{"P\\Tests\\Feature\\Requests\\FileCabinets\\Upload\\AppendFilesToADataRecordTest::__pest_evaluable_it_can_attach_files_to_a_data_record":0.563,"P\\Tests\\Feature\\Requests\\Documents\\ClipUnclipStapleUnstaple\\ClipTest::__pest_evaluable_it_can_clip_2_documents":7.226,"P\\Tests\\Feature\\Requests\\FileCabinets\\Dialogs\\GetDialogsOfASpecificTypeTest::__pest_evaluable_it_can_list_dialogs_for_a_file_cabinet":0.709,"P\\Tests\\Feature\\Requests\\FileCabinets\\Upload\\AppendFilesToADataRecordTest::__pest_evaluable_it_can_attach_a_file_to_a_data_record":1.051,"P\\Tests\\Unit\\DTO\\DocumentIndex\\IndexDateTimeDTOTest::__pest_evaluable_it_create_index_date_time_dto":0.001,"P\\Tests\\Unit\\DTO\\DocumentIndex\\IndexTextDTOTest::__pest_evaluable_it_create_prepare_index_text_dto":0,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetUsers\\GetUsersOfAGroupTest::__pest_evaluable_it_can_list_users_of_a_group":0.873,"P\\Tests\\Feature\\Requests\\Documents\\Sections\\GetASpecificSectionTest::__pest_evaluable_it_can_get_a_specific_section":1.001,"P\\Tests\\Core\\ArchTest::__pest_evaluable_it_will_not_use_any_debug_function":0.202,"P\\Tests\\Feature\\Requests\\FileCabinets\\Search\\GetDocumentsFromAFileCabinetTest::__pest_evaluable_it_can_get_all_documents":1.128,"P\\Tests\\Feature\\Requests\\Documents\\ApplicationProperties\\ApplicationPropertiesTest::__pest_evaluable_it_can_add_get_update_delete_application_properties_to_a_document":1.321,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyRoles\\AddRemoveUserToARoleTest::__pest_evaluable_it_can_add_roles_to_a_user":7.208,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyRoles\\AddRemoveUserToARoleTest::__pest_evaluable_it_can_remove_roles_to_a_user":5.942,"P\\Tests\\Feature\\Requests\\Documents\\PutDocumentFieldsRequestTest::__pest_evaluable_it_can_update_multiple_document_values":0.897,"P\\Tests\\Feature\\Requests\\Documents\\PutDocumentFieldsRequestTest::__pest_evaluable_it_can_update_a_document_value":0.917,"P\\Tests\\Feature\\Requests\\Documents\\Download\\DownloadSectionTest::__pest_evaluable_it_can_download_a_section":0.958,"P\\Tests\\Feature\\Requests\\Documents\\ClipUnclipStapleUnstaple\\StapleTest::__pest_evaluable_it_can_staple_2_documents":12.678,"P\\Tests\\Feature\\Requests\\Documents\\ClipUnclipStapleUnstaple\\UnclipTest::__pest_evaluable_it_can_unclip_2_documents":12.252,"P\\Tests\\Feature\\DocuWareAuthenticationTest::__pest_evaluable_it_can_get_oath_responsible_identity_service":0.681,"P\\Tests\\Feature\\DocuWareAuthenticationTest::__pest_evaluable_it_can_authenticate_with_DocuWare_Credentials":0.657,"P\\Tests\\Feature\\DocuWareAuthenticationTest::__pest_evaluable_it_can_get_oath_identity_service_configuration":1.107,"P\\Tests\\Feature\\Requests\\FileCabinets\\Search\\GetASpecificDocumentFromAFileCabinetTest::__pest_evaluable_it_can_show_a_document":0.986,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyGroups\\GetGroupsTest::__pest_evaluable_it_can_list_groups":0.725,"P\\Tests\\Feature\\Requests\\Documents\\Thumbnail\\GetDocumentDownloadThumbnailRequestTest::__pest_evaluable_it_can_download_a_document_thumbnail":1.22,"P\\Tests\\Feature\\Requests\\Documents\\Download\\DownloadDocumentTest::__pest_evaluable_it_can_download_a_document":0.874,"P\\Tests\\Feature\\Requests\\Organization\\GetOrganizationsRequestTest::__pest_evaluable_it_can_list_organizations":0.689,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyGroups\\GetAllGroupsForASpecificUserTest::__pest_evaluable_it_can_list_groups_for_a_specific_user":0.92,"P\\Tests\\Feature\\Requests\\Fields\\GetFieldsRequestTest::__pest_evaluable_it_can_list_fields_for_a_file_cabinet":0.752,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetUsers\\GetUserByIdTest::__pest_evaluable_it_can_get_user_by_id":1.005,"P\\Tests\\Feature\\Requests\\Documents\\Download\\DownloadThumbnailTest::__pest_evaluable_it_can_download_a_thumbnail":0.996,"P\\Tests\\Feature\\SleepTest::__pest_evaluable_sleep":0.544,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetUsers\\GetUsersTest::__pest_evaluable_it_can_list_users":0.812,"P\\Tests\\Unit\\DTO\\DocumentIndex\\IndexDecimalDTOTest::__pest_evaluable_it_create_index_numeric_dto":0.001,"P\\Tests\\Feature\\Requests\\Documents\\PostDocumentRequestTest::__pest_evaluable_it_can_upload_document_with_index_values_and_delete_it":0.836,"P\\Tests\\Feature\\Requests\\Documents\\PostDocumentRequestTest::__pest_evaluable_it_can_upload_document_without_file_name_and_file_content_and_delete_it":0.76,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_override_search_documents_dates_filter_by_using_equal_operator":0.72,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_search_documents_with_null_values":0.714,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_override_search_documents_dates_filter_by_using_same_operator":0.781,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_t_search_documents_by_more_than_two_dates":0.544,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_t_search_documents_by_diverged_date_range":0.555,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_search_documents_dates_filter_in_future":0.763,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_search_documents_dates_filter_in_past":0.816,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_search_documents":0.779,"P\\Tests\\Feature\\Requests\\Search\\GetSearchRequestTest::__pest_evaluable_it_can_search_documents_with_multiple_values":1.354,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyGroups\\AddRemoveUserToAGroupTest::__pest_evaluable_it_can_add_groups_to_a_user":7.049,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyGroups\\AddRemoveUserToAGroupTest::__pest_evaluable_it_can_remove_groups_to_a_user":6.021,"P\\Tests\\Feature\\Requests\\Documents\\Sections\\DeleteSectionTest::__pest_evaluable_it_can_delete_a_specific_section":1.031,"P\\Tests\\Feature\\Requests\\FileCabinets\\Dialogs\\GetASpecificDialogTest::__pest_evaluable_it_can_get_a_dialog":0.767,"P\\Tests\\Feature\\Requests\\Workflow\\GetDocumentWorkflowHistoryTest::__pest_evaluable_it_can_get_document_workflow_history":5.948,"P\\Tests\\Feature\\Requests\\Documents\\GetDocumentPreviewRequestTest::__pest_evaluable_it_can_preview_a_document_image":1.154,"P\\Tests\\Unit\\DTO\\DocumentIndex\\IndexDateDTOTest::__pest_evaluable_it_create_index_date_dto":0.003,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\DeleteDocumentsFromTrashBinTest::__pest_evaluable_it_can_delete_documents_in_trash":1.141,"P\\Tests\\Unit\\DTO\\DocumentIndex\\PrepareTableDTOTest::__pest_evaluable_it_create_prepare_index_table_dto":0.002,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyRoles\\GetAllRolesForASpecificUserTest::__pest_evaluable_it_can_list_groups":1.082,"P\\Tests\\Feature\\Requests\\Documents\\Sections\\GetAllSectionsFromADocumentTest::__pest_evaluable_it_can_get_all_sections_from_a_document":0.904,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetUsers\\GetUsersOfARoleTest::__pest_evaluable_it_can_list_users_of_a_role":0.767,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\RestoreDocumentsFromTrashBinTest::__pest_evaluable_it_can_restore_documents_in_trash":1.114,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_document_paginator":0.54,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_dialog":0.544,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_field":0.561,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_organization":0.549,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_table_row":0.562,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_document":0.554,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_organization_index":0.568,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_suggestion_field":0.535,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_file_cabinet":0.548,"P\\Tests\\Feature\\DTOTest::__pest_evaluable_it_create_a_fake_document_field":0.551,"P\\Tests\\Unit\\DTO\\DocumentIndex\\PrepareDTOTest::__pest_evaluable_it_create_prepare_makeContent_dto":0.001,"P\\Tests\\Unit\\DTO\\DocumentIndex\\PrepareDTOTest::__pest_evaluable_it_create_prepare_index_dto":0.002,"P\\Tests\\Feature\\Requests\\FileCabinets\\General\\GetFileCabinetInformationTest::__pest_evaluable_it_can_get_file_cabinet_information":0.83,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\CreateUpdateUsers\\CreateUpdateUserTest::__pest_evaluable_it_can_create_users":1.484,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\CreateUpdateUsers\\CreateUpdateUserTest::__pest_evaluable_it_can_update_users":6.052,"P\\Tests\\Unit\\DTO\\DocumentIndex\\IndexNumericDTOTest::__pest_evaluable_it_create_index_numeric_dto":0.001,"P\\Tests\\Feature\\DocuWareTest::__pest_evaluable_it_can_create_encrypted_url_for_a_document_in_a_basket":0.59,"P\\Tests\\Feature\\DocuWareTest::__pest_evaluable_it_can_create_encrypted_url_for_a_document_in_a_file_cabinet":0.541,"P\\Tests\\Unit\\DTO\\DocumentIndex\\IndexTableDTOTest::__pest_evaluable_it_create_prepare_index_text_dto":0.001,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_search_documents_with_null_values_in_trash":0.783,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_t_search_documents_by_diverged_date_range":0.546,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_override_search_documents_dates_filter_by_using_same_operator_in_trash":0.679,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_search_documents_dates_filter_in_future_in_trash":0.66,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_search_documents_dates_filter_in_past_in_trash":0.68,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_search_documents_in_trash":0.69,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_override_search_documents_dates_filter_by_using_equal_operator_in_trash":0.678,"P\\Tests\\Feature\\Requests\\Documents\\DocumentsTrashBin\\GetDocumentsFromTrashBinTest::__pest_evaluable_it_can_t_search_documents_by_more_than_two_dates_in_trash":0.534,"P\\Tests\\Feature\\Requests\\Workflow\\GetDocumentWorkflowHistoryStepsTest::__pest_evaluable_it_can_get_document_workflow_history":6.748,"P\\Tests\\Feature\\Requests\\Documents\\ClipUnclipStapleUnstaple\\UnstapleTest::__pest_evaluable_it_can_unstaple_a_document":13.846,"P\\Tests\\Feature\\Requests\\General\\UserManagement\\GetModifyRoles\\GetRolesTest::__pest_evaluable_it_can_list_groups":0.688,"P\\Tests\\Feature\\Requests\\Documents\\GetDocumentCountRequestTest::__pest_evaluable_it_can_get_a_total_count_of_documents":0.938}} \ No newline at end of file diff --git a/README.md b/README.md index a5f925f6..04e0ea46 100644 --- a/README.md +++ b/README.md @@ -20,37 +20,134 @@ then optimize the processes that power the core of your business. ## 🛠 Requirements -### > = v4.0 (alpha) +
+ Version Support + +### \> = v11.0 (alpha) + +- PHP: `^8.2`` + - Laravel: `^11.*` + - DocuWare Cloud Access + +### \> = v4.0 (alpha) - PHP: `^8.2`` - Laravel: `^11.*` - DocuWare Cloud Access -### > = v3.0 +### \> = v3.0 - PHP: `^8.2`` - Laravel: `^10.*` - DocuWare Cloud Access -### > = v2.0 +### \> = v2.0 - PHP: `^8.1` |`^8.2` - Laravel: `^9.*` | `^10.*` - DocuWare Cloud Access -- -### > = v1.2 +### \> = v1.2 - PHP: `^8.1` - Laravel: `^9.*` - DocuWare Cloud Access -### < v1.2 +### \< v1.2 - PHP: `^8.0` - Laravel: `^8.*` - DocuWare Cloud Access +
+ +
+ Current Support + +| Group | Request | Supported | TODO | +|-------------------------------------|-------------------------------------------------------------|-----------|------| +| Authentication/OAuth | 1. Get Responsible Identity Service | ✅ | | +| Authentication/OAuth | 2. Get Identity Service Configuration | ✅ | | +| Authentication/OAuth | 3.a Request Token w/ Username & Password | ✅ | | +| Authentication/OAuth | 3.b Request Token w/ a DocuWare Token | 🕣 | | +| Authentication/OAuth | 3.c Request Token w/ Username & Password (Trusted User) | 🕣 | | +| Authentication/OAuth | 3.d.1 Obtain Windows Authorization (On Premises Only) | 🕣 | | +| Authentication/OAuth | 3.d.2 Request Token /w a Windows Account (On Premises Only) | 🕣 | | +| General/Organisation | Get Login Token | ✅ | | +| General/Organisation | Get Organization | ✅ | | +| General/Organisation | Get All File Cabinets and Document Trays | ✅ | | +| General/UserManagement | Get Users by ID | ✅ | | +| General/UserManagement | Get Users of a Role | ✅ | | +| General/UserManagement | Get Users of a Group | ✅ | | +| General/UserManagement | Create User | ✅ | | +| General/UserManagement | Update User | ✅ | | +| General/UserManagement | Get Groups | ✅ | | +| General/UserManagement | Get All Groups for a Specific User | ✅ | | +| General/UserManagement | Add User to a Group | ✅ | | +| General/UserManagement | Remove User from a Group | ✅ | | +| General/UserManagement | Get Roles | ✅ | | +| General/UserManagement | Get All Roles for a Specific User | ✅ | | +| General/UserManagement | Add User to a Role | ✅ | | +| General/UserManagement | Remove User from a Role | ✅ | | +| FileCabinets/General | Get File Cabinet Information | ✅ | | +| FileCabinets/General | Get Total Number of Documents | ✅ | | +| FileCabinets/Dialogs | Get All Dialogs | ✅ | | +| FileCabinets/Dialogs | Get a Specific Dialog | ✅ | | +| FileCabinets/Dialogs | Get Dialogs of a Specific Type | ✅ | | +| FileCabinets/Search | Get Documents from a File Cabinet | ✅ | | +| FileCabinets/Search | Get a Specific Document From a File Cabinet | ✅ | | +| FileCabinets/Search | Search for Documents in a Single File Cabinet | ✅ | | +| FileCabinets/Search | Search for Documents in Multiple File Cabinets | ✅ | | +| FileCabinets/CheckInCheckOut | Check-out & Download a Document | 🕣 | | +| FileCabinets/CheckInCheckOut | Check-in a Document from the File System | 🕣 | | +| FileCabinets/CheckInCheckOut | Undo Check-out | 🕣 | | +| FileCabinets/SelectLists | Get Select Lists & Get Filtered Select Lists | ✅ | | +| FileCabinets/Upload | Create Data Record | ✅ | | +| FileCabinets/Upload | Append File(s) to a Data Record | ✅ | | +| FileCabinets/Upload | Upload a Single File for a Data Record | ❌ | - | +| FileCabinets/Upload | Create a Data Record & Upload File | ❌ | - | +| FileCabinets/Upload | Create Data Record & Upload File Using Store Dialog | ❌ | - | +| FileCabinets/Upload | Append a Single PDF to a Document | ❌ | - | +| FileCabinets/Upload | Replace a PDF Document Section | ❌ | - | +| FileCabinets/BatchIndexFieldsUpdate | Batch Update Index Fields By Id | ❌ | - | +| FileCabinets/BatchIndexFieldsUpdate | Batch Update Index Fields By Search | ❌ | - | +| FileCabinets/BatchIndexFieldsUpdate | Batch Append/Update Keyword Fields By Id | ❌ | - | +| Documents/UpdateIndexValues | Update Index Values | ✅ | | +| Documents/UpdateIndexValues | Update Table Field Values | ❌ | - ? | +| Documents/ModifyDocuments | Transfer Document | ✅ | | +| Documents/ModifyDocuments | Delete Document | ✅ | | +| Documents/ClipUnclip&StapleUnstaple | Clip | ✅ | | +| Documents/ClipUnclip&StapleUnstaple | Unclip | ✅ | | +| Documents/ClipUnclip&StapleUnstaple | Staple | ✅ | | +| Documents/ClipUnclip&StapleUnstaple | Unstaple | ✅ | | +| Documents/AnnotationsStamps | AddStampWithPosition | 🕣 | | +| Documents/AnnotationsStamps | AddStampWithBestPosition | 🕣 | | +| Documents/AnnotationsStamps | AddTextAnnotation | 🕣 | | +| Documents/AnnotationsStamps | AddRectEntryAnnotation | 🕣 | | +| Documents/AnnotationsStamps | AddLineEntryAnnotation | 🕣 | | +| Documents/AnnotationsStamps | AddPolyLineEntryAnnotation | ❌ | - | +| Documents/AnnotationsStamps | DeleteAnnotation | ❌ | - | +| Documents/AnnotationsStamps | UpdateTextAnnotation | 🕣 | | +| Documents/AnnotationsStamps | Get Stamps | ❌ | - | +| Documents/DocumentsTrashBin | Get Documents | ✅ | | +| Documents/DocumentsTrashBin | Delete Documents | ✅ | | +| Documents/DocumentsTrashBin | Restore Documents | ✅ | | +| Documents/ApplicationProperties | Get Application Properties | ✅ | | +| Documents/ApplicationProperties | Add Application Properties | ✅ | | +| Documents/ApplicationProperties | Delete Application Properties | ✅ | | +| Documents/ApplicationProperties | Update Application Properties | ✅ | | +| Documents/Sections | Get All Sections from a Document | ✅ | | +| Documents/Sections | Get a Specific Section | ✅ | | +| Documents/Sections | Delete Section | ✅ | | +| Documents/Download | Download Document | ✅ | | +| Documents/Download | Download Section | ✅ | | +| Documents/Download | Download Thumbnail | ✅ | | +| Workflow | Get Document Workflow History | ✅ | | +| Workflow | Get Document Workflow History Steps | ✅ | | + +
+ + ## ⚙️ Installation You can install the package via composer: @@ -60,14 +157,12 @@ composer require codebar-ag/laravel-docuware ``` Add the following environment variables to your `.env` file: -The "DOCUWARE_COOKIES" variable is optional and only used if you want to set the request cookie manually. ```bash DOCUWARE_URL=https://domain.docuware.cloud DOCUWARE_USERNAME=user@domain.test DOCUWARE_PASSWORD=password DOCUWARE_PASSPHRASE="passphrase" -DOCUWARE_COOKIES="cookie" ``` With the passphrase we are able to encrypt the URLs. @@ -84,231 +179,584 @@ DOCUWARE_PASSPHRASE="a#bcd>2~C1'abc\\#" ## 🏗 Usage +### Getting Started with OAuth +
+ Getting Started with OAuth + +> This package automatically handles the generation of OAuth token for you and stores them in cache. + +### Getting a new token via Username & Password: + ```php -use CodebarAg\DocuWare\Connectors\DocuWareStaticConnector; +use CodebarAg\DocuWare\Connectors\DocuWareConnector; +use CodebarAg\DocuWare\DTO\Config\ConfigWithCredentials; -// Will use user credentials defined in config to authenticate and store cookie in cache -$connector = new DocuWareStaticConnector(); +$connector = new DocuWareConnector( + configuration: new ConfigWithCredentials( + username: 'username', + password: 'password', + ) +); +``` -// OR +### Getting a new token via Username & Password (Trusted User): -// Pass in a config manually -$config = Config::make([ - 'url' => 'https://domain.docuware.cloud', - 'cookie' => 'cookie', - 'cache_driver' => 'file', - 'cache_lifetime_in_seconds' => 60, - 'request_timeout_in_seconds' => 15, -]); +```php +use CodebarAg\DocuWare\Connectors\DocuWareConnector; +use CodebarAg\DocuWare\DTO\Config\ConfigWithCredentialsTrustedUser; -$connector = new DocuWareDynamicConnector($config); +$connector = new DocuWareConnector( + configuration: new ConfigWithCredentialsTrustedUser( + username: 'username', + password: 'password', + impersonatedUsername: 'impersonatedUsername', + ) +); ``` +### Extending the connector + +We understand it may be repetitive to pass the configuration every time you create a new connector. + +You can extend the connector and set the configuration once. + +#### Create a new connector + ```php -/** - * Return an organization. - */ - -$organization = $connector->send(new GetOrganizationRequest($id))->dto(); +send(new GetOrganizationsRequest())->dto(); +use App\Connectors\CustomDocuWareConnector; +use CodebarAg\DocuWare\DTO\Config\ConfigWithCredentials; + +$connector = new CustomDocuWareConnector(); ``` + +
+ +### Available Requests + +
+ Documents + +#### Add Application Properties ```php -/** - * Return all file cabinets. - */ - -$fileCabinets = $connector->send(new GetFileCabinetsRequest())->dto(); +use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\AddApplicationProperties; + +$addProperties = $connector->send(new AddApplicationProperties( + $fileCabinetId, + $documentId, + [ + [ + 'Name' => 'Key1', + 'Value' => 'Key1 Value', + ], + [ + 'Name' => 'Key2', + 'Value' => 'Key2 Value', + ], + ], +))->dto(); ``` +#### Update Application Properties ```php -/** - * Return all fields of a file cabinet. - */ - -$fields = $connector->send(new GetFieldsRequest($fileCabinetId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\UpdateApplicationProperties; + +$updateProperties = $connector->send(new UpdateApplicationProperties( + $fileCabinetId, + $documentId, + [ + [ + 'Name' => 'Key1', + 'Value' => 'Key1 Value Updated', + ], + ], +))->dto()->sortBy('Name'); ``` +#### Delete Application Properties ```php -/** - * Return all dialogs of a file cabinet. - */ - -$dialogs = $connector->send(new GetDialogsRequest($fileCabinetId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\DeleteApplicationProperties; + +$deleteProperties = $connector->send(new DeleteApplicationProperties( + $fileCabinetId, + $document->id, + [ + 'Key1', + ], +))->dto(); ``` +#### Get Application Properties ```php -/** - * Return all used values for a specific field. - */ - -$values = $connector->send(new GetSelectListRequest($fileCabinetId, $dialogId, $fieldName))->dto(); +use CodebarAg\DocuWare\Requests\Documents\ApplicationProperties\GetApplicationProperties; + +$properties = $connector->send(new GetApplicationProperties( + $fileCabinetId, + $document->id, +))->dto(); ``` + +#### Clip ```php -/** - * Return a document. - */ - -$document = $connector->send(new GetDocumentRequest($fileCabinetId, $documentId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\ClipUnclipStapleUnstaple\Clip; + +$clip = $connector->send(new Clip( + $fileCabinetId, + [ + $documentId, + $document2Id, + ] +))->dto(); ``` +#### Unclip ```php -/** - * Return all documents for a file cabinet. - */ - -$documents = $connector->send(new GetDocumentsRequest($fileCabinetId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\ClipUnclipStapleUnstaple\Unclip; + +$unclip = $connector->send(new Unclip( + $fileCabinetId, + $clipId +))->dto(); ``` +#### Staple ```php -/** - * Return image preview of a document. - */ - -$content = $connector->send(new GetDocumentPreviewRequest($fileCabinetId, $documentId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\ClipUnclipStapleUnstaple\Staple; + +$staple = $connector->send(new Staple( + $fileCabinetId, + [ + $documentId, + $document2Id, + ] +))->dto(); ``` +#### Unstaple ```php -/** - * Download single document. - */ - -$content = $connector->send(new GetDocumentDownloadRequest($fileCabinetId, $documentId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\ClipUnclipStapleUnstaple\Unstaple; + +$unclip = $connector->send(new Unstaple( + $fileCabinetId, + $stapleId +))->dto(); ``` +#### Delete Documents ```php -/** - * Download multiple documents. - * - * Although there are no mentioned limits in the documentation, - * it is not advisable to download more than 100 documents at once. - * - * Also note there is a default request timeout of 30 seconds. - */ - -$content = $connector->send(new GetDocumentsDownloadRequest($fileCabinetId, $documentIds))->dto(); +use CodebarAg\DocuWare\Requests\Documents\DocumentsTrashBin\DeleteDocuments; + +$delete = $connector->send(new DeleteDocuments([$documentID, $document2ID]))->dto(); ``` +#### Restore Documents ```php -/** - * Get sections of a document. - */ - -$section = $connector->send(new GetSectionsRequest($fileCabinetId, $documentId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\DocumentsTrashBin\RestoreDocuments; + +$delete = $connector->send(new RestoreDocuments([$documentID, $document2ID]))->dto(); ``` +#### Download Document ```php -/** - * Download a document thumbnail. - * - * You will use $section->id from above as $thumbnailId. - */ - -$thumbnail = $connector->send(new GetDocumentDownloadThumbnailRequest($fileCabinetId, $thumbnailId, $page = 0))->dto(); +use CodebarAg\DocuWare\Requests\Documents\Download\DownloadDocument; + +$contents = $connector->send(new DownloadDocument( + $fileCabinetId, + $documentId +))->dto(); ``` +#### Download Section ```php -/** - * Update value of a indexed field. - */ - -$value = $connector->send(new PutDocumentFieldsRequest($fileCabinetId, $documentId, [$fieldName => $newValue]))->dto(); +use CodebarAg\DocuWare\Requests\Documents\Download\DownloadSection; + +$contents = $connector->send(new DownloadSection( + $fileCabinetId, + $sectionId +))->dto(); ``` +#### Download Thumbnail ```php -/** - * Update multiple values of indexed fields. - */ - -$values = $connector->send(new PutDocumentFieldsRequest($fileCabinetId, $documentId, [ - $fieldName => $newValue, - $field2Name => $new2Value, -]))->dto(); +use CodebarAg\DocuWare\Requests\Documents\Download\DownloadThumbnail; + +$contents = $connector->send(new DownloadThumbnail( + $fileCabinetId, + $sectionId +))->dto(); ``` +#### Delete Section ```php -/** - * Upload new document. - */ - -$document = $connector->send(new PostDocumentRequest($fileCabinetId, $fileContent, $fileName))->dto(); +use CodebarAg\DocuWare\Requests\Documents\Sections\DeleteSection; + +$deleted = $connector->send(new DeleteSection( + $fileCabinetId, + $sectionId +))->dto(); ``` +#### Get All Section ```php -/** - * Get total document count. - */ - -$content = $connector->send(new GetDocumentCountRequest($fileCabinetId, $dialogId))->dto(); +use CodebarAg\DocuWare\Requests\Documents\Sections\GetAllSectionsFromADocument; + +$sections = $connector->send(new GetAllSectionsFromADocument( + $fileCabinetId, + $documentId +))->dto(); ``` +#### Get Specific Section ```php -/** - * Upload new document with index values. - */ - -use CodebarAg\DocuWare\DTO\DocumentIndex\PrepareDTO; - -$indexes = collect([ - PrepareDTO::make('FIELD_TEXT', 'Indexed Text'), - PrepareDTO::make('FIELD_NUMERIC', 1), - PrepareDTO::make('FIELD_DECIMAL', 1.00), - PrepareDTO::make('FIELD_DATE', now()), -]); - -$document = $connector->send(new PostDocumentRequest( +use CodebarAg\DocuWare\Requests\Documents\Sections\GetASpecificSection; + +$section = $connector->send(new GetASpecificSection( $fileCabinetId, - $fileContent, - $fileName, - $indexes, + $sectionsId ))->dto(); ``` + +#### Get Total Number Of Documents ```php -/** - * Upload new data entry with index values. - */ - -use CodebarAg\DocuWare\DTO\DocumentIndex\PrepareDTO; - -$indexes = collect([ - PrepareDTO::make('FIELD_TEXT', 'Indexed Text'), - PrepareDTO::make('FIELD_NUMERIC', 1), - PrepareDTO::make('FIELD_DECIMAL', 1.00), - PrepareDTO::make('FIELD_DATE', now()), -]); - -$document = $connector->send(new PostDocumentRequest( +use CodebarAg\DocuWare\Requests\FileCabinets\General\GetTotalNumberOfDocuments; + +$count = $connector->send(new GetTotalNumberOfDocuments( + $fileCabinetId, + $dialogId +))->dto(); +``` + +#### Get Document Preview +```php +use CodebarAg\DocuWare\Requests\Documents\GetDocumentPreviewRequest; + +$image = $connector->send(new GetDocumentPreviewRequest($fileCabinetId, $documentId))->dto(); +``` + +#### Create Data Record +```php +use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord; + +$document = $connector->send(new CreateDataRecord( $fileCabinetId, null, null, - $indexes, + collect([ + IndexTextDTO::make('DOCUMENT_LABEL', '::data-entry::'), + ]), ))->dto(); ``` +#### Update Index Values ```php -/** - * Delete document. - */ - -$connector->send(new DeleteDocumentRequest($fileCabinetId, $document->id))->dto(); +use CodebarAg\DocuWare\Requests\Documents\UpdateIndexValues\UpdateIndexValues; + +$response = $connector->send(new UpdateIndexValues( + $fileCabinetId, + $documentId, + collect([ + IndexTextDTO::make('DOCUMENT_LABEL', '::new-data-entry::'), + ]) +))->dto(); +``` +
+ + +
+ Fields + +#### Get Fields +```php +use CodebarAg\DocuWare\Requests\Fields\GetFieldsRequest; + +$fields = $connector->send(new GetFieldsRequest($fileCabinetId))->dto(); +``` + +
+ +
+ File Cabinets + +#### Get All Dialogs +```php +use CodebarAg\DocuWare\Requests\FileCabinets\Dialogs\GetAllDialogs; + +$dialogs = $connector->send(new GetAllDialogs($fileCabinetId))->dto(); +``` + +#### Get Dialogs of a Specific Type +```php +use CodebarAg\DocuWare\Requests\FileCabinets\Dialogs\GetASpecificDialog; + +$dialog = $connector->send(new GetASpecificDialog($fileCabinetId, $dialogId))->dto(); +``` + +#### Get Dialogs Of A Specific Type +```php +use CodebarAg\DocuWare\Enums\DialogType; +use CodebarAg\DocuWare\Requests\FileCabinets\Dialogs\GetDialogsOfASpecificType; + +$dialogs = $connector->send(new GetDialogsOfASpecificType($fileCabinetId, DialogType::SEARCH))->dto(); +``` + +#### Get File Cabinet Information +```php +use CodebarAg\DocuWare\Requests\FileCabinets\General\GetFileCabinetInformation; + +$fileCabinet = $connector->send(new GetFileCabinetInformation($fileCabinetId))->dto(); +``` + +#### Get A Specific Document From A File Cabinet +```php +use CodebarAg\DocuWare\Requests\FileCabinets\Search\GetASpecificDocumentFromAFileCabinet; + +$document = $connector->send(new GetASpecificDocumentFromAFileCabinet($fileCabinetId, $documentId))->dto(); +``` + +#### Get Documents From A File Cabinet +```php +use CodebarAg\DocuWare\Requests\FileCabinets\Search\GetDocumentsFromAFileCabinet; + +$documents = $connector->send(new GetDocumentsFromAFileCabinet( + config('laravel-docuware.tests.file_cabinet_id') +))->dto(); +``` + +#### Append Files To A Data Record +```php +use CodebarAg\DocuWare\Requests\FileCabinets\Upload\AppendFilesToADataRecord; + +$response = $connector->send( + new AppendFilesToADataRecord( + fileCabinetId: $fileCabinetId, + dataRecordId: $document->id, + files: collect([ + new MultipartValue( + name: 'File[]', + value: file_get_contents(__DIR__.'/../../../../Fixtures/files/test-2.pdf'), + filename: 'test-2.pdf', + ), + new MultipartValue( + name: 'File[]', + value: file_get_contents(__DIR__.'/../../../../Fixtures/files/test-3.pdf'), + filename: 'test-3.pdf', + ), + ]) + ) +)->dto(); +``` +
+ +
+ General + +#### Create User +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\CreateUpdateUsers\CreateUser; + +$user = $connector->send(new CreateUser(new User( + name: $timestamp.' - Test User', + dbName: $timestamp, + email: $timestamp.'-test@example.test', + password: 'TESTPASSWORD', +)))->dto(); +``` + +#### Update User +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\CreateUpdateUsers\UpdateUser; + +$user->name .= ' - Updated'; +$user->active = false; + +$user = $connector->send(new UpdateUser($user))->dto(); +``` + +#### Add User To A Group +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyGroups\AddUserToAGroup; + +$response = $connector->send(new AddUserToAGroup( + userId: $userId, + ids: [$groupId], +))->dto(); +``` + +#### Remove User From A Group +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyGroups\RemoveUserFromAGroup; + +$response = $connector->send(new RemoveUserFromAGroup( + userId: $userId, + ids: [$groupId], +))->dto(); +``` + +#### Get All Groups For A Specific User +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyGroups\GetAllGroupsForASpecificUser; + +$groups = $connector->send(new GetAllGroupsForASpecificUser($userId))->dto(); +``` + +#### Get Groups +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyGroups\GetGroups; + +$groups = $connector->send(new GetGroups())->dto(); +``` + +#### Add User To A Role +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyRoles\AddUserToARole; + +$response = $connector->send(new AddUserToARole( + userId: $userId, + ids: [$roleId], +))->dto(); +``` + +#### Remove User From A Role +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyRoles\RemoveUserFromARole; + +$response = $connector->send(new RemoveUserFromARole( + userId: $userId, + ids: [$roleId], +))->dto(); +``` + +#### Get All Roles For A Specific User +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyRoles\GetAllRolesForASpecificUser; + +$roles = $connector->send(new GetAllRolesForASpecificUser($userId))->dto(); +``` + +#### Get Roles +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetModifyRoles\GetRoles; + +$roles = $this->connector->send(new GetRoles())->dto(); +``` + +#### Get User By Id +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetUsers\GetUserById; + +$user = $this->connector->send(new GetUserById($userId))->dto(); +``` + +#### Get Users Of A Group +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetUsers\GetUsersOfAGroup; + +$users = $this->connector->send(new GetUsersOfAGroup($groupId))->dto(); +``` + +#### Get Users Of A Role +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetUsers\GetUsersOfARole; + +$users = $this->connector->send(new GetUsersOfARole($roleId))->dto(); +``` + +### Get Users +```php +use CodebarAg\DocuWare\Requests\General\UserManagement\GetUsers\GetUsers; + +$users = $this->connector->send(new GetUsers())->dto(); +``` + +
+ +
+ Organization + +#### Get Organization +```php +use CodebarAg\DocuWare\Requests\General\Organization\GetOrganization; + +$organizations = $this->connector->send(new GetOrganization())->dto(); +``` + +
+ +
+ Select List + +#### Get Select Lists +```php +use CodebarAg\DocuWare\Requests\FileCabinets\SelectLists\GetSelectLists; + +$types = $this->connector->send(new GetSelectLists( + $fileCabinetId, + $dialogId, + $fieldName, +))->dto(); +``` + +
+ +
+ Workflow + +#### Get Document Workflow History +```php +use CodebarAg\DocuWare\Requests\Workflow\GetDocumentWorkflowHistory; + +$history = $this->connector->send(new GetDocumentWorkflowHistory( + $fileCabinetId, + $documentId +))->dto(); ``` +#### Get Document Workflow History Steps +```php +use CodebarAg\DocuWare\Requests\Workflow\GetDocumentWorkflowHistorySteps; + +$historySteps = $this->connector->send(new GetDocumentWorkflowHistorySteps( + $workflowId, + $historyId, +))->dto(); +``` + +
+ ## 🔍 Search usage +
+ Search Usage ```php use CodebarAg\DocuWare\Facades\DocuWare; -use CodebarAg\DocuWare\Connectors\DocuWareStaticConnector; +use CodebarAg\DocuWare\Connectors\DocuWareConnector; -$connector = new DocuWareStaticConnector(); +$connector = new DocuWareConnector(); ``` ```php @@ -488,9 +936,27 @@ $paginatorRequest = DocuWare::searchRequestBuilder() $paginator = $connector->send($paginatorRequest)->dto(); ``` +
+ +## 🔍 Search usage TrashBin +
+ Search Usage + +> You can use the same methods as in the search usage. The only difference is that you have to use the `trashBin` method after the `searchRequestBuilder` method. + +```php +use CodebarAg\DocuWare\DocuWare; + +$paginatorRequest = (new DocuWare()) + ->searchRequestBuilder() + ->trashBin() +``` ## 🖼 Make encrypted URL +
+ Make encrypted URL + ```php use CodebarAg\DocuWare\Facades\DocuWare; ``` @@ -535,47 +1001,50 @@ $url = DocuWare::url() ->make(); ``` -Please see [Tests](tests/Feature/DocuWare.php) for more details. +
## 🏋️ Document Index Fields DTO showcase +
+ Document Index Fields DTO showcase + ```php -CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO { +CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO { +name: "FIELD_TEXT" // string +value: "Value" // null|string } ``` ```php -CodebarAg\DocuWare\DTO\DocumentIndex\IndexNumericDTO { +CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO { +name: "FIELD_NUMERIC" // string +value: 1 // null|int } ``` ```php -CodebarAg\DocuWare\DTO\DocumentIndex\IndexDecimalDTO { +CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO { +name: "FIELD_DECIMAL" // string +value: 1.00 // null|int|float } ``` ```php -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateDTO { + { +name: "FIELD_DATE" // string +value: now(), // null|Carbon } ``` ```php -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateTimeDTO { + { +name: "FIELD_DATETIME" // string +value: now(), // null|Carbon } ``` ```php -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTableDTO { + { +name: "FIELD_TABLE" // string +value: collect([ 0 => [ @@ -596,7 +1065,11 @@ use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTableDTO { } ``` -## 🏋️ DTO showcase +
+ +## 🏋️ DTO Showcase +
+ DTO Showcase ```php CodebarAg\DocuWare\DTO\OrganizationIndex { @@ -725,65 +1198,20 @@ CodebarAg\DocuWare\DTO\DocumentPaginator } ``` -## 🔐 Authentication - -You only need to provide correct credentials. Everything else is automatically -handled from the package. Under the hood we are storing the authentication -cookie in the cache named *docuware.cookies*. - -You can run `php artisan docuware:list-auth-cookie` command to get your auth session that you can use in your `.env` -file `DOCUWARE_COOKIES` key. - -But if you need further control you can use the following methods to login and -logout with DocuWare: +
-```php -use CodebarAg\DocuWare\Facades\DocuWare; -``` - -```php -/** - * Receive a cookie - */ - -DocuWare::cookie(string $url, string $username, string $password); -``` - -```php -/** - * Login with your credentials. You only need to login once. Afterwards the - * authentication cookie is stored in the cache as `docuware.cookies` and - * is used for all further requests. - */ - -DocuWare::login(); -``` - -```php -/** - * Logout your current session. Removes the authentication cookie in the cache. - */ - -DocuWare::logout(); -``` - -### Manual authentication - -If you want to provide your own authentication cookie you can use the following connector -to authenticate with the DocuWare REST API: - -```php -use CodebarAg\DocuWare\Connectors\StaticCookieConnector; -``` ## 📦 Caching requests +
+ Caching requests + All Get Requests are cachable and will be cached by default. To determine if the response is cached you can use the following method: ```php -$connector = new DocuWareStaticConnector(); +$connector = new DocuWareConnector(); $response = $connector->send(new GetDocumentRequest($fileCabinetId, $documentId)); $response->isCached(); // false @@ -797,7 +1225,7 @@ $response->isCached(); // true To invalidate the cache for a specific request you can use the following method: ```php -$connector = new DocuWareStaticConnector(); +$connector = new DocuWareConnector(); $request = new GetDocumentRequest($fileCabinetId, $documentId); $request->invalidateCache(); @@ -808,7 +1236,7 @@ $response = $connector->send($request); To temporarily disable caching for a specific request you can use the following method: ```php -$connector = new DocuWareStaticConnector(); +$connector = new DocuWareConnector(); $request = new GetDocumentRequest($fileCabinetId, $documentId); $request->disableCaching(); @@ -816,8 +1244,13 @@ $request->disableCaching(); $response = $connector->send($request); ``` +
+ ## 💥 Exceptions explained +
+ Exceptions explained + - `CodebarAg\DocuWare\Exceptions\UnableToMakeRequest` This is thrown if you are not authorized to make the request. @@ -887,6 +1320,8 @@ DocuWareResponseLog::class => [ ], ``` +
+ ## 🔧 Configuration file You can publish the config file with: @@ -901,15 +1336,6 @@ This is the contents of the published config file: ConnectionEnum::WITHOUT_COOKIE, /* |-------------------------------------------------------------------------- @@ -921,16 +1347,6 @@ return [ 'cache_driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_DRIVER', 'file')), - /* - |-------------------------------------------------------------------------- - | Cookies - |-------------------------------------------------------------------------- - | This variable is optional and only used if you want to set the request cookie manually. - | - */ - - 'cookies' => env('DOCUWARE_COOKIES'), - /* |-------------------------------------------------------------------------- | Requests timeout @@ -971,19 +1387,6 @@ return [ 'passphrase' => env('DOCUWARE_PASSPHRASE'), - /* - |-------------------------------------------------------------------------- - | Authentication Cookie Lifetime - |-------------------------------------------------------------------------- - | - | Here you may define the amount of minutes the authentication cookie is - | valid. Afterwards it will be removed from the cache and you need to - | provide a fresh one. By default, the lifetime lasts for one year. - | - */ - - 'cookie_lifetime' => (int) env('DOCUWARE_COOKIE_LIFETIME', 525600), - /* |-------------------------------------------------------------------------- | Configurations @@ -1000,7 +1403,7 @@ return [ * to false (default) or always a new one is executed when ForceRefresh is set to true. */ - 'force_refresh' => false, + 'force_refresh' => true, 'include_suggestions' => false, 'additional_result_fields' => [], ], @@ -1009,7 +1412,7 @@ return [ 'lifetime_in_seconds' => env('DOCUWARE_CACHE_LIFETIME_IN_SECONDS', 60), ], ], - + /* |-------------------------------------------------------------------------- | Tests @@ -1020,7 +1423,18 @@ return [ 'file_cabinet_id' => env('DOCUWARE_TESTS_FILE_CABINET_ID'), 'dialog_id' => env('DOCUWARE_TESTS_DIALOG_ID'), 'basket_id' => env('DOCUWARE_TESTS_BASKET_ID'), + 'section' => (int) env('DOCUWARE_TESTS_SECTION'), 'organization_id' => env('DOCUWARE_TESTS_ORGANIZATION_ID'), + 'document_id' => (int) env('DOCUWARE_TESTS_DOCUMENT_ID'), + 'document_file_size_preview' => (int) env('DOCUWARE_TESTS_DOCUMENT_FILE_SIZE_PREVIEW'), + 'document_file_size' => (int) env('DOCUWARE_TESTS_DOCUMENT_FILE_SIZE'), + 'document_count' => (int) env('DOCUWARE_TESTS_DOCUMENT_COUNT'), + 'document_thumbnail_mime_type' => env('DOCUWARE_TESTS_DOCUMENT_THUMBNAIL_MIME_TYPE'), + 'document_thumbnail_file_size' => (int) env('DOCUWARE_TESTS_DOCUMENT_THUMBNAIL_FILE_SIZE'), + 'document_ids' => json_decode(env('DOCUWARE_TESTS_DOCUMENTS_IDS', '[]')), + 'documents_file_size' => (int) env('DOCUWARE_TESTS_DOCUMENTS_FILE_SIZE'), + 'field_name' => env('DOCUWARE_TESTS_FIELD_NAME'), + 'field_name_2' => env('DOCUWARE_TESTS_FIELD_NAME_2'), ], ]; ``` @@ -1036,14 +1450,13 @@ cp phpunit.xml.dist phpunit.xml Modify environment variables in the phpunit.xml-file: ```xml - + - - - // Disable caching for tests + + diff --git a/composer.json b/composer.json index 210acbb0..aec33a34 100644 --- a/composer.json +++ b/composer.json @@ -24,20 +24,20 @@ } ], "require": { - "php": "^8.2", + "php": ">=8.2", "guzzlehttp/guzzle": "^7.8", - "illuminate/contracts": "^10.0|^11.0", + "illuminate/contracts": "^11.0", "nesbot/carbon": "^2.72", "saloonphp/cache-plugin": "^3.0", - "saloonphp/saloon": "^3.4", - "saloonphp/laravel-plugin": "^3.2", + "saloonphp/laravel-plugin": "^3.5", + "saloonphp/saloon": "^3.7", "spatie/laravel-package-tools": "^1.16" }, "require-dev": { - "laravel/pint": "^1.13", - "nunomaduro/larastan": "^2.8", - "orchestra/testbench": "^8.20|^9.0", - "pestphp/pest": "^2.31", + "laravel/pint": "^1.14", + "nunomaduro/larastan": "^2.9", + "orchestra/testbench": "^9.0", + "pestphp/pest": "^2.34", "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.1", "phpstan/phpstan-phpunit": "^1.3", diff --git a/config/laravel-docuware.php b/config/laravel-docuware.php index a9240f4d..3b7d467e 100644 --- a/config/laravel-docuware.php +++ b/config/laravel-docuware.php @@ -12,16 +12,6 @@ 'cache_driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_DRIVER', 'file')), - /* - |-------------------------------------------------------------------------- - | Cookies - |-------------------------------------------------------------------------- - | This variable is optional and only used if you want to set the request cookie manually. - | - */ - - 'cookies' => env('DOCUWARE_COOKIES'), - /* |-------------------------------------------------------------------------- | Requests timeout @@ -62,19 +52,6 @@ 'passphrase' => env('DOCUWARE_PASSPHRASE'), - /* - |-------------------------------------------------------------------------- - | Authentication Cookie Lifetime - |-------------------------------------------------------------------------- - | - | Here you may define the amount of minutes the authentication cookie is - | valid. Afterwards it will be removed from the cache and you need to - | provide a fresh one. By default, the lifetime lasts for one year. - | - */ - - 'cookie_lifetime' => (int) env('DOCUWARE_COOKIE_LIFETIME', 525600), - /* |-------------------------------------------------------------------------- | Configurations @@ -99,6 +76,12 @@ 'driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_DRIVER', 'file')), 'lifetime_in_seconds' => env('DOCUWARE_CACHE_LIFETIME_IN_SECONDS', 60), ], + 'request' => [ + 'timeout_in_seconds' => env('DOCUWARE_CACHE_TIMEOUT_IN_SECONDS', 60), + ], + + 'client_id' => env('DOCUWARE_CLIENT_ID', 'docuware.platform.net.client'), + 'scope' => env('DOCUWARE_SCOPE', 'docuware.platform'), ], /* diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7e1c7e6e..cc3e2d8d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -37,17 +37,20 @@ + - + - - - - + + + + + + diff --git a/src/Commands/ListAuthCookie.php b/src/Commands/ListAuthCookie.php deleted file mode 100644 index 0e3914dc..00000000 --- a/src/Commands/ListAuthCookie.php +++ /dev/null @@ -1,52 +0,0 @@ -info('No cookie found for the Key "'.$cacheKey.'".'); - } - if ($cookieHash) { - $this->info($cookieHash); - if ($this->option('with-date')) { - $this->newLine(); - $this->info("Created At: {$cookieCreationDate}"); - } - } - - return Command::SUCCESS; - } -} diff --git a/src/Connectors/DocuWareConnector.php b/src/Connectors/DocuWareConnector.php new file mode 100644 index 00000000..ddc2e4a4 --- /dev/null +++ b/src/Connectors/DocuWareConnector.php @@ -0,0 +1,127 @@ +configuration->url.'/DocuWare/Platform'; + } + + public function defaultHeaders(): array + { + return [ + 'Accept' => 'application/json', + ]; + } + + public function defaultConfig(): array + { + return [ + 'timeout' => $this->configuration->requestTimeoutInSeconds, + ]; + } + + protected function defaultAuth(): TokenAuthenticator + { + return new TokenAuthenticator($this->getOrCreateNewOAuthToken()); + } + + /** + * @throws InvalidArgumentException + */ + protected function getOrCreateNewOAuthToken() + { + $cache = Cache::store($this->configuration->cacheDriver); + + // get instance name of $this->configuration as string + $instanceName = get_class($this->configuration); + + $cacheKey = 'docuware.oauth.'.$instanceName.'.'.$this->configuration->url.'.'.($this->configuration->username ?? ''); + + $token = null; + + if ($cache->has(key: $cacheKey)) { + $token = Crypt::decrypt($cache->get(key: $cacheKey)); + + DocuWareOAuthLog::dispatch($this->configuration->url, $this->configuration->username, 'Token retrieved from cache'); + } else { + if ($this->configuration instanceof ConfigWithCredentials) { + $token = $this->getNewOAuthTokenWithCredentials(); + + DocuWareOAuthLog::dispatch($this->configuration->url, $this->configuration->username, 'Token retrieved from API'); + } + + if ($this->configuration instanceof ConfigWithCredentialsTrustedUser) { + $token = $this->getNewOAuthTokenWithCredentialsTrustedUser(); + + DocuWareOAuthLog::dispatch($this->configuration->url, $this->configuration->username, 'Token retrieved from API'); + } + + $cache->put(key: $cacheKey, value: Crypt::encrypt($token), ttl: $token->expiresIn - 60); + } + + return $token->accessToken; + } + + protected function getAuthenticationTokenEndpoint(): IdentityServiceConfiguration + { + $responsibleIdentityServiceResponse = (new GetResponsibleIdentityService)->send(); + + $identityServiceConfigurationResponse = (new GetIdentityServiceConfiguration( + identityServiceUrl: $responsibleIdentityServiceResponse->dto()->identityServiceUrl + ))->send(); + + return $identityServiceConfigurationResponse->dto(); + } + + protected function getNewOAuthTokenWithCredentials(): RequestTokenDto + { + $requestTokenResponse = (new RequestTokenWithCredentials( + tokenEndpoint: $this->getAuthenticationTokenEndpoint()->tokenEndpoint, + clientId: $this->configuration->clientId, + scope: $this->configuration->scope, + username: $this->configuration->username, + password: $this->configuration->password, + ))->send(); + + return $requestTokenResponse->dto(); + } + + protected function getNewOAuthTokenWithCredentialsTrustedUser(): RequestTokenDto + { + $requestTokenResponse = (new RequestTokenWithCredentialsTrustedUser( + tokenEndpoint: $this->getAuthenticationTokenEndpoint()->tokenEndpoint, + clientId: $this->configuration->clientId, + scope: $this->configuration->scope, + username: $this->configuration->username, + password: $this->configuration->password, + impersonateName: $this->configuration->impersonatedUsername, + ))->send(); + + return $requestTokenResponse->dto(); + } +} diff --git a/src/Connectors/DocuWareDynamicConnector.php b/src/Connectors/DocuWareDynamicConnector.php deleted file mode 100644 index f8eca50c..00000000 --- a/src/Connectors/DocuWareDynamicConnector.php +++ /dev/null @@ -1,58 +0,0 @@ -configuration = $config; - - $this->cookieJar = CookieJar::fromArray( - [Auth::COOKIE_NAME => $this->configuration->cookie], - parse_url($config->url, PHP_URL_HOST) - ); - } - - /** - * @throws \Exception - */ - public function resolveBaseUrl(): string - { - return $this->configuration->url.'/DocuWare/Platform'; - } - - public function defaultHeaders(): array - { - return [ - 'Accept' => 'application/json', - ]; - } - - public function defaultConfig(): array - { - return [ - 'timeout' => $this->configuration->requestTimeoutInSeconds, - 'cookies' => $this->cookieJar, - ]; - } - - public function getCoookieJar(): CookieJar - { - return $this->cookieJar; - } - - public function getConfiguration(): Config - { - return $this->configuration; - } -} diff --git a/src/Connectors/DocuWareStaticConnector.php b/src/Connectors/DocuWareStaticConnector.php deleted file mode 100644 index e18ff25d..00000000 --- a/src/Connectors/DocuWareStaticConnector.php +++ /dev/null @@ -1,50 +0,0 @@ -cookieJar = Auth::cookieJar() ?? throw new \Exception('No cookie jar found'); - } - - /** - * @throws \Exception - */ - public function resolveBaseUrl(): string - { - return config('laravel-docuware.credentials.url').'/DocuWare/Platform'; - } - - public function defaultHeaders(): array - { - return [ - 'Accept' => 'application/json', - ]; - } - - public function defaultConfig(): array - { - return [ - 'timeout' => config('laravel-docuware.timeout'), - 'cookies' => $this->cookieJar, - ]; - } - - public function getCoookieJar(): CookieJar - { - return $this->cookieJar; - } -} diff --git a/src/DTO/Authentication/OAuth/IdentityServiceConfiguration.php b/src/DTO/Authentication/OAuth/IdentityServiceConfiguration.php new file mode 100644 index 00000000..503bd7f9 --- /dev/null +++ b/src/DTO/Authentication/OAuth/IdentityServiceConfiguration.php @@ -0,0 +1,85 @@ +addSeconds(Arr::get($data, 'expires_in')), + ); + } + + public function __construct( + public string $accessToken, + public string $tokenType, + public string $scope, + public int $expiresIn, + public Carbon $expiresAt, + ) {} +} diff --git a/src/DTO/Authentication/OAuth/ResponsibleIdentityService.php b/src/DTO/Authentication/OAuth/ResponsibleIdentityService.php new file mode 100644 index 00000000..8099d024 --- /dev/null +++ b/src/DTO/Authentication/OAuth/ResponsibleIdentityService.php @@ -0,0 +1,21 @@ +username = $username; + $this->password = $password; + + $this->url = filled($url) ? $url : config('laravel-docuware.credentials.url'); + + $this->passphrase = filled($passphrase) ? $passphrase : config('laravel-docuware.passphrase'); + + $this->cacheDriver = filled($cacheDriver) ? $cacheDriver : config('laravel-docuware.configurations.cache.driver'); + + $this->cacheLifetimeInSeconds = filled($cacheLifetimeInSeconds) ? $cacheLifetimeInSeconds : config('laravel-docuware.configurations.cache.lifetime_in_seconds'); + + $this->requestTimeoutInSeconds = filled($requestTimeoutInSeconds) ? $requestTimeoutInSeconds : config('laravel-docuware.configurations.request.timeout_in_seconds'); + + $this->clientId = filled($clientId) ? $clientId : config('laravel-docuware.configurations.client_id'); + + $this->scope = filled($scope) ? $scope : config('laravel-docuware.configurations.scope'); + } +} diff --git a/src/DTO/Config/ConfigWithCredentialsTrustedUser.php b/src/DTO/Config/ConfigWithCredentialsTrustedUser.php new file mode 100644 index 00000000..2ec3fd48 --- /dev/null +++ b/src/DTO/Config/ConfigWithCredentialsTrustedUser.php @@ -0,0 +1,57 @@ +username = $username; + $this->password = $password; + $this->impersonatedUsername = $impersonatedUsername; + + $this->url = filled($url) ? $url : config('laravel-docuware.credentials.url'); + + $this->passphrase = filled($passphrase) ? $passphrase : config('laravel-docuware.passphrase'); + + $this->cacheDriver = filled($cacheDriver) ? $cacheDriver : config('laravel-docuware.configurations.cache.driver'); + + $this->cacheLifetimeInSeconds = filled($cacheLifetimeInSeconds) ? $cacheLifetimeInSeconds : config('laravel-docuware.configurations.cache.lifetime_in_seconds'); + + $this->requestTimeoutInSeconds = filled($requestTimeoutInSeconds) ? $requestTimeoutInSeconds : config('laravel-docuware.configurations.request.timeout_in_seconds'); + + $this->clientId = filled($clientId) ? $clientId : config('laravel-docuware.configurations.client_id'); + + $this->scope = filled($scope) ? $scope : config('laravel-docuware.configurations.scope'); + } +} diff --git a/src/DTO/Cookie.php b/src/DTO/Cookie.php deleted file mode 100644 index 6375f46d..00000000 --- a/src/DTO/Cookie.php +++ /dev/null @@ -1,32 +0,0 @@ -toArray() === [], UnableToLoginNoCookies::create()); - - $data = collect($cookieJar->toArray()) - ->reject(fn (array $cookie) => Arr::get($cookie, 'Value') === '') - ->firstWhere('Name', '.DWPLATFORMAUTH'); - - return new self( - cookie: Arr::get($data, 'Value'), - cookie_created_at: now(), - cookie_lifetime_until: now()->addMinutes(525600 * 0.75), - ); - } -} diff --git a/src/DTO/Document.php b/src/DTO/Documents/Document.php similarity index 86% rename from src/DTO/Document.php rename to src/DTO/Documents/Document.php index 233fdc67..5a9f1eaf 100644 --- a/src/DTO/Document.php +++ b/src/DTO/Documents/Document.php @@ -1,8 +1,10 @@ mapWithKeys(function (array $section) { + return [$section['Id'] => Section::fromJson($section)]; + }); + } + public function __construct( public int $id, public int $file_size, @@ -62,6 +76,7 @@ public function __construct( public Carbon $created_at, public Carbon $updated_at, public ?Collection $fields, + public ?Collection $sections, public ?Collection $suggestions, ) {} @@ -115,6 +130,7 @@ public static function fake( ?Carbon $created_at = null, ?Carbon $updated_at = null, ?Collection $fields = null, + ?Collection $sections = null, ?Collection $suggestions = null, ): self { return new self( @@ -132,6 +148,7 @@ public static function fake( DocumentField::fake(), DocumentField::fake(), ]), + sections: $sections ?? null, suggestions: $suggestions ?? null ); } diff --git a/src/DTO/DocumentField.php b/src/DTO/Documents/DocumentField.php similarity index 97% rename from src/DTO/DocumentField.php rename to src/DTO/Documents/DocumentField.php index 9b033b45..d7fe0c13 100644 --- a/src/DTO/DocumentField.php +++ b/src/DTO/Documents/DocumentField.php @@ -1,6 +1,6 @@ current_page > 1; + } + + public function showNext(): bool + { + return $this->current_page < $this->last_page; + } + + public function successful(): bool + { + return is_null($this->error); + } + + public function failed(): bool + { + return ! $this->successful(); + } + + public static function fromJson( + array $data, + int $page, + int $perPage, + ): self { + $total = Arr::get($data, 'Count.Value'); + + $lastPage = (int) ceil($total / $perPage); + + $from = $page === 1 ? 1 : (($page - 1) * $perPage) + 1; + + $to = $page === $lastPage ? $total : $page * $perPage; + + $headers = collect(Arr::get($data, 'Headers')); + $documents = collect(Arr::get($data, 'Rows')); + + $mappedDocuments = $documents->map(function (array $document) use ($headers) { + $document = collect($document); + + return $document->mapWithKeys(function ($value, $key) use ($headers) { + $header = collect($headers->get($key)); + + return $header->has('FieldName') ? [$header->get('FieldName') => $value] : []; + })->filter(); + }); + + return new self( + total: $total, + per_page: $perPage, + current_page: $page, + last_page: $lastPage, + from: $from, + to: $to, + headers: $headers, + documents: $documents, + mappedDocuments: $mappedDocuments, + ); + } + + public static function fromFailed(Exception $e): self + { + return new self( + total: 0, + per_page: 0, + current_page: 0, + last_page: 0, + from: 0, + to: 0, + headers: collect(), + documents: collect(), + mappedDocuments: collect(), + error: ErrorBag::make($e), + ); + } + + public static function fake( + ?int $total = null, + ?int $per_page = null, + ?int $current_page = null, + ?int $last_page = null, + ?int $from = null, + ?int $to = null, + ?Collection $headers = null, + ?Collection $documents = null, + ?Collection $mappedDocuments = null, + ): self { + return new self( + total: $total ?? random_int(10, 100), + per_page: $per_page ?? 10, + current_page: $current_page ?? random_int(1, 10), + last_page: $last_page ?? random_int(10, 20), + from: $from ?? 1, + to: $to ?? 10, + headers: $headers, + documents: $documents, + mappedDocuments: $mappedDocuments, + ); + } +} diff --git a/src/DTO/FileCabinet.php b/src/DTO/FileCabinet.php deleted file mode 100644 index af6948eb..00000000 --- a/src/DTO/FileCabinet.php +++ /dev/null @@ -1,44 +0,0 @@ -after('(')->before(')'); + $startDateTime = Carbon::createFromTimestamp($startDateTime); + } + + if ($endDateTime = Arr::get($data, 'EndDateTime')) { + $endDateTime = Str::of($endDateTime)->after('(')->before(')'); + $endDateTime = Carbon::createFromTimestamp($endDateTime); + } + + return new self( + isOutOfOffice: Arr::get($data, 'IsOutOfOffice'), + startDateTime: $startDateTime, + startDateTimeSpecified: Arr::get($data, 'StartDateTimeSpecified'), + endDateTime: $endDateTime, + endDateTimeSpecified: Arr::get($data, 'EndDateTimeSpecified'), + ); + } + + public function __construct( + public bool $isOutOfOffice, + public ?Carbon $startDateTime, + public bool $startDateTimeSpecified, + public ?Carbon $endDateTime, + public bool $endDateTimeSpecified, + ) {} +} diff --git a/src/DTO/General/UserManagement/GetUsers/RegionalSettings.php b/src/DTO/General/UserManagement/GetUsers/RegionalSettings.php new file mode 100644 index 00000000..c926ee80 --- /dev/null +++ b/src/DTO/General/UserManagement/GetUsers/RegionalSettings.php @@ -0,0 +1,21 @@ +after('(')->before(')'); + $contentModifiedDateTime = Carbon::createFromTimestamp($contentModifiedDateTime); + } + return new self( id: Arr::get($data, 'Id'), contentType: Arr::get($data, 'ContentType'), @@ -15,7 +22,7 @@ public static function fromJson(array $data): self pageCount: Arr::get($data, 'PageCount'), fileSize: Arr::get($data, 'FileSize'), originalFileName: Arr::get($data, 'OriginalFileName'), - contentModified: Arr::get($data, 'ContentModified'), + contentModified: $contentModifiedDateTime, annotationsPreview: Arr::get($data, 'AnnotationsPreview'), hasTextAnnotations: Arr::get($data, 'HasTextAnnotations'), ); @@ -28,7 +35,7 @@ public function __construct( public int $pageCount, public int $fileSize, public string $originalFileName, - public string $contentModified, + public ?Carbon $contentModified, public bool $annotationsPreview, public ?bool $hasTextAnnotations = null, ) {} diff --git a/src/DTO/Workflow/HistoryStep.php b/src/DTO/Workflow/HistoryStep.php new file mode 100644 index 00000000..20a832ad --- /dev/null +++ b/src/DTO/Workflow/HistoryStep.php @@ -0,0 +1,37 @@ +after('(')->before(')'); + $stepDateTime = Carbon::createFromTimestamp($stepDateTime); + } + + return new self( + infoItem: collect(Arr::get($data, 'Info.Item')), + stepNumber: Arr::get($data, 'StepNumber'), + stepDate: $stepDateTime, + activityName: Arr::get($data, 'ActivityName'), + activityType: Arr::get($data, 'ActivityType'), + stepType: Arr::get($data, 'StepType'), + ); + } + + public function __construct( + public Collection $infoItem, + public int $stepNumber, + public Carbon $stepDate, + public string $activityName, + public string $activityType, + public string $stepType, + ) {} +} diff --git a/src/DTO/Workflow/InstanceHistory.php b/src/DTO/Workflow/InstanceHistory.php new file mode 100644 index 00000000..3ae14e0f --- /dev/null +++ b/src/DTO/Workflow/InstanceHistory.php @@ -0,0 +1,45 @@ +after('(')->before(')'); + $startDateTime = Carbon::createFromTimestamp($startDateTime); + } + + if ($historySteps = Arr::get($data, 'HistorySteps')) { + $historySteps = collect($historySteps)->map(fn (array $historyStep) => HistoryStep::fromJson($historyStep)); + } + + return new self( + id: Arr::get($data, 'Id'), + workflowId: Arr::get($data, 'WorkflowId'), + name: Arr::get($data, 'Name'), + version: Arr::get($data, 'Version'), + workflowRequest: Arr::get($data, 'WorkflowRequest'), + startedAt: $startDateTime, + docId: Arr::get($data, 'DocId'), + historySteps: $historySteps, + ); + } + + public function __construct( + public string $id, + public string $workflowId, + public string $name, + public int $version, + public bool $workflowRequest, + public Carbon $startedAt, + public string $docId, + public ?Collection $historySteps = null, + ) {} +} diff --git a/src/DocuWare.php b/src/DocuWare.php index 8dcf661a..59914ecd 100644 --- a/src/DocuWare.php +++ b/src/DocuWare.php @@ -2,90 +2,42 @@ namespace CodebarAg\DocuWare; -use CodebarAg\DocuWare\DTO\Cookie; -use CodebarAg\DocuWare\Events\DocuWareResponseLog; -use CodebarAg\DocuWare\Requests\Auth\GetLogoffRequest; -use CodebarAg\DocuWare\Requests\Auth\PostLoginRequest; -use CodebarAg\DocuWare\Support\Auth; -use CodebarAg\DocuWare\Support\EnsureValidCookie; -use CodebarAg\DocuWare\Support\EnsureValidCredentials; -use CodebarAg\DocuWare\Support\EnsureValidResponse; -use GuzzleHttp\Cookie\CookieJar; -use Saloon\Exceptions\InvalidResponseClassException; -use Saloon\Exceptions\PendingRequestException; +use CodebarAg\DocuWare\DTO\Authentication\OAuth\RequestToken as RequestTokenDto; +use CodebarAg\DocuWare\Requests\Authentication\OAuth\GetIdentityServiceConfiguration; +use CodebarAg\DocuWare\Requests\Authentication\OAuth\GetResponsibleIdentityService; +use CodebarAg\DocuWare\Requests\Authentication\OAuth\RequestTokenWithCredentials; class DocuWare { - /** - * @throws InvalidResponseClassException - * @throws \Throwable - * @throws \ReflectionException - * @throws PendingRequestException - */ - public function cookie(string $url, string $username, string $password, $rememberMe = false, $redirectToMyselfInCaseOfError = false, $licenseType = null): Cookie - { - $cookieJar = new CookieJar(); - - $request = new PostLoginRequest( - $url, - $username, - $password, - $rememberMe, - $redirectToMyselfInCaseOfError, - $licenseType); - - $request->config()->add('cookies', $cookieJar); - - $response = $request->send(); - - event(new DocuWareResponseLog($response)); - - EnsureValidResponse::from($response); - - return Cookie::make($cookieJar); - - } - - /** - * @throws InvalidResponseClassException - * @throws \Throwable - * @throws \ReflectionException - * @throws PendingRequestException - */ - public function login(): void - { - EnsureValidCredentials::check(); - // Checks if already logged in, if not, logs in - EnsureValidCookie::check(); - } - - /** - * @throws InvalidResponseClassException - * @throws \Throwable - * @throws \ReflectionException - * @throws PendingRequestException - */ - public function logout(): void - { - // SoloRequest - $request = new GetLogoffRequest(); - - $response = $request->send(); - - event(new DocuWareResponseLog($response)); - - Auth::forget(); - - $response->throw(); + public function getNewAuthenticationOAuthToken( + ?string $username = '', + ?string $password = '', + ?string $grantType = 'password', + ?string $clientId = 'docuware.platform.net.client' + ): RequestTokenDto { + $responsibleIdentityServiceResponse = (new GetResponsibleIdentityService)->send(); + + $identityServiceConfigurationResponse = (new GetIdentityServiceConfiguration( + identityServiceUrl: $responsibleIdentityServiceResponse->dto()->identityServiceUrl + ))->send(); + + $requestTokenResponse = (new RequestTokenWithCredentials( + tokenEndpoint: $identityServiceConfigurationResponse->dto()->tokenEndpoint, + username: $username, + password: $password, + clientId: $clientId, + ))->send(); + + return $requestTokenResponse->dto(); } public function searchRequestBuilder(): DocuWareSearchRequestBuilder { - return new DocuWareSearchRequestBuilder(); + return new DocuWareSearchRequestBuilder; } public function url(): DocuWareUrl { - return new DocuWareUrl(); + return new DocuWareUrl; } } diff --git a/src/DocuWareSearchRequestBuilder.php b/src/DocuWareSearchRequestBuilder.php index a347c1c7..0e70ee76 100644 --- a/src/DocuWareSearchRequestBuilder.php +++ b/src/DocuWareSearchRequestBuilder.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use CodebarAg\DocuWare\Exceptions\UnableToSearch; +use CodebarAg\DocuWare\Requests\Documents\DocumentsTrashBin\GetDocuments; use CodebarAg\DocuWare\Requests\Search\GetSearchRequest; use Illuminate\Support\Str; use Saloon\Exceptions\InvalidResponseClassException; @@ -31,6 +32,15 @@ class DocuWareSearchRequestBuilder protected array $usedDateOperators = []; + protected bool $trashBin = false; + + public function trashBin(): self + { + $this->trashBin = true; + + return $this; + } + public function fileCabinet(string $fileCabinetId): self { $this->fileCabinetId = $fileCabinetId; @@ -144,7 +154,7 @@ public function filterIn(string $name, mixed $values): self * @throws InvalidResponseClassException * @throws PendingRequestException */ - public function get(): GetSearchRequest + public function get(): GetSearchRequest|GetDocuments { $this->checkDateFilterRangeDivergence(); $this->restructureMonoDateFilterRange(); @@ -170,6 +180,17 @@ public function get(): GetSearchRequest ]; } + if ($this->trashBin) { + return new GetDocuments( + page: $this->page, + perPage: $this->perPage, + searchTerm: $this->searchTerm, + orderField: $this->orderField, + orderDirection: $this->orderDirection, + condition: $condition, + ); + } + return new GetSearchRequest( fileCabinetId: $this->fileCabinetId, dialogId: $this->dialogId, @@ -186,7 +207,7 @@ public function get(): GetSearchRequest protected function guard(): void { throw_if( - is_null($this->fileCabinetId), + is_null($this->fileCabinetId) && $this->trashBin === false, UnableToSearch::cabinetNotSet(), ); diff --git a/src/DocuWareServiceProvider.php b/src/DocuWareServiceProvider.php index face78e2..c221f2fd 100644 --- a/src/DocuWareServiceProvider.php +++ b/src/DocuWareServiceProvider.php @@ -2,7 +2,6 @@ namespace CodebarAg\DocuWare; -use CodebarAg\DocuWare\Commands\ListAuthCookie; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -12,7 +11,6 @@ public function configurePackage(Package $package): void { $package ->name('laravel-docuware') - ->hasConfigFile('laravel-docuware') - ->hasCommand(ListAuthCookie::class); + ->hasConfigFile('laravel-docuware'); } } diff --git a/src/Enums/DialogType.php b/src/Enums/DialogType.php new file mode 100644 index 00000000..517786f7 --- /dev/null +++ b/src/Enums/DialogType.php @@ -0,0 +1,13 @@ +url.'/DocuWare/Platform/Account/Logon'; - } - - protected function defaultBody(): array - { - return [ - 'UserName' => $this->username, - 'Password' => $this->password, - 'RememberMe' => $this->rememberMe, - 'RedirectToMyselfInCaseOfError' => $this->redirectToMyselfInCaseOfError, - 'LicenseType' => $this->licenseType, - ]; - } - - public function createDtoFromResponse(Response $response): Response - { - event(new DocuWareResponseLog($response)); - - EnsureValidResponse::from($response); - - return $response; - } -} diff --git a/src/Requests/Auth/PostLogonRequest.php b/src/Requests/Auth/PostLogonRequest.php deleted file mode 100644 index 7345c0dc..00000000 --- a/src/Requests/Auth/PostLogonRequest.php +++ /dev/null @@ -1,31 +0,0 @@ - config('laravel-docuware.credentials.username'), - 'Password' => config('laravel-docuware.credentials.password'), - 'RememberMe' => false, - 'RedirectToMyselfInCaseOfError' => false, - 'LicenseType' => null, - ]; - } -} diff --git a/src/Requests/Authentication/OAuth/GetIdentityServiceConfiguration.php b/src/Requests/Authentication/OAuth/GetIdentityServiceConfiguration.php new file mode 100644 index 00000000..b07a5425 --- /dev/null +++ b/src/Requests/Authentication/OAuth/GetIdentityServiceConfiguration.php @@ -0,0 +1,56 @@ +identityServiceUrl.'/.well-known/openid-configuration'; + } + + public function defaultHeaders(): array + { + return [ + 'Accept' => 'application/json', + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): IdentityServiceConfiguration + { + event(new DocuWareResponseLog($response)); + + EnsureValidResponse::from($response); + + return IdentityServiceConfiguration::make($response->json()); + } +} diff --git a/src/Requests/Authentication/OAuth/GetResponsibleIdentityService.php b/src/Requests/Authentication/OAuth/GetResponsibleIdentityService.php new file mode 100644 index 00000000..08aad971 --- /dev/null +++ b/src/Requests/Authentication/OAuth/GetResponsibleIdentityService.php @@ -0,0 +1,49 @@ + 'application/json', + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): ResponsibleIdentityService + { + return GetResponsibleIdentityServiceResponse::fromResponse($response); + } +} diff --git a/src/Requests/Authentication/OAuth/RequestTokenWithCredentials.php b/src/Requests/Authentication/OAuth/RequestTokenWithCredentials.php new file mode 100644 index 00000000..01bd572d --- /dev/null +++ b/src/Requests/Authentication/OAuth/RequestTokenWithCredentials.php @@ -0,0 +1,54 @@ +tokenEndpoint; + } + + public function defaultHeaders(): array + { + return [ + 'Accept' => 'application/json', + ]; + } + + public function defaultBody(): array + { + return [ + 'grant_type' => 'password', + 'scope' => $this->scope, + 'client_id' => $this->clientId, + 'username' => filled($this->username) ? $this->username : config('laravel-docuware.credentials.username'), + 'password' => filled($this->password) ? $this->password : config('laravel-docuware.credentials.password'), + ]; + } + + public function createDtoFromResponse(Response $response): RequestTokenDto + { + return RequestTokenResponse::fromResponse($response); + } +} diff --git a/src/Requests/Authentication/OAuth/RequestTokenWithCredentialsTrustedUser.php b/src/Requests/Authentication/OAuth/RequestTokenWithCredentialsTrustedUser.php new file mode 100644 index 00000000..ef4d65f6 --- /dev/null +++ b/src/Requests/Authentication/OAuth/RequestTokenWithCredentialsTrustedUser.php @@ -0,0 +1,56 @@ +tokenEndpoint; + } + + public function defaultHeaders(): array + { + return [ + 'Accept' => 'application/json', + ]; + } + + public function defaultBody(): array + { + return [ + 'grant_type' => 'trusted', + 'scope' => $this->scope, + 'client_id' => $this->clientId, + 'username' => $this->username, + 'password' => $this->password, + 'impersonateName' => $this->impersonateName, + ]; + } + + public function createDtoFromResponse(Response $response): RequestTokenDto + { + return RequestTokenResponse::fromResponse($response); + } +} diff --git a/src/Requests/Document/GetDocumentsDownloadRequest.php b/src/Requests/Document/GetDocumentsDownloadRequest.php deleted file mode 100644 index 0653cd30..00000000 --- a/src/Requests/Document/GetDocumentsDownloadRequest.php +++ /dev/null @@ -1,64 +0,0 @@ -documentId = Arr::get($documentIds, 0); - $this->documentIds = array_slice($documentIds, 1); - } - - public function resolveEndpoint(): string - { - return '/FileCabinets/'.$this->fileCabinetId.'/Documents/'.$this->documentId.'/FileDownload'; - } - - public function resolveCacheDriver(): LaravelCacheDriver - { - return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); - } - - public function cacheExpiryInSeconds(): int - { - return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); - } - - public function defaultQuery(): array - { - return [ - 'keepAnnotations' => 'false', - 'append' => implode(',', $this->documentIds), - ]; - } - - public function createDtoFromResponse(Response $response): string - { - return GetDocumentsDownloadResponse::fromResponse($response); - } -} diff --git a/src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php b/src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php new file mode 100644 index 00000000..40fd9b7b --- /dev/null +++ b/src/Requests/Documents/ApplicationProperties/AddApplicationProperties.php @@ -0,0 +1,55 @@ +fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties'; + } + + public function defaultBody() + { + return [ + 'DocumentApplicationProperty' => $this->properties, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetApplicationPropertiesResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php b/src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php new file mode 100644 index 00000000..67d1c4f6 --- /dev/null +++ b/src/Requests/Documents/ApplicationProperties/DeleteApplicationProperties.php @@ -0,0 +1,62 @@ +fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties'; + } + + public function defaultBody() + { + $props = collect($this->propertyNames)->map(function ($name) { + return [ + 'Name' => $name, + 'Value' => null, + ]; + }); + + return [ + 'DocumentApplicationProperty' => $props, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetApplicationPropertiesResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ApplicationProperties/GetApplicationProperties.php b/src/Requests/Documents/ApplicationProperties/GetApplicationProperties.php new file mode 100644 index 00000000..03330bab --- /dev/null +++ b/src/Requests/Documents/ApplicationProperties/GetApplicationProperties.php @@ -0,0 +1,44 @@ +fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties'; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetApplicationPropertiesResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php b/src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php new file mode 100644 index 00000000..44ac8039 --- /dev/null +++ b/src/Requests/Documents/ApplicationProperties/UpdateApplicationProperties.php @@ -0,0 +1,55 @@ +fileCabinetId.'/Documents/'.$this->documentId.'/DocumentApplicationProperties'; + } + + public function defaultBody() + { + return [ + 'DocumentApplicationProperty' => $this->properties, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetApplicationPropertiesResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ClipUnclipStapleUnstaple/Clip.php b/src/Requests/Documents/ClipUnclipStapleUnstaple/Clip.php new file mode 100644 index 00000000..52cd9f52 --- /dev/null +++ b/src/Requests/Documents/ClipUnclipStapleUnstaple/Clip.php @@ -0,0 +1,43 @@ +documentTrayId.'/Operations/ContentMerge'; + } + + public function defaultBody(): array + { + return [ + 'Documents' => $this->documents, + 'Operation' => 'Clip', + 'Force' => $this->force, + ]; + } + + public function createDtoFromResponse(Response $response): Document + { + return GetASpecificDocumentFromAFileCabinetResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ClipUnclipStapleUnstaple/Staple.php b/src/Requests/Documents/ClipUnclipStapleUnstaple/Staple.php new file mode 100644 index 00000000..f3f86651 --- /dev/null +++ b/src/Requests/Documents/ClipUnclipStapleUnstaple/Staple.php @@ -0,0 +1,43 @@ +documentTrayId.'/Operations/ContentMerge'; + } + + public function defaultBody(): array + { + return [ + 'Documents' => $this->documents, + 'Operation' => 'Staple', + 'Force' => $this->force, + ]; + } + + public function createDtoFromResponse(Response $response): Document + { + return GetASpecificDocumentFromAFileCabinetResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ClipUnclipStapleUnstaple/Unclip.php b/src/Requests/Documents/ClipUnclipStapleUnstaple/Unclip.php new file mode 100644 index 00000000..352df770 --- /dev/null +++ b/src/Requests/Documents/ClipUnclipStapleUnstaple/Unclip.php @@ -0,0 +1,47 @@ +documentTrayId.'/Operations/ContentDivide'; + } + + public function defaultQuery(): array + { + return [ + 'DocId' => $this->documentId, + ]; + } + + public function defaultBody(): array + { + return [ + 'Operation' => 'Unclip', + ]; + } + + public function createDtoFromResponse(Response $response): DocumentPaginator + { + return GetDocumentsFromAFileCabinetResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/ClipUnclipStapleUnstaple/Unstaple.php b/src/Requests/Documents/ClipUnclipStapleUnstaple/Unstaple.php new file mode 100644 index 00000000..7d4f861c --- /dev/null +++ b/src/Requests/Documents/ClipUnclipStapleUnstaple/Unstaple.php @@ -0,0 +1,47 @@ +documentTrayId.'/Operations/ContentDivide'; + } + + public function defaultQuery(): array + { + return [ + 'DocId' => $this->documentId, + ]; + } + + public function defaultBody(): array + { + return [ + 'Operation' => 'Unstaple', + ]; + } + + public function createDtoFromResponse(Response $response): DocumentPaginator + { + return GetDocumentsFromAFileCabinetResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/DocumentsTrashBin/DeleteDocuments.php b/src/Requests/Documents/DocumentsTrashBin/DeleteDocuments.php new file mode 100644 index 00000000..e935c1e3 --- /dev/null +++ b/src/Requests/Documents/DocumentsTrashBin/DeleteDocuments.php @@ -0,0 +1,40 @@ + $this->ids instanceof Collection ? $this->ids->toArray() : $this->ids, + ]; + } + + public function createDtoFromResponse(Response $response): DeleteDocumentsDto + { + return DeleteDocumentsResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/DocumentsTrashBin/GetDocuments.php b/src/Requests/Documents/DocumentsTrashBin/GetDocuments.php new file mode 100644 index 00000000..71466142 --- /dev/null +++ b/src/Requests/Documents/DocumentsTrashBin/GetDocuments.php @@ -0,0 +1,72 @@ + $this->perPage, + 'Start' => ($this->page - 1) * $this->perPage, + 'Condition' => $this->condition, + 'SortOrder' => $this->orderField ? [ + [ + 'Field' => $this->orderField, + 'Direction' => $this->orderDirection, + ], + ] : null, + 'Operation' => config('laravel-docuware.configurations.search.operation', 'And'), + 'ForceRefresh' => config('laravel-docuware.configurations.search.force_refresh', true), + 'IncludeSuggestions' => config('laravel-docuware.configurations.search.include_suggestions', false), + 'AdditionalResultFields' => config('laravel-docuware.configurations.search.additional_result_fields', []), + ]; + } + + public function createDtoFromResponse(Response $response): TrashDocumentPaginator + { + return GetTrashSearchResponse::fromResponse($response, $this->page, $this->perPage); + } +} diff --git a/src/Requests/Documents/DocumentsTrashBin/RestoreDocuments.php b/src/Requests/Documents/DocumentsTrashBin/RestoreDocuments.php new file mode 100644 index 00000000..33b29adc --- /dev/null +++ b/src/Requests/Documents/DocumentsTrashBin/RestoreDocuments.php @@ -0,0 +1,40 @@ + $this->ids instanceof Collection ? $this->ids->toArray() : $this->ids, + ]; + } + + public function createDtoFromResponse(Response $response): RestoreDocumentsDto + { + return RestoreDocumentsResponse::fromResponse($response); + } +} diff --git a/src/Requests/Document/GetDocumentDownloadRequest.php b/src/Requests/Documents/Download/DownloadDocument.php similarity index 74% rename from src/Requests/Document/GetDocumentDownloadRequest.php rename to src/Requests/Documents/Download/DownloadDocument.php index faa705e8..662b0ade 100644 --- a/src/Requests/Document/GetDocumentDownloadRequest.php +++ b/src/Requests/Documents/Download/DownloadDocument.php @@ -1,8 +1,8 @@ fileCabinetId.'/Sections/'.$this->sectionId.'/Data'; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return DownloadSectionResponse::fromResponse($response); + } +} diff --git a/src/Requests/Document/Thumbnail/GetDocumentDownloadThumbnailRequest.php b/src/Requests/Documents/Download/DownloadThumbnail.php similarity index 74% rename from src/Requests/Document/Thumbnail/GetDocumentDownloadThumbnailRequest.php rename to src/Requests/Documents/Download/DownloadThumbnail.php index ebc8601c..5dc5afe8 100644 --- a/src/Requests/Document/Thumbnail/GetDocumentDownloadThumbnailRequest.php +++ b/src/Requests/Documents/Download/DownloadThumbnail.php @@ -1,8 +1,8 @@ fileCabinetId.'/Rendering/'.$this->thumbnailId.'/Thumbnail'; + return '/FileCabinets/'.$this->fileCabinetId.'/Rendering/'.$this->sectionId.'/Thumbnail'; } public function resolveCacheDriver(): LaravelCacheDriver @@ -47,6 +47,6 @@ public function defaultQuery(): array public function createDtoFromResponse(Response $response): mixed { - return GetDocumentDownloadThumbnailResponse::fromResponse($response); + return DownloadThumbnailResponse::fromResponse($response); } } diff --git a/src/Requests/Document/GetDocumentPreviewRequest.php b/src/Requests/Documents/GetDocumentPreviewRequest.php similarity index 90% rename from src/Requests/Document/GetDocumentPreviewRequest.php rename to src/Requests/Documents/GetDocumentPreviewRequest.php index 778df9fa..e099ea31 100644 --- a/src/Requests/Document/GetDocumentPreviewRequest.php +++ b/src/Requests/Documents/GetDocumentPreviewRequest.php @@ -1,8 +1,8 @@ fileCabinetId.'/Sections/'.$this->sectionId; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): bool + { + return DeleteSectionResponse::fromResponse($response); + } +} diff --git a/src/Requests/Documents/Sections/GetASpecificSection.php b/src/Requests/Documents/Sections/GetASpecificSection.php new file mode 100644 index 00000000..840c1d21 --- /dev/null +++ b/src/Requests/Documents/Sections/GetASpecificSection.php @@ -0,0 +1,45 @@ +fileCabinetId.'/Sections/'.$this->sectionId; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Section + { + return GetASecificSectionResponse::fromResponse($response); + } +} diff --git a/src/Requests/Sections/GetSectionsRequest.php b/src/Requests/Documents/Sections/GetAllSectionsFromADocument.php similarity index 77% rename from src/Requests/Sections/GetSectionsRequest.php rename to src/Requests/Documents/Sections/GetAllSectionsFromADocument.php index 06d96a9d..eb106e3b 100644 --- a/src/Requests/Sections/GetSectionsRequest.php +++ b/src/Requests/Documents/Sections/GetAllSectionsFromADocument.php @@ -1,8 +1,8 @@ fileCabinetId.'/Dialogs'; + } + + public function defaultQuery(): array + { + return [ + 'DialogType' => $this->dialogType->value, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetAllDialogsResponse::fromResponse($response); + } +} diff --git a/src/Requests/Organization/GetOrganizationRequest.php b/src/Requests/FileCabinets/General/GetFileCabinetInformation.php similarity index 58% rename from src/Requests/Organization/GetOrganizationRequest.php rename to src/Requests/FileCabinets/General/GetFileCabinetInformation.php index d67d290f..9ab5021c 100644 --- a/src/Requests/Organization/GetOrganizationRequest.php +++ b/src/Requests/FileCabinets/General/GetFileCabinetInformation.php @@ -1,9 +1,9 @@ organizationId; + return '/FileCabinets/'.$this->fileCabinetId; } public function resolveCacheDriver(): LaravelCacheDriver @@ -37,8 +37,8 @@ public function cacheExpiryInSeconds(): int return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); } - public function createDtoFromResponse(Response $response): Organization + public function createDtoFromResponse(Response $response): FileCabinetInformation { - return GetOrganizationResponse::fromResponse($response); + return GetFileCabinetInformationResponse::fromResponse($response); } } diff --git a/src/Requests/Document/GetDocumentCountRequest.php b/src/Requests/FileCabinets/General/GetTotalNumberOfDocuments.php similarity index 72% rename from src/Requests/Document/GetDocumentCountRequest.php rename to src/Requests/FileCabinets/General/GetTotalNumberOfDocuments.php index ac35c47c..a1fcfb2b 100644 --- a/src/Requests/Document/GetDocumentCountRequest.php +++ b/src/Requests/FileCabinets/General/GetTotalNumberOfDocuments.php @@ -1,8 +1,8 @@ fileCabinetId.'/Query/CountExpression'; } + public function defaultQuery(): array + { + return [ + 'DialogId' => $this->searchDialogId, + ]; + } + public function resolveCacheDriver(): LaravelCacheDriver { return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); @@ -37,15 +44,8 @@ public function cacheExpiryInSeconds(): int return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); } - public function defaultQuery(): array - { - return [ - 'dialogId' => $this->dialogId, - ]; - } - public function createDtoFromResponse(Response $response): int { - return GetDocumentCountResponse::fromResponse($response); + return GetTotalNumberOfDocumentsResponse::fromResponse($response); } } diff --git a/src/Requests/Document/GetDocumentRequest.php b/src/Requests/FileCabinets/Search/GetASpecificDocumentFromAFileCabinet.php similarity index 73% rename from src/Requests/Document/GetDocumentRequest.php rename to src/Requests/FileCabinets/Search/GetASpecificDocumentFromAFileCabinet.php index 0c4c6120..85ef4c4b 100644 --- a/src/Requests/Document/GetDocumentRequest.php +++ b/src/Requests/FileCabinets/Search/GetASpecificDocumentFromAFileCabinet.php @@ -1,9 +1,9 @@ filled($this->fields) ? implode(',', $this->fields) : null, 'count' => $this->perPage, 'start' => ($this->page - 1) * $this->perPage, ]; @@ -49,6 +51,6 @@ public function cacheExpiryInSeconds(): int public function createDtoFromResponse(Response $response): DocumentPaginator { - return GetDocumentsResponse::fromResponse($response, $this->page, $this->perPage); + return GetDocumentsFromAFileCabinetResponse::fromResponse($response, $this->page, $this->perPage); } } diff --git a/src/Requests/FileCabinets/SelectLists/GetFilteredSelectLists.php b/src/Requests/FileCabinets/SelectLists/GetFilteredSelectLists.php new file mode 100644 index 00000000..df675a80 --- /dev/null +++ b/src/Requests/FileCabinets/SelectLists/GetFilteredSelectLists.php @@ -0,0 +1,53 @@ +fileCabinetId.'/Query/SelectListExpression'; + } + + public function defaultQuery(): array + { + return [ + 'DialogId' => $this->dialogId, + 'FieldName' => $this->fieldName, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): mixed + { + return GetSelectListsResponse::fromResponse($response); + } +} diff --git a/src/Requests/SelectList/GetSelectListRequest.php b/src/Requests/FileCabinets/SelectLists/GetSelectLists.php similarity index 76% rename from src/Requests/SelectList/GetSelectListRequest.php rename to src/Requests/FileCabinets/SelectLists/GetSelectLists.php index d31ffe72..7b70a4cb 100644 --- a/src/Requests/SelectList/GetSelectListRequest.php +++ b/src/Requests/FileCabinets/SelectLists/GetSelectLists.php @@ -1,8 +1,8 @@ fileCabinetId.'/Query/SelectListExpression'; } + public function defaultQuery(): array + { + return [ + 'DialogId' => $this->dialogId, + 'FieldName' => $this->fieldName, + ]; + } + public function resolveCacheDriver(): LaravelCacheDriver { return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); @@ -38,16 +46,8 @@ public function cacheExpiryInSeconds(): int return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); } - public function defaultQuery(): array - { - return [ - 'dialogId' => $this->dialogId, - 'fieldName' => $this->fieldName, - ]; - } - public function createDtoFromResponse(Response $response): mixed { - return GetSelectListResponse::fromResponse($response); + return GetSelectListsResponse::fromResponse($response); } } diff --git a/src/Requests/FileCabinets/Upload/AppendFilesToADataRecord.php b/src/Requests/FileCabinets/Upload/AppendFilesToADataRecord.php new file mode 100644 index 00000000..6fb25a87 --- /dev/null +++ b/src/Requests/FileCabinets/Upload/AppendFilesToADataRecord.php @@ -0,0 +1,40 @@ +fileCabinetId.'/Documents/'.$this->dataRecordId; + } + + protected function defaultBody(): array + { + return $this->files->toArray(); + } + + public function createDtoFromResponse(Response $response): Document + { + return CreateDataRecordResponse::fromResponse($response); + } +} diff --git a/src/Requests/Document/PostDocumentRequest.php b/src/Requests/FileCabinets/Upload/CreateDataRecord.php similarity index 77% rename from src/Requests/Document/PostDocumentRequest.php rename to src/Requests/FileCabinets/Upload/CreateDataRecord.php index 28fa506b..fb44e8a6 100644 --- a/src/Requests/Document/PostDocumentRequest.php +++ b/src/Requests/FileCabinets/Upload/CreateDataRecord.php @@ -1,10 +1,10 @@ $this->organizationId, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Collection|Enumerable + { + return GetAllFileCabinetsAndDocumentTraysResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/Organization/GetLoginToken.php b/src/Requests/General/Organization/GetLoginToken.php new file mode 100644 index 00000000..12f65fb6 --- /dev/null +++ b/src/Requests/General/Organization/GetLoginToken.php @@ -0,0 +1,57 @@ + $this->targetProducts, + 'Usage' => $this->usage, + 'Lifetime' => $this->lifetime, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): string + { + return RequestLoginTokenResponse::fromResponse($response); + } +} diff --git a/src/Requests/Organization/GetOrganizationsRequest.php b/src/Requests/General/Organization/GetOrganization.php similarity index 77% rename from src/Requests/Organization/GetOrganizationsRequest.php rename to src/Requests/General/Organization/GetOrganization.php index 21872337..1518ebb8 100644 --- a/src/Requests/Organization/GetOrganizationsRequest.php +++ b/src/Requests/General/Organization/GetOrganization.php @@ -1,8 +1,8 @@ 'application/vnd.docuware.platform.createorganizationuser+json', + ]; + } + + protected function defaultBody(): array + { + return [ + 'Name' => $this->user->name, + 'DbName' => $this->user->dbName, + 'Email' => $this->user->email, + 'NetworkId' => $this->user->networkId, + 'Password' => $this->user->password, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): GetUser + { + return GetUserResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/CreateUpdateUsers/UpdateUser.php b/src/Requests/General/UserManagement/CreateUpdateUsers/UpdateUser.php new file mode 100644 index 00000000..2d06e910 --- /dev/null +++ b/src/Requests/General/UserManagement/CreateUpdateUsers/UpdateUser.php @@ -0,0 +1,72 @@ + 'application/json', + ]; + } + + protected function defaultBody(): array + { + return [ + 'Id' => $this->user->id, + 'Active' => $this->user->active, + 'FirstName' => $this->user->firstName, + 'LastName' => $this->user->lastName, + 'Salutation' => $this->user->salutation, + 'Name' => $this->user->name, + 'Email' => $this->user->email, + 'OutOfOffice' => [ + 'IsOutOfOffice' => $this->user->outOfOffice->isOutOfOffice, + 'StartDateTime' => $this->user->outOfOffice->startDateTime?->toISOString(), + 'EndDateTime' => $this->user->outOfOffice->endDateTime?->toISOString(), + ], + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): User + { + return GetUserResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetModifyGroups/AddUserToAGroup.php b/src/Requests/General/UserManagement/GetModifyGroups/AddUserToAGroup.php new file mode 100644 index 00000000..00db60de --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyGroups/AddUserToAGroup.php @@ -0,0 +1,52 @@ + $this->userId, + ]; + } + + protected function defaultBody(): array + { + return [ + 'Ids' => $this->ids, + 'OperationType' => 'Add', + ]; + } + + public function createDtoFromResponse(Response $response): Response + { + event(new DocuWareResponseLog($response)); + + EnsureValidResponse::from($response); + + return $response; + } +} diff --git a/src/Requests/General/UserManagement/GetModifyGroups/GetAllGroupsForASpecificUser.php b/src/Requests/General/UserManagement/GetModifyGroups/GetAllGroupsForASpecificUser.php new file mode 100644 index 00000000..7d3812b7 --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyGroups/GetAllGroupsForASpecificUser.php @@ -0,0 +1,56 @@ + $this->userId, + 'Name' => $this->name, + 'Active' => $this->active, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Enumerable|Collection + { + return GetGroupsResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetModifyGroups/GetGroups.php b/src/Requests/General/UserManagement/GetModifyGroups/GetGroups.php new file mode 100644 index 00000000..bfcb872f --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyGroups/GetGroups.php @@ -0,0 +1,54 @@ + $this->name, + 'Active' => $this->active, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Enumerable|Collection + { + return GetGroupsResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetModifyGroups/RemoveUserFromAGroup.php b/src/Requests/General/UserManagement/GetModifyGroups/RemoveUserFromAGroup.php new file mode 100644 index 00000000..a1a04cf6 --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyGroups/RemoveUserFromAGroup.php @@ -0,0 +1,52 @@ + $this->userId, + ]; + } + + protected function defaultBody(): array + { + return [ + 'Ids' => $this->ids, + 'OperationType' => 'Remove', + ]; + } + + public function createDtoFromResponse(Response $response): Response + { + event(new DocuWareResponseLog($response)); + + EnsureValidResponse::from($response); + + return $response; + } +} diff --git a/src/Requests/General/UserManagement/GetModifyRoles/AddUserToARole.php b/src/Requests/General/UserManagement/GetModifyRoles/AddUserToARole.php new file mode 100644 index 00000000..f61095b2 --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyRoles/AddUserToARole.php @@ -0,0 +1,52 @@ + $this->userId, + ]; + } + + protected function defaultBody(): array + { + return [ + 'Ids' => $this->ids, + 'OperationType' => 'Add', + ]; + } + + public function createDtoFromResponse(Response $response): Response + { + event(new DocuWareResponseLog($response)); + + EnsureValidResponse::from($response); + + return $response; + } +} diff --git a/src/Requests/General/UserManagement/GetModifyRoles/GetAllRolesForASpecificUser.php b/src/Requests/General/UserManagement/GetModifyRoles/GetAllRolesForASpecificUser.php new file mode 100644 index 00000000..5d2b70ba --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyRoles/GetAllRolesForASpecificUser.php @@ -0,0 +1,58 @@ + $this->userId, + 'Name' => $this->name, + 'Active' => $this->active, + 'Type' => $this->type, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Enumerable|Collection + { + return GetRolesResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetModifyRoles/GetRoles.php b/src/Requests/General/UserManagement/GetModifyRoles/GetRoles.php new file mode 100644 index 00000000..961b2518 --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyRoles/GetRoles.php @@ -0,0 +1,56 @@ + $this->name, + 'Active' => $this->active, + 'Type' => $this->type, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Enumerable|Collection + { + return GetRolesResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetModifyRoles/RemoveUserFromARole.php b/src/Requests/General/UserManagement/GetModifyRoles/RemoveUserFromARole.php new file mode 100644 index 00000000..abc7cf73 --- /dev/null +++ b/src/Requests/General/UserManagement/GetModifyRoles/RemoveUserFromARole.php @@ -0,0 +1,52 @@ + $this->userId, + ]; + } + + protected function defaultBody(): array + { + return [ + 'Ids' => $this->ids, + 'OperationType' => 'Remove', + ]; + } + + public function createDtoFromResponse(Response $response): Response + { + event(new DocuWareResponseLog($response)); + + EnsureValidResponse::from($response); + + return $response; + } +} diff --git a/src/Requests/General/UserManagement/GetUsers/GetUserById.php b/src/Requests/General/UserManagement/GetUsers/GetUserById.php new file mode 100644 index 00000000..c48fd1af --- /dev/null +++ b/src/Requests/General/UserManagement/GetUsers/GetUserById.php @@ -0,0 +1,51 @@ + $this->userId, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): User + { + return GetUserResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetUsers/GetUsers.php b/src/Requests/General/UserManagement/GetUsers/GetUsers.php new file mode 100644 index 00000000..5645dc09 --- /dev/null +++ b/src/Requests/General/UserManagement/GetUsers/GetUsers.php @@ -0,0 +1,54 @@ + $this->name, + 'Active' => $this->active, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Enumerable|Collection + { + return GetUsersResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetUsers/GetUsersOfAGroup.php b/src/Requests/General/UserManagement/GetUsers/GetUsersOfAGroup.php new file mode 100644 index 00000000..753ae7b5 --- /dev/null +++ b/src/Requests/General/UserManagement/GetUsers/GetUsersOfAGroup.php @@ -0,0 +1,52 @@ + $this->groupId, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Enumerable|Collection + { + return GetUsersResponse::fromResponse($response); + } +} diff --git a/src/Requests/General/UserManagement/GetUsers/GetUsersOfARole.php b/src/Requests/General/UserManagement/GetUsers/GetUsersOfARole.php new file mode 100644 index 00000000..217cfd2a --- /dev/null +++ b/src/Requests/General/UserManagement/GetUsers/GetUsersOfARole.php @@ -0,0 +1,54 @@ + $this->roleId, + 'IncludeGroupUsers' => $this->includeGroupUsers, + ]; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): Enumerable|Collection + { + return GetUsersResponse::fromResponse($response); + } +} diff --git a/src/Requests/Search/GetSearchRequest.php b/src/Requests/Search/GetSearchRequest.php index f4df557f..2438c00f 100644 --- a/src/Requests/Search/GetSearchRequest.php +++ b/src/Requests/Search/GetSearchRequest.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Requests\Search; -use CodebarAg\DocuWare\DTO\DocumentPaginator; +use CodebarAg\DocuWare\DTO\Documents\DocumentPaginator; use CodebarAg\DocuWare\Responses\Search\GetSearchResponse; use Illuminate\Support\Facades\Cache; use Saloon\CachePlugin\Contracts\Cacheable; diff --git a/src/Requests/FileCabinets/GetFileCabinetsRequest.php b/src/Requests/Workflow/GetDocumentWorkflowHistory.php similarity index 61% rename from src/Requests/FileCabinets/GetFileCabinetsRequest.php rename to src/Requests/Workflow/GetDocumentWorkflowHistory.php index 3fbef5af..e3fd08e7 100644 --- a/src/Requests/FileCabinets/GetFileCabinetsRequest.php +++ b/src/Requests/Workflow/GetDocumentWorkflowHistory.php @@ -1,10 +1,9 @@ fileCabinetId.'/Documents/'.$this->documentId.'/WorkflowHistory'; } public function resolveCacheDriver(): LaravelCacheDriver @@ -34,8 +38,8 @@ public function cacheExpiryInSeconds(): int return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); } - public function createDtoFromResponse(Response $response): Collection|Enumerable + public function createDtoFromResponse(Response $response): Collection { - return GetFileCabinetsResponse::fromResponse($response); + return GetDocumentWorkflowHistoryResponse::fromResponse($response); } } diff --git a/src/Requests/Workflow/GetDocumentWorkflowHistorySteps.php b/src/Requests/Workflow/GetDocumentWorkflowHistorySteps.php new file mode 100644 index 00000000..47992123 --- /dev/null +++ b/src/Requests/Workflow/GetDocumentWorkflowHistorySteps.php @@ -0,0 +1,45 @@ +workflowId.'/Instances/'.$this->workflowInstanceId.'/History'; + } + + public function resolveCacheDriver(): LaravelCacheDriver + { + return new LaravelCacheDriver(Cache::store(config('laravel-docuware.configurations.cache.driver'))); + } + + public function cacheExpiryInSeconds(): int + { + return config('laravel-docuware.configurations.cache.lifetime_in_seconds', 3600); + } + + public function createDtoFromResponse(Response $response): InstanceHistory + { + return GetDocumentWorkflowHistoryStepsResponse::fromResponse($response); + } +} diff --git a/src/Responses/Authentication/OAuth/GetResponsibleIdentityServiceResponse.php b/src/Responses/Authentication/OAuth/GetResponsibleIdentityServiceResponse.php new file mode 100644 index 00000000..abf4cbe5 --- /dev/null +++ b/src/Responses/Authentication/OAuth/GetResponsibleIdentityServiceResponse.php @@ -0,0 +1,20 @@ +json()); + } +} diff --git a/src/Responses/Authentication/OAuth/RequestTokenResponse.php b/src/Responses/Authentication/OAuth/RequestTokenResponse.php new file mode 100644 index 00000000..c5fc13c7 --- /dev/null +++ b/src/Responses/Authentication/OAuth/RequestTokenResponse.php @@ -0,0 +1,20 @@ +json()); + } +} diff --git a/src/Responses/Documents/ApplicationProperties/GetApplicationPropertiesResponse.php b/src/Responses/Documents/ApplicationProperties/GetApplicationPropertiesResponse.php new file mode 100644 index 00000000..35d9184c --- /dev/null +++ b/src/Responses/Documents/ApplicationProperties/GetApplicationPropertiesResponse.php @@ -0,0 +1,19 @@ +throw()->json('DocumentApplicationProperty')); + } +} diff --git a/src/Responses/Documents/DocumentsTrashBin/DeleteDocumentsResponse.php b/src/Responses/Documents/DocumentsTrashBin/DeleteDocumentsResponse.php new file mode 100644 index 00000000..083babd6 --- /dev/null +++ b/src/Responses/Documents/DocumentsTrashBin/DeleteDocumentsResponse.php @@ -0,0 +1,20 @@ +throw()->json()); + } +} diff --git a/src/Responses/Documents/DocumentsTrashBin/RestoreDocumentsResponse.php b/src/Responses/Documents/DocumentsTrashBin/RestoreDocumentsResponse.php new file mode 100644 index 00000000..bce11346 --- /dev/null +++ b/src/Responses/Documents/DocumentsTrashBin/RestoreDocumentsResponse.php @@ -0,0 +1,20 @@ +throw()->json()); + } +} diff --git a/src/Responses/Documents/Download/DownloadDocumentResponse.php b/src/Responses/Documents/Download/DownloadDocumentResponse.php new file mode 100644 index 00000000..a29dd49d --- /dev/null +++ b/src/Responses/Documents/Download/DownloadDocumentResponse.php @@ -0,0 +1,19 @@ +throw()->body(); + } +} diff --git a/src/Responses/Document/GetDocumentsDownloadResponse.php b/src/Responses/Documents/Download/DownloadSectionResponse.php similarity index 64% rename from src/Responses/Document/GetDocumentsDownloadResponse.php rename to src/Responses/Documents/Download/DownloadSectionResponse.php index d7891c7b..e03d6000 100644 --- a/src/Responses/Document/GetDocumentsDownloadResponse.php +++ b/src/Responses/Documents/Download/DownloadSectionResponse.php @@ -1,14 +1,14 @@ status() === 200; + } +} diff --git a/src/Responses/Documents/Sections/GetASecificSectionResponse.php b/src/Responses/Documents/Sections/GetASecificSectionResponse.php new file mode 100644 index 00000000..b8ea3365 --- /dev/null +++ b/src/Responses/Documents/Sections/GetASecificSectionResponse.php @@ -0,0 +1,20 @@ +throw()->json()); + } +} diff --git a/src/Responses/Sections/GetSectionsResponse.php b/src/Responses/Documents/Sections/GetAllSectionsFromADocumentResponse.php similarity index 59% rename from src/Responses/Sections/GetSectionsResponse.php rename to src/Responses/Documents/Sections/GetAllSectionsFromADocumentResponse.php index 192f113c..8388ffb5 100644 --- a/src/Responses/Sections/GetSectionsResponse.php +++ b/src/Responses/Documents/Sections/GetAllSectionsFromADocumentResponse.php @@ -1,6 +1,6 @@ throw()->json(); - - $sections = collect(); - - foreach ($res['Section'] as $section) { - $sections->push(Section::fromJson($section)); - } - - return $sections; + return collect($response->throw()->json('Section'))->map(fn ($section) => Section::fromJson($section)); } } diff --git a/src/Responses/Document/PutDocumentFieldsResponse.php b/src/Responses/Documents/UpdateIndexValues/UpdateIndexValuesResponse.php similarity index 85% rename from src/Responses/Document/PutDocumentFieldsResponse.php rename to src/Responses/Documents/UpdateIndexValues/UpdateIndexValuesResponse.php index b1e7937f..912e998c 100644 --- a/src/Responses/Document/PutDocumentFieldsResponse.php +++ b/src/Responses/Documents/UpdateIndexValues/UpdateIndexValuesResponse.php @@ -1,6 +1,6 @@ throw()->json(); + + return FileCabinetInformation::fromJson($cabinet); + } +} diff --git a/src/Responses/Document/GetDocumentCountResponse.php b/src/Responses/FileCabinets/General/GetTotalNumberOfDocumentsResponse.php similarity index 88% rename from src/Responses/Document/GetDocumentCountResponse.php rename to src/Responses/FileCabinets/General/GetTotalNumberOfDocumentsResponse.php index 6c97d7a7..6fd2f0d5 100644 --- a/src/Responses/Document/GetDocumentCountResponse.php +++ b/src/Responses/FileCabinets/General/GetTotalNumberOfDocumentsResponse.php @@ -1,6 +1,6 @@ throw()->json('Organization'); - return collect($organizations)->map(fn (array $cabinet) => OrganizationIndex::fromJson($cabinet)); + return collect($organizations)->map(fn (array $organization) => Organization::fromJson($organization)); } } diff --git a/src/Responses/Document/GetDocumentDownloadResponse.php b/src/Responses/General/Organization/RequestLoginTokenResponse.php similarity index 70% rename from src/Responses/Document/GetDocumentDownloadResponse.php rename to src/Responses/General/Organization/RequestLoginTokenResponse.php index 0741be16..e5b82d32 100644 --- a/src/Responses/Document/GetDocumentDownloadResponse.php +++ b/src/Responses/General/Organization/RequestLoginTokenResponse.php @@ -1,12 +1,12 @@ throw()->body(); + return $response->body(); } } diff --git a/src/Responses/General/UserManagement/GetModifyGroups/GetGroupsResponse.php b/src/Responses/General/UserManagement/GetModifyGroups/GetGroupsResponse.php new file mode 100644 index 00000000..58228264 --- /dev/null +++ b/src/Responses/General/UserManagement/GetModifyGroups/GetGroupsResponse.php @@ -0,0 +1,24 @@ +throw()->json('Item'); + + return collect($groups)->map(fn (array $group) => Group::fromJson($group)); + } +} diff --git a/src/Responses/General/UserManagement/GetModifyRoles/GetRolesResponse.php b/src/Responses/General/UserManagement/GetModifyRoles/GetRolesResponse.php new file mode 100644 index 00000000..b07ff814 --- /dev/null +++ b/src/Responses/General/UserManagement/GetModifyRoles/GetRolesResponse.php @@ -0,0 +1,24 @@ +throw()->json('Item'); + + return collect($roles)->map(fn (array $role) => Role::fromJson($role)); + } +} diff --git a/src/Responses/General/UserManagement/GetUsers/GetUserResponse.php b/src/Responses/General/UserManagement/GetUsers/GetUserResponse.php new file mode 100644 index 00000000..6961de41 --- /dev/null +++ b/src/Responses/General/UserManagement/GetUsers/GetUserResponse.php @@ -0,0 +1,22 @@ +throw()->json(); + + return User::fromJson($user); + } +} diff --git a/src/Responses/General/UserManagement/GetUsers/GetUsersResponse.php b/src/Responses/General/UserManagement/GetUsers/GetUsersResponse.php new file mode 100644 index 00000000..40104035 --- /dev/null +++ b/src/Responses/General/UserManagement/GetUsers/GetUsersResponse.php @@ -0,0 +1,24 @@ +throw()->json('User'); + + return collect($users)->map(fn (array $user) => User::fromJson($user)); + } +} diff --git a/src/Responses/Organization/GetOrganizationResponse.php b/src/Responses/Organization/GetOrganizationResponse.php deleted file mode 100644 index 3693e793..00000000 --- a/src/Responses/Organization/GetOrganizationResponse.php +++ /dev/null @@ -1,22 +0,0 @@ -throw()->json(); - - return Organization::fromJson($organization); - } -} diff --git a/src/Responses/Search/GetSearchResponse.php b/src/Responses/Search/GetSearchResponse.php index 42e45358..0faa8877 100644 --- a/src/Responses/Search/GetSearchResponse.php +++ b/src/Responses/Search/GetSearchResponse.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Responses\Search; -use CodebarAg\DocuWare\DTO\DocumentPaginator; +use CodebarAg\DocuWare\DTO\Documents\DocumentPaginator; use CodebarAg\DocuWare\Events\DocuWareResponseLog; use CodebarAg\DocuWare\Support\EnsureValidResponse; use Exception; diff --git a/src/Responses/Search/GetTrashSearchResponse.php b/src/Responses/Search/GetTrashSearchResponse.php new file mode 100644 index 00000000..6cc028a2 --- /dev/null +++ b/src/Responses/Search/GetTrashSearchResponse.php @@ -0,0 +1,31 @@ +throw()->json(); + } catch (Exception $e) { + return TrashDocumentPaginator::fromFailed($e); + } + + return TrashDocumentPaginator::fromJson( + $data, + $page, + $perPage, + ); + } +} diff --git a/src/Responses/Workflow/GetDocumentWorkflowHistoryResponse.php b/src/Responses/Workflow/GetDocumentWorkflowHistoryResponse.php new file mode 100644 index 00000000..0396d9b5 --- /dev/null +++ b/src/Responses/Workflow/GetDocumentWorkflowHistoryResponse.php @@ -0,0 +1,23 @@ +throw()->json('InstanceHistory'); + + return collect($instanceHistories)->map(fn (array $instanceHistory) => InstanceHistory::fromJson($instanceHistory)); + } +} diff --git a/src/Responses/Workflow/GetDocumentWorkflowHistoryStepsResponse.php b/src/Responses/Workflow/GetDocumentWorkflowHistoryStepsResponse.php new file mode 100644 index 00000000..0fbd9549 --- /dev/null +++ b/src/Responses/Workflow/GetDocumentWorkflowHistoryStepsResponse.php @@ -0,0 +1,20 @@ +throw()->json()); + } +} diff --git a/src/Support/Auth.php b/src/Support/Auth.php index 76ac725c..2b7887a6 100644 --- a/src/Support/Auth.php +++ b/src/Support/Auth.php @@ -60,7 +60,7 @@ public static function forget(): void public static function domain(): string { throw_if( - empty(config('laravel-docuware.credentials.url')), + blank(config('laravel-docuware.credentials.url')), UnableToFindUrlCredential::create(), ); diff --git a/src/Support/EnsureValidCookie.php b/src/Support/EnsureValidCookie.php deleted file mode 100644 index f07f75d0..00000000 --- a/src/Support/EnsureValidCookie.php +++ /dev/null @@ -1,43 +0,0 @@ -config()->add('cookies', $cookieJar); - - $response = $request->send(); - - event(new DocuWareResponseLog($response)); - - throw_if($response->status() === Response::HTTP_UNAUTHORIZED, UnableToLogin::create()); - throw_if($cookieJar->toArray() === [], UnableToLoginNoCookies::create()); - - Auth::store($cookieJar); - } -} diff --git a/src/Support/EnsureValidCredentials.php b/src/Support/EnsureValidCredentials.php index 640275db..4173a69c 100644 --- a/src/Support/EnsureValidCredentials.php +++ b/src/Support/EnsureValidCredentials.php @@ -11,17 +11,17 @@ class EnsureValidCredentials public static function check(): void { throw_if( - empty(config('laravel-docuware.credentials.url')), + blank(config('laravel-docuware.credentials.url')), UnableToFindUrlCredential::create(), ); throw_if( - empty(config('laravel-docuware.credentials.username')), + blank(config('laravel-docuware.credentials.username')), UnableToFindUserCredential::create(), ); throw_if( - empty(config('laravel-docuware.credentials.password')), + blank(config('laravel-docuware.credentials.password')), UnableToFindPasswordCredential::create(), ); diff --git a/src/Support/EnsureValidPassphrase.php b/src/Support/EnsureValidPassphrase.php index 73a46cbd..2651d877 100644 --- a/src/Support/EnsureValidPassphrase.php +++ b/src/Support/EnsureValidPassphrase.php @@ -9,7 +9,7 @@ class EnsureValidPassphrase public static function check(): void { throw_if( - empty(config('laravel-docuware.passphrase')), + blank(config('laravel-docuware.passphrase')), UnableToFindPassphrase::create(), ); } diff --git a/src/Support/ParseValue.php b/src/Support/ParseValue.php index 1637b2fa..46db420c 100644 --- a/src/Support/ParseValue.php +++ b/src/Support/ParseValue.php @@ -3,7 +3,7 @@ namespace CodebarAg\DocuWare\Support; use Carbon\Carbon; -use CodebarAg\DocuWare\DTO\TableRow; +use CodebarAg\DocuWare\DTO\Documents\TableRow; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Str; diff --git a/tests/Console/ListAuthCookieCommandTest.php b/tests/Console/ListAuthCookieCommandTest.php deleted file mode 100644 index 800b811c..00000000 --- a/tests/Console/ListAuthCookieCommandTest.php +++ /dev/null @@ -1,32 +0,0 @@ -group('console'); - -beforeEach(function () { - Auth::forget(); - EnsureValidCookie::check(); - - if (! Arr::get(Auth::cookies(), Auth::COOKIE_NAME)) { - $this->markTestIncomplete('No cookie configured'); - } -}); - -it('lists auth cookie without creation date', function () { - $this->artisan('docuware:list-auth-cookie') - ->assertSuccessful() - ->expectsOutputToContain(Arr::get(Auth::cookies(), Auth::COOKIE_NAME)) - ->doesntExpectOutputToContain('Created At:'); -}); - -it('lists auth cookie with creation date', function () { - $this->artisan('docuware:list-auth-cookie', ['--with-date' => true]) - ->assertSuccessful() - ->expectsOutputToContain(Arr::get(Auth::cookies(), Auth::COOKIE_NAME)) - ->expectsOutputToContain('Created At:'); -}); diff --git a/tests/Feature/DTOTest.php b/tests/Feature/DTOTest.php index d82d677b..412eef29 100644 --- a/tests/Feature/DTOTest.php +++ b/tests/Feature/DTOTest.php @@ -2,16 +2,16 @@ namespace CodebarAg\DocuWare\Tests\Feature; -use CodebarAg\DocuWare\DTO\Dialog; -use CodebarAg\DocuWare\DTO\Document; -use CodebarAg\DocuWare\DTO\DocumentField; -use CodebarAg\DocuWare\DTO\DocumentPaginator; -use CodebarAg\DocuWare\DTO\Field; -use CodebarAg\DocuWare\DTO\FileCabinet; -use CodebarAg\DocuWare\DTO\Organization; -use CodebarAg\DocuWare\DTO\OrganizationIndex; +use CodebarAg\DocuWare\DTO\Documents\Document; +use CodebarAg\DocuWare\DTO\Documents\DocumentField; +use CodebarAg\DocuWare\DTO\Documents\DocumentPaginator; +use CodebarAg\DocuWare\DTO\Documents\Field; +use CodebarAg\DocuWare\DTO\Documents\TableRow; +use CodebarAg\DocuWare\DTO\FileCabinets\Dialog; +use CodebarAg\DocuWare\DTO\FileCabinets\General\FileCabinetInformation; +use CodebarAg\DocuWare\DTO\General\Organization\Organization; +use CodebarAg\DocuWare\DTO\General\Organization\OrganizationIndex; use CodebarAg\DocuWare\DTO\SuggestionField; -use CodebarAg\DocuWare\DTO\TableRow; uses()->group('dto'); @@ -26,8 +26,8 @@ }); it('create a fake file cabinet', function () { - $fake = FileCabinet::fake(); - $this->assertInstanceOf(FileCabinet::class, $fake); + $fake = FileCabinetInformation::fake(); + $this->assertInstanceOf(FileCabinetInformation::class, $fake); }); it('create a fake dialog', function () { diff --git a/tests/Feature/DocuWareAuthenticationTest.php b/tests/Feature/DocuWareAuthenticationTest.php new file mode 100644 index 00000000..aa96b0bd --- /dev/null +++ b/tests/Feature/DocuWareAuthenticationTest.php @@ -0,0 +1,40 @@ +send(); + + expect($responsibleIdentityServiceResponse->dto())->toBeInstanceOf(ResponsibleIdentityService::class); +})->group('authentication'); + +it('can get oath identity service configuration', function () { + $responsibleIdentityServiceResponse = (new GetResponsibleIdentityService)->send(); + + $identityServiceConfigurationResponse = (new GetIdentityServiceConfiguration( + identityServiceUrl: $responsibleIdentityServiceResponse->dto()->identityServiceUrl + ))->send(); + + expect($identityServiceConfigurationResponse->dto())->toBeInstanceOf(IdentityServiceConfiguration::class); +})->group('authentication'); + +it('can authenticate with DocuWare Credentials', function () { + Event::fake(); + + $connector = new DocuWareConnector(new ConfigWithCredentials( + username: config('laravel-docuware.credentials.username'), + password: config('laravel-docuware.credentials.password'), + )); + + $connector->send(new GetOrganization); + + Event::assertDispatched(DocuWareOAuthLog::class); + +})->group('authentication'); diff --git a/tests/Feature/DocuWareConnectorTest.php b/tests/Feature/DocuWareConnectorTest.php deleted file mode 100644 index a2840acb..00000000 --- a/tests/Feature/DocuWareConnectorTest.php +++ /dev/null @@ -1,29 +0,0 @@ -defaultConfig(), 'timeout'); - //$cookies = Arr::get($connector->defaultConfig(), 'cookies'); - - expect($timeout)->toBe(config('laravel-docuware.timeout')); - //expect($cookies)->toBe(Auth::cookieJar()); - -})->group('connector'); - -it('returns the correct base url', function () { - $connector = new DocuWareStaticConnector(); - - expect($connector->resolveBaseUrl())->toBe(config('laravel-docuware.credentials.url').'/DocuWare/Platform'); -})->group('connector'); - -it('returns the correct default headers', function () { - $connector = new DocuWareStaticConnector(); - - expect($connector->defaultHeaders())->toBe([ - 'Accept' => 'application/json', - ]); -})->group('connector'); diff --git a/tests/Feature/DocuWareTest.php b/tests/Feature/DocuWareTest.php index 6860e22f..34c9be43 100644 --- a/tests/Feature/DocuWareTest.php +++ b/tests/Feature/DocuWareTest.php @@ -11,7 +11,7 @@ $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); $documentId = config('laravel-docuware.tests.document_id'); - $url = (new DocuWare()) + $url = (new DocuWare) ->url() ->fileCabinet($fileCabinetId) ->document($documentId) @@ -35,7 +35,7 @@ $basketId = config('laravel-docuware.tests.basket_id'); $documentId = config('laravel-docuware.tests.document_id'); - $url = (new DocuWare()) + $url = (new DocuWare) ->url() ->basket($basketId) ->document($documentId) diff --git a/tests/Feature/Facades/DocuWare/CookieTest.php b/tests/Feature/Facades/DocuWare/CookieTest.php deleted file mode 100644 index 688d9280..00000000 --- a/tests/Feature/Facades/DocuWare/CookieTest.php +++ /dev/null @@ -1,13 +0,0 @@ -not()->toBeEmpty(); -}); diff --git a/tests/Feature/Requests/Document/GetDocumentsDownloadRequestTest.php b/tests/Feature/Requests/Document/GetDocumentsDownloadRequestTest.php deleted file mode 100644 index 19ffd96b..00000000 --- a/tests/Feature/Requests/Document/GetDocumentsDownloadRequestTest.php +++ /dev/null @@ -1,32 +0,0 @@ -connector->send(new PostDocumentRequest( - $fileCabinetId, - '::fake-file-content::', - 'example.txt' - ))->dto(); - - $document2 = $this->connector->send(new PostDocumentRequest( - $fileCabinetId, - '::fake-file-content::', - 'example.txt' - ))->dto(); - - $contents = $this->connector->send(new GetDocumentsDownloadRequest( - $fileCabinetId, - [$document1->id, $document2->id] - ))->dto(); - - $this->assertSame(478, strlen($contents)); - Event::assertDispatched(DocuWareResponseLog::class); -}); diff --git a/tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php b/tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php new file mode 100644 index 00000000..3eb84b97 --- /dev/null +++ b/tests/Feature/Requests/Documents/ApplicationProperties/ApplicationPropertiesTest.php @@ -0,0 +1,87 @@ +connector->send(new CreateDataRecord( + $fileCabinetId, + '::fake-file-content::', + 'example.txt' + ))->dto(); + + $addProperties = $this->connector->send(new AddApplicationProperties( + $fileCabinetId, + $document->id, + [ + [ + 'Name' => 'Key1', + 'Value' => 'Key1 Value', + ], + [ + 'Name' => 'Key2', + 'Value' => 'Key2 Value', + ], + ], + ))->dto(); + + expect($addProperties)->toBeInstanceOf(Collection::class) + ->and($addProperties->count())->toBe(2) + ->and($addProperties->first()['Name'])->toBe('Key1') + ->and($addProperties->first()['Value'])->toBe('Key1 Value') + ->and($addProperties->last()['Name'])->toBe('Key2') + ->and($addProperties->last()['Value'])->toBe('Key2 Value'); + + $updateProperties = $this->connector->send(new UpdateApplicationProperties( + $fileCabinetId, + $document->id, + [ + [ + 'Name' => 'Key1', + 'Value' => 'Key1 Value Updated', + ], + ], + ))->dto()->sortBy('Name'); + + expect($updateProperties)->toBeInstanceOf(Collection::class) + ->and($updateProperties->count())->toBe(2) + ->and($updateProperties->first()['Name'])->toBe('Key1') + ->and($updateProperties->first()['Value'])->toBe('Key1 Value Updated') + ->and($updateProperties->last()['Name'])->toBe('Key2') + ->and($updateProperties->last()['Value'])->toBe('Key2 Value'); + + $deleteProperties = $this->connector->send(new DeleteApplicationProperties( + $fileCabinetId, + $document->id, + [ + 'Key1', + ], + ))->dto(); + + expect($deleteProperties)->toBeInstanceOf(Collection::class) + ->and($deleteProperties->count())->toBe(1) + ->and($deleteProperties->first()['Name'])->toBe('Key2') + ->and($deleteProperties->first()['Value'])->toBe('Key2 Value'); + + $properties = $this->connector->send(new GetApplicationProperties( + $fileCabinetId, + $document->id, + ))->dto(); + + expect($properties)->toBeInstanceOf(Collection::class) + ->and($properties->count())->toBe(1) + ->and($properties->first()['Name'])->toBe('Key2') + ->and($properties->first()['Value'])->toBe('Key2 Value'); + + Event::assertDispatched(DocuWareResponseLog::class); +})->group('application-properties'); diff --git a/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/ClipTest.php b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/ClipTest.php new file mode 100644 index 00000000..910c982c --- /dev/null +++ b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/ClipTest.php @@ -0,0 +1,30 @@ +connector, $fileCabinetId); + + [$document, $document2] = uploadFiles($this->connector, $fileCabinetId, $path); + + $clip = $this->connector->send(new Clip( + $fileCabinetId, + [ + $document->id, + $document2->id, + ] + ))->dto(); + + expect($clip->id)->toBe($document->id) + ->and($clip->total_pages)->toBe($document->total_pages + $document2->total_pages) + ->and($clip->sections->count())->toBe(2); + + Event::assertDispatched(DocuWareResponseLog::class); +})->group('clip'); diff --git a/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/StapleTest.php b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/StapleTest.php new file mode 100644 index 00000000..9fbbbdc4 --- /dev/null +++ b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/StapleTest.php @@ -0,0 +1,38 @@ +connector, $fileCabinetId); + + [$document, $document2] = uploadFiles($this->connector, $fileCabinetId, $path); + + $staple = $this->connector->send(new Staple( + $fileCabinetId, + [ + $document->id, + $document2->id, + ] + ))->dto(); + + Sleep::for(5)->seconds(); // Wait for the files to be uploaded and processed + + $stapledDocument = $this->connector->send(new GetASpecificDocumentFromAFileCabinet( + $fileCabinetId, + $staple->id + ))->dto(); + + expect($stapledDocument->title)->toBe($document->title) + ->and($stapledDocument->total_pages)->toBe($document->total_pages + $document2->total_pages); + + Event::assertDispatched(DocuWareResponseLog::class); +})->group('staple'); diff --git a/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/UnclipTest.php b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/UnclipTest.php new file mode 100644 index 00000000..21c5c18d --- /dev/null +++ b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/UnclipTest.php @@ -0,0 +1,41 @@ +connector, $fileCabinetId); + + [$document, $document2] = uploadFiles($this->connector, $fileCabinetId, $path); + + $clip = $this->connector->send(new Clip( + $fileCabinetId, + [ + $document->id, + $document2->id, + ] + ))->dto(); + + Sleep::for(5)->seconds(); + + $unclip = $this->connector->send(new Unclip( + $fileCabinetId, + $clip->id + ))->dto(); + + expect($unclip->documents->count())->toBe(2) + ->and($unclip->documents->first()->title)->toBe($document->title) + ->and($unclip->documents->first()->file_size)->toBe($document->file_size) + ->and($unclip->documents->last()->title)->toBe($document2->title) + ->and($unclip->documents->last()->file_size)->toBe($document2->file_size); + + Event::assertDispatched(DocuWareResponseLog::class); +})->group('unclip'); diff --git a/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/UnstapleTest.php b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/UnstapleTest.php new file mode 100644 index 00000000..8d53a3cf --- /dev/null +++ b/tests/Feature/Requests/Documents/ClipUnclipStapleUnstaple/UnstapleTest.php @@ -0,0 +1,37 @@ +connector, $fileCabinetId); + + [$document, $document2] = uploadFiles($this->connector, $fileCabinetId, $path); + + $staple = $this->connector->send(new Staple( + $fileCabinetId, + [ + $document->id, + $document2->id, + ] + ))->dto(); + + Sleep::for(5)->seconds(); + + $unclip = $this->connector->send(new Unstaple( + $fileCabinetId, + $staple->id + ))->dto(); + + expect($unclip->documents->count())->toBe($staple->total_pages); + + Event::assertDispatched(DocuWareResponseLog::class); +})->group('unstaple'); diff --git a/tests/Feature/Requests/Documents/DocumentsTrashBin/DeleteDocumentsFromTrashBinTest.php b/tests/Feature/Requests/Documents/DocumentsTrashBin/DeleteDocumentsFromTrashBinTest.php new file mode 100644 index 00000000..19bbb912 --- /dev/null +++ b/tests/Feature/Requests/Documents/DocumentsTrashBin/DeleteDocumentsFromTrashBinTest.php @@ -0,0 +1,33 @@ +connector->send(new CreateDataRecord( + config('laravel-docuware.tests.file_cabinet_id'), + file_get_contents(__DIR__.'/../../../../Fixtures/files/test-1.pdf'), + 'test-1.pdf', + ))->dto(); + + $this->connector->send(new DeleteDocument( + config('laravel-docuware.tests.file_cabinet_id'), + $document->id, + ))->dto(); + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $delete = $this->connector->send(new DeleteDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto(); + + expect($delete->successCount)->toBe($paginator->total); +})->group('delete', 'trash'); diff --git a/tests/Feature/Requests/Documents/DocumentsTrashBin/GetDocumentsFromTrashBinTest.php b/tests/Feature/Requests/Documents/DocumentsTrashBin/GetDocumentsFromTrashBinTest.php new file mode 100644 index 00000000..fa1b09c2 --- /dev/null +++ b/tests/Feature/Requests/Documents/DocumentsTrashBin/GetDocumentsFromTrashBinTest.php @@ -0,0 +1,172 @@ +searchRequestBuilder() + ->trashBin() + ->page(1) + ->perPage(5) + ->fulltext('test') + ->filterDate('DELETEDATETIME', '>=', Carbon::create(2021)) + ->filterDate('DELETEDATETIME', '<', now()) + ->filter('DOCUMENT_TYPE', 'Abrechnung') + ->orderBy('DELETEDATETIME', 'desc') + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $this->assertInstanceOf(TrashDocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); +})->group('search', 'trash'); + +it('can\'t search documents by more than two dates in trash', function () { + Event::fake(); + + $this->expectException(UnableToSearch::class); + + $request = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->page(1) + ->perPage(5) + ->fulltext('test') + ->filterDate('DELETEDATETIME', '>=', Carbon::create(2020)) + ->filterDate('DELETEDATETIME', '>=', Carbon::create(2021)) + ->filterDate('DELETEDATETIME', '<', now()) + ->filter('DOCUMENT_TYPE', 'Abrechnung') + ->orderBy('DELETEDATETIME', 'desc') + ->get(); + + $this->connector->send($request)->dto(); +})->group('search', 'trash'); + +it('can override search documents dates filter by using same operator in trash', function () { + Event::fake(); + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->page(1) + ->perPage(5) + ->fulltext('test') + ->filterDate('DELETEDATETIME', '<=', Carbon::create(2022)) + ->filterDate('DELETEDATETIME', '>=', Carbon::create(2020)) + ->filterDate('DELETEDATETIME', '>=', Carbon::create(2021)) + ->filter('DOCUMENT_TYPE', 'Abrechnung') + ->orderBy('DELETEDATETIME', 'desc') + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $this->assertInstanceOf(TrashDocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); +})->group('search', 'trash'); + +it('can override search documents dates filter by using equal operator in trash', function () { + Event::fake(); + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->page(1) + ->perPage(5) + ->fulltext('test') + ->filterDate('DELETEDATETIME', '>=', Carbon::create(2020)) + ->filterDate('DELETEDATETIME', '=', Carbon::create(2021)) + ->filter('DOCUMENT_TYPE', 'Abrechnung') + ->orderBy('DELETEDATETIME', 'desc') + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $this->assertInstanceOf(TrashDocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); +})->group('search', 'trash'); + +it('can\'t search documents by diverged date range', function () { + Event::fake(); + + $this->expectException(UnableToSearch::class); + + $request = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->page(1) + ->perPage(5) + ->fulltext('test') + ->filterDate('DELETEDATETIME', '<=', Carbon::create(2020)) + ->filterDate('DELETEDATETIME', '>=', Carbon::create(2021)) + ->filter('DOCUMENT_TYPE', 'Abrechnung') + ->orderBy('DELETEDATETIME', 'desc') + ->get(); + + $this->connector->send($request)->dto(); +})->group('search', 'trash'); + +it('can search documents dates filter in future in trash', function () { + Event::fake(); + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->page(1) + ->perPage(5) + ->fulltext('test') + ->filterDate('DELETEDATETIME', '>', Carbon::create(2018)) + ->filter('DOCUMENT_TYPE', 'Abrechnung') + ->orderBy('DELETEDATETIME', 'desc') + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $this->assertInstanceOf(TrashDocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); +})->group('search', 'trash'); + +it('can search documents dates filter in past in trash', function () { + Event::fake(); + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->page(1) + ->perPage(5) + ->fulltext('test') + ->filterDate('DELETEDATETIME', '<=', Carbon::create(2020)) + ->filter('DOCUMENT_TYPE', 'Abrechnung') + ->orderBy('DELETEDATETIME', 'desc') + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $this->assertInstanceOf(TrashDocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); +})->group('search', 'trash'); + +it('can search documents with null values in trash', function () { + Event::fake(); + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->page(null) + ->perPage(null) + ->fulltext(null) + ->filter('DOCUMENT_TYPE', null) + ->orderBy('DELETEDATETIME', null) + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $this->assertInstanceOf(TrashDocumentPaginator::class, $paginator); + Event::assertDispatched(DocuWareResponseLog::class); +})->group('search', 'trash'); diff --git a/tests/Feature/Requests/Documents/DocumentsTrashBin/RestoreDocumentsFromTrashBinTest.php b/tests/Feature/Requests/Documents/DocumentsTrashBin/RestoreDocumentsFromTrashBinTest.php new file mode 100644 index 00000000..7a9330d2 --- /dev/null +++ b/tests/Feature/Requests/Documents/DocumentsTrashBin/RestoreDocumentsFromTrashBinTest.php @@ -0,0 +1,33 @@ +connector->send(new CreateDataRecord( + config('laravel-docuware.tests.file_cabinet_id'), + file_get_contents(__DIR__.'/../../../../Fixtures/files/test-1.pdf'), + 'test-1.pdf', + ))->dto(); + + $this->connector->send(new DeleteDocument( + config('laravel-docuware.tests.file_cabinet_id'), + $document->id, + ))->dto(); + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->get(); + + $paginator = $this->connector->send($paginatorRequest)->dto(); + + $delete = $this->connector->send(new RestoreDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto(); + + expect($delete->successCount)->toBe($paginator->total); +})->group('restore', 'trash'); diff --git a/tests/Feature/Requests/Document/GetDocumentDownloadRequestTest.php b/tests/Feature/Requests/Documents/Download/DownloadDocumentTest.php similarity index 64% rename from tests/Feature/Requests/Document/GetDocumentDownloadRequestTest.php rename to tests/Feature/Requests/Documents/Download/DownloadDocumentTest.php index d27fbed7..ab915f4e 100644 --- a/tests/Feature/Requests/Document/GetDocumentDownloadRequestTest.php +++ b/tests/Feature/Requests/Documents/Download/DownloadDocumentTest.php @@ -1,8 +1,8 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt' ))->dto(); - $contents = $this->connector->send(new GetDocumentDownloadRequest( + $contents = $this->connector->send(new DownloadDocument( $fileCabinetId, $document->id ))->dto(); @@ -24,4 +24,4 @@ $this->assertSame(strlen('::fake-file-content::'), strlen($contents)); Event::assertDispatched(DocuWareResponseLog::class); -}); +})->group('download'); diff --git a/tests/Feature/Requests/Documents/Download/DownloadSectionTest.php b/tests/Feature/Requests/Documents/Download/DownloadSectionTest.php new file mode 100644 index 00000000..29a73f1d --- /dev/null +++ b/tests/Feature/Requests/Documents/Download/DownloadSectionTest.php @@ -0,0 +1,33 @@ +connector->send(new CreateDataRecord( + $fileCabinetId, + '::fake-file-content::', + 'example.txt' + ))->dto(); + + $sections = $this->connector->send(new GetAllSectionsFromADocument( + $fileCabinetId, + $document->id + ))->dto(); + + $contents = $this->connector->send(new DownloadSection( + $fileCabinetId, + $sections->first()->id + ))->dto(); + + $this->assertSame(strlen('::fake-file-content::'), strlen($contents)); + Event::assertDispatched(DocuWareResponseLog::class); + +})->group('download'); diff --git a/tests/Feature/Requests/Documents/Download/DownloadThumbnailTest.php b/tests/Feature/Requests/Documents/Download/DownloadThumbnailTest.php new file mode 100644 index 00000000..e9c117b7 --- /dev/null +++ b/tests/Feature/Requests/Documents/Download/DownloadThumbnailTest.php @@ -0,0 +1,34 @@ +connector->send(new CreateDataRecord( + $fileCabinetId, + '::fake-file-content::', + 'example.txt' + ))->dto(); + + $sections = $this->connector->send(new GetAllSectionsFromADocument( + $fileCabinetId, + $document->id + ))->dto(); + + $contents = $this->connector->send(new DownloadThumbnail( + $fileCabinetId, + $sections->first()->id + ))->dto(); + + expect($contents)->toBeInstanceOf(DocumentThumbnail::class); + Event::assertDispatched(DocuWareResponseLog::class); + +})->group('download'); diff --git a/tests/Feature/Requests/Document/GetDocumentCountRequestTest.php b/tests/Feature/Requests/Documents/GetDocumentCountRequestTest.php similarity index 67% rename from tests/Feature/Requests/Document/GetDocumentCountRequestTest.php rename to tests/Feature/Requests/Documents/GetDocumentCountRequestTest.php index d23b6551..59ae74c0 100644 --- a/tests/Feature/Requests/Document/GetDocumentCountRequestTest.php +++ b/tests/Feature/Requests/Documents/GetDocumentCountRequestTest.php @@ -1,8 +1,8 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt' ))->dto(); - $count = $this->connector->send(new GetDocumentCountRequest( + $count = $this->connector->send(new GetTotalNumberOfDocuments( $fileCabinetId, $dialogId ))->dto(); diff --git a/tests/Feature/Requests/Document/GetDocumentPreviewRequestTest.php b/tests/Feature/Requests/Documents/GetDocumentPreviewRequestTest.php similarity index 73% rename from tests/Feature/Requests/Document/GetDocumentPreviewRequestTest.php rename to tests/Feature/Requests/Documents/GetDocumentPreviewRequestTest.php index 651ffb46..a5609581 100644 --- a/tests/Feature/Requests/Document/GetDocumentPreviewRequestTest.php +++ b/tests/Feature/Requests/Documents/GetDocumentPreviewRequestTest.php @@ -1,8 +1,8 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt' diff --git a/tests/Feature/Requests/Document/PostDocumentRequestTest.php b/tests/Feature/Requests/Documents/PostDocumentRequestTest.php similarity index 82% rename from tests/Feature/Requests/Document/PostDocumentRequestTest.php rename to tests/Feature/Requests/Documents/PostDocumentRequestTest.php index 8942b4c0..5d7ad43b 100644 --- a/tests/Feature/Requests/Document/PostDocumentRequestTest.php +++ b/tests/Feature/Requests/Documents/PostDocumentRequestTest.php @@ -1,10 +1,10 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, null, null, @@ -38,7 +38,7 @@ $fileContent = '::fake-file-content::'; $fileName = 'example.txt'; - $document = $this->connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, $fileContent, $fileName, diff --git a/tests/Feature/Requests/Document/PutDocumentFieldsRequestTest.php b/tests/Feature/Requests/Documents/PutDocumentFieldsRequestTest.php similarity index 75% rename from tests/Feature/Requests/Document/PutDocumentFieldsRequestTest.php rename to tests/Feature/Requests/Documents/PutDocumentFieldsRequestTest.php index 4dc47bd9..c3446d9b 100644 --- a/tests/Feature/Requests/Document/PutDocumentFieldsRequestTest.php +++ b/tests/Feature/Requests/Documents/PutDocumentFieldsRequestTest.php @@ -1,9 +1,9 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt' ))->dto(); - $response = $this->connector->send(new PutDocumentFieldsRequest( + $response = $this->connector->send(new UpdateIndexValues( $fileCabinetId, $document->id, collect([ @@ -37,13 +37,13 @@ $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); - $document = $this->connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt' ))->dto(); - $response = $this->connector->send(new PutDocumentFieldsRequest( + $response = $this->connector->send(new UpdateIndexValues( $fileCabinetId, $document->id, collect([ diff --git a/tests/Feature/Requests/Documents/Sections/DeleteSectionTest.php b/tests/Feature/Requests/Documents/Sections/DeleteSectionTest.php new file mode 100644 index 00000000..9c56884e --- /dev/null +++ b/tests/Feature/Requests/Documents/Sections/DeleteSectionTest.php @@ -0,0 +1,35 @@ +connector->send(new CreateDataRecord( + $fileCabinetId, + '::fake-file-content::', + 'example.txt' + ))->dto(); + + $sections = $this->connector->send(new GetAllSectionsFromADocument( + $fileCabinetId, + $document->id + ))->dto(); + + $deleted = $this->connector->send(new DeleteSection( + $fileCabinetId, + $sections->first()->id + ))->dto(); + + expect($deleted)->toBeTrue(); + + Event::assertDispatched(DocuWareResponseLog::class); + +})->group('requests', 'sections'); diff --git a/tests/Feature/Requests/Documents/Sections/GetASpecificSectionTest.php b/tests/Feature/Requests/Documents/Sections/GetASpecificSectionTest.php new file mode 100644 index 00000000..7da557a7 --- /dev/null +++ b/tests/Feature/Requests/Documents/Sections/GetASpecificSectionTest.php @@ -0,0 +1,35 @@ +connector->send(new CreateDataRecord( + $fileCabinetId, + '::fake-file-content::', + 'example.txt' + ))->dto(); + + $sections = $this->connector->send(new GetAllSectionsFromADocument( + $fileCabinetId, + $document->id + ))->dto(); + + $section = $this->connector->send(new GetASpecificSection( + $fileCabinetId, + $sections->first()->id + ))->dto(); + + expect($section->id)->toBe($sections->first()->id); + + Event::assertDispatched(DocuWareResponseLog::class); + +})->group('requests', 'sections'); diff --git a/tests/Feature/Requests/Documents/Sections/GetAllSectionsFromADocumentTest.php b/tests/Feature/Requests/Documents/Sections/GetAllSectionsFromADocumentTest.php new file mode 100644 index 00000000..70a78c84 --- /dev/null +++ b/tests/Feature/Requests/Documents/Sections/GetAllSectionsFromADocumentTest.php @@ -0,0 +1,33 @@ +connector->send(new CreateDataRecord( + $fileCabinetId, + '::fake-file-content::', + 'example.txt' + ))->dto(); + + $sections = $this->connector->send(new GetAllSectionsFromADocument( + $fileCabinetId, + $document->id + ))->dto(); + + expect($sections)->toBeInstanceOf(Collection::class) + ->and($sections->count())->toBeGreaterThan(0) + ->and($sections->first())->toBeInstanceOf(Section::class); + + Event::assertDispatched(DocuWareResponseLog::class); + +})->group('requests', 'sections'); diff --git a/tests/Feature/Requests/Document/Thumbnail/GetDocumentDownloadThumbnailRequestTest.php b/tests/Feature/Requests/Documents/Thumbnail/GetDocumentDownloadThumbnailRequestTest.php similarity index 60% rename from tests/Feature/Requests/Document/Thumbnail/GetDocumentDownloadThumbnailRequestTest.php rename to tests/Feature/Requests/Documents/Thumbnail/GetDocumentDownloadThumbnailRequestTest.php index b479bd9c..9297ae49 100644 --- a/tests/Feature/Requests/Document/Thumbnail/GetDocumentDownloadThumbnailRequestTest.php +++ b/tests/Feature/Requests/Documents/Thumbnail/GetDocumentDownloadThumbnailRequestTest.php @@ -1,10 +1,10 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt' ))->dto(); - $sections = $this->connector->send(new GetSectionsRequest( + $sections = $this->connector->send(new GetAllSectionsFromADocument( $fileCabinetId, $document->id, ))->dto(); - $contents = $this->connector->send(new GetDocumentDownloadThumbnailRequest( + $contents = $this->connector->send(new DownloadThumbnail( $fileCabinetId, $sections->first()->id, ))->dto(); diff --git a/tests/Feature/Requests/Fields/GetFieldsRequestTest.php b/tests/Feature/Requests/Fields/GetFieldsRequestTest.php index 2dd7809b..b1e94c50 100644 --- a/tests/Feature/Requests/Fields/GetFieldsRequestTest.php +++ b/tests/Feature/Requests/Fields/GetFieldsRequestTest.php @@ -1,6 +1,6 @@ connector->send(new GetDialogRequest($fileCabinetId, $dialogId))->dto(); + $dialog = $this->connector->send(new GetASpecificDialog($fileCabinetId, $dialogId))->dto(); $this->assertInstanceOf(Dialog::class, $dialog); diff --git a/tests/Feature/Requests/Dialogs/GetDialogsRequestTest.php b/tests/Feature/Requests/FileCabinets/Dialogs/GetAllDialogs.php similarity index 73% rename from tests/Feature/Requests/Dialogs/GetDialogsRequestTest.php rename to tests/Feature/Requests/FileCabinets/Dialogs/GetAllDialogs.php index c9f344da..13e19e92 100644 --- a/tests/Feature/Requests/Dialogs/GetDialogsRequestTest.php +++ b/tests/Feature/Requests/FileCabinets/Dialogs/GetAllDialogs.php @@ -1,8 +1,8 @@ connector->send(new GetDialogsRequest($fileCabinetId))->dto(); + $dialogs = $this->connector->send(new GetAllDialogs($fileCabinetId))->dto(); $this->assertInstanceOf(Collection::class, $dialogs); diff --git a/tests/Feature/Requests/FileCabinets/Dialogs/GetDialogsOfASpecificTypeTest.php b/tests/Feature/Requests/FileCabinets/Dialogs/GetDialogsOfASpecificTypeTest.php new file mode 100644 index 00000000..1ce23bad --- /dev/null +++ b/tests/Feature/Requests/FileCabinets/Dialogs/GetDialogsOfASpecificTypeTest.php @@ -0,0 +1,26 @@ +connector->send(new GetDialogsOfASpecificType($fileCabinetId, DialogType::SEARCH))->dto(); + + $this->assertInstanceOf(Collection::class, $dialogs); + + $this->assertNotCount(0, $dialogs); + + foreach ($dialogs as $dialog) { + $this->assertInstanceOf(Dialog::class, $dialog); + } + + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/FileCabinets/General/GetFileCabinetInformationTest.php b/tests/Feature/Requests/FileCabinets/General/GetFileCabinetInformationTest.php new file mode 100644 index 00000000..df9516b7 --- /dev/null +++ b/tests/Feature/Requests/FileCabinets/General/GetFileCabinetInformationTest.php @@ -0,0 +1,16 @@ +connector->send(new GetFileCabinetInformation(env('DOCUWARE_TESTS_FILE_CABINET_ID')))->dto(); + + $this->assertInstanceOf(FileCabinetInformation::class, $fileCabinet); + + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/FileCabinets/GetFileCabinetsRequestTest.php b/tests/Feature/Requests/FileCabinets/GetFileCabinetsRequestTest.php deleted file mode 100644 index 6ad64bcd..00000000 --- a/tests/Feature/Requests/FileCabinets/GetFileCabinetsRequestTest.php +++ /dev/null @@ -1,23 +0,0 @@ -connector->send(new GetFileCabinetsRequest())->dto(); - - $this->assertInstanceOf(Collection::class, $fileCabinets); - - foreach ($fileCabinets as $fileCabinet) { - $this->assertInstanceOf(FileCabinet::class, $fileCabinet); - } - - $this->assertNotCount(0, $fileCabinets); - Event::assertDispatched(DocuWareResponseLog::class); - -}); diff --git a/tests/Feature/Requests/Document/GetDocumentRequestTest.php b/tests/Feature/Requests/FileCabinets/Search/GetASpecificDocumentFromAFileCabinetTest.php similarity index 59% rename from tests/Feature/Requests/Document/GetDocumentRequestTest.php rename to tests/Feature/Requests/FileCabinets/Search/GetASpecificDocumentFromAFileCabinetTest.php index 2d483d01..41331f29 100644 --- a/tests/Feature/Requests/Document/GetDocumentRequestTest.php +++ b/tests/Feature/Requests/FileCabinets/Search/GetASpecificDocumentFromAFileCabinetTest.php @@ -1,9 +1,9 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt' ))->dto(); - $getdocument = $this->connector->send(new GetDocumentRequest($fileCabinetId, $document->id))->dto(); + $getdocument = $this->connector->send(new GetASpecificDocumentFromAFileCabinet($fileCabinetId, $document->id))->dto(); $this->assertInstanceOf(Document::class, $getdocument); diff --git a/tests/Feature/Requests/Document/GetDocumentsRequestTest.php b/tests/Feature/Requests/FileCabinets/Search/GetDocumentsFromAFileCabinetTest.php similarity index 62% rename from tests/Feature/Requests/Document/GetDocumentsRequestTest.php rename to tests/Feature/Requests/FileCabinets/Search/GetDocumentsFromAFileCabinetTest.php index b68acd95..4b801ff4 100644 --- a/tests/Feature/Requests/Document/GetDocumentsRequestTest.php +++ b/tests/Feature/Requests/FileCabinets/Search/GetDocumentsFromAFileCabinetTest.php @@ -1,25 +1,25 @@ connector->send(new PostDocumentRequest( + $this->connector->send(new CreateDataRecord( config('laravel-docuware.tests.file_cabinet_id'), '::fake-file-content::', 'example.txt' ))->dto(); - $this->connector->send(new PostDocumentRequest( + $this->connector->send(new CreateDataRecord( config('laravel-docuware.tests.file_cabinet_id'), '::fake-file-content::', 'example.txt' ))->dto(); - $documents = $this->connector->send(new GetDocumentsRequest( + $documents = $this->connector->send(new GetDocumentsFromAFileCabinet( config('laravel-docuware.tests.file_cabinet_id') ))->dto(); diff --git a/tests/Feature/Requests/FileCabinets/Upload/AppendFilesToADataRecordTest.php b/tests/Feature/Requests/FileCabinets/Upload/AppendFilesToADataRecordTest.php new file mode 100644 index 00000000..8f066857 --- /dev/null +++ b/tests/Feature/Requests/FileCabinets/Upload/AppendFilesToADataRecordTest.php @@ -0,0 +1,86 @@ +connector->send(new CreateDataRecord( + fileCabinetId: $fileCabinetId, + fileContent: file_get_contents(__DIR__.'/../../../../Fixtures/files/test-1.pdf'), + fileName: 'test-1.pdf', + indexes: null + ))->dto(); + + $response = $this->connector->send( + new AppendFilesToADataRecord( + fileCabinetId: $fileCabinetId, + dataRecordId: $document->id, + files: collect([ + new MultipartValue( + name: 'File[]', + value: file_get_contents(__DIR__.'/../../../../Fixtures/files/test-2.pdf'), + filename: 'test-2.pdf', + ), + ]) + ) + )->dto(); + + expect($response)->toBeInstanceOf(Document::class) + ->and($response->sections->count())->toBe(2) + ->and($response->sections->first()->originalFileName)->toBe('test-1.pdf') + ->and($response->sections->last()->originalFileName)->toBe('test-2.pdf'); + + Event::assertDispatched(DocuWareResponseLog::class); +}); + +it('can attach files to a data record', function () { + Event::fake(); + + $fileCabinetId = env('DOCUWARE_TESTS_FILE_CABINET_ID'); + + $document = $this->connector->send(new CreateDataRecord( + fileCabinetId: $fileCabinetId, + fileContent: file_get_contents(__DIR__.'/../../../../Fixtures/files/test-1.pdf'), + fileName: 'test-1.pdf', + indexes: null + ))->dto(); + + $response = $this->connector->send( + new AppendFilesToADataRecord( + fileCabinetId: $fileCabinetId, + dataRecordId: $document->id, + files: collect([ + new MultipartValue( + name: 'File[]', + value: file_get_contents(__DIR__.'/../../../../Fixtures/files/test-2.pdf'), + filename: 'test-2.pdf', + ), + new MultipartValue( + name: 'File[]', + value: file_get_contents(__DIR__.'/../../../../Fixtures/files/test-3.pdf'), + filename: 'test-3.pdf', + ), + ]) + ) + )->dto(); + + $sections = $response->sections->values(); + + ray($sections->toArray()); + + expect($response)->toBeInstanceOf(Document::class) + ->and($sections->count())->toBe(3) + ->and($sections[0]->originalFileName)->toBe('test-1.pdf') + ->and($sections[1]->originalFileName)->toBe('test-2.pdf') + ->and($sections[2]->originalFileName)->toBe('test-3.pdf'); + + Event::assertDispatched(DocuWareResponseLog::class); +})->skip(); diff --git a/tests/Feature/Requests/General/UserManagement/CreateUpdateUsers/CreateUpdateUserTest.php b/tests/Feature/Requests/General/UserManagement/CreateUpdateUsers/CreateUpdateUserTest.php new file mode 100644 index 00000000..707a89ae --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/CreateUpdateUsers/CreateUpdateUserTest.php @@ -0,0 +1,44 @@ +timestamp, -8); + + $user = $this->connector->send(new CreateUser(new User( + name: $timestamp.' - Test User', + dbName: $timestamp, + email: $timestamp.'-test@example.test', + password: 'TESTPASSWORD', + )))->dto(); + + $this->assertInstanceOf(GetUser::class, $user); + + Event::assertDispatched(DocuWareResponseLog::class); + + return $user; +}); + +it('can update users', function ($user) { + Event::fake(); + + Sleep::for(5)->seconds(); + + $user->name .= ' - Updated'; + $user->active = false; + + $user = $this->connector->send(new UpdateUser($user))->dto(); + + $this->assertInstanceOf(GetUser::class, $user); + + Event::assertDispatched(DocuWareResponseLog::class); +})->depends('it can create users'); diff --git a/tests/Feature/Requests/General/UserManagement/GetModifyGroups/AddRemoveUserToAGroupTest.php b/tests/Feature/Requests/General/UserManagement/GetModifyGroups/AddRemoveUserToAGroupTest.php new file mode 100644 index 00000000..a201c1ba --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetModifyGroups/AddRemoveUserToAGroupTest.php @@ -0,0 +1,55 @@ +timestamp, -8); + + $user = $this->connector->send(new CreateUser(new User( + name: $timestamp.' - Test User', + dbName: $timestamp, + email: $timestamp.'-test@example.test', + password: 'TESTPASSWORD', + )))->dto(); + + Sleep::for(5)->seconds(); + + $response = $this->connector->send(new AddUserToAGroup( + userId: $user->id, + ids: [ + env('DOCUWARE_TESTS_GROUP_ID'), + ] + ))->dto(); + + expect($response->status())->toBe(200); + + Event::assertDispatched(DocuWareResponseLog::class); + + return $user; +}); + +it('can remove groups to a user', function ($user) { + Event::fake(); + + Sleep::for(5)->seconds(); + + $response = $this->connector->send(new RemoveUserFromAGroup( + userId: $user->id, + ids: [ + env('DOCUWARE_TESTS_GROUP_ID'), + ] + ))->dto(); + + expect($response->status())->toBe(200); + + Event::assertDispatched(DocuWareResponseLog::class); +})->depends('it can add groups to a user'); diff --git a/tests/Feature/Requests/General/UserManagement/GetModifyGroups/GetAllGroupsForASpecificUserTest.php b/tests/Feature/Requests/General/UserManagement/GetModifyGroups/GetAllGroupsForASpecificUserTest.php new file mode 100644 index 00000000..37c8ba95 --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetModifyGroups/GetAllGroupsForASpecificUserTest.php @@ -0,0 +1,25 @@ +connector->send(new GetUsers)->dto(); + + $groups = $this->connector->send(new GetAllGroupsForASpecificUser($users->get(2)->id))->dto(); + + $this->assertInstanceOf(Collection::class, $groups); + + foreach ($groups as $group) { + $this->assertInstanceOf(Group::class, $group); + } + + $this->assertNotCount(0, $groups); + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/General/UserManagement/GetModifyGroups/GetGroupsTest.php b/tests/Feature/Requests/General/UserManagement/GetModifyGroups/GetGroupsTest.php new file mode 100644 index 00000000..c9849612 --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetModifyGroups/GetGroupsTest.php @@ -0,0 +1,22 @@ +connector->send(new GetGroups)->dto(); + + $this->assertInstanceOf(Collection::class, $groups); + + foreach ($groups as $group) { + $this->assertInstanceOf(Group::class, $group); + } + + $this->assertNotCount(0, $groups); + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/General/UserManagement/GetModifyRoles/AddRemoveUserToARoleTest.php b/tests/Feature/Requests/General/UserManagement/GetModifyRoles/AddRemoveUserToARoleTest.php new file mode 100644 index 00000000..1f9cc6c3 --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetModifyRoles/AddRemoveUserToARoleTest.php @@ -0,0 +1,55 @@ +timestamp, -8); + + $user = $this->connector->send(new CreateUser(new User( + name: $timestamp.' - Test User', + dbName: $timestamp, + email: $timestamp.'-test@example.test', + password: 'TESTPASSWORD', + )))->dto(); + + Sleep::for(5)->seconds(); + + $response = $this->connector->send(new AddUserToARole( + userId: $user->id, + ids: [ + env('DOCUWARE_TESTS_ROLE_ID'), + ] + ))->dto(); + + expect($response->status())->toBe(200); + + Event::assertDispatched(DocuWareResponseLog::class); + + return $user; +}); + +it('can remove roles to a user', function ($user) { + Event::fake(); + + Sleep::for(5)->seconds(); + + $response = $this->connector->send(new RemoveUserFromARole( + userId: $user->id, + ids: [ + env('DOCUWARE_TESTS_ROLE_ID'), + ] + ))->dto(); + + expect($response->status())->toBe(200); + + Event::assertDispatched(DocuWareResponseLog::class); +})->depends('it can add roles to a user'); diff --git a/tests/Feature/Requests/General/UserManagement/GetModifyRoles/GetAllRolesForASpecificUserTest.php b/tests/Feature/Requests/General/UserManagement/GetModifyRoles/GetAllRolesForASpecificUserTest.php new file mode 100644 index 00000000..45ab728b --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetModifyRoles/GetAllRolesForASpecificUserTest.php @@ -0,0 +1,25 @@ +connector->send(new GetUsers)->dto(); + + $roles = $this->connector->send(new GetAllRolesForASpecificUser($users->get(2)->id))->dto(); + + $this->assertInstanceOf(Collection::class, $roles); + + foreach ($roles as $role) { + $this->assertInstanceOf(Role::class, $role); + } + + $this->assertNotCount(0, $roles); + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/General/UserManagement/GetModifyRoles/GetRolesTest.php b/tests/Feature/Requests/General/UserManagement/GetModifyRoles/GetRolesTest.php new file mode 100644 index 00000000..cafd5d3a --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetModifyRoles/GetRolesTest.php @@ -0,0 +1,22 @@ +connector->send(new GetRoles)->dto(); + + $this->assertInstanceOf(Collection::class, $roles); + + foreach ($roles as $role) { + $this->assertInstanceOf(Role::class, $role); + } + + $this->assertNotCount(0, $roles); + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/General/UserManagement/GetUsers/GetUserByIdTest.php b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUserByIdTest.php new file mode 100644 index 00000000..db417ab7 --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUserByIdTest.php @@ -0,0 +1,19 @@ +connector->send(new GetUsers)->dto(); + + $user = $this->connector->send(new GetUserById($users->get(2)->id))->dto(); + + $this->assertInstanceOf(User::class, $user); + + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersOfAGroupTest.php b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersOfAGroupTest.php new file mode 100644 index 00000000..5be8470a --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersOfAGroupTest.php @@ -0,0 +1,25 @@ +connector->send(new GetGroups)->dto(); + + $users = $this->connector->send(new GetUsersOfAGroup($groups->first()->id))->dto(); + + $this->assertInstanceOf(Collection::class, $users); + + foreach ($users as $user) { + $this->assertInstanceOf(User::class, $user); + } + + $this->assertNotCount(0, $users); + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersOfARoleTest.php b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersOfARoleTest.php new file mode 100644 index 00000000..f9de422d --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersOfARoleTest.php @@ -0,0 +1,25 @@ +connector->send(new GetRoles)->dto(); + + $users = $this->connector->send(new GetUsersOfARole($roles->first()->id))->dto(); + + $this->assertInstanceOf(Collection::class, $users); + + foreach ($users as $user) { + $this->assertInstanceOf(User::class, $user); + } + + $this->assertNotCount(0, $users); + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersTest.php b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersTest.php new file mode 100644 index 00000000..6b8696a6 --- /dev/null +++ b/tests/Feature/Requests/General/UserManagement/GetUsers/GetUsersTest.php @@ -0,0 +1,22 @@ +connector->send(new GetUsers)->dto(); + + $this->assertInstanceOf(Collection::class, $users); + + foreach ($users as $user) { + $this->assertInstanceOf(User::class, $user); + } + + $this->assertNotCount(0, $users); + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/Organization/GetOrganizationRequestTest.php b/tests/Feature/Requests/Organization/GetOrganizationRequestTest.php deleted file mode 100644 index 64d8d28a..00000000 --- a/tests/Feature/Requests/Organization/GetOrganizationRequestTest.php +++ /dev/null @@ -1,17 +0,0 @@ -connector->send(new GetOrganizationRequest($orgID))->dto(); - - $this->assertInstanceOf(Organization::class, $organization); - Event::assertDispatched(DocuWareResponseLog::class); -}); diff --git a/tests/Feature/Requests/Organization/GetOrganizationsRequestTest.php b/tests/Feature/Requests/Organization/GetOrganizationsRequestTest.php index cb7566a1..145529c0 100644 --- a/tests/Feature/Requests/Organization/GetOrganizationsRequestTest.php +++ b/tests/Feature/Requests/Organization/GetOrganizationsRequestTest.php @@ -1,20 +1,20 @@ connector->send(new GetOrganizationsRequest())->dto(); + $organizations = $this->connector->send(new GetOrganization)->dto(); $this->assertInstanceOf(Collection::class, $organizations); foreach ($organizations as $organization) { - $this->assertInstanceOf(OrganizationIndex::class, $organization); + $this->assertInstanceOf(Organization::class, $organization); } $this->assertNotCount(0, $organizations); diff --git a/tests/Feature/Requests/Search/GetSearchRequestTest.php b/tests/Feature/Requests/Search/GetSearchRequestTest.php index 44229edd..6d66889d 100644 --- a/tests/Feature/Requests/Search/GetSearchRequestTest.php +++ b/tests/Feature/Requests/Search/GetSearchRequestTest.php @@ -2,11 +2,11 @@ use Carbon\Carbon; use CodebarAg\DocuWare\DocuWare; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO; -use CodebarAg\DocuWare\DTO\DocumentPaginator; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentPaginator; use CodebarAg\DocuWare\Events\DocuWareResponseLog; use CodebarAg\DocuWare\Exceptions\UnableToSearch; -use CodebarAg\DocuWare\Requests\Document\PostDocumentRequest; +use CodebarAg\DocuWare\Requests\FileCabinets\Upload\CreateDataRecord; use Illuminate\Support\Facades\Event; it('can search documents', function () { @@ -15,7 +15,7 @@ $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); $dialogId = config('laravel-docuware.tests.dialog_id'); - $paginatorRequest = (new DocuWare()) + $paginatorRequest = (new DocuWare) ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) @@ -42,7 +42,7 @@ $this->expectException(UnableToSearch::class); - $request = (new DocuWare()) + $request = (new DocuWare) ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) @@ -65,7 +65,7 @@ $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); $dialogId = config('laravel-docuware.tests.dialog_id'); - $paginatorRequest = (new DocuWare()) + $paginatorRequest = (new DocuWare) ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) @@ -91,7 +91,7 @@ $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); $dialogId = config('laravel-docuware.tests.dialog_id'); - $paginatorRequest = (new DocuWare()) + $paginatorRequest = (new DocuWare) ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) @@ -118,7 +118,7 @@ $this->expectException(UnableToSearch::class); - $request = (new DocuWare()) + $request = (new DocuWare) ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) @@ -140,7 +140,7 @@ $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); $dialogId = config('laravel-docuware.tests.dialog_id'); - $paginatorRequest = (new DocuWare()) + $paginatorRequest = (new DocuWare) ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) @@ -164,7 +164,7 @@ $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); $dialogId = config('laravel-docuware.tests.dialog_id'); - $paginatorRequest = (new DocuWare()) + $paginatorRequest = (new DocuWare) ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) @@ -189,7 +189,7 @@ config('laravel-docuware.tests.file_cabinet_id'), ]; - $paginatorRequest = (new DocuWare()) + $paginatorRequest = (new DocuWare) ->searchRequestBuilder() ->fileCabinets($fileCabinetIds) ->page(null) @@ -212,7 +212,7 @@ $fileContent = '::fake-file-content::'; $fileName = 'example.txt'; - $documentOne = $this->connector->send(new PostDocumentRequest( + $documentOne = $this->connector->send(new CreateDataRecord( $fileCabinetId, $fileContent, $fileName, @@ -222,7 +222,7 @@ ]), ))->dto(); - $documentTwo = $this->connector->send(new PostDocumentRequest( + $documentTwo = $this->connector->send(new CreateDataRecord( $fileCabinetId, $fileContent, $fileName, @@ -232,7 +232,7 @@ ]), ))->dto(); - $documentThree = $this->connector->send(new PostDocumentRequest( + $documentThree = $this->connector->send(new CreateDataRecord( $fileCabinetId, $fileContent, $fileName, @@ -243,7 +243,7 @@ ))->dto(); // Should filter down to documentOne and documentTwo. documentThree should be filtered out. - $paginatorRequestBothDocuments = (new DocuWare()) + $paginatorRequestBothDocuments = (new DocuWare) ->searchRequestBuilder() ->fileCabinets([$fileCabinetId]) ->page(null) diff --git a/tests/Feature/Requests/SelectList/GetSelectListRequest.php b/tests/Feature/Requests/SelectList/GetSelectListRequest.php index c0f89f20..6b98cba9 100644 --- a/tests/Feature/Requests/SelectList/GetSelectListRequest.php +++ b/tests/Feature/Requests/SelectList/GetSelectListRequest.php @@ -1,9 +1,9 @@ connector->send(new PostDocumentRequest( + $document = $this->connector->send(new CreateDataRecord( $fileCabinetId, '::fake-file-content::', 'example.txt', @@ -22,7 +22,7 @@ ]) ))->dto(); - $types = $this->connector->send(new GetSelectListRequest( + $types = $this->connector->send(new GetSelectLists( $fileCabinetId, $dialogId, $fieldName, diff --git a/tests/Feature/Requests/Workflow/GetDocumentWorkflowHistoryStepsTest.php b/tests/Feature/Requests/Workflow/GetDocumentWorkflowHistoryStepsTest.php new file mode 100644 index 00000000..79c17e8a --- /dev/null +++ b/tests/Feature/Requests/Workflow/GetDocumentWorkflowHistoryStepsTest.php @@ -0,0 +1,45 @@ +connector->send(new CreateDataRecord( + config('laravel-docuware.tests.file_cabinet_id'), + '::fake-file-content::', + 'example.txt' + ))->dto(); + + Sleep::for(5)->seconds(); + + $history = $this->connector->send(new GetDocumentWorkflowHistory( + config('laravel-docuware.tests.file_cabinet_id'), + $document->id + ))->dto(); + + $historySteps = $this->connector->send(new GetDocumentWorkflowHistorySteps( + $history->first()->workflowId, + $history->first()->id, + ))->dto(); + + expect($historySteps)->toHaveKeys([ + 'id', + 'workflowId', + 'name', + 'version', + 'workflowRequest', + 'startedAt', + 'docId', + 'historySteps', + ]) + ->and($historySteps->historySteps)->toBeInstanceOf(Collection::class); + + Event::assertDispatched(DocuWareResponseLog::class); +})->group('workflow'); diff --git a/tests/Feature/Requests/Workflow/GetDocumentWorkflowHistoryTest.php b/tests/Feature/Requests/Workflow/GetDocumentWorkflowHistoryTest.php new file mode 100644 index 00000000..7a0074c8 --- /dev/null +++ b/tests/Feature/Requests/Workflow/GetDocumentWorkflowHistoryTest.php @@ -0,0 +1,38 @@ +connector->send(new CreateDataRecord( + config('laravel-docuware.tests.file_cabinet_id'), + '::fake-file-content::', + 'example.txt' + ))->dto(); + + Sleep::for(5)->seconds(); + + $history = $this->connector->send(new GetDocumentWorkflowHistory( + config('laravel-docuware.tests.file_cabinet_id'), + $document->id + ))->dto(); + + expect($history)->toBeInstanceOf(Collection::class) + ->and($history->first())->toHaveKeys([ + 'id', + 'workflowId', + 'name', + 'version', + 'workflowRequest', + 'startedAt', + 'docId', + ]); + + Event::assertDispatched(DocuWareResponseLog::class); +})->group('workflow'); diff --git a/tests/Feature/SleepTest.php b/tests/Feature/SleepTest.php new file mode 100644 index 00000000..fba0ba42 --- /dev/null +++ b/tests/Feature/SleepTest.php @@ -0,0 +1,12 @@ +toDateTimeString()); + Sleep::for(5)->seconds(); + Log::info(now()->toDateTimeString()); + +})->expectNotToPerformAssertions() + ->skip('Testing sleep function.'); diff --git a/tests/Fixtures/files/test-1.pdf b/tests/Fixtures/files/test-1.pdf new file mode 100644 index 00000000..505f6f48 Binary files /dev/null and b/tests/Fixtures/files/test-1.pdf differ diff --git a/tests/Fixtures/files/test-2.pdf b/tests/Fixtures/files/test-2.pdf new file mode 100644 index 00000000..2a9a4169 Binary files /dev/null and b/tests/Fixtures/files/test-2.pdf differ diff --git a/tests/Fixtures/files/test-3.pdf b/tests/Fixtures/files/test-3.pdf new file mode 100644 index 00000000..5cf3fc47 Binary files /dev/null and b/tests/Fixtures/files/test-3.pdf differ diff --git a/tests/Pest.php b/tests/Pest.php index 20ac8c57..126d33ae 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,14 +1,19 @@ group('docuware') ->in(__DIR__); uses() @@ -17,38 +22,108 @@ clearFiles(); }) + ->afterEach(function () { + setUsersInactive(); + }) ->in('Feature'); -/** - * @throws Throwable - */ -function getConnector(): object +function clearFiles(): void { - EnsureValidCookie::check(); + $connector = getConnector(); + + $paginator = $connector->send(new GetDocumentsFromAFileCabinet( + config('laravel-docuware.tests.file_cabinet_id') + ))->dto(); + + foreach ($paginator->documents as $document) { + $connector->send(new DeleteDocument( + config('laravel-docuware.tests.file_cabinet_id'), + $document->id, + ))->dto(); + } + + $paginatorRequest = (new DocuWare) + ->searchRequestBuilder() + ->trashBin() + ->perPage(1000) + ->get(); - $config = Config::make([ - 'url' => config('laravel-docuware.credentials.url'), - 'cookie' => config('laravel-docuware.cookies'), - 'cache_driver' => config('laravel-docuware.configurations.cache.driver'), - 'cache_lifetime_in_seconds' => config('laravel-docuware.configurations.cache.lifetime_in_seconds'), - 'request_timeout_in_seconds' => config('laravel-docuware.timeout'), - ]); + $paginator = $connector->send($paginatorRequest)->dto(); - return new DocuWareStaticConnector($config); + if ($paginator->total > 0) { + $connector->send(new DeleteDocuments($paginator->mappedDocuments->pluck('ID')->all()))->dto(); + } } -function clearFiles(): void +function setUsersInactive(): void { $connector = getConnector(); - $paginator = $connector->send(new GetDocumentsRequest( - config('laravel-docuware.tests.file_cabinet_id') + $response = $connector->send(new GetUsers); + + $users = $response->dto()->filter(function ($user) { + return Str::contains($user->email, 'test@example.test') && $user->active === true; + }); + + foreach ($users as $user) { + $user->active = false; + + $connector->send(new UpdateUser($user)); + } +} + +/** + * @throws Throwable + */ +function getConnector(): object +{ + return new DocuWareConnector(new ConfigWithCredentials( + username: config('laravel-docuware.credentials.username'), + password: config('laravel-docuware.credentials.password'), + )); +} + +function cleanup($connector, $fileCabinetId): void +{ + $paginator = $connector->send(new GetDocumentsFromAFileCabinet( + $fileCabinetId ))->dto(); foreach ($paginator->documents as $document) { - $connector->send(new DeleteDocumentRequest( - config('laravel-docuware.tests.file_cabinet_id'), + $connector->send(new DeleteDocument( + $fileCabinetId, $document->id, ))->dto(); } } + +function uploadFiles($connector, $fileCabinetId, $path): array +{ + $document = $connector->send(new CreateDataRecord( + $fileCabinetId, + file_get_contents($path.'/test-1.pdf'), + 'test-1.pdf', + ))->dto(); + + $document2 = $connector->send(new CreateDataRecord( + $fileCabinetId, + file_get_contents($path.'/test-2.pdf'), + 'test-2.pdf', + ))->dto(); + + Sleep::for(5)->seconds(); // Wait for the files to be uploaded and processed + + // Have to get document again as returned data is incorrect + $document = $connector->send(new GetASpecificDocumentFromAFileCabinet( + $fileCabinetId, + $document->id + ))->dto(); + + // Have to get document2 again as returned data is incorrect + $document2 = $connector->send(new GetASpecificDocumentFromAFileCabinet( + $fileCabinetId, + $document2->id + ))->dto(); + + return [$document, $document2]; +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 746ffaf7..fd588b78 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,11 @@ namespace CodebarAg\DocuWare\Tests; use CodebarAg\DocuWare\DocuWareServiceProvider; +use CodebarAg\DocuWare\Events\DocuWareOAuthLog; +use CodebarAg\DocuWare\Events\DocuWareResponseLog; use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Log; use Orchestra\Testbench\TestCase as Orchestra; class TestCase extends Orchestra @@ -15,6 +19,19 @@ protected function setUp(): void Factory::guessFactoryNamesUsing( fn (string $modelName) => 'codebar\\DocuWare\\Database\\Factories\\'.class_basename($modelName).'Factory', ); + + // Event::listen(DocuWareResponseLog::class, function (DocuWareResponseLog $event) { + // Log::info('Docuware response', [ + // $event->response->getPendingRequest()->getUrl(), + // ]); + // }); + // + // Event::listen(DocuWareOAuthLog::class, function (DocuWareOAuthLog $event) { + // Log::info($event->message, [ + // 'url' => $event->url, + // 'username' => $event->username, + // ]); + // }); } protected function getPackageProviders($app): array diff --git a/tests/Unit/DTO/DocumentIndex/IndexDateDTOTest.php b/tests/Unit/DTO/DocumentIndex/IndexDateDTOTest.php index 8a68faa3..da4913d6 100644 --- a/tests/Unit/DTO/DocumentIndex/IndexDateDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/IndexDateDTOTest.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO; it('create index date dto', function () { diff --git a/tests/Unit/DTO/DocumentIndex/IndexDateTimeDTOTest.php b/tests/Unit/DTO/DocumentIndex/IndexDateTimeDTOTest.php index 6a5c391c..baf2a0c0 100644 --- a/tests/Unit/DTO/DocumentIndex/IndexDateTimeDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/IndexDateTimeDTOTest.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateTimeDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateTimeDTO; it('create index date time dto', function () { diff --git a/tests/Unit/DTO/DocumentIndex/IndexDecimalDTOTest.php b/tests/Unit/DTO/DocumentIndex/IndexDecimalDTOTest.php index 3aa463c6..9154e640 100644 --- a/tests/Unit/DTO/DocumentIndex/IndexDecimalDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/IndexDecimalDTOTest.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDecimalDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDecimalDTO; it('create index numeric dto', function () { diff --git a/tests/Unit/DTO/DocumentIndex/IndexNumericDTOTest.php b/tests/Unit/DTO/DocumentIndex/IndexNumericDTOTest.php index 959ebb0c..b7ae4d6e 100644 --- a/tests/Unit/DTO/DocumentIndex/IndexNumericDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/IndexNumericDTOTest.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexNumericDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexNumericDTO; it('create index numeric dto', function () { diff --git a/tests/Unit/DTO/DocumentIndex/IndexTableDTOTest.php b/tests/Unit/DTO/DocumentIndex/IndexTableDTOTest.php index a77f1455..db4761dc 100644 --- a/tests/Unit/DTO/DocumentIndex/IndexTableDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/IndexTableDTOTest.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTableDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTableDTO; it('create prepare index text dto', function () { diff --git a/tests/Unit/DTO/DocumentIndex/IndexTextDTOTest.php b/tests/Unit/DTO/DocumentIndex/IndexTextDTOTest.php index 0fe0f62b..6556ebfa 100644 --- a/tests/Unit/DTO/DocumentIndex/IndexTextDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/IndexTextDTOTest.php @@ -2,7 +2,7 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO; it('create prepare index text dto', function () { diff --git a/tests/Unit/DTO/DocumentIndex/PrepareDTOTest.php b/tests/Unit/DTO/DocumentIndex/PrepareDTOTest.php index 0d08ccb7..80f35bab 100644 --- a/tests/Unit/DTO/DocumentIndex/PrepareDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/PrepareDTOTest.php @@ -2,9 +2,9 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateDTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\PrepareDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexTextDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\PrepareDTO; it('create prepare index dto', function () { diff --git a/tests/Unit/DTO/DocumentIndex/PrepareTableDTOTest.php b/tests/Unit/DTO/DocumentIndex/PrepareTableDTOTest.php index 3b2ff45a..454c6306 100644 --- a/tests/Unit/DTO/DocumentIndex/PrepareTableDTOTest.php +++ b/tests/Unit/DTO/DocumentIndex/PrepareTableDTOTest.php @@ -2,8 +2,8 @@ namespace CodebarAg\DocuWare\Tests\Unit\DTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\IndexDateDTO; -use CodebarAg\DocuWare\DTO\DocumentIndex\PrepareTableDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\IndexDateDTO; +use CodebarAg\DocuWare\DTO\Documents\DocumentIndex\PrepareTableDTO; it('create prepare index table dto', function () {