2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.persistence
.dao
.initializer
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
14 import java
.util
.stream
.Collectors
;
16 import org
.apache
.commons
.lang3
.StringUtils
;
19 * @author a.kohlbecker
23 public class EntityInitStrategy
{
25 private static final String DOT
= ".";
27 List
<String
> propertyPaths
= new ArrayList
<>();
29 public EntityInitStrategy(){
34 public EntityInitStrategy(List
<String
> propertyPaths
){
35 if(propertyPaths
!= null){
36 this.propertyPaths
.addAll(propertyPaths
);
40 public EntityInitStrategy(String
... propertyPaths
){
41 if(propertyPaths
!= null){
42 this.propertyPaths
.addAll(Arrays
.asList(propertyPaths
));
47 * Extends the property base bath by all property definitions in the
48 * <code>extensions</code> and adds the resulting property path to the
51 * Potential duplicate property paths de-duplicated.
54 * can be NUll or empty to just append the extensions to the init
57 * @param basePathIsCollection
59 public EntityInitStrategy
extend(String basePath
, EntityInitStrategy extensions
, boolean basePathIsCollection
) {
60 return extend(basePath
, extensions
.getPropertyPaths(), basePathIsCollection
);
64 * Extends the property base bath by all property definitions in the
65 * <code>extensions</code> and adds the resulting property path to the
68 * Potential duplicate property paths de-duplicated.
71 * can be NUll or empty to just add the extensions to the init
74 * @param basePathIsCollection
76 public EntityInitStrategy
extend(String basePath
, List
<String
> extensions
, boolean basePathIsCollection
){
77 for(String appendix
: extensions
){
78 if(basePathIsCollection
&& (appendix
.startsWith("$") || appendix
.startsWith("*"))){
79 // need to suppress wildcards, see AdvancedBeanInitializer.initializeNodeWildcard()
82 if(!StringUtils
.isEmpty(basePath
)){
83 propertyPaths
.add(basePath
+ DOT
+ appendix
);
84 propertyPaths
.remove(basePath
);
86 propertyPaths
.add(appendix
);
89 propertyPaths
= propertyPaths
.stream().distinct().collect(Collectors
.toList());
97 public List
<String
> getPropertyPaths() {
102 public EntityInitStrategy
clone() {
103 return new EntityInitStrategy(this.propertyPaths
);