Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Jun 27, 2022
2 parents 6aa5fad + d32027f commit 2d1e242
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 22 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local machine for development and testing purposes.
```sh
docker-compose pull
docker-compose up --detach
```

4. Install composer packages

Expand Down Expand Up @@ -65,7 +66,26 @@ local machine for development and testing purposes.
5. Install profile

```sh
docker-compose exec phpfpm vendor/bin/drush site:install os2forms_forloeb_profile --existing-config
docker-compose exec phpfpm vendor/bin/drush site:install os2forms_forloeb_profile --existing-config
```

Should you encounter the following error:

```sh
In EntityStorageBase.php line 557:
"config_entity_revisions_type" entity with ID 'webform_revisions' already exists.
```

Proceed to remove this entry from the db via the sql cli:

```sh
itkdev-docker-compose vendor/bin/drush sql:query 'DELETE FROM config WHERE name="config_entity_revisions.config_entity_revisions_type.webform_revisions";'
```

Afterwards, run config-import to import config from files:

```sh
docker-compose exec phpfpm vendor/bin/drush config:import
```

6. Download and install external libraries
Expand Down Expand Up @@ -132,6 +152,26 @@ $config['os2forms_get_organized'] = [
];
```
### Maestro
We use the [Maestro module](https://www.drupal.org/project/maestro) to make workflows.
To avoid having to run the
[Orchestrator](https://www.drupal.org/docs/contributed-modules/maestro/installation#s-maestro-engine-also-know-as-the-orchestrator)
manually, a token must be set in
`/admin/config/workflow/maestro`. The Orchestrator can then be run by visiting
`https://[site]/orchestrator/{token}`.
Adding the following cronjob to your crontab will run
the Orchestrator every five minutes.
```cron
*/5 * * * * /usr/bin/curl --location https://[site]/orchestrator/{token} > /dev/null 2>&1; /usr/local/bin/cron-exit-status -c 'Some exit message probably containing [site]' -v $?
```
In `/admin/config/workflow/maestro` you can also configure
whether a refresh of the Maestro Task Console should run the Orchestrator,
which certainly could be an advantage during tests.
### REST API
We use [Webform REST](https://www.drupal.org/project/webform_rest) to expose a
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"drupal/system_status": "^2.9",
"drupal/webform_remote_select": "^1.0",
"drush/drush": "^10.6",
"itk-dev/getorganized-api-client-php": "dev-develop",
"itk-dev/getorganized-api-client-php": "^1.0",
"itk-dev/os2forms_cpr_lookup": "^1.6.3",
"itk-dev/os2forms_cvr_lookup": "^1.1",
"itk-dev/os2forms_digital_post": "dev-develop",
Expand Down
18 changes: 8 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#default_value' => $this->configuration['api_url'] ?? '',
];

$form['api_token'] = [
$form['api_authorization_header'] = [
'#type' => 'textfield',
'#title' => $this->t('API token'),
'#description' => $this->t('The API token. Will be sent in an authorization header: <code>Authorization: Token «API token»</code>.'),
'#title' => $this->t('API authorization header'),
'#description' => $this->t('The API authorization header value. Will be sent in an authorization header: <code>Authorization: «value»</code>.'),
'#required' => TRUE,
'#default_value' => $this->configuration['api_token'] ?? '',
'#default_value' => $this->configuration['api_authorization_header'] ?? '',
];

return $this->setSettingsParents($form);
Expand All @@ -106,7 +106,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['api_url'] = $form_state->getValue('api_url');
$this->configuration['api_token'] = $form_state->getValue('api_token');
$this->configuration['api_authorization_header'] = $form_state->getValue('api_authorization_header');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ public function post(array $payload) {
}

$apiUrl = $handlerConfiguration['api_url'] ?? NULL;
$apiToken = $handlerConfiguration['api_token'] ?? NULL;

$headers = [];

if (!empty($handlerConfiguration['api_authorization_header'])) {
$headers['Authorization'] = trim($handlerConfiguration['api_authorization_header']);
}

$this->client->request('POST', $apiUrl, [
'headers' => [
'Authorization' => sprintf('Token %s', $apiToken),
],
'headers' => $headers,
RequestOptions::JSON => $data,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ public function archive(string $submissionId, array $handlerConfiguration) {

/** @var \ItkDev\GetOrganized\Service\Documents $documentService */
$documentService = $this->client->api('documents');
$documentService->AddToDocumentLibrary($tempFile, $getOrganizedCaseId, $getOrganizedFileName);
$result = $documentService->AddToDocumentLibrary($tempFile, $getOrganizedCaseId, $getOrganizedFileName);

// Remove temp file.
unlink($tempFile);

// Handle finalization ("journalisering").
$shouldBeFinalized = $handlerConfiguration['should_be_finalized'] ?? FALSE;

if ($shouldBeFinalized) {
if (isset($result['DocId'])) {
$documentService->Finalize($result['DocId']);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#default_value' => $this->configuration['case_id'] ?? '',
];

$form['should_be_finalized'] = [
'#title' => $this->t('Should document be finalized?'),
'#type' => 'checkbox',
'#default_value' => $this->configuration['should_be_finalized'] ?? FALSE,
'#description' => $this->t('If enabled, documents will be finalized (journaliseret) in GetOrganized.'),
'#required' => FALSE,
];

$form['attachment_element'] = [
'#type' => 'select',
'#title' => $this->t('Attachment element'),
Expand All @@ -94,6 +102,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
parent::submitConfigurationForm($form, $form_state);
$this->configuration['case_id'] = $form_state->getValue('case_id');
$this->configuration['attachment_element'] = $form_state->getValue('attachment_element');
$this->configuration['should_be_finalized'] = $form_state->getValue('should_be_finalized');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ type: module
description: 'OS2Form REST API'
package: Web services
core_version_requirement: ^9
dependencies:
- drupal:key_auth

0 comments on commit 2d1e242

Please sign in to comment.