Merge branch 'release/5.44.0'
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / strategy / StrategyBase.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.cdm.strategy;
10
11 import java.io.Serializable;
12 import java.util.Collection;
13 import java.util.UUID;
14
15 import org.apache.commons.lang3.StringUtils;
16 import org.apache.logging.log4j.LogManager;
17 import org.apache.logging.log4j.Logger;
18 import org.joda.time.DateTime;
19
20 import eu.etaxonomy.cdm.common.CdmUtils;
21 import eu.etaxonomy.cdm.common.DOI;
22 import eu.etaxonomy.cdm.common.URI;
23 import eu.etaxonomy.cdm.model.agent.Contact;
24 import eu.etaxonomy.cdm.model.agent.ORCID;
25 import eu.etaxonomy.cdm.model.common.CdmBase;
26 import eu.etaxonomy.cdm.model.common.ExternallyManaged;
27 import eu.etaxonomy.cdm.model.common.LSID;
28 import eu.etaxonomy.cdm.model.common.TimePeriod;
29 import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
30
31 public abstract class StrategyBase
32 implements IStrategy, Serializable {
33
34 private static final long serialVersionUID = -274791080847215663L;
35 @SuppressWarnings("unused")
36 private static final Logger logger = LogManager.getLogger();
37
38 abstract protected UUID getUuid();
39
40 // ************************** CONSTRUCTOR ********************************/
41
42 protected StrategyBase(){}
43
44 // ************************* METHODS ****************************************/
45 /**
46 * @param fieldType
47 * @return
48 */
49 protected static boolean isCollection(Class<?> fieldType) {
50 if (Collection.class.isAssignableFrom(fieldType) ){
51 return true;
52 }else{
53 return false;
54 }
55 }
56
57 protected boolean isPrimitive(Class<?> fieldType) {
58 if (fieldType.isPrimitive()){
59 return true;
60 }else{
61 return false;
62 }
63 }
64
65 protected boolean isSingleCdmBaseObject(Class<?> fieldType) {
66 if (CdmBase.class.isAssignableFrom(fieldType)){
67 return true;
68 }else{
69 return false;
70 }
71 }
72
73 protected boolean isUserType(Class<?> fieldType) {
74 if ( fieldType == TimePeriod.class ||
75 fieldType == VerbatimTimePeriod.class ||
76 fieldType == DateTime.class ||
77 fieldType == LSID.class ||
78 fieldType == Contact.class ||
79 fieldType == URI.class ||
80 fieldType == DOI.class ||
81 fieldType == ORCID.class ||
82 fieldType == ExternallyManaged.class
83 ){
84 return true;
85 }else{
86 return false;
87 }
88 }
89
90 /**
91 * Null safe string. Returns the given string if it is not <code>null</code>.
92 * Empty string otherwise.
93 * @see CdmUtils#Nz(String)
94 * @return the null-safe string
95 */
96 protected String Nz(String str){
97 return CdmUtils.Nz(str);
98 }
99
100 /**
101 * Checks if a string is not blank.
102 * @see StringUtils#isNotBlank(String)
103 */
104 protected boolean isNotBlank(String str){
105 return StringUtils.isNotBlank(str);
106 }
107
108 /**
109 * Checks if a string is blank.
110 * @see StringUtils#isNotBlank(String)
111 */
112 protected static boolean isBlank(String str){
113 return StringUtils.isBlank(str);
114 }
115
116 protected String removeTrailingDots(String str){
117 return CdmUtils.removeTrailingDots(str);
118 }
119 }