Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.43% covered (success)
91.43%
32 / 35
86.67% covered (warning)
86.67%
13 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 1
File
91.43% covered (success)
91.43%
32 / 35
86.67% covered (warning)
86.67%
13 / 15
16.16
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 isDeletedAccount
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getUserId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getStatusEnum
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setStatus
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 setStatusEnum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSignatureFlowEnum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSignatureFlowEnum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDocmdpLevelEnum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDocmdpLevelEnum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNodeTypeEnum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNodeTypeEnum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isEnvelope
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasParent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Db;
10
11use OCA\Libresign\Enum\FileStatus;
12use OCA\Libresign\Enum\NodeType;
13use OCA\Libresign\Enum\SignatureFlow;
14use OCP\AppFramework\Db\Entity;
15use OCP\DB\Types;
16
17/**
18 * @method void setId(int $id)
19 * @method int getId()
20 * @method void setNodeId(?int $nodeId)
21 * @method ?int getNodeId()
22 * @method void setSignedNodeId(?int $nodeId)
23 * @method ?int getSignedNodeId()
24 * @method void setSignedHash(?string $hash)
25 * @method ?string getSignedHash()
26 * @method void setUserId(?string $userId)
27 * @method string getUserId()
28 * @method void setUuid(string $uuid)
29 * @method string getUuid()
30 * @method void setCreatedAt(\DateTime $createdAt)
31 * @method \DateTime getCreatedAt()
32 * @method void setName(string $name)
33 * @method non-falsy-string getName()
34 * @method void setCallback(string $callback)
35 * @method ?string getCallback()
36 * @method void setStatus(int $status)
37 * @method int getStatus()
38 * @method void setMetadata(array $metadata)
39 * @method ?array getMetadata()
40 * @method void setModificationStatus(int $modificationStatus)
41 * @method int getModificationStatus()
42 * @method void setSignatureFlow(int $signatureFlow)
43 * @method int getSignatureFlow()
44 * @method void setDocmdpLevel(int $docmdpLevel)
45 * @method int getDocmdpLevel()
46 * @method void setNodeType(string $nodeType)
47 * @method 'file'|'envelope' getNodeType()
48 * @method void setParentFileId(?int $parentFileId)
49 * @method ?int getParentFileId()
50 */
51class File extends Entity {
52    protected ?int $nodeId = null;
53    protected string $uuid = '';
54    protected ?\DateTime $createdAt = null;
55    protected string $name = '';
56    protected ?int $status = null;
57    protected ?string $userId = null;
58    protected ?int $signedNodeId = null;
59    protected ?string $signedHash = null;
60    protected ?string $callback = null;
61    protected ?array $metadata = null;
62    protected int $modificationStatus = 0;
63    protected int $signatureFlow = SignatureFlow::NUMERIC_NONE;
64    protected int $docmdpLevel = 0;
65    protected string $nodeType = 'file';
66    protected ?int $parentFileId = null;
67
68    public const MODIFICATION_UNCHECKED = 0;
69    public const MODIFICATION_UNMODIFIED = 1;
70    public const MODIFICATION_ALLOWED = 2;
71    public const MODIFICATION_VIOLATION = 3;
72
73    public function __construct() {
74        $this->addType('id', Types::INTEGER);
75        $this->addType('nodeId', Types::INTEGER);
76        $this->addType('signedNodeId', Types::INTEGER);
77        $this->addType('signedHash', Types::STRING);
78        $this->addType('userId', Types::STRING);
79        $this->addType('uuid', Types::STRING);
80        $this->addType('createdAt', Types::DATETIME);
81        $this->addType('name', Types::STRING);
82        $this->addType('callback', Types::STRING);
83        $this->addType('status', Types::INTEGER);
84        $this->addType('metadata', Types::JSON);
85        $this->addType('modificationStatus', Types::SMALLINT);
86        $this->addType('signatureFlow', Types::SMALLINT);
87        $this->addType('docmdpLevel', Types::SMALLINT);
88        $this->addType('nodeType', Types::STRING);
89        $this->addType('parentFileId', Types::INTEGER);
90    }
91
92    public function isDeletedAccount(): bool {
93        $metadata = $this->getMetadata();
94        return isset($metadata['deleted_account']);
95    }
96
97    public function getUserId(): string {
98        $metadata = $this->getMetadata();
99        return $metadata['deleted_account']['account'] ?? $this->userId ?? '';
100    }
101
102    public function getStatusEnum(): FileStatus {
103        return FileStatus::from($this->getStatus());
104    }
105
106    public function getStatus(): int {
107        return $this->status ?? FileStatus::DRAFT->value;
108    }
109
110    public function setStatus(int $status): void {
111        if (FileStatus::tryFrom($status) === null) {
112            throw new \InvalidArgumentException(sprintf('Invalid file status code: %d', $status));
113        }
114
115        $this->status = $status;
116        $this->markFieldUpdated('status');
117    }
118
119    public function setStatusEnum(FileStatus $status): void {
120        $this->setStatus($status->value);
121    }
122
123    public function getSignatureFlowEnum(): \OCA\Libresign\Enum\SignatureFlow {
124        return \OCA\Libresign\Enum\SignatureFlow::fromNumeric($this->signatureFlow);
125    }
126
127    public function setSignatureFlowEnum(\OCA\Libresign\Enum\SignatureFlow $flow): void {
128        $this->setSignatureFlow($flow->toNumeric());
129    }
130
131    public function getDocmdpLevelEnum(): \OCA\Libresign\Enum\DocMdpLevel {
132        return \OCA\Libresign\Enum\DocMdpLevel::tryFrom($this->docmdpLevel) ?? \OCA\Libresign\Enum\DocMdpLevel::NOT_CERTIFIED;
133    }
134
135    public function setDocmdpLevelEnum(\OCA\Libresign\Enum\DocMdpLevel $level): void {
136        $this->setDocmdpLevel($level->value);
137    }
138
139    public function getNodeTypeEnum(): NodeType {
140        return NodeType::from($this->nodeType);
141    }
142
143    public function setNodeTypeEnum(NodeType $nodeType): void {
144        $this->setNodeType($nodeType->value);
145    }
146
147    public function isEnvelope(): bool {
148        return $this->getNodeTypeEnum()->isEnvelope();
149    }
150
151    public function hasParent(): bool {
152        return $this->parentFileId !== null;
153    }
154}