forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSource.php
More file actions
133 lines (119 loc) · 3.45 KB
/
Copy pathDataSource.php
File metadata and controls
133 lines (119 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace ProcessMaker\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rule;
use ProcessMaker\Traits\Encryptable;
use ProcessMaker\Traits\HasCategories;
use ProcessMaker\Traits\HideSystemResources;
use ProcessMaker\Traits\MakeHttpRequests;
use ProcessMaker\Traits\SerializeToIso8601;
/**
* Class DataSource
*
* @package ProcessMaker\Packages\Connectors\DataSources\Models
*
* @property integer id
* @property string name
* @property string description
* @property array endpoints
* @property array mappings
* @property string authtype
* @property string credentials
* @property string status
* @property integer data_source_category_id
* @property Carbon $updated_at
* @property Carbon $created_at
*
* @OA\Schema(
* schema="dataSourceEditable",
* @OA\Property(property="id", type="string", format="id"),
* @OA\Property(property="name", type="string"),
* @OA\Property(property="description", type="string"),
* @OA\Property(property="endpoints", type="string"),
* @OA\Property(property="mappings", type="string"),
* @OA\Property(property="authtype", type="string"),
* @OA\Property(property="credentials", type="string"),
* @OA\Property(property="status", type="string"),
* @OA\Property(property="data_source_category_id", type="string"),
* ),
* @OA\Schema(
* schema="dataSource",
* allOf={@OA\Schema(ref="#/components/schemas/dataSourceEditable")},
* @OA\Property(property="created_at", type="string", format="date-time"),
* @OA\Property(property="updated_at", type="string", format="date-time"),
* )
*
*/
class DataSource extends Model
{
use Encryptable;
use MakeHttpRequests;
use SerializeToIso8601;
use HideSystemResources;
use HasCategories;
const categoryClass = DataSourceCategory::class;
protected $connection = 'processmaker';
protected $encryptable = [
'credentials'
];
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [
'id',
'created_at',
'updated_at',
];
protected $casts = [
'endpoints' => 'array',
];
/**
* Validation rules
*
* @param $existing
*
* @return array
*/
public static function rules($existing = null)
{
$unique = Rule::unique('data_sources')->ignore($existing);
return [
'name' => ['required', $unique, 'alpha_spaces'],
'authtype' => 'required|in:NONE,BASIC,OAUTH2_BEARER,OAUTH2_PASSWORD',
'status' => 'in:ACTIVE,INACTIVE',
'data_source_category_id' => 'required',
];
}
/**
* Get the associated category
*/
public function category()
{
return $this->belongsTo(DataSourceCategory::class, 'data_source_category_id');
}
/**
* Set multiple|single categories to the data source
*
* @param string $value the value is a comma separated list of category ids
*
* @return DataSource
*/
public function setDataSourceCategoryIdAttribute($value)
{
return $this->setMultipleCategories($value, 'data_source_category_id');
}
/**
* Get multiple|single categories of the data source
*
* @param string $value
*
* @return DataSource
*/
public function getDataSourceCategoryIdAttribute($value)
{
return implode(',', $this->categories()->pluck('category_id')->toArray()) ?: $value;
}
}