You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

302 lines
7.8 KiB

<?php
namespace SamApiLib;
class Archive
{
private $sam_api;
function __construct(SamApi $sam_api)
{
$this->sam_api = $sam_api;
}
/**
* list all archives
* http://sam2_dev.localhost/openapi.html#operation/recordsManagement/archives/read
* @return array[]|mixed[]
*/
public function read ()
{
$ws_route = "get /recordsManagement/archives";
$url_params = [];
$query_params = [
"archiveId" => "",
"profileReference" => "",
"status" => "",
"archiveName" => "",
"agreementReference" => "",
"archiveExpired" => "",
"finalDisposition" => "",
"originatorOrgRegNumber" => "",
"originatorOwnerOrgId" => "",
"originatorArchiveId" => "",
"originatingDate" => "",
"filePlanPosition" => "",
"hasParent" => "",
"description" => "",
"partialRetentionRule" => "",
"retentionRuleCode" => "",
"depositStartDate" => "",
"depositEndDate" => "",
"originatingStartDate" => "",
"originatingEndDate" => "",
"archiverArchiveId" => "",
"maxResults" => "",
];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
if(!empty($body))
return $body;
else
null;
}
/**
* list archives only inside an organization / folder
* @param string $registrationNumber
* @param string $folderId
* @return array[]|mixed[]
*/
public function readList ($registrationNumber = "", $folderId = "")
{
$ws_route = "get /recordsManagement/archives/List";
$url_params = [];
$query_params = [
"originatorOrgRegNumber" => $registrationNumber, // registrationNumber : m183129110301321
"filePlanPosition" => $folderId, // folderId : SAM_rak426-6xon-f8ywrz
"archiveUnit" => ""
];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
if(!empty($body))
return $body;
else
null;
}
/**
* get a particular archive
* @param $id
* @return array[]|mixed[]
*/
public function getArchiveById ($id)
{
$ws_route = " get /recordsManagement/archiveDescription/{archiveId}";
$url_params = [
"archiveId" => $id,
];
$query_params = [
"isCommunication" => "",
];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
if(!empty($body))
return $body;
else
null;
}
/**
* get archive metadata
* @param $archive_id
* @return array[]|mixed[]
*/
public function getMetadata ($archive_id)
{
$ws_route = " get /recordsManagement/archive/Metadata/{archiveId}";
$url_params = [
"archiveId" => $archive_id,
];
$query_params = [];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body;
}
/**
* get a resoure's content base 64 encoded
* @param $archive_id
* @param $resource_id
* @return array[]|mixed[]
*/
public function getResourceContentBase64 ($archive_id, $resource_id)
{
$ws_route = " get /recordsManagement/archive/Consultation/{archiveId}/Digitalresource/{resId}";
$url_params = [
"archiveId" => $archive_id,
"resId" => $resource_id,
];
$query_params = [
"isCommunication" => "",
"embedded" => "",
];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body; // use ["attachment"]["data"] for direct access to base64 content
}
/**
* create an archive
* @param $archive_name
* @param $originatorOrgRegNumber
* @param $file_plan_position
* @return array[]|mixed[]
*/
public function createArchive ($archive_name, $originatorOrgRegNumber, $file_plan_position)
{
$ws_route = " post /recordsManagement/archive";
$url_params = [];
$query_params = [];
$body_params = [
"archive" => [
"archiveName" => $archive_name,
"filePlanPosition" => $file_plan_position,
],
"zipContainer" => false,
];
$body_params = [
"archive" => [
"archiveName" => $archive_name,
"originatorOrgRegNumber" => $originatorOrgRegNumber,// organization registration number (registrationNumber)
"filePlanPosition" => $file_plan_position, // folder id (folderId), or null if root of an organization
],
"zipContainer" => false,
];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body;
}
/**
* create an archive
* @param $archive_name
* @param $originatorOrgRegNumber
* @param $file_plan_position
* @return array[]|mixed[]
*/
public function createArchiveWithResource ($archiveId, $originatorOwnerOrgRegNumber, $originatorOrgRegNumber, $content, $file_name, $hash, $hashAlgorithm)
{
$ws_route = " post /digitalSafe/digitalSafe/{originatorOwnerOrgRegNumber}/{originatorOrgRegNumber}";
$url_params = [
"originatorOwnerOrgRegNumber" => $originatorOwnerOrgRegNumber,
"originatorOrgRegNumber" => $originatorOrgRegNumber
];
$query_params = [];
$body_params = [
"originatorArchiveId" => $archiveId,
"digitalResources" => [
[
"handler" => base64_encode($content),
"fileName" => $file_name,
"hash" => $hash,
"hashAlgorithm" => $hashAlgorithm
]
]
];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body;
}
/**
* add resource content (base 64 encoded) to an archive
* @param $archive_id
* @param $content
* @param $file_name
* @return array[]|mixed[]
*/
public function addResourceBase64ToArchive ($archive_id, $content, $file_name)
{
$ws_route = " post /recordsManagement/archive/{archiveId}/Digitalresource";
$url_params = [
"archiveId" => $archive_id,
];
$query_params = [];
$body_params = [
"contents" => $content,
"filename" => $file_name,
];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body;
}
/**
* add resource content (raw) to an archive
* @param $archive_id
* @param $content
* @param $file_name
* @return array|mixed[]
*/
public function addResourceToArchive ($archive_id, $content, $file_name)
{
return $this->addResourceBase64ToArchive($archive_id, base64_encode($content), $file_name);
}
/**
* count all archives
* @return array[]|mixed[]
*/
public function count ()
{
$ws_route = "get /recordsManagement/archives/Count";
$url_params = [];
$query_params = [
"originatorOrgRegNumber" => "",
"filePlanPosition" => "",
];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body;
}
/**
* ask for an archive destruction
* @param $originatorOwnerOrgRegNumber
* @param $originatorOrgRegNumber
* @param $archiveId
* @return array[]|mixed[]
*/
public function destruct ($originatorOwnerOrgRegNumber, $originatorOrgRegNumber, $archiveId)
{
$ws_route = " delete /digitalSafe/digitalSafe/{originatorOwnerOrgRegNumber}/{originatorOrgRegNumber}/{archiveId}";
$url_params = [
"originatorOwnerOrgRegNumber" => $originatorOwnerOrgRegNumber,
"originatorOrgRegNumber" => $originatorOrgRegNumber,
"archiveId" => $archiveId,
];
$query_params = [];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body;
}
/**
* ask for an archive integrity check
* @param $archiveId
* @return array[]|mixed[]
*/
public function checkIntegrity ($archiveId)
{
$ws_route = " get /recordsManagement/archives/Integritycheck";
$url_params = [];
$query_params = [
"archiveIds" => [$archiveId],
];
$body_params = [];
list($headers, $body) = $this->sam_api->query($ws_route, $url_params, $query_params, $body_params);
return $body;
}
}