Skip to content

Commit bcfeb6f

Browse files
committed
Merge commit 'refs/changes/70/14970/4' of ssh://gerrit.tuleap.net:29418/tuleap into HEAD
Change-Id: I8cddeab7684397725adaed893337460669ae381e
2 parents 8384fd3 + dd71196 commit bcfeb6f

18 files changed

+628
-169
lines changed

plugins/docman/include/REST/v1/DocmanFoldersResource.php

Lines changed: 310 additions & 44 deletions
Large diffs are not rendered by default.

plugins/docman/include/REST/v1/DocmanItemCreator.php

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use Tuleap\Docman\REST\v1\Metadata\HardcodedMetadataUsageChecker;
3838
use Tuleap\Docman\REST\v1\Metadata\HardcodedMetdataObsolescenceDateChecker;
3939
use Tuleap\Docman\REST\v1\Metadata\ItemStatusMapper;
40-
use Tuleap\Docman\REST\v1\Metadata\StatusNotFoundException;
4140
use Tuleap\Docman\REST\v1\Wiki\DocmanWikiPOSTRepresentation;
4241
use Tuleap\Docman\Upload\Document\DocumentOngoingUploadRetriever;
4342
use Tuleap\Docman\Upload\Document\DocumentToUploadCreator;
@@ -141,25 +140,15 @@ private function checkDocumentIsNotBeingUploaded(
141140
}
142141

143142
/**
144-
* @param $item_type_id
145-
* @param \DateTimeImmutable $current_time
146-
* @param Docman_Item $parent_item
147-
* @param PFUser $user
148-
* @param Project $project
149-
* @param $title
150-
* @param $description
151-
* @param string $status
152-
* @param string $obsolescence_date
153-
* @param $wiki_page
154-
* @param $link_url
155-
* @param $content
156-
*
157143
* @return CreatedItemRepresentation
158144
* @throws Metadata\InvalidDateComparisonException
159145
* @throws Metadata\InvalidDateTimeFormatException
160146
* @throws Metadata\ItemStatusUsageMismatchException
161-
* @throws Metadata\ObsoloscenceDateUsageMismatchException
162-
* @throws StatusNotFoundException
147+
* @throws Metadata\ObsolescenceDateDisabledException
148+
* @throws Metadata\ObsolescenceDateMissingParameterException
149+
* @throws Metadata\ObsolescenceDateNullException
150+
* @throws Metadata\StatusNotFoundBadStatusGivenException
151+
* @throws Metadata\StatusNotFoundNullException
163152
* @throws \Tuleap\Docman\CannotInstantiateItemWeHaveJustCreatedInDBException
164153
*/
165154
private function createDocument(
@@ -223,12 +212,15 @@ private function createDocument(
223212
}
224213

225214
/**
226-
* @throws RestException
227-
* @throws Metadata\ItemStatusUsageMismatchException
228-
* @throws StatusNotFoundException
229-
* @throws Metadata\ObsoloscenceDateUsageMismatchException
230-
* @throws Metadata\InvalidDateTimeFormatException
231215
* @throws Metadata\InvalidDateComparisonException
216+
* @throws Metadata\InvalidDateTimeFormatException
217+
* @throws Metadata\ItemStatusUsageMismatchException
218+
* @throws Metadata\ObsolescenceDateDisabledException
219+
* @throws Metadata\ObsolescenceDateMissingParameterException
220+
* @throws Metadata\ObsolescenceDateNullException
221+
* @throws Metadata\StatusNotFoundBadStatusGivenException
222+
* @throws Metadata\StatusNotFoundNullException
223+
* @throws RestException
232224
*/
233225
public function createFileDocument(
234226
Docman_Item $parent_item,
@@ -296,19 +288,15 @@ public function createFileDocument(
296288
}
297289

298290
/**
299-
* @param Docman_Item $parent_item
300-
* @param PFUser $user
301-
* @param DocmanFolderPOSTRepresentation $representation
302-
* @param \DateTimeImmutable $current_time
303-
* @param Project $project
304-
*
305-
* @return CreatedItemRepresentation
306291
* @throws Metadata\InvalidDateComparisonException
307292
* @throws Metadata\InvalidDateTimeFormatException
308293
* @throws Metadata\ItemStatusUsageMismatchException
309-
* @throws Metadata\ObsoloscenceDateUsageMismatchException
294+
* @throws Metadata\ObsolescenceDateDisabledException
295+
* @throws Metadata\ObsolescenceDateMissingParameterException
296+
* @throws Metadata\ObsolescenceDateNullException
297+
* @throws Metadata\StatusNotFoundBadStatusGivenException
298+
* @throws Metadata\StatusNotFoundNullException
310299
* @throws RestException
311-
* @throws StatusNotFoundException
312300
* @throws \Tuleap\Docman\CannotInstantiateItemWeHaveJustCreatedInDBException
313301
*/
314302
public function createFolder(
@@ -347,19 +335,15 @@ public function createFolder(
347335
}
348336

349337
/**
350-
* @param Docman_Item $parent_item
351-
* @param PFUser $user
352-
* @param DocmanEmptyPOSTRepresentation $representation
353-
* @param \DateTimeImmutable $current_time
354-
* @param Project $project
355-
*
356-
* @return CreatedItemRepresentation
357338
* @throws Metadata\InvalidDateComparisonException
358339
* @throws Metadata\InvalidDateTimeFormatException
359340
* @throws Metadata\ItemStatusUsageMismatchException
360-
* @throws Metadata\ObsoloscenceDateUsageMismatchException
341+
* @throws Metadata\ObsolescenceDateDisabledException
342+
* @throws Metadata\ObsolescenceDateMissingParameterException
343+
* @throws Metadata\ObsolescenceDateNullException
344+
* @throws Metadata\StatusNotFoundBadStatusGivenException
345+
* @throws Metadata\StatusNotFoundNullException
361346
* @throws RestException
362-
* @throws StatusNotFoundException
363347
* @throws \Tuleap\Docman\CannotInstantiateItemWeHaveJustCreatedInDBException
364348
*/
365349
public function createEmpty(
@@ -397,19 +381,15 @@ public function createEmpty(
397381
}
398382

399383
/**
400-
* @param Docman_Item $parent_item
401-
* @param PFUser $user
402-
* @param DocmanWikiPOSTRepresentation $representation
403-
* @param \DateTimeImmutable $current_time
404-
* @param Project $project
405-
*
406-
* @return CreatedItemRepresentation
407384
* @throws Metadata\InvalidDateComparisonException
408385
* @throws Metadata\InvalidDateTimeFormatException
409386
* @throws Metadata\ItemStatusUsageMismatchException
410-
* @throws Metadata\ObsoloscenceDateUsageMismatchException
387+
* @throws Metadata\ObsolescenceDateDisabledException
388+
* @throws Metadata\ObsolescenceDateMissingParameterException
389+
* @throws Metadata\ObsolescenceDateNullException
390+
* @throws Metadata\StatusNotFoundBadStatusGivenException
391+
* @throws Metadata\StatusNotFoundNullException
411392
* @throws RestException
412-
* @throws StatusNotFoundException
413393
* @throws \Tuleap\Docman\CannotInstantiateItemWeHaveJustCreatedInDBException
414394
*/
415395
public function createWiki(
@@ -454,19 +434,16 @@ public function createWiki(
454434
}
455435

456436
/**
457-
* @param Docman_Item $parent_item
458-
* @param PFUser $user
459-
* @param DocmanEmbeddedPOSTRepresentation $representation
460-
* @param \DateTimeImmutable $current_time
461-
* @param Project $project
462-
*
463437
* @return CreatedItemRepresentation
464438
* @throws Metadata\InvalidDateComparisonException
465439
* @throws Metadata\InvalidDateTimeFormatException
466440
* @throws Metadata\ItemStatusUsageMismatchException
467-
* @throws Metadata\ObsoloscenceDateUsageMismatchException
441+
* @throws Metadata\ObsolescenceDateDisabledException
442+
* @throws Metadata\ObsolescenceDateMissingParameterException
443+
* @throws Metadata\ObsolescenceDateNullException
444+
* @throws Metadata\StatusNotFoundBadStatusGivenException
445+
* @throws Metadata\StatusNotFoundNullException
468446
* @throws RestException
469-
* @throws StatusNotFoundException
470447
* @throws \Tuleap\Docman\CannotInstantiateItemWeHaveJustCreatedInDBException
471448
*/
472449
public function createEmbedded(
@@ -504,19 +481,16 @@ public function createEmbedded(
504481
}
505482

506483
/**
507-
* @param Docman_Item $parent_item
508-
* @param PFUser $user
509-
* @param DocmanLinkPOSTRepresentation $representation
510-
* @param \DateTimeImmutable $current_time
511-
* @param Project $project
512-
*
513484
* @return CreatedItemRepresentation
514485
* @throws Metadata\InvalidDateComparisonException
515486
* @throws Metadata\InvalidDateTimeFormatException
516487
* @throws Metadata\ItemStatusUsageMismatchException
517-
* @throws Metadata\ObsoloscenceDateUsageMismatchException
488+
* @throws Metadata\ObsolescenceDateDisabledException
489+
* @throws Metadata\ObsolescenceDateMissingParameterException
490+
* @throws Metadata\ObsolescenceDateNullException
491+
* @throws Metadata\StatusNotFoundBadStatusGivenException
492+
* @throws Metadata\StatusNotFoundNullException
518493
* @throws RestException
519-
* @throws StatusNotFoundException
520494
* @throws \Tuleap\Docman\CannotInstantiateItemWeHaveJustCreatedInDBException
521495
*/
522496
public function createLink(

plugins/docman/include/REST/v1/DocmanLinksResource.php

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Docman_LockFactory;
2828
use Docman_PermissionsManager;
2929
use Docman_SettingsBo;
30-
use Luracast\Restler\RestException;
3130
use Docman_VersionFactory;
3231
use Project;
3332
use ProjectManager;
@@ -169,16 +168,67 @@ public function patch(int $id, DocmanLinkPATCHRepresentation $representation)
169168
400,
170169
$exception->getMessage()
171170
);
172-
} catch (Metadata\StatusNotFoundException $e) {
173-
throw new RestException(400, $e->getMessage());
174171
} catch (Metadata\ItemStatusUsageMismatchException $e) {
175-
throw new RestException(403, 'The "Status" property is not activated for this item.');
172+
throw new I18NRestException(
173+
400,
174+
dgettext(
175+
'tuleap-docman',
176+
'The "Status" property is not activated for this item.'
177+
)
178+
);
176179
} catch (Metadata\InvalidDateComparisonException $e) {
177-
throw new RestException(400, 'The obsolescence date is before the current date');
180+
throw new I18NRestException(
181+
400,
182+
dgettext(
183+
'tuleap-docman',
184+
'The obsolescence date is before the current date'
185+
)
186+
);
178187
} catch (Metadata\InvalidDateTimeFormatException $e) {
179-
throw new RestException(400, 'The date format is incorrect. The format should be YYYY-MM-DD');
180-
} catch (Metadata\ObsoloscenceDateUsageMismatchException $e) {
181-
throw new RestException(403, $e->getMessage());
188+
throw new I18NRestException(
189+
400,
190+
dgettext(
191+
'tuleap-docman',
192+
'The date format is incorrect. The format must be "YYYY-MM-DD"'
193+
)
194+
);
195+
} catch (Metadata\ObsolescenceDateDisabledException $e) {
196+
throw new I18NRestException(
197+
400,
198+
dgettext(
199+
'tuleap-docman',
200+
'The project does not support obsolescence date, you should not provide it to create a new document.'
201+
)
202+
);
203+
} catch (Metadata\ObsolescenceDateMissingParameterException $e) {
204+
throw new I18NRestException(
205+
400,
206+
dgettext(
207+
'tuleap-docman',
208+
'"obsolescence_date" parameter is required to create a new document.'
209+
)
210+
);
211+
} catch (Metadata\ObsolescenceDateNullException $e) {
212+
throw new I18NRestException(
213+
400,
214+
dgettext(
215+
'tuleap-docman',
216+
'The date cannot be null'
217+
)
218+
);
219+
} catch (Metadata\StatusNotFoundBadStatusGivenException $e) {
220+
throw new I18NRestException(
221+
400,
222+
sprintf(
223+
dgettext('tuleap-docman', 'The status "%s" is invalid.'),
224+
$representation->status
225+
)
226+
);
227+
} catch (Metadata\StatusNotFoundNullException $e) {
228+
throw new I18NRestException(
229+
400,
230+
dgettext('tuleap-docman', 'null is not a valid status.')
231+
);
182232
}
183233
}
184234

plugins/docman/include/REST/v1/DocmanWikiResource.php

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use Docman_PermissionsManager;
2626
use Docman_SettingsBo;
2727
use Docman_VersionFactory;
28-
use Luracast\Restler\RestException;
2928
use Project;
3029
use ProjectManager;
3130
use Tuleap\DB\DBFactory;
@@ -156,16 +155,67 @@ public function patch(int $id, DocmanWikiPATCHRepresentation $representation): v
156155
403,
157156
dgettext('tuleap-docman', 'Document is locked by another user.')
158157
);
159-
} catch (Metadata\StatusNotFoundException $e) {
160-
throw new RestException(400, $e->getMessage());
161158
} catch (Metadata\ItemStatusUsageMismatchException $e) {
162-
throw new RestException(400, 'The "Status" property is not activated for this item.');
159+
throw new I18NRestException(
160+
400,
161+
dgettext(
162+
'tuleap-docman',
163+
'The "Status" property is not activated for this item.'
164+
)
165+
);
163166
} catch (Metadata\InvalidDateComparisonException $e) {
164-
throw new RestException(400, 'The obsolescence date is before the current date');
167+
throw new I18NRestException(
168+
400,
169+
dgettext(
170+
'tuleap-docman',
171+
'The obsolescence date is before the current date'
172+
)
173+
);
165174
} catch (Metadata\InvalidDateTimeFormatException $e) {
166-
throw new RestException(400, 'The date format is incorrect. The format should be YYYY-MM-DD');
167-
} catch (Metadata\ObsoloscenceDateUsageMismatchException $e) {
168-
throw new RestException(400, $e->getMessage());
175+
throw new I18NRestException(
176+
400,
177+
dgettext(
178+
'tuleap-docman',
179+
'The date format is incorrect. The format must be "YYYY-MM-DD"'
180+
)
181+
);
182+
} catch (Metadata\ObsolescenceDateDisabledException $e) {
183+
throw new I18NRestException(
184+
400,
185+
dgettext(
186+
'tuleap-docman',
187+
'The project does not support obsolescence date, you should not provide it to create a new document.'
188+
)
189+
);
190+
} catch (Metadata\ObsolescenceDateMissingParameterException $e) {
191+
throw new I18NRestException(
192+
400,
193+
dgettext(
194+
'tuleap-docman',
195+
'"obsolescence_date" parameter is required to create a new document.'
196+
)
197+
);
198+
} catch (Metadata\ObsolescenceDateNullException $e) {
199+
throw new I18NRestException(
200+
400,
201+
dgettext(
202+
'tuleap-docman',
203+
'The date cannot be null'
204+
)
205+
);
206+
} catch (Metadata\StatusNotFoundBadStatusGivenException $e) {
207+
throw new I18NRestException(
208+
400,
209+
sprintf(
210+
dgettext('tuleap-docman', 'The status "%s" is invalid.'),
211+
$representation->status
212+
)
213+
);
214+
} catch (Metadata\StatusNotFoundNullException $e) {
215+
throw new I18NRestException(
216+
400,
217+
dgettext('tuleap-docman', 'null is not a valid status.')
218+
);
169219
}
170220
}
171221

plugins/docman/include/REST/v1/Links/DocmanLinkUpdator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ public function __construct(
120120
* @throws \Tuleap\Docman\REST\v1\Metadata\InvalidDateComparisonException
121121
* @throws \Tuleap\Docman\REST\v1\Metadata\InvalidDateTimeFormatException
122122
* @throws \Tuleap\Docman\REST\v1\Metadata\ItemStatusUsageMismatchException
123-
* @throws \Tuleap\Docman\REST\v1\Metadata\ObsoloscenceDateUsageMismatchException
124-
* @throws \Tuleap\Docman\REST\v1\Metadata\StatusNotFoundException
123+
* @throws \Tuleap\Docman\REST\v1\Metadata\ObsolescenceDateDisabledException
124+
* @throws \Tuleap\Docman\REST\v1\Metadata\ObsolescenceDateMissingParameterException
125+
* @throws \Tuleap\Docman\REST\v1\Metadata\ObsolescenceDateNullException
126+
* @throws \Tuleap\Docman\REST\v1\Metadata\StatusNotFoundBadStatusGivenException
127+
* @throws \Tuleap\Docman\REST\v1\Metadata\StatusNotFoundNullException
125128
*/
126129
public function updateLink(
127130
\Docman_Link $item,

plugins/docman/include/REST/v1/Metadata/HardcodedMetdataObsolescenceDateChecker.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public function checkDateValidity(int $current_date, int $obsolescence_date, int
5252
}
5353

5454
/**
55-
* @throws ObsoloscenceDateUsageMismatchException
55+
* @throws ObsolescenceDateDisabledException
56+
* @throws ObsolescenceDateMissingParameterException
57+
* @throws ObsolescenceDateNullException
5658
*/
5759
public function checkObsolescenceDateUsage(?string $date, int $item_type): void
5860
{
@@ -61,19 +63,15 @@ public function checkObsolescenceDateUsage(?string $date, int $item_type): void
6163
}
6264

6365
if ($date === null) {
64-
throw new ObsoloscenceDateUsageMismatchException('The date cannot be null');
66+
throw new ObsolescenceDateNullException();
6567
}
6668

6769
if ($date === ItemRepresentation::OBSOLESCENCE_DATE_NONE && $this->isObsolescenceMetadataUsed()) {
68-
throw new ObsoloscenceDateUsageMismatchException(
69-
'"obsolescence_date" parameter is required to create a new document.'
70-
);
70+
throw new ObsolescenceDateMissingParameterException();
7171
}
7272

7373
if ($date !== ItemRepresentation::OBSOLESCENCE_DATE_NONE && !$this->isObsolescenceMetadataUsed()) {
74-
throw new ObsoloscenceDateUsageMismatchException(
75-
'The project does not support obsolescence date, you should not provide it to create a new document.'
76-
);
74+
throw new ObsolescenceDateDisabledException();
7775
}
7876
}
7977

0 commit comments

Comments
 (0)