forked from liferay/liferay-portal
/
DDMStructureLocalServiceImpl.java
2101 lines (1745 loc) · 69.7 KB
/
DDMStructureLocalServiceImpl.java
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.dynamic.data.mapping.service.impl;
import com.liferay.dynamic.data.mapping.background.task.DDMStructureIndexerBackgroundTaskExecutor;
import com.liferay.dynamic.data.mapping.exception.InvalidParentStructureException;
import com.liferay.dynamic.data.mapping.exception.InvalidStructureVersionException;
import com.liferay.dynamic.data.mapping.exception.NoSuchStructureException;
import com.liferay.dynamic.data.mapping.exception.RequiredStructureException;
import com.liferay.dynamic.data.mapping.exception.StructureDefinitionException;
import com.liferay.dynamic.data.mapping.exception.StructureDuplicateElementException;
import com.liferay.dynamic.data.mapping.exception.StructureDuplicateStructureKeyException;
import com.liferay.dynamic.data.mapping.exception.StructureNameException;
import com.liferay.dynamic.data.mapping.internal.util.DDMFormTemplateSynchonizer;
import com.liferay.dynamic.data.mapping.io.DDMFormJSONDeserializer;
import com.liferay.dynamic.data.mapping.io.DDMFormJSONSerializer;
import com.liferay.dynamic.data.mapping.io.DDMFormXSDDeserializer;
import com.liferay.dynamic.data.mapping.model.DDMDataProviderInstance;
import com.liferay.dynamic.data.mapping.model.DDMDataProviderInstanceLink;
import com.liferay.dynamic.data.mapping.model.DDMForm;
import com.liferay.dynamic.data.mapping.model.DDMFormField;
import com.liferay.dynamic.data.mapping.model.DDMFormLayout;
import com.liferay.dynamic.data.mapping.model.DDMFormRule;
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.model.DDMStructureConstants;
import com.liferay.dynamic.data.mapping.model.DDMStructureVersion;
import com.liferay.dynamic.data.mapping.model.DDMTemplate;
import com.liferay.dynamic.data.mapping.model.DDMTemplateConstants;
import com.liferay.dynamic.data.mapping.security.permission.DDMPermissionSupport;
import com.liferay.dynamic.data.mapping.service.base.DDMStructureLocalServiceBaseImpl;
import com.liferay.dynamic.data.mapping.storage.StorageType;
import com.liferay.dynamic.data.mapping.util.DDM;
import com.liferay.dynamic.data.mapping.util.DDMXML;
import com.liferay.dynamic.data.mapping.validator.DDMFormValidationException;
import com.liferay.dynamic.data.mapping.validator.DDMFormValidator;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskManager;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.LocaleException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactory;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.model.ResourceConstants;
import com.liferay.portal.kernel.model.SystemEventConstants;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.search.DDMStructureIndexer;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.IndexerRegistryUtil;
import com.liferay.portal.kernel.security.auth.CompanyThreadLocal;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.permission.ModelPermissions;
import com.liferay.portal.kernel.spring.aop.Skip;
import com.liferay.portal.kernel.systemevent.SystemEvent;
import com.liferay.portal.kernel.transaction.TransactionCommitCallbackUtil;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.GroupThreadLocal;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.MapUtil;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.SetUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.spring.extender.service.ServiceReference;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Provides the local service for accessing, adding, deleting, and updating
* dynamic data mapping (DDM) structures.
*
* <p>
* DDM structures (structures) are used in Liferay to store structured content
* like document types, dynamic data definitions, or web contents.
* </p>
*
* <p>
* Structures support inheritance via parent structures. They also support
* multi-language names and descriptions.
* </p>
*
* <p>
* Structures can be related to many models in Liferay, such as those for web
* contents, dynamic data lists, and documents. This relationship can be
* established via the model's class name ID.
* </p>
*
* @author Brian Wing Shun Chan
* @author Bruno Basto
* @author Marcellus Tavares
* @author Juan Fernández
*/
public class DDMStructureLocalServiceImpl
extends DDMStructureLocalServiceBaseImpl {
@Override
public DDMStructure addStructure(
long userId, long groupId, long parentStructureId, long classNameId,
String structureKey, Map<Locale, String> nameMap,
Map<Locale, String> descriptionMap, DDMForm ddmForm,
DDMFormLayout ddmFormLayout, String storageType, int type,
ServiceContext serviceContext)
throws PortalException {
// Structure
User user = userLocalService.getUser(userId);
if (Validator.isNull(structureKey)) {
structureKey = String.valueOf(counterLocalService.increment());
}
else {
structureKey = StringUtil.toUpperCase(structureKey.trim());
}
validate(
groupId, parentStructureId, classNameId, structureKey, nameMap,
ddmForm);
long structureId = counterLocalService.increment();
DDMStructure structure = ddmStructurePersistence.create(structureId);
structure.setUuid(serviceContext.getUuid());
structure.setGroupId(groupId);
structure.setCompanyId(user.getCompanyId());
structure.setUserId(user.getUserId());
structure.setUserName(user.getFullName());
structure.setVersionUserId(user.getUserId());
structure.setVersionUserName(user.getFullName());
structure.setParentStructureId(parentStructureId);
structure.setClassNameId(classNameId);
structure.setStructureKey(structureKey);
structure.setVersion(DDMStructureConstants.VERSION_DEFAULT);
structure.setDescriptionMap(descriptionMap, ddmForm.getDefaultLocale());
structure.setNameMap(nameMap, ddmForm.getDefaultLocale());
structure.setDefinition(ddmFormJSONSerializer.serialize(ddmForm));
structure.setStorageType(storageType);
structure.setType(type);
ddmStructurePersistence.update(structure);
// Resources
if (serviceContext.isAddGroupPermissions() ||
serviceContext.isAddGuestPermissions()) {
addStructureResources(
structure, serviceContext.isAddGroupPermissions(),
serviceContext.isAddGuestPermissions());
}
else {
addStructureResources(
structure, serviceContext.getModelPermissions());
}
// Structure version
DDMStructureVersion structureVersion = addStructureVersion(
user, structure, DDMStructureConstants.VERSION_DEFAULT,
serviceContext);
// Structure layout
ddmStructureLayoutLocalService.addStructureLayout(
userId, groupId, structureVersion.getStructureVersionId(),
ddmFormLayout, serviceContext);
// Data provider instance links
addDataProviderInstanceLinks(groupId, structureId, ddmForm);
return structure;
}
/**
* Adds a structure referencing its parent structure.
*
* @param userId the primary key of the structure's creator/owner
* @param groupId the primary key of the group
* @param parentStructureId the primary key of the parent structure
* (optionally {@link
* DDMStructureConstants#DEFAULT_PARENT_STRUCTURE_ID})
* @param classNameId the primary key of the class name for the
* structure's related model
* @param structureKey the unique string identifying the structure
* (optionally <code>null</code>)
* @param nameMap the structure's locales and localized names
* @param descriptionMap the structure's locales and localized
* descriptions
* @param definition the structure's XML schema definition
* @param storageType the structure's storage type. It can be "xml" or
* "expando". For more information, see {@link StorageType}.
* @param type the structure's type. For more information, see {@link
* DDMStructureConstants}.
* @param serviceContext the service context to be applied. Can set the
* UUID, creation date, modification date, guest permissions,
* and group permissions for the structure.
* @return the structure
* @deprecated As of Wilberforce (7.0.x), replaced by {@link
* #addStructure(long, long, long, long, String, Map, Map,
* DDMForm, DDMFormLayout, String, int, ServiceContext)}
*/
@Deprecated
@Override
public DDMStructure addStructure(
long userId, long groupId, long parentStructureId, long classNameId,
String structureKey, Map<Locale, String> nameMap,
Map<Locale, String> descriptionMap, String definition,
String storageType, int type, ServiceContext serviceContext)
throws PortalException {
ddmXML.validateXML(definition);
DDMForm ddmForm = ddmFormXSDDeserializer.deserialize(definition);
DDMFormLayout ddmFormLayout = ddm.getDefaultDDMFormLayout(ddmForm);
return addStructure(
userId, groupId, parentStructureId, classNameId, structureKey,
nameMap, descriptionMap, ddmForm, ddmFormLayout, storageType, type,
serviceContext);
}
@Override
public DDMStructure addStructure(
long userId, long groupId, long classNameId,
Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
DDMForm ddmForm, DDMFormLayout ddmFormLayout, String storageType,
ServiceContext serviceContext)
throws PortalException {
return addStructure(
userId, groupId, DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID,
classNameId, null, nameMap, descriptionMap, ddmForm, ddmFormLayout,
storageType, DDMStructureConstants.TYPE_DEFAULT, serviceContext);
}
/**
* Adds a structure referencing a default parent structure, using the portal
* property <code>dynamic.data.lists.storage.type</code> storage type and
* default structure type.
*
* @param userId the primary key of the structure's creator/owner
* @param groupId the primary key of the group
* @param classNameId the primary key of the class name for the
* structure's related model
* @param nameMap the structure's locales and localized names
* @param descriptionMap the structure's locales and localized
* descriptions
* @param definition the structure's XML schema definition
* @param serviceContext the service context to be applied. Can set the
* UUID, creation date, modification date, guest permissions,
* and group permissions for the structure.
* @return the structure
* @deprecated As of Wilberforce (7.0.x), replaced by {@link
* #addStructure(long, long, long, Map, Map, DDMForm,
* DDMFormLayout, ServiceContext)}
*/
@Deprecated
@Override
public DDMStructure addStructure(
long userId, long groupId, long classNameId,
Map<Locale, String> nameMap, Map<Locale, String> descriptionMap,
String definition, ServiceContext serviceContext)
throws PortalException {
return addStructure(
userId, groupId, DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID,
classNameId, null, nameMap, descriptionMap, definition,
StorageType.JSON.toString(), DDMStructureConstants.TYPE_DEFAULT,
serviceContext);
}
@Override
public DDMStructure addStructure(
long userId, long groupId, String parentStructureKey,
long classNameId, String structureKey, Map<Locale, String> nameMap,
Map<Locale, String> descriptionMap, DDMForm ddmForm,
DDMFormLayout ddmFormLayout, String storageType, int type,
ServiceContext serviceContext)
throws PortalException {
DDMStructure parentStructure = fetchStructure(
groupId, classNameId, parentStructureKey);
long parentStructureId =
DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID;
if (parentStructure != null) {
parentStructureId = parentStructure.getStructureId();
}
return addStructure(
userId, groupId, parentStructureId, classNameId, structureKey,
nameMap, descriptionMap, ddmForm, ddmFormLayout, storageType, type,
serviceContext);
}
/**
* Adds a structure referencing a default parent structure if the parent
* structure is not found.
*
* @param userId the primary key of the structure's creator/owner
* @param groupId the primary key of the group
* @param parentStructureKey the unique string identifying the parent
* structure (optionally <code>null</code>)
* @param classNameId the primary key of the class name for the
* structure's related model
* @param structureKey the unique string identifying the structure
* (optionally <code>null</code>)
* @param nameMap the structure's locales and localized names
* @param descriptionMap the structure's locales and localized
* descriptions
* @param definition the structure's XML schema definition
* @param storageType the structure's storage type. It can be "xml" or
* "expando". For more information, see {@link StorageType}.
* @param type the structure's type. For more information, see {@link
* DDMStructureConstants}.
* @param serviceContext the service context to be applied. Can set the
* UUID, creation date, modification date, guest permissions and
* group permissions for the structure.
* @return the structure
* @deprecated As of Wilberforce (7.0.x), replaced by {@link
* #addStructure(long, long, String, long, String, Map, Map,
* DDMForm, DDMFormLayout, String, int, ServiceContext)}
*/
@Deprecated
@Override
public DDMStructure addStructure(
long userId, long groupId, String parentStructureKey,
long classNameId, String structureKey, Map<Locale, String> nameMap,
Map<Locale, String> descriptionMap, String definition,
String storageType, int type, ServiceContext serviceContext)
throws PortalException {
ddmXML.validateXML(definition);
DDMForm ddmForm = ddmFormXSDDeserializer.deserialize(definition);
DDMFormLayout ddmFormLayout = ddm.getDefaultDDMFormLayout(ddmForm);
return addStructure(
userId, groupId, parentStructureKey, classNameId, structureKey,
nameMap, descriptionMap, ddmForm, ddmFormLayout, storageType, type,
serviceContext);
}
/**
* Adds the resources to the structure.
*
* @param structure the structure to add resources to
* @param addGroupPermissions whether to add group permissions
* @param addGuestPermissions whether to add guest permissions
*/
@Override
public void addStructureResources(
DDMStructure structure, boolean addGroupPermissions,
boolean addGuestPermissions)
throws PortalException {
String resourceName =
ddmPermissionSupport.getStructureModelResourceName(
structure.getClassName());
resourceLocalService.addResources(
structure.getCompanyId(), structure.getGroupId(),
structure.getUserId(), resourceName, structure.getStructureId(),
false, addGroupPermissions, addGuestPermissions);
}
/**
* Adds the model resources with the permissions to the structure.
*
* @param structure the structure to add resources to
* @param modelPermissions the model permissions to be added
*/
@Override
public void addStructureResources(
DDMStructure structure, ModelPermissions modelPermissions)
throws PortalException {
String resourceName =
ddmPermissionSupport.getStructureModelResourceName(
structure.getClassName());
resourceLocalService.addModelResources(
structure.getCompanyId(), structure.getGroupId(),
structure.getUserId(), resourceName, structure.getStructureId(),
modelPermissions);
}
/**
* Copies a structure, creating a new structure with all the values
* extracted from the original one. The new structure supports a new name
* and description.
*
* @param userId the primary key of the structure's creator/owner
* @param structureId the primary key of the structure to be copied
* @param nameMap the new structure's locales and localized names
* @param descriptionMap the new structure's locales and localized
* descriptions
* @param serviceContext the service context to be applied. Can set the
* UUID, creation date, modification date, guest permissions, and
* group permissions for the structure.
* @return the new structure
*/
@Override
public DDMStructure copyStructure(
long userId, long structureId, Map<Locale, String> nameMap,
Map<Locale, String> descriptionMap, ServiceContext serviceContext)
throws PortalException {
DDMStructure structure = ddmStructurePersistence.findByPrimaryKey(
structureId);
return addStructure(
userId, structure.getGroupId(), structure.getParentStructureId(),
structure.getClassNameId(), null, nameMap, descriptionMap,
structure.getDDMForm(), structure.getDDMFormLayout(),
structure.getStorageType(), structure.getType(), serviceContext);
}
@Override
public DDMStructure copyStructure(
long userId, long structureId, ServiceContext serviceContext)
throws PortalException {
DDMStructure structure = ddmStructurePersistence.findByPrimaryKey(
structureId);
return addStructure(
userId, structure.getGroupId(), structure.getParentStructureId(),
structure.getClassNameId(), null, structure.getNameMap(),
structure.getDescriptionMap(), structure.getDDMForm(),
structure.getDDMFormLayout(), structure.getStorageType(),
structure.getType(), serviceContext);
}
/**
* Deletes the structure and its resources.
*
* <p>
* Before deleting the structure, this method verifies whether the structure
* is required by another entity. If it is needed, an exception is thrown.
* </p>
*
* @param structure the structure to be deleted
*/
@Override
@SystemEvent(type = SystemEventConstants.TYPE_DELETE)
public void deleteStructure(DDMStructure structure) throws PortalException {
if (!GroupThreadLocal.isDeleteInProcess()) {
if (ddmStructureLinkPersistence.countByStructureId(
structure.getStructureId()) > 0) {
throw new RequiredStructureException.
MustNotDeleteStructureReferencedByStructureLinks(
structure.getStructureId());
}
if (ddmStructurePersistence.countByParentStructureId(
structure.getStructureId()) > 0) {
throw new RequiredStructureException.
MustNotDeleteStructureThatHasChild(
structure.getStructureId());
}
if (ddmTemplatePersistence.countByClassPK(
structure.getStructureId()) > 0) {
throw new RequiredStructureException.
MustNotDeleteStructureReferencedByTemplates(
structure.getStructureId());
}
}
// Structure
ddmStructurePersistence.remove(structure);
// Data provider instance links
ddmDataProviderInstanceLinkPersistence.removeByStructureId(
structure.getStructureId());
// Structure links
ddmStructureLinkPersistence.removeByStructureId(
structure.getStructureId());
// Structure versions
List<DDMStructureVersion> structureVersions =
ddmStructureVersionLocalService.getStructureVersions(
structure.getStructureId());
for (DDMStructureVersion structureVersion : structureVersions) {
ddmStructureLayoutPersistence.removeByStructureVersionId(
structureVersion.getStructureVersionId());
ddmStructureVersionPersistence.remove(structureVersion);
}
// Resources
String resourceName =
ddmPermissionSupport.getStructureModelResourceName(
structure.getClassName());
resourceLocalService.deleteResource(
structure.getCompanyId(), resourceName,
ResourceConstants.SCOPE_INDIVIDUAL, structure.getStructureId());
// Background tasks
String backgroundTaskName =
DDMStructureIndexerBackgroundTaskExecutor.getBackgroundTaskName(
structure.getStructureId());
backgroundTaskmanager.deleteGroupBackgroundTasks(
structure.getGroupId(), backgroundTaskName,
DDMStructureIndexerBackgroundTaskExecutor.class.getName());
}
/**
* Deletes the structure and its resources.
*
* <p>
* Before deleting the structure, the system verifies whether the structure
* is required by another entity. If it is needed, an exception is thrown.
* </p>
*
* @param structureId the primary key of the structure to be deleted
*/
@Override
public void deleteStructure(long structureId) throws PortalException {
DDMStructure structure = ddmStructurePersistence.findByPrimaryKey(
structureId);
ddmStructureLocalService.deleteStructure(structure);
}
/**
* Deletes the matching structure and its resources.
*
* <p>
* Before deleting the structure, the system verifies whether the structure
* is required by another entity. If it is needed, an exception is thrown.
* </p>
*
* @param groupId the primary key of the group
* @param classNameId the primary key of the class name for the structure's
* related model
* @param structureKey the unique string identifying the structure
*/
@Override
public void deleteStructure(
long groupId, long classNameId, String structureKey)
throws PortalException {
structureKey = getStructureKey(structureKey);
DDMStructure structure = ddmStructurePersistence.findByG_C_S(
groupId, classNameId, structureKey);
ddmStructureLocalService.deleteStructure(structure);
}
/**
* Deletes all the structures of the group.
*
* <p>
* Before deleting the structures, the system verifies whether each
* structure is required by another entity. If any of the structures are
* needed, an exception is thrown.
* </p>
*
* @param groupId the primary key of the group
*/
@Override
public void deleteStructures(long groupId) throws PortalException {
List<DDMStructure> structures = ddmStructurePersistence.findByGroupId(
groupId);
deleteStructures(structures);
}
@Override
public void deleteStructures(long groupId, long classNameId)
throws PortalException {
List<DDMStructure> structures = ddmStructurePersistence.findByG_C(
groupId, classNameId);
deleteStructures(structures);
}
/**
* Returns the structure with the ID.
*
* @param structureId the primary key of the structure
* @return the structure with the structure ID, or <code>null</code> if a
* matching structure could not be found
*/
@Override
public DDMStructure fetchStructure(long structureId) {
return ddmStructurePersistence.fetchByPrimaryKey(structureId);
}
/**
* Returns the structure matching the class name ID, structure key, and
* group.
*
* @param groupId the primary key of the group
* @param classNameId the primary key of the class name for the structure's
* related model
* @param structureKey the unique string identifying the structure
* @return the matching structure, or <code>null</code> if a matching
* structure could not be found
*/
@Override
public DDMStructure fetchStructure(
long groupId, long classNameId, String structureKey) {
structureKey = getStructureKey(structureKey);
return ddmStructurePersistence.fetchByG_C_S(
groupId, classNameId, structureKey);
}
/**
* Returns the structure matching the class name ID, structure key, and
* group, optionally searching ancestor sites (that have sharing enabled)
* and global scoped sites.
*
* <p>
* This method first searches in the group. If the structure is still not
* found and <code>includeAncestorStructures</code> is set to
* <code>true</code>, this method searches the group's ancestor sites (that
* have sharing enabled) and lastly searches global scoped sites.
* </p>
*
* @param groupId the primary key of the group
* @param classNameId the primary key of the class name for the structure's
* related model
* @param structureKey the unique string identifying the structure
* @param includeAncestorStructures whether to include ancestor sites (that
* have sharing enabled) and include global scoped sites in the
* search
* @return the matching structure, or <code>null</code> if a matching
* structure could not be found
*/
@Override
public DDMStructure fetchStructure(
long groupId, long classNameId, String structureKey,
boolean includeAncestorStructures) {
structureKey = getStructureKey(structureKey);
DDMStructure structure = ddmStructurePersistence.fetchByG_C_S(
groupId, classNameId, structureKey);
if (structure != null) {
return structure;
}
if (!includeAncestorStructures) {
return null;
}
for (long ancestorSiteGroupId :
PortalUtil.getAncestorSiteGroupIds(groupId)) {
structure = ddmStructurePersistence.fetchByG_C_S(
ancestorSiteGroupId, classNameId, structureKey);
if (structure != null) {
return structure;
}
}
return null;
}
@Override
public DDMStructure fetchStructureByUuidAndGroupId(
String uuid, long groupId, boolean includeAncestorStructures) {
DDMStructure structure = ddmStructurePersistence.fetchByUUID_G(
uuid, groupId);
if (structure != null) {
return structure;
}
if (!includeAncestorStructures) {
return null;
}
for (long ancestorSiteGroupId :
PortalUtil.getAncestorSiteGroupIds(groupId)) {
structure = ddmStructurePersistence.fetchByUUID_G(
uuid, ancestorSiteGroupId);
if (structure != null) {
return structure;
}
}
return null;
}
@Override
public List<DDMStructure> getChildrenStructures(long parentStructureId) {
return ddmStructurePersistence.findByParentStructureId(
parentStructureId);
}
/**
* Returns all the structures matching the class name ID.
*
* @param companyId the primary key of the structure's company
* @param classNameId the primary key of the class name for the structure's
* related model
* @return the structures matching the class name ID
*/
@Override
public List<DDMStructure> getClassStructures(
long companyId, long classNameId) {
return ddmStructurePersistence.findByC_C(companyId, classNameId);
}
/**
* Returns a range of all the structures matching the class name ID.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end -
* start</code> instances. <code>start</code> and <code>end</code> are not
* primary keys, they are indexes in the result set. Thus, <code>0</code>
* refers to the first result in the set. Setting both <code>start</code>
* and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
* result set.
* </p>
*
* @param companyId the primary key of the structure's company
* @param classNameId the primary key of the class name for the structure's
* related model
* @param start the lower bound of the range of structures to return
* @param end the upper bound of the range of structures to return (not
* inclusive)
* @return the range of matching structures
*/
@Override
public List<DDMStructure> getClassStructures(
long companyId, long classNameId, int start, int end) {
return ddmStructurePersistence.findByC_C(
companyId, classNameId, start, end);
}
/**
* Returns all the structures matching the class name ID ordered by the
* comparator.
*
* @param companyId the primary key of the structure's company
* @param classNameId the primary key of the class name for the structure's
* related model
* @param orderByComparator the comparator to order the structures
* (optionally <code>null</code>)
* @return the matching structures ordered by the comparator
*/
@Override
public List<DDMStructure> getClassStructures(
long companyId, long classNameId,
OrderByComparator<DDMStructure> orderByComparator) {
return ddmStructurePersistence.findByC_C(
companyId, classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
orderByComparator);
}
/**
* Returns the structure with the ID.
*
* @param structureId the primary key of the structure
* @return the structure with the ID
*/
@Override
public DDMStructure getStructure(long structureId) throws PortalException {
return ddmStructurePersistence.findByPrimaryKey(structureId);
}
/**
* Returns the structure matching the class name ID, structure key, and
* group.
*
* @param groupId the primary key of the structure's group
* @param classNameId the primary key of the class name for the structure's
* related model
* @param structureKey the unique string identifying the structure
* @return the matching structure
*/
@Override
public DDMStructure getStructure(
long groupId, long classNameId, String structureKey)
throws PortalException {
structureKey = getStructureKey(structureKey);
return ddmStructurePersistence.findByG_C_S(
groupId, classNameId, structureKey);
}
/**
* Returns the structure matching the class name ID, structure key, and
* group, optionally searching ancestor sites (that have sharing enabled)
* and global scoped sites.
*
* <p>
* This method first searches in the group. If the structure is still not
* found and <code>includeAncestorStructures</code> is set to
* <code>true</code>, this method searches the group's ancestor sites (that
* have sharing enabled) and lastly searches global scoped sites.
* </p>
*
* @param groupId the primary key of the structure's group
* @param classNameId the primary key of the class name for the structure's
* related model
* @param structureKey the unique string identifying the structure
* @param includeAncestorStructures whether to include ancestor sites (that
* have sharing enabled) and include global scoped sites in the
* search in the search
* @return the matching structure
*/
@Override
public DDMStructure getStructure(
long groupId, long classNameId, String structureKey,
boolean includeAncestorStructures)
throws PortalException {
structureKey = getStructureKey(structureKey);
DDMStructure structure = ddmStructurePersistence.fetchByG_C_S(
groupId, classNameId, structureKey);
if (structure != null) {
return structure;
}
if (!includeAncestorStructures) {
throw new NoSuchStructureException(
"No DDMStructure exists with the structure key " +
structureKey);
}
for (long curGroupId : PortalUtil.getAncestorSiteGroupIds(groupId)) {
structure = ddmStructurePersistence.fetchByG_C_S(
curGroupId, classNameId, structureKey);
if (structure != null) {
return structure;
}
}
throw new NoSuchStructureException(
"No DDMStructure exists with the structure key " + structureKey +
" in the ancestor groups");
}
/**
* Returns all the structures matching the group, name, and description.
*
* @param groupId the primary key of the structure's group
* @param name the structure's name
* @param description the structure's description
* @return the matching structures
*/
@Override
public List<DDMStructure> getStructure(
long groupId, String name, String description) {
return ddmStructurePersistence.findByG_N_D(groupId, name, description);
}
@Override
@Skip
public DDMForm getStructureDDMForm(DDMStructure structure)
throws PortalException {
return ddmFormJSONDeserializer.deserialize(structure.getDefinition());
}
/**
* Returns all the structures present in the system.
*
* @return the structures present in the system
*/
@Override
public List<DDMStructure> getStructures() {
return ddmStructurePersistence.findAll();
}
/**
* Returns all the structures present in the group.
*
* @param groupId the primary key of the group
* @return the structures present in the group
*/
@Override
public List<DDMStructure> getStructures(long groupId) {
return ddmStructurePersistence.findByGroupId(groupId);
}
/**
* Returns a range of all the structures belonging to the group.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end -
* start</code> instances. <code>start</code> and <code>end</code> are not
* primary keys, they are indexes in the result set. Thus, <code>0</code>
* refers to the first result in the set. Setting both <code>start</code>
* and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
* result set.
* </p>
*
* @param groupId the primary key of the group
* @param start the lower bound of the range of structures to return
* @param end the upper bound of the range of structures to return (not
* inclusive)
* @return the range of matching structures
*/
@Override
public List<DDMStructure> getStructures(long groupId, int start, int end) {
return ddmStructurePersistence.findByGroupId(groupId, start, end);
}
/**
* Returns all the structures matching class name ID and group.
*
* @param groupId the primary key of the group
* @param classNameId the primary key of the class name for the structure's
* related model
* @return the matching structures
*/
@Override
public List<DDMStructure> getStructures(long groupId, long classNameId) {
return ddmStructurePersistence.findByG_C(groupId, classNameId);
}
/**
* Returns a range of all the structures that match the class name ID and
* group.
*
* <p>
* Useful when paginating results. Returns a maximum of <code>end -
* start</code> instances. <code>start</code> and <code>end</code> are not
* primary keys, they are indexes in the result set. Thus, <code>0</code>
* refers to the first result in the set. Setting both <code>start</code>
* and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full
* result set.
* </p>
*
* @param groupId the primary key of the group
* @param classNameId the primary key of the class name for the structure's
* related model
* @param start the lower bound of the range of structures to return
* @param end the upper bound of the range of structures to return (not
* inclusive)
* @return the range of matching structures