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