• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

smartsheet / smartsheet-java-sdk / #55

02 Oct 2024 07:40PM UTC coverage: 60.548% (+0.7%) from 59.836%
#55

push

github

web-flow
Release prep for 3.2.1 (#103)

4156 of 6864 relevant lines covered (60.55%)

0.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.56
/src/main/java/com/smartsheet/api/models/Share.java
1
/*
2
 * Copyright (C) 2024 Smartsheet
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.smartsheet.api.models;
18

19
import com.smartsheet.api.models.enums.AccessLevel;
20
import com.smartsheet.api.models.enums.ShareScope;
21
import com.smartsheet.api.models.enums.ShareType;
22

23
import java.util.Date;
24

25
/**
26
 * Represents a Share Object.
27
 *
28
 * @see <a href="http://help.smartsheet.com/customer/portal/articles/520104-sharing-sheets">Sharing Sheets</a>
29
 */
30
public class Share extends NamedModel<String> {
1✔
31
    /**
32
     * Represents the access level for this specific share.
33
     */
34
    private AccessLevel accessLevel;
35

36
    /**
37
     * Represents the email for this specific share.
38
     */
39
    private String email;
40

41
    /**
42
     * Represents the userId if the share is of type {@link ShareType#USER}
43
     */
44
    private Long userId;
45

46
    /**
47
     * Represents the groupId if the share is of type {@link ShareType#GROUP}
48
     */
49
    private Long groupId;
50

51
    /**
52
     * Indicates what type of share this is.
53
     */
54
    private ShareType type;
55

56
    /**
57
     * The scope of this share. One of the following values:
58
     * ITEM: an item-level share (i.e., the specific object to which the Share applies is shared with the user or group)
59
     * WORKSPACE: a workspace-level share (i.e., the workspace that contains the object to which the Share
60
     * applies is shared with the user or group)
61
     */
62
    private ShareScope scope;
63

64
    /**
65
     * Time that the share was created.
66
     */
67
    private Date createdAt;
68

69
    /**
70
     * Time that the share was modified.
71
     */
72
    private Date modifiedAt;
73

74
    /**
75
     * Represents the subject of the email that will optionally be sent to notify the recipient.
76
     */
77
    private String subject;
78

79
    /**
80
     * Represents the message to be included in the body of the email.
81
     */
82
    private String message;
83

84
    /**
85
     * Represents the flag to indicate whether or not to send a copy of the email to the sharer of the sheet.
86
     */
87
    private Boolean ccMe;
88

89
    /**
90
     * Provide an 'override' of setName (returns Share not NamedModel)
91
     *
92
     * @param name the new name
93
     */
94
    public Share setName(String name) {
95
        super.setName(name);
1✔
96
        return this;
1✔
97
    }
98

99
    /**
100
     * Gets the subject of the email that will optionally be sent to notify the recipient.
101
     *
102
     * @return the subject
103
     */
104
    public String getSubject() {
105
        return subject;
1✔
106
    }
107

108
    /**
109
     * Sets the subject of the email that will optionally be sent to notify the recipient.
110
     *
111
     * @param subject the subject of the email
112
     */
113
    public Share setSubject(String subject) {
114
        this.subject = subject;
×
115
        return this;
×
116
    }
117

118
    /**
119
     * Gets the message to be included in the body of the email.
120
     *
121
     * @return the message
122
     */
123
    public String getMessage() {
124
        return message;
1✔
125
    }
126

127
    /**
128
     * Sets the message to be included in the body of the email.
129
     *
130
     * @param message the message
131
     */
132
    public Share setMessage(String message) {
133
        this.message = message;
×
134
        return this;
×
135
    }
136

137
    /**
138
     * Gets the flag to indicate whether or not to send a copy of the email to the sharer
139
     *
140
     * @return the flag for CC
141
     */
142
    public Boolean isCcMe() {
143
        return ccMe;
1✔
144
    }
145

146
    /**
147
     * Sets the flag to indicate whether or not to send a copy of the email to the sharer.
148
     *
149
     * @param ccMe the flag for CC
150
     */
151
    public Share setCcMe(Boolean ccMe) {
152
        this.ccMe = ccMe;
×
153
        return this;
×
154
    }
155

156
    /**
157
     * Gets the access level for this specific share.
158
     *
159
     * @return the access level
160
     */
161
    public AccessLevel getAccessLevel() {
162
        return accessLevel;
1✔
163
    }
164

165
    /**
166
     * Sets the access level for this specific share.
167
     *
168
     * @param accessLevel the new access level
169
     */
170
    public Share setAccessLevel(AccessLevel accessLevel) {
171
        this.accessLevel = accessLevel;
1✔
172
        return this;
1✔
173
    }
174

175
    /**
176
     * Gets the email for this specific share.
177
     *
178
     * @return the email
179
     */
180
    public String getEmail() {
181
        return email;
1✔
182
    }
183

184
    /**
185
     * Sets the email for this specific share.
186
     *
187
     * @param email the new email
188
     */
189
    public Share setEmail(String email) {
190
        this.email = email;
1✔
191
        return this;
1✔
192
    }
193

194
    /**
195
     * Get the scope of this share. One of ITEM or WORKSPACE
196
     *
197
     * @return scope
198
     */
199
    public ShareScope getScope() {
200
        return scope;
1✔
201
    }
202

203
    /**
204
     * Set the scope of this share. One of ITEM or WORKSPACE
205
     */
206
    public Share setScope(ShareScope scope) {
207
        this.scope = scope;
×
208
        return this;
×
209
    }
210

211
    /**
212
     * Gets the time that the share was created
213
     *
214
     * @return createdAt
215
     */
216
    public Date getCreatedAt() {
217
        return createdAt;
1✔
218
    }
219

220
    /**
221
     * Sets the time that the share was created
222
     */
223
    public Share setCreatedAt(Date createdAt) {
224
        this.createdAt = createdAt;
×
225
        return this;
×
226
    }
227

228
    /**
229
     * Gets the time that the share was last modified
230
     *
231
     * @return modifiedAt
232
     */
233
    public Date getModifiedAt() {
234
        return modifiedAt;
1✔
235
    }
236

237
    /**
238
     * Sets the time that the share was last modified
239
     */
240
    public Share setModifiedAt(Date modifiedAt) {
241
        this.modifiedAt = modifiedAt;
×
242
        return this;
×
243
    }
244

245
    /**
246
     * @return the userId, <code>null</code> if is {@link ShareType#GROUP}
247
     */
248
    public Long getUserId() {
249
        return userId;
1✔
250
    }
251

252
    /**
253
     * @param userId the userId to set
254
     */
255
    public Share setUserId(Long userId) {
256
        this.userId = userId;
1✔
257
        return this;
1✔
258
    }
259

260
    /**
261
     * @return the groupId, <code>null</code> if is {@link ShareType#USER}
262
     */
263
    public Long getGroupId() {
264
        return groupId;
1✔
265
    }
266

267
    /**
268
     * @param groupId the groupId to set
269
     */
270
    public Share setGroupId(Long groupId) {
271
        this.groupId = groupId;
1✔
272
        return this;
1✔
273
    }
274

275
    /**
276
     * @return the type
277
     */
278
    public ShareType getType() {
279
        return type;
1✔
280
    }
281

282
    /**
283
     * @param type the {@link ShareType} to set
284
     */
285
    public Share setType(ShareType type) {
286
        this.type = type;
1✔
287
        return this;
1✔
288
    }
289

290
    /**
291
     * A convenience class for creating a {@link Share} with the necessary fields for sharing the sheet to one user.
292
     */
293
    public static class ShareToOneUserBuilder {
×
294
        private AccessLevel accessLevel;
295
        private String email;
296

297
        /**
298
         * Access level for this specific share.
299
         *
300
         * @param accessLevel the access level
301
         * @return the share to one builder
302
         */
303
        public ShareToOneUserBuilder setAccessLevel(AccessLevel accessLevel) {
304
            this.accessLevel = accessLevel;
×
305
            return this;
×
306
        }
307

308
        /**
309
         * Email address for this specific share.
310
         *
311
         * @param email the email
312
         * @return the share to one builder
313
         */
314
        public ShareToOneUserBuilder setEmail(String email) {
315
            this.email = email;
×
316
            return this;
×
317
        }
318

319
        /**
320
         * Gets the access level.
321
         *
322
         * @return the access level
323
         */
324
        public AccessLevel getAccessLevel() {
325
            return accessLevel;
×
326
        }
327

328
        /**
329
         * Gets the email.
330
         *
331
         * @return the email
332
         */
333
        public String getEmail() {
334
            return email;
×
335
        }
336

337
        /**
338
         * Builds the {@link Share} object.
339
         *
340
         * @return the share
341
         */
342
        public Share build() {
343
            if (accessLevel == null || email == null) {
×
344
                throw new InstantiationError("emailAddress and accessLevel are required");
×
345
            }
346

347
            Share share = new Share();
×
348
            share.accessLevel = accessLevel;
×
349
            share.email = email;
×
350
            return share;
×
351
        }
352
    }
353

354
    /**
355
     * A convenience class for creating a {@link Share} with the necessary fields for sharing the sheet to one {@link Group}.
356
     */
357
    public static class ShareToOneGroupBuilder {
×
358
        private AccessLevel accessLevel;
359
        private Long groupId;
360

361
        /**
362
         * Access level for this specific share.
363
         *
364
         * @param accessLevel the access level
365
         * @return the share to one builder
366
         */
367
        public ShareToOneGroupBuilder setAccessLevel(AccessLevel accessLevel) {
368
            this.accessLevel = accessLevel;
×
369
            return this;
×
370
        }
371

372
        /**
373
         * Group Id for this share.
374
         *
375
         * @param groupId the group Id.
376
         * @return the share to one builder
377
         */
378
        public ShareToOneGroupBuilder setGroupId(Long groupId) {
379
            this.groupId = groupId;
×
380
            return this;
×
381
        }
382

383
        /**
384
         * Gets the access level.
385
         *
386
         * @return the access level
387
         */
388
        public AccessLevel getAccessLevel() {
389
            return accessLevel;
×
390
        }
391

392
        /**
393
         * Gets the group Id.
394
         *
395
         * @return the group Id
396
         */
397
        public Long getGroupId() {
398
            return groupId;
×
399
        }
400

401
        /**
402
         * Builds the {@link Share} object.
403
         *
404
         * @return the share
405
         */
406
        public Share build() {
407
            if (accessLevel == null || groupId == null) {
×
408
                throw new InstantiationError("You must provide a groupId and accessLevel");
×
409
            }
410

411
            Share share = new Share();
×
412
            share.accessLevel = accessLevel;
×
413
            share.groupId = groupId;
×
414
            return share;
×
415
        }
416
    }
417

418
    /**
419
     * A convenience class for creating a {@link Share} with the necessary fields to update a specific share.
420
     */
421
    public static class UpdateShareBuilder {
×
422
        private AccessLevel accessLevel;
423
        private String id;
424

425
        /**
426
         * Share Id for this specific share.
427
         *
428
         * @return the builder
429
         */
430
        public String getShareId() {
431
            return id;
×
432
        }
433

434
        /**
435
         * Set the Share ID
436
         */
437
        public UpdateShareBuilder setShareId(String shareId) {
438
            this.id = shareId;
×
439
            return this;
×
440
        }
441

442
        /**
443
         * Access level for the share.
444
         *
445
         * @param accessLevel the access level
446
         * @return the update share builder
447
         */
448
        public UpdateShareBuilder setAccessLevel(AccessLevel accessLevel) {
449
            this.accessLevel = accessLevel;
×
450
            return this;
×
451
        }
452

453
        /**
454
         * Gets the access level.
455
         *
456
         * @return the access level
457
         */
458
        public AccessLevel getAccessLevel() {
459
            return accessLevel;
×
460
        }
461

462
        /**
463
         * Builds the {@link Share} object.
464
         *
465
         * @return the share
466
         */
467
        public Share build() {
468
            if (accessLevel == null || id == null) {
×
469
                throw new InstantiationError("The access level and share id must be specified.");
×
470
            }
471

472
            Share share = new Share();
×
473
            share.accessLevel = accessLevel;
×
474
            share.setId(id);
×
475
            return share;
×
476
        }
477
    }
478

479
    /**
480
     * A convenience class for creating a {@link Share} with the necessary fields to create a {@link ShareType#USER} {@link Share}.
481
     * You must set one and only of of emailAddress and userId.
482
     */
483
    public static class CreateUserShareBuilder {
1✔
484
        private String email;
485
        private AccessLevel accessLevel;
486

487
        /**
488
         * Email address for the {@link ShareType#USER} share.
489
         *
490
         * @param emailAddress the email address
491
         * @return the {@link CreateUserShareBuilder}
492
         */
493
        public CreateUserShareBuilder setEmailAddress(String emailAddress) {
494
            this.email = emailAddress;
1✔
495
            return this;
1✔
496
        }
497

498
        /**
499
         * Gets the email address.
500
         *
501
         * @return the email address
502
         */
503
        public String getEmailAddress() {
504
            return email;
×
505
        }
506

507
        /**
508
         * Gets the access level
509
         *
510
         * @return the access level
511
         */
512
        public AccessLevel getAccessLevel() {
513
            return accessLevel;
×
514
        }
515

516
        /**
517
         * Sets the access level
518
         *
519
         * @param accessLevel the access level
520
         */
521
        public CreateUserShareBuilder setAccessLevel(AccessLevel accessLevel) {
522
            this.accessLevel = accessLevel;
1✔
523
            return this;
1✔
524
        }
525

526
        /**
527
         * Builds the {@link Share} object.
528
         *
529
         * @return the share
530
         */
531
        public Share build() {
532
            if (accessLevel == null || email == null) {
1✔
533
                throw new InstantiationError("emailAddress and accessLevel are required");
×
534
            }
535

536
            Share share = new Share();
1✔
537
            share.email = email;
1✔
538
            share.accessLevel = accessLevel;
1✔
539
            return share;
1✔
540
        }
541
    }
542

543
    /**
544
     * A convenience class for creating a {@link Share} with the necessary fields to create a {@link ShareType#GROUP} {@link Share}.
545
     * You must set groupId
546
     */
547
    public static class CreateGroupShareBuilder {
1✔
548
        private AccessLevel accessLevel;
549
        private Long groupId;
550

551
        /**
552
         * Access level for this specific share.
553
         *
554
         * @param accessLevel the access level
555
         * @return the group share builder
556
         */
557
        public CreateGroupShareBuilder setAccessLevel(AccessLevel accessLevel) {
558
            this.accessLevel = accessLevel;
1✔
559
            return this;
1✔
560
        }
561

562
        /**
563
         * Group Id for this share.
564
         *
565
         * @param groupId the group Id.
566
         * @return the group share builder
567
         */
568
        public CreateGroupShareBuilder setGroupId(Long groupId) {
569
            this.groupId = groupId;
1✔
570
            return this;
1✔
571
        }
572

573
        /**
574
         * Gets the access level.
575
         *
576
         * @return the access level
577
         */
578
        public AccessLevel getAccessLevel() {
579
            return accessLevel;
×
580
        }
581

582
        /**
583
         * Gets the group Id.
584
         *
585
         * @return the group Id
586
         */
587
        public Long getGroupId() {
588
            return groupId;
×
589
        }
590

591
        /**
592
         * Builds the {@link Share} object.
593
         *
594
         * @return the share
595
         */
596
        public Share build() {
597
            if (accessLevel == null || groupId == null) {
1✔
598
                throw new InstantiationError("You must provide a groupId and accessLevel");
×
599
            }
600

601
            Share share = new Share();
1✔
602
            share.accessLevel = accessLevel;
1✔
603
            share.groupId = groupId;
1✔
604
            return share;
1✔
605
        }
606
    }
607
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc