001
014
015 package com.liferay.portlet.documentlibrary.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.systemevent.SystemEvent;
020 import com.liferay.portal.kernel.util.ArrayUtil;
021 import com.liferay.portal.kernel.util.LocaleUtil;
022 import com.liferay.portal.kernel.util.OrderByComparator;
023 import com.liferay.portal.kernel.util.ParamUtil;
024 import com.liferay.portal.kernel.util.SortedArrayList;
025 import com.liferay.portal.kernel.util.Validator;
026 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
027 import com.liferay.portal.model.SystemEventConstants;
028 import com.liferay.portal.model.User;
029 import com.liferay.portal.service.ServiceContext;
030 import com.liferay.portal.util.PortalUtil;
031 import com.liferay.portlet.documentlibrary.DuplicateFileEntryTypeException;
032 import com.liferay.portlet.documentlibrary.NoSuchFolderException;
033 import com.liferay.portlet.documentlibrary.NoSuchMetadataSetException;
034 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
035 import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
036 import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
037 import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
038 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
039 import com.liferay.portlet.documentlibrary.model.DLFolder;
040 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
041 import com.liferay.portlet.documentlibrary.service.base.DLFileEntryTypeLocalServiceBaseImpl;
042 import com.liferay.portlet.documentlibrary.util.DLUtil;
043 import com.liferay.portlet.dynamicdatamapping.RequiredStructureException;
044 import com.liferay.portlet.dynamicdatamapping.StructureXsdException;
045 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
046 import com.liferay.portlet.dynamicdatamapping.model.DDMStructureConstants;
047
048 import java.util.ArrayList;
049 import java.util.Date;
050 import java.util.HashMap;
051 import java.util.List;
052 import java.util.Locale;
053 import java.util.Map;
054
055
062 public class DLFileEntryTypeLocalServiceImpl
063 extends DLFileEntryTypeLocalServiceBaseImpl {
064
065 @Override
066 public DLFileEntryType addFileEntryType(
067 long userId, long groupId, String fileEntryTypeKey,
068 Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
069 long[] ddmStructureIds, ServiceContext serviceContext)
070 throws PortalException, SystemException {
071
072 User user = userPersistence.findByPrimaryKey(userId);
073
074 if (Validator.isNull(fileEntryTypeKey)) {
075 fileEntryTypeKey = String.valueOf(counterLocalService.increment());
076 }
077 else {
078 fileEntryTypeKey = fileEntryTypeKey.trim().toUpperCase();
079 }
080
081 String fileEntryTypeUuid = serviceContext.getUuid();
082
083 if (Validator.isNull(fileEntryTypeUuid)) {
084 fileEntryTypeUuid = PortalUUIDUtil.generate();
085 }
086
087 long fileEntryTypeId = counterLocalService.increment();
088
089 long ddmStructureId = updateDDMStructure(
090 userId, fileEntryTypeUuid, fileEntryTypeId, groupId, nameMap,
091 descriptionMap, serviceContext);
092
093 if (ddmStructureId > 0) {
094 ddmStructureIds = ArrayUtil.append(ddmStructureIds, ddmStructureId);
095 }
096
097 Date now = new Date();
098
099 validate(fileEntryTypeId, groupId, fileEntryTypeKey, ddmStructureIds);
100
101 DLFileEntryType dlFileEntryType = dlFileEntryTypePersistence.create(
102 fileEntryTypeId);
103
104 dlFileEntryType.setUuid(fileEntryTypeUuid);
105 dlFileEntryType.setGroupId(groupId);
106 dlFileEntryType.setCompanyId(user.getCompanyId());
107 dlFileEntryType.setUserId(user.getUserId());
108 dlFileEntryType.setUserName(user.getFullName());
109 dlFileEntryType.setCreateDate(serviceContext.getCreateDate(now));
110 dlFileEntryType.setModifiedDate(serviceContext.getModifiedDate(now));
111 dlFileEntryType.setFileEntryTypeKey(fileEntryTypeKey);
112 dlFileEntryType.setNameMap(nameMap);
113 dlFileEntryType.setDescriptionMap(descriptionMap);
114
115 dlFileEntryTypePersistence.update(dlFileEntryType);
116
117 dlFileEntryTypePersistence.addDDMStructures(
118 fileEntryTypeId, ddmStructureIds);
119
120 if (serviceContext.isAddGroupPermissions() ||
121 serviceContext.isAddGuestPermissions()) {
122
123 addFileEntryTypeResources(
124 dlFileEntryType, serviceContext.isAddGroupPermissions(),
125 serviceContext.isAddGuestPermissions());
126 }
127 else {
128 addFileEntryTypeResources(
129 dlFileEntryType, serviceContext.getGroupPermissions(),
130 serviceContext.getGuestPermissions());
131 }
132
133 return dlFileEntryType;
134 }
135
136 @Override
137 public DLFileEntryType addFileEntryType(
138 long userId, long groupId, String name, String description,
139 long[] ddmStructureIds, ServiceContext serviceContext)
140 throws PortalException, SystemException {
141
142 Map<Locale, String> nameMap = new HashMap<Locale, String>();
143
144 nameMap.put(LocaleUtil.getSiteDefault(), name);
145
146 Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
147
148 descriptionMap.put(LocaleUtil.getSiteDefault(), description);
149
150 return addFileEntryType(
151 userId, groupId, null, nameMap, descriptionMap, ddmStructureIds,
152 serviceContext);
153 }
154
155 @Override
156 public void cascadeFileEntryTypes(long userId, DLFolder dlFolder)
157 throws PortalException, SystemException {
158
159 List<DLFileEntryType> dlFileEntryTypes = getFolderFileEntryTypes(
160 new long[] {dlFolder.getGroupId()}, dlFolder.getFolderId(), true);
161
162 List<Long> fileEntryTypeIds = getFileEntryTypeIds(dlFileEntryTypes);
163
164 long defaultFileEntryTypeId = getDefaultFileEntryTypeId(
165 dlFolder.getFolderId());
166
167 ServiceContext serviceContext = new ServiceContext();
168
169 serviceContext.setCompanyId(dlFolder.getCompanyId());
170 serviceContext.setScopeGroupId(dlFolder.getGroupId());
171 serviceContext.setUserId(userId);
172
173 cascadeFileEntryTypes(
174 dlFolder.getGroupId(), dlFolder.getFolderId(),
175 defaultFileEntryTypeId, fileEntryTypeIds, serviceContext);
176 }
177
178 @Override
179 @SystemEvent(
180 action = SystemEventConstants.ACTION_SKIP,
181 type = SystemEventConstants.TYPE_DELETE)
182 public void deleteFileEntryType(DLFileEntryType dlFileEntryType)
183 throws PortalException, SystemException {
184
185 if (dlFileEntryPersistence.countByFileEntryTypeId(
186 dlFileEntryType.getFileEntryTypeId()) > 0) {
187
188 throw new RequiredStructureException(
189 RequiredStructureException.REFERENCED_STRUCTURE);
190 }
191
192 DDMStructure ddmStructure = ddmStructureLocalService.fetchStructure(
193 dlFileEntryType.getGroupId(),
194 PortalUtil.getClassNameId(DLFileEntryMetadata.class),
195 DLUtil.getDDMStructureKey(dlFileEntryType));
196
197 if (ddmStructure == null) {
198 ddmStructure = ddmStructureLocalService.fetchStructure(
199 dlFileEntryType.getGroupId(),
200 PortalUtil.getClassNameId(DLFileEntryMetadata.class),
201 DLUtil.getDeprecatedDDMStructureKey(dlFileEntryType));
202 }
203
204 if (ddmStructure != null) {
205 ddmStructureLocalService.deleteStructure(
206 ddmStructure.getStructureId());
207 }
208
209 dlFileEntryTypePersistence.remove(dlFileEntryType);
210 }
211
212 @Override
213 public void deleteFileEntryType(long fileEntryTypeId)
214 throws PortalException, SystemException {
215
216 DLFileEntryType dlFileEntryType =
217 dlFileEntryTypePersistence.findByPrimaryKey(fileEntryTypeId);
218
219 deleteFileEntryType(dlFileEntryType);
220 }
221
222 @Override
223 public void deleteFileEntryTypes(long groupId)
224 throws PortalException, SystemException {
225
226 List<DLFileEntryType> dlFileEntryTypes =
227 dlFileEntryTypePersistence.findByGroupId(groupId);
228
229 for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
230 deleteFileEntryType(dlFileEntryType);
231 }
232 }
233
234 @Override
235 public DLFileEntryType fetchFileEntryType(long fileEntryTypeId)
236 throws SystemException {
237
238 return dlFileEntryTypePersistence.fetchByPrimaryKey(fileEntryTypeId);
239 }
240
241 @Override
242 public long getDefaultFileEntryTypeId(long folderId)
243 throws PortalException, SystemException {
244
245 folderId = getFileEntryTypesPrimaryFolderId(folderId);
246
247 if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
248 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
249
250 return dlFolder.getDefaultFileEntryTypeId();
251 }
252 else {
253 return 0;
254 }
255 }
256
257 @Override
258 public DLFileEntryType getFileEntryType(long fileEntryTypeId)
259 throws PortalException, SystemException {
260
261 return dlFileEntryTypePersistence.findByPrimaryKey(fileEntryTypeId);
262 }
263
264 @Override
265 public DLFileEntryType getFileEntryType(
266 long groupId, String fileEntryTypeKey)
267 throws PortalException, SystemException {
268
269 fileEntryTypeKey = fileEntryTypeKey.trim().toUpperCase();
270
271 return dlFileEntryTypePersistence.findByG_F(groupId, fileEntryTypeKey);
272 }
273
274 @Override
275 public List<DLFileEntryType> getFileEntryTypes(long[] groupIds)
276 throws SystemException {
277
278 return dlFileEntryTypePersistence.findByGroupId(groupIds);
279 }
280
281 @Override
282 public List<DLFileEntryType> getFolderFileEntryTypes(
283 long[] groupIds, long folderId, boolean inherited)
284 throws PortalException, SystemException {
285
286 if (!inherited) {
287 return dlFolderPersistence.getDLFileEntryTypes(folderId);
288 }
289
290 List<DLFileEntryType> dlFileEntryTypes = null;
291
292 folderId = getFileEntryTypesPrimaryFolderId(folderId);
293
294 if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
295 dlFileEntryTypes = dlFolderPersistence.getDLFileEntryTypes(
296 folderId);
297 }
298
299 if ((dlFileEntryTypes == null) || dlFileEntryTypes.isEmpty()) {
300 dlFileEntryTypes = new ArrayList<DLFileEntryType>(
301 getFileEntryTypes(groupIds));
302
303 DLFileEntryType dlFileEntryType =
304 dlFileEntryTypePersistence.fetchByPrimaryKey(
305 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);
306
307 dlFileEntryTypes.add(0, dlFileEntryType);
308 }
309
310 return dlFileEntryTypes;
311 }
312
313 @Override
314 public List<DLFileEntryType> search(
315 long companyId, long[] groupIds, String keywords,
316 boolean includeBasicFileEntryType, int start, int end,
317 OrderByComparator orderByComparator)
318 throws SystemException {
319
320 return dlFileEntryTypeFinder.findByKeywords(
321 companyId, groupIds, keywords, includeBasicFileEntryType, start,
322 end, orderByComparator);
323 }
324
325 @Override
326 public int searchCount(
327 long companyId, long[] groupIds, String keywords,
328 boolean includeBasicFileEntryType)
329 throws SystemException {
330
331 return dlFileEntryTypeFinder.countByKeywords(
332 companyId, groupIds, keywords, includeBasicFileEntryType);
333 }
334
335 @Override
336 public void unsetFolderFileEntryTypes(long folderId)
337 throws SystemException {
338
339 List<DLFileEntryType> dlFileEntryTypes =
340 dlFolderPersistence.getDLFileEntryTypes(folderId);
341
342 for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
343 dlFolderPersistence.removeDLFileEntryType(
344 folderId, dlFileEntryType);
345 }
346 }
347
348 @Override
349 public DLFileEntry updateFileEntryFileEntryType(
350 DLFileEntry dlFileEntry, ServiceContext serviceContext)
351 throws PortalException, SystemException {
352
353 long groupId = serviceContext.getScopeGroupId();
354 long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
355
356 DLFolder dlFolder = dlFolderPersistence.fetchByPrimaryKey(
357 dlFileEntry.getFolderId());
358
359 if (dlFolder != null) {
360 groupId = dlFolder.getGroupId();
361 folderId = dlFolder.getFolderId();
362 }
363
364 List<DLFileEntryType> dlFileEntryTypes = getFolderFileEntryTypes(
365 PortalUtil.getSiteAndCompanyGroupIds(groupId), folderId, true);
366
367 List<Long> fileEntryTypeIds = getFileEntryTypeIds(dlFileEntryTypes);
368
369 if (fileEntryTypeIds.contains(dlFileEntry.getFileEntryTypeId())) {
370 return dlFileEntry;
371 }
372
373 long defaultFileEntryTypeId = getDefaultFileEntryTypeId(folderId);
374
375 DLFileVersion dlFileVersion =
376 dlFileVersionLocalService.getLatestFileVersion(
377 dlFileEntry.getFileEntryId(), true);
378
379 if (dlFileVersion.isPending()) {
380 workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(
381 dlFileVersion.getCompanyId(), dlFileEntry.getGroupId(),
382 DLFileEntry.class.getName(), dlFileVersion.getFileVersionId());
383 }
384
385 return dlFileEntryLocalService.updateFileEntry(
386 serviceContext.getUserId(), dlFileEntry.getFileEntryId(), null,
387 null, null, null, null, false, defaultFileEntryTypeId, null, null,
388 null, 0, serviceContext);
389 }
390
391 @Override
392 public void updateFileEntryType(
393 long userId, long fileEntryTypeId, Map<Locale, String> nameMap,
394 Map<Locale, String> descriptionMap, long[] ddmStructureIds,
395 ServiceContext serviceContext)
396 throws PortalException, SystemException {
397
398 DLFileEntryType dlFileEntryType =
399 dlFileEntryTypePersistence.findByPrimaryKey(fileEntryTypeId);
400
401 long ddmStructureId = updateDDMStructure(
402 userId, dlFileEntryType.getUuid(), fileEntryTypeId,
403 dlFileEntryType.getGroupId(), nameMap, descriptionMap,
404 serviceContext);
405
406 if (ddmStructureId > 0) {
407 ddmStructureIds = ArrayUtil.append(ddmStructureIds, ddmStructureId);
408 }
409
410 dlFileEntryType.setModifiedDate(serviceContext.getModifiedDate(null));
411 dlFileEntryType.setNameMap(nameMap);
412 dlFileEntryType.setDescriptionMap(descriptionMap);
413
414 dlFileEntryTypePersistence.update(dlFileEntryType);
415
416 dlFileEntryTypePersistence.setDDMStructures(
417 fileEntryTypeId, ddmStructureIds);
418 }
419
420 @Override
421 public void updateFileEntryType(
422 long userId, long fileEntryTypeId, String name, String description,
423 long[] ddmStructureIds, ServiceContext serviceContext)
424 throws PortalException, SystemException {
425
426 Map<Locale, String> nameMap = new HashMap<Locale, String>();
427
428 nameMap.put(LocaleUtil.getSiteDefault(), name);
429
430 Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
431
432 descriptionMap.put(LocaleUtil.getSiteDefault(), description);
433
434 updateFileEntryType(
435 userId, fileEntryTypeId, nameMap, descriptionMap, ddmStructureIds,
436 serviceContext);
437 }
438
439 @Override
440 public void updateFolderFileEntryTypes(
441 DLFolder dlFolder, List<Long> fileEntryTypeIds,
442 long defaultFileEntryTypeId, ServiceContext serviceContext)
443 throws PortalException, SystemException {
444
445 List<Long> originalFileEntryTypeIds = getFileEntryTypeIds(
446 dlFolderPersistence.getDLFileEntryTypes(dlFolder.getFolderId()));
447
448 if (fileEntryTypeIds.equals(originalFileEntryTypeIds)) {
449 return;
450 }
451
452 for (Long fileEntryTypeId : fileEntryTypeIds) {
453 if (!originalFileEntryTypeIds.contains(fileEntryTypeId)) {
454 dlFolderPersistence.addDLFileEntryType(
455 dlFolder.getFolderId(), fileEntryTypeId);
456 }
457 }
458
459 for (Long originalFileEntryTypeId : originalFileEntryTypeIds) {
460 if (!fileEntryTypeIds.contains(originalFileEntryTypeId)) {
461 dlFolderPersistence.removeDLFileEntryType(
462 dlFolder.getFolderId(), originalFileEntryTypeId);
463
464 workflowDefinitionLinkLocalService.deleteWorkflowDefinitionLink(
465 dlFolder.getCompanyId(), dlFolder.getGroupId(),
466 DLFolder.class.getName(), dlFolder.getFolderId(),
467 originalFileEntryTypeId);
468 }
469 }
470 }
471
472 protected void addFileEntryTypeResources(
473 DLFileEntryType dlFileEntryType, boolean addGroupPermissions,
474 boolean addGuestPermissions)
475 throws PortalException, SystemException {
476
477 resourceLocalService.addResources(
478 dlFileEntryType.getCompanyId(), dlFileEntryType.getGroupId(),
479 dlFileEntryType.getUserId(), DLFileEntryType.class.getName(),
480 dlFileEntryType.getFileEntryTypeId(), false, addGroupPermissions,
481 addGuestPermissions);
482 }
483
484 protected void addFileEntryTypeResources(
485 DLFileEntryType dlFileEntryType, String[] groupPermissions,
486 String[] guestPermissions)
487 throws PortalException, SystemException {
488
489 resourceLocalService.addModelResources(
490 dlFileEntryType.getCompanyId(), dlFileEntryType.getGroupId(),
491 dlFileEntryType.getUserId(), DLFileEntryType.class.getName(),
492 dlFileEntryType.getFileEntryTypeId(), groupPermissions,
493 guestPermissions);
494 }
495
496 protected void cascadeFileEntryTypes(
497 long groupId, long folderId, long defaultFileEntryTypeId,
498 List<Long> fileEntryTypeIds, ServiceContext serviceContext)
499 throws PortalException, SystemException {
500
501 List<DLFileEntry> dlFileEntries = dlFileEntryPersistence.findByG_F(
502 groupId, folderId);
503
504 for (DLFileEntry dlFileEntry : dlFileEntries) {
505 Long fileEntryTypeId = dlFileEntry.getFileEntryTypeId();
506
507 if (fileEntryTypeIds.contains(fileEntryTypeId)) {
508 continue;
509 }
510
511 DLFileVersion dlFileVersion =
512 dlFileVersionLocalService.getLatestFileVersion(
513 dlFileEntry.getFileEntryId(), true);
514
515 if (dlFileVersion.isPending()) {
516 workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(
517 dlFileVersion.getCompanyId(), groupId,
518 DLFileEntry.class.getName(),
519 dlFileVersion.getFileVersionId());
520 }
521
522 dlFileEntryService.updateFileEntry(
523 dlFileEntry.getFileEntryId(), null, null, null, null, null,
524 false, defaultFileEntryTypeId, null, null, null, 0,
525 serviceContext);
526 }
527
528 List<DLFolder> subFolders = dlFolderPersistence.findByG_M_P_H(
529 groupId, false, folderId, false);
530
531 for (DLFolder subFolder : subFolders) {
532 long subFolderId = subFolder.getFolderId();
533
534 if (subFolder.isOverrideFileEntryTypes()) {
535 continue;
536 }
537
538 cascadeFileEntryTypes(
539 groupId, subFolderId, defaultFileEntryTypeId, fileEntryTypeIds,
540 serviceContext);
541 }
542 }
543
544 protected void fixDDMStructureKey(
545 String fileEntryTypeUuid, long fileEntryTypeId, long groupId)
546 throws SystemException {
547
548 DDMStructure ddmStructure = ddmStructureLocalService.fetchStructure(
549 groupId, PortalUtil.getClassNameId(DLFileEntryMetadata.class),
550 DLUtil.getDeprecatedDDMStructureKey(fileEntryTypeId));
551
552 if (ddmStructure != null) {
553 ddmStructure.setStructureKey(
554 DLUtil.getDDMStructureKey(fileEntryTypeUuid));
555
556 ddmStructureLocalService.updateDDMStructure(ddmStructure);
557 }
558 }
559
560 protected List<Long> getFileEntryTypeIds(
561 List<DLFileEntryType> dlFileEntryTypes) {
562
563 List<Long> fileEntryTypeIds = new SortedArrayList<Long>();
564
565 for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
566 fileEntryTypeIds.add(dlFileEntryType.getFileEntryTypeId());
567 }
568
569 return fileEntryTypeIds;
570 }
571
572 protected long getFileEntryTypesPrimaryFolderId(long folderId)
573 throws NoSuchFolderException, SystemException {
574
575 while (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
576 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
577
578 if (dlFolder.isOverrideFileEntryTypes()) {
579 break;
580 }
581
582 folderId = dlFolder.getParentFolderId();
583 }
584
585 return folderId;
586 }
587
588 protected long updateDDMStructure(
589 long userId, String fileEntryTypeUuid, long fileEntryTypeId,
590 long groupId, Map<Locale, String> nameMap,
591 Map<Locale, String> descriptionMap, ServiceContext serviceContext)
592 throws PortalException, SystemException {
593
594 fixDDMStructureKey(fileEntryTypeUuid, fileEntryTypeId, groupId);
595
596 String ddmStructureKey = DLUtil.getDDMStructureKey(fileEntryTypeUuid);
597
598 String xsd = ParamUtil.getString(serviceContext, "xsd");
599
600 DDMStructure ddmStructure = ddmStructureLocalService.fetchStructure(
601 groupId, PortalUtil.getClassNameId(DLFileEntryMetadata.class),
602 ddmStructureKey);
603
604 if ((ddmStructure != null) && Validator.isNull(xsd)) {
605 xsd = ddmStructure.getXsd();
606 }
607
608 try {
609 if (ddmStructure == null) {
610 ddmStructure = ddmStructureLocalService.addStructure(
611 userId, groupId,
612 DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID,
613 PortalUtil.getClassNameId(DLFileEntryMetadata.class),
614 ddmStructureKey, nameMap, descriptionMap, xsd, "xml",
615 DDMStructureConstants.TYPE_AUTO, serviceContext);
616 }
617 else {
618 ddmStructure = ddmStructureLocalService.updateStructure(
619 ddmStructure.getStructureId(),
620 ddmStructure.getParentStructureId(), nameMap,
621 descriptionMap, xsd, serviceContext);
622 }
623
624 return ddmStructure.getStructureId();
625 }
626 catch (StructureXsdException sxe) {
627 if (ddmStructure != null) {
628 ddmStructureLocalService.deleteStructure(
629 ddmStructure.getStructureId());
630 }
631 }
632
633 return 0;
634 }
635
636 protected void validate(
637 long fileEntryTypeId, long groupId, String fileEntryTypeKey,
638 long[] ddmStructureIds)
639 throws PortalException, SystemException {
640
641 DLFileEntryType dlFileEntryType = dlFileEntryTypePersistence.fetchByG_F(
642 groupId, fileEntryTypeKey);
643
644 if ((dlFileEntryType != null) &&
645 (dlFileEntryType.getFileEntryTypeId() != fileEntryTypeId)) {
646
647 throw new DuplicateFileEntryTypeException(fileEntryTypeKey);
648 }
649
650 if (ddmStructureIds.length == 0) {
651 throw new NoSuchMetadataSetException();
652 }
653
654 for (long ddmStructureId : ddmStructureIds) {
655 DDMStructure ddmStructure =
656 ddmStructurePersistence.fetchByPrimaryKey(ddmStructureId);
657
658 if (ddmStructure == null) {
659 throw new NoSuchMetadataSetException();
660 }
661 }
662 }
663
664 }