| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.datadictionary; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.LinkedHashMap; |
| 20 | |
import java.util.List; |
| 21 | |
import java.util.Map; |
| 22 | |
|
| 23 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentAuthorizer; |
| 24 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 25 | |
import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; |
| 26 | |
import org.kuali.rice.kns.datadictionary.exception.ClassValidationException; |
| 27 | |
import org.kuali.rice.kns.datadictionary.exception.DuplicateEntryException; |
| 28 | |
import org.kuali.rice.kns.document.Document; |
| 29 | |
import org.kuali.rice.kns.document.MaintenanceDocumentBase; |
| 30 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public class MaintenanceDocumentEntry extends DocumentEntry { |
| 38 | |
|
| 39 | |
protected Class<? extends BusinessObject> businessObjectClass; |
| 40 | |
protected Class<? extends Maintainable> maintainableClass; |
| 41 | |
|
| 42 | 0 | protected List<MaintainableSectionDefinition> maintainableSections = new ArrayList<MaintainableSectionDefinition>(); |
| 43 | 0 | protected List<String> lockingKeys = new ArrayList<String>(); |
| 44 | |
|
| 45 | 0 | protected Map<String,MaintainableSectionDefinition> maintainableSectionMap = new LinkedHashMap<String, MaintainableSectionDefinition>(); |
| 46 | |
|
| 47 | |
|
| 48 | 0 | protected boolean allowsNewOrCopy = true; |
| 49 | |
protected String additionalSectionsFile; |
| 50 | |
|
| 51 | |
|
| 52 | 0 | protected boolean preserveLockingKeysOnCopy = false; |
| 53 | |
|
| 54 | |
|
| 55 | 0 | protected boolean allowsRecordDeletion = false; |
| 56 | |
|
| 57 | 0 | protected boolean translateCodes = false; |
| 58 | |
|
| 59 | |
public MaintenanceDocumentEntry() { |
| 60 | 0 | super(); |
| 61 | 0 | setDocumentClass(getStandardDocumentBaseClass()); |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
public Class<? extends Document> getStandardDocumentBaseClass() { |
| 65 | 0 | return MaintenanceDocumentBase.class; |
| 66 | |
} |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public void setBusinessObjectClass(Class<? extends BusinessObject> businessObjectClass) { |
| 73 | 0 | if (businessObjectClass == null) { |
| 74 | 0 | throw new IllegalArgumentException("invalid (null) businessObjectClass"); |
| 75 | |
} |
| 76 | |
|
| 77 | 0 | this.businessObjectClass = businessObjectClass; |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
public Class<? extends BusinessObject> getBusinessObjectClass() { |
| 81 | 0 | return businessObjectClass; |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
@SuppressWarnings("unchecked") |
| 88 | |
@Override |
| 89 | |
public Class getEntryClass() { |
| 90 | 0 | return businessObjectClass; |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
public void setMaintainableClass(Class<? extends Maintainable> maintainableClass) { |
| 100 | 0 | if (maintainableClass == null) { |
| 101 | 0 | throw new IllegalArgumentException("invalid (null) maintainableClass"); |
| 102 | |
} |
| 103 | 0 | this.maintainableClass = maintainableClass; |
| 104 | 0 | } |
| 105 | |
|
| 106 | |
public Class<? extends Maintainable> getMaintainableClass() { |
| 107 | 0 | return maintainableClass; |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
public List<MaintainableSectionDefinition> getMaintainableSections() { |
| 114 | 0 | return maintainableSections; |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
public List<String> getLockingKeyFieldNames() { |
| 121 | 0 | return lockingKeys; |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
public boolean getAllowsNewOrCopy() { |
| 129 | 0 | return allowsNewOrCopy; |
| 130 | |
} |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
public void setAllowsNewOrCopy(boolean allowsNewOrCopy) { |
| 139 | 0 | this.allowsNewOrCopy = allowsNewOrCopy; |
| 140 | 0 | } |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
public void completeValidation() { |
| 149 | 0 | super.completeValidation(); |
| 150 | |
|
| 151 | 0 | for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) { |
| 152 | 0 | maintainableSectionDefinition.completeValidation(businessObjectClass, null); |
| 153 | |
} |
| 154 | |
|
| 155 | 0 | for ( String lockingKey : lockingKeys ) { |
| 156 | 0 | if (!DataDictionary.isPropertyOf(businessObjectClass, lockingKey)) { |
| 157 | 0 | throw new AttributeValidationException("unable to find attribute '" + lockingKey + "' for lockingKey in businessObjectClass '" + businessObjectClass.getName() ); |
| 158 | |
} |
| 159 | |
} |
| 160 | |
|
| 161 | 0 | for ( ReferenceDefinition reference : defaultExistenceChecks ) { |
| 162 | 0 | reference.completeValidation(businessObjectClass, null); |
| 163 | |
} |
| 164 | |
|
| 165 | 0 | if (documentAuthorizerClass != null && !MaintenanceDocumentAuthorizer.class.isAssignableFrom(documentAuthorizerClass)) { |
| 166 | 0 | throw new ClassValidationException("This maintenance document for '" + businessObjectClass.getName() + "' has an invalid " + "documentAuthorizerClass ('" + documentAuthorizerClass.getName() + "'). " + "Maintenance Documents must use an implementation of MaintenanceDocumentAuthorizer."); |
| 167 | |
} |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
public String toString() { |
| 175 | 0 | return "MaintenanceDocumentEntry for documentType " + getDocumentTypeName(); |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
public String getAdditionalSectionsFile() { |
| 180 | 0 | return additionalSectionsFile; |
| 181 | |
} |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
public void setAdditionalSectionsFile(String additionalSectionsFile) { |
| 191 | 0 | this.additionalSectionsFile = additionalSectionsFile; |
| 192 | 0 | } |
| 193 | |
|
| 194 | |
|
| 195 | |
public List<String> getLockingKeys() { |
| 196 | 0 | return lockingKeys; |
| 197 | |
} |
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
public void setLockingKeys(List<String> lockingKeys) { |
| 206 | 0 | for ( String lockingKey : lockingKeys ) { |
| 207 | 0 | if (lockingKey == null) { |
| 208 | 0 | throw new IllegalArgumentException("invalid (null) lockingKey"); |
| 209 | |
} |
| 210 | |
} |
| 211 | 0 | this.lockingKeys = lockingKeys; |
| 212 | 0 | } |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
public void setMaintainableSections(List<MaintainableSectionDefinition> maintainableSections) { |
| 229 | 0 | maintainableSectionMap.clear(); |
| 230 | 0 | for ( MaintainableSectionDefinition maintainableSectionDefinition : maintainableSections ) { |
| 231 | 0 | if (maintainableSectionDefinition == null) { |
| 232 | 0 | throw new IllegalArgumentException("invalid (null) maintainableSectionDefinition"); |
| 233 | |
} |
| 234 | |
|
| 235 | 0 | String sectionTitle = maintainableSectionDefinition.getTitle(); |
| 236 | 0 | if (maintainableSectionMap.containsKey(sectionTitle)) { |
| 237 | 0 | throw new DuplicateEntryException("section '" + sectionTitle + "' already defined for maintenanceDocument '" + getDocumentTypeName() + "'"); |
| 238 | |
} |
| 239 | |
|
| 240 | 0 | maintainableSectionMap.put(sectionTitle, maintainableSectionDefinition); |
| 241 | 0 | } |
| 242 | 0 | this.maintainableSections = maintainableSections; |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
public boolean getPreserveLockingKeysOnCopy() { |
| 251 | 0 | return this.preserveLockingKeysOnCopy; |
| 252 | |
} |
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
public void setPreserveLockingKeysOnCopy(boolean preserveLockingKeysOnCopy) { |
| 258 | 0 | this.preserveLockingKeysOnCopy = preserveLockingKeysOnCopy; |
| 259 | 0 | } |
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
public boolean getAllowsRecordDeletion() { |
| 265 | 0 | return this.allowsRecordDeletion; |
| 266 | |
} |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
public void setAllowsRecordDeletion(boolean allowsRecordDeletion) { |
| 272 | 0 | this.allowsRecordDeletion = allowsRecordDeletion; |
| 273 | 0 | } |
| 274 | |
|
| 275 | |
public boolean isTranslateCodes() { |
| 276 | 0 | return this.translateCodes; |
| 277 | |
} |
| 278 | |
|
| 279 | |
public void setTranslateCodes(boolean translateCodes) { |
| 280 | 0 | this.translateCodes = translateCodes; |
| 281 | 0 | } |
| 282 | |
|
| 283 | |
} |