001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.api.doctype; 017 018import org.apache.commons.collections.CollectionUtils; 019import org.apache.commons.lang.StringUtils; 020import org.kuali.rice.core.api.CoreConstants; 021import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 022import org.kuali.rice.core.api.mo.ModelBuilder; 023import org.kuali.rice.kew.api.KewApiConstants; 024import org.w3c.dom.Element; 025 026import javax.xml.bind.annotation.XmlAccessType; 027import javax.xml.bind.annotation.XmlAccessorType; 028import javax.xml.bind.annotation.XmlAnyElement; 029import javax.xml.bind.annotation.XmlElement; 030import javax.xml.bind.annotation.XmlElementWrapper; 031import javax.xml.bind.annotation.XmlRootElement; 032import javax.xml.bind.annotation.XmlType; 033import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 034import java.io.Serializable; 035import java.util.ArrayList; 036import java.util.Collection; 037import java.util.Collections; 038import java.util.HashMap; 039import java.util.List; 040import java.util.Map; 041 042@XmlRootElement(name = DocumentType.Constants.ROOT_ELEMENT_NAME) 043@XmlAccessorType(XmlAccessType.NONE) 044@XmlType(name = DocumentType.Constants.TYPE_NAME, propOrder = { 045 DocumentType.Elements.ID, 046 DocumentType.Elements.NAME, 047 DocumentType.Elements.DOCUMENT_TYPE_VERSION, 048 DocumentType.Elements.LABEL, 049 DocumentType.Elements.DESCRIPTION, 050 DocumentType.Elements.PARENT_ID, 051 DocumentType.Elements.ACTIVE, 052 DocumentType.Elements.UNRESOLVED_DOC_HANDLER_URL, 053 DocumentType.Elements.RESOLVED_DOC_HANDLER_URL, 054 DocumentType.Elements.HELP_DEFINITION_URL, 055 DocumentType.Elements.DOC_SEARCH_HELP_URL, 056 DocumentType.Elements.POST_PROCESSOR_NAME, 057 DocumentType.Elements.APPLICATION_ID, 058 DocumentType.Elements.CURRENT, 059 DocumentType.Elements.BLANKET_APPROVE_GROUP_ID, 060 DocumentType.Elements.SUPER_USER_GROUP_ID, 061 DocumentType.Elements.POLICIES, 062 DocumentType.Elements.DOCUMENT_TYPE_ATTRIBUTES, 063 CoreConstants.CommonElements.VERSION_NUMBER, 064 DocumentType.Elements.AUTHORIZER, 065 CoreConstants.CommonElements.FUTURE_ELEMENTS 066}) 067public final class DocumentType extends AbstractDataTransferObject implements DocumentTypeContract { 068 069 private static final long serialVersionUID = 6866926296038814812L; 070 071 @XmlElement(name = Elements.ID, required = false) 072 private final String id; 073 074 @XmlElement(name = Elements.NAME, required = true) 075 private final String name; 076 077 @XmlElement(name = Elements.DOCUMENT_TYPE_VERSION, required = false) 078 private final Integer documentTypeVersion; 079 080 @XmlElement(name = Elements.LABEL, required = false) 081 private final String label; 082 083 @XmlElement(name = Elements.DESCRIPTION, required = false) 084 private final String description; 085 086 @XmlElement(name = Elements.PARENT_ID, required = false) 087 private final String parentId; 088 089 @XmlElement(name = Elements.ACTIVE, required = true) 090 private final boolean active; 091 092 @XmlElement(name = Elements.UNRESOLVED_DOC_HANDLER_URL, required = false) 093 private final String unresolvedDocHandlerUrl; 094 095 @XmlElement(name = Elements.RESOLVED_DOC_HANDLER_URL, required = false) 096 private final String resolvedDocumentHandlerUrl; 097 098 @XmlElement(name = Elements.HELP_DEFINITION_URL, required = false) 099 private final String helpDefinitionUrl; 100 101 @XmlElement(name = Elements.DOC_SEARCH_HELP_URL, required = false) 102 private final String docSearchHelpUrl; 103 104 @XmlElement(name = Elements.POST_PROCESSOR_NAME, required = false) 105 private final String postProcessorName; 106 107 @XmlElement(name = Elements.APPLICATION_ID, required = false) 108 private final String applicationId; 109 110 @XmlElement(name = Elements.CURRENT, required = true) 111 private final boolean current; 112 113 @XmlElement(name = Elements.BLANKET_APPROVE_GROUP_ID, required = false) 114 private final String blanketApproveGroupId; 115 116 @XmlElement(name = Elements.SUPER_USER_GROUP_ID, required = false) 117 private final String superUserGroupId; 118 119 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 120 private final Long versionNumber; 121 122 @XmlElement(name = Elements.POLICIES, required = true) 123 @XmlJavaTypeAdapter(DocumentTypePolicyMapAdapter.class) 124 private final Map<DocumentTypePolicy, String> policies; 125 126 @XmlElementWrapper(name = Elements.DOCUMENT_TYPE_ATTRIBUTES, required = false) 127 @XmlElement(name = Elements.DOCUMENT_TYPE_ATTRIBUTE, required = false) 128 private final List<DocumentTypeAttribute> documentTypeAttributes; 129 130 /** 131 * @since 2.1.3 132 */ 133 @XmlElement(name = Elements.AUTHORIZER, required = false) 134 private final String authorizer; 135 136 @SuppressWarnings("unused") 137 @XmlAnyElement 138 private final Collection<Element> _futureElements = null; 139 140 /** 141 * Private constructor used only by JAXB. 142 */ 143 private DocumentType() { 144 this.id = null; 145 this.name = null; 146 this.documentTypeVersion = null; 147 this.label = null; 148 this.description = null; 149 this.parentId = null; 150 this.active = false; 151 this.unresolvedDocHandlerUrl = null; 152 this.resolvedDocumentHandlerUrl = null; 153 this.helpDefinitionUrl = null; 154 this.docSearchHelpUrl = null; 155 this.postProcessorName = null; 156 this.applicationId = null; 157 this.current = false; 158 this.blanketApproveGroupId = null; 159 this.superUserGroupId = null; 160 this.policies = null; 161 this.versionNumber = null; 162 this.documentTypeAttributes = null; 163 this.authorizer = null; 164 } 165 166 private DocumentType(Builder builder) { 167 this.name = builder.getName(); 168 this.id = builder.getId(); 169 this.documentTypeVersion = builder.getDocumentTypeVersion(); 170 this.label = builder.getLabel(); 171 this.description = builder.getDescription(); 172 this.parentId = builder.getParentId(); 173 this.active = builder.isActive(); 174 this.unresolvedDocHandlerUrl = builder.getUnresolvedDocHandlerUrl(); 175 this.resolvedDocumentHandlerUrl = builder.getResolvedDocumentHandlerUrl(); 176 this.helpDefinitionUrl = builder.getHelpDefinitionUrl(); 177 this.docSearchHelpUrl = builder.getDocSearchHelpUrl(); 178 this.postProcessorName = builder.getPostProcessorName(); 179 this.applicationId = builder.getApplicationId(); 180 this.current = builder.isCurrent(); 181 this.blanketApproveGroupId = builder.getBlanketApproveGroupId(); 182 this.superUserGroupId = builder.getSuperUserGroupId(); 183 if (builder.getPolicies() == null) { 184 this.policies = Collections.emptyMap(); 185 } else { 186 this.policies = Collections.unmodifiableMap(new HashMap<DocumentTypePolicy, String>(builder.getPolicies())); 187 } 188 this.versionNumber = builder.getVersionNumber(); 189 190 List<DocumentTypeAttribute> tempAttributes = new ArrayList<DocumentTypeAttribute>(); 191 if (CollectionUtils.isNotEmpty(builder.getDocumentTypeAttributes())) { 192 for (DocumentTypeAttribute.Builder externalId : builder.getDocumentTypeAttributes()) { 193 tempAttributes.add(externalId.build()); 194 } 195 } 196 this.documentTypeAttributes = Collections.unmodifiableList(tempAttributes); 197 this.authorizer = builder.getAuthorizer(); 198 } 199 200 @Override 201 public String getId() { 202 return this.id; 203 } 204 205 @Override 206 public String getName() { 207 return this.name; 208 } 209 210 @Override 211 public Integer getDocumentTypeVersion() { 212 return this.documentTypeVersion; 213 } 214 215 @Override 216 public String getLabel() { 217 return this.label; 218 } 219 220 @Override 221 public String getDescription() { 222 return this.description; 223 } 224 225 @Override 226 public String getParentId() { 227 return this.parentId; 228 } 229 230 @Override 231 public boolean isActive() { 232 return this.active; 233 } 234 235 @Override 236 public String getUnresolvedDocHandlerUrl() { 237 return this.unresolvedDocHandlerUrl; 238 } 239 240 @Override 241 public String getHelpDefinitionUrl() { 242 return this.helpDefinitionUrl; 243 } 244 245 @Override 246 public String getDocSearchHelpUrl() { 247 return this.docSearchHelpUrl; 248 } 249 250 @Override 251 public String getPostProcessorName() { 252 return this.postProcessorName; 253 } 254 255 @Override 256 public String getApplicationId() { 257 return this.applicationId; 258 } 259 260 @Override 261 public boolean isCurrent() { 262 return this.current; 263 } 264 265 @Override 266 public String getBlanketApproveGroupId() { 267 return this.blanketApproveGroupId; 268 } 269 270 @Override 271 public String getSuperUserGroupId() { 272 return this.superUserGroupId; 273 } 274 275 @Override 276 public Map<DocumentTypePolicy, String> getPolicies() { 277 return this.policies; 278 } 279 280 @Override 281 public List<DocumentTypeAttribute> getDocumentTypeAttributes() { 282 return this.documentTypeAttributes; 283 } 284 285 @Override 286 public Long getVersionNumber() { 287 return this.versionNumber; 288 } 289 290 @Override 291 public String getResolvedDocumentHandlerUrl() { 292 return this.resolvedDocumentHandlerUrl; 293 } 294 295 /** 296 * @since 2.1.3 297 * @ 298 */ 299 @Override 300 public String getAuthorizer() { 301 return this.authorizer; 302 } 303 304 /** 305 * A builder which can be used to construct {@link DocumentType} instances. Enforces the 306 * constraints of the {@link DocumentTypeContract}. 307 */ 308 public final static class Builder implements Serializable, ModelBuilder, DocumentTypeContract { 309 310 private static final long serialVersionUID = 1678979180435181578L; 311 312 private String id; 313 private String name; 314 private Integer documentTypeVersion; 315 private String label; 316 private String description; 317 private String parentId; 318 private boolean active; 319 private String unresolvedDocHandlerUrl; 320 private String resolvedDocumentHandlerUrl; 321 private String helpDefinitionUrl; 322 private String docSearchHelpUrl; 323 private String postProcessorName; 324 private String applicationId; 325 private boolean current; 326 private String blanketApproveGroupId; 327 private String superUserGroupId; 328 private Map<DocumentTypePolicy, String> policies; 329 private List<DocumentTypeAttribute.Builder> documentTypeAttributes; 330 private Long versionNumber; 331 private String authorizer; 332 333 private Builder(String name) { 334 setName(name); 335 setActive(true); 336 setCurrent(true); 337 this.policies = new HashMap<DocumentTypePolicy, String>(); 338 this.documentTypeAttributes = Collections.emptyList(); 339 } 340 341 public static Builder create(String name) { 342 return new Builder(name); 343 } 344 345 public static Builder create(DocumentTypeContract contract) { 346 if (contract == null) { 347 throw new IllegalArgumentException("contract was null"); 348 } 349 Builder builder = create(contract.getName()); 350 builder.setId(contract.getId()); 351 builder.setDocumentTypeVersion(contract.getDocumentTypeVersion()); 352 builder.setLabel(contract.getLabel()); 353 builder.setDescription(contract.getDescription()); 354 builder.setParentId(contract.getParentId()); 355 builder.setActive(contract.isActive()); 356 builder.setUnresolvedDocHandlerUrl(contract.getUnresolvedDocHandlerUrl()); 357 builder.setResolvedDocHandlerUrl(contract.getResolvedDocumentHandlerUrl()); 358 builder.setHelpDefinitionUrl(contract.getHelpDefinitionUrl()); 359 builder.setDocSearchHelpUrl(contract.getDocSearchHelpUrl()); 360 builder.setPostProcessorName(contract.getPostProcessorName()); 361 builder.setApplicationId(contract.getApplicationId()); 362 builder.setCurrent(contract.isCurrent()); 363 builder.setBlanketApproveGroupId(contract.getBlanketApproveGroupId()); 364 builder.setSuperUserGroupId(contract.getSuperUserGroupId()); 365 builder.setPolicies(new HashMap<DocumentTypePolicy, String>(contract.getPolicies())); 366 if (contract.getDocumentTypeAttributes() != null) { 367 List<DocumentTypeAttribute.Builder> tempAttrs = new ArrayList<DocumentTypeAttribute.Builder>(); 368 for (DocumentTypeAttributeContract attrContract : contract.getDocumentTypeAttributes()) { 369 tempAttrs.add(DocumentTypeAttribute.Builder.create(attrContract)); 370 } 371 builder.setDocumentTypeAttributes(tempAttrs); 372 } 373 builder.setVersionNumber(contract.getVersionNumber()); 374 builder.setAuthorizer(contract.getAuthorizer()); 375 return builder; 376 } 377 378 public DocumentType build() { 379 return new DocumentType(this); 380 } 381 382 @Override 383 public String getId() { 384 return this.id; 385 } 386 387 @Override 388 public String getName() { 389 return this.name; 390 } 391 392 @Override 393 public Integer getDocumentTypeVersion() { 394 return this.documentTypeVersion; 395 } 396 397 @Override 398 public String getLabel() { 399 return this.label; 400 } 401 402 @Override 403 public String getDescription() { 404 return this.description; 405 } 406 407 @Override 408 public String getParentId() { 409 return this.parentId; 410 } 411 412 @Override 413 public boolean isActive() { 414 return this.active; 415 } 416 417 @Override 418 public String getUnresolvedDocHandlerUrl() { 419 return this.unresolvedDocHandlerUrl; 420 } 421 422 @Override 423 public String getResolvedDocumentHandlerUrl() { 424 return this.resolvedDocumentHandlerUrl; 425 } 426 427 @Override 428 public String getHelpDefinitionUrl() { 429 return this.helpDefinitionUrl; 430 } 431 432 @Override 433 public String getDocSearchHelpUrl() { 434 return this.docSearchHelpUrl; 435 } 436 437 @Override 438 public String getPostProcessorName() { 439 return this.postProcessorName; 440 } 441 442 @Override 443 public String getApplicationId() { 444 return this.applicationId; 445 } 446 447 @Override 448 public boolean isCurrent() { 449 return this.current; 450 } 451 452 @Override 453 public String getBlanketApproveGroupId() { 454 return this.blanketApproveGroupId; 455 } 456 457 @Override 458 public String getSuperUserGroupId() { 459 return this.superUserGroupId; 460 } 461 462 @Override 463 public Map<DocumentTypePolicy, String> getPolicies() { 464 return this.policies; 465 } 466 467 @Override 468 public List<DocumentTypeAttribute.Builder> getDocumentTypeAttributes() { 469 return this.documentTypeAttributes; 470 } 471 472 @Override 473 public Long getVersionNumber() { 474 return this.versionNumber; 475 } 476 477 /** 478 * @since 2.1.3 479 * @ 480 */ 481 @Override 482 public String getAuthorizer() { 483 return this.authorizer; 484 } 485 486 public void setId(String id) { 487 this.id = id; 488 } 489 490 public void setName(String name) { 491 if (StringUtils.isBlank(name)) { 492 throw new IllegalArgumentException("name was null or blank"); 493 } 494 this.name = name; 495 } 496 497 public void setDocumentTypeVersion(Integer documentTypeVersion) { 498 this.documentTypeVersion = documentTypeVersion; 499 } 500 501 public void setLabel(String label) { 502 this.label = label; 503 } 504 505 public void setDescription(String description) { 506 this.description = description; 507 } 508 509 public void setParentId(String parentId) { 510 this.parentId = parentId; 511 } 512 513 public void setActive(boolean active) { 514 this.active = active; 515 } 516 517 public void setUnresolvedDocHandlerUrl(String unresolvedDocHandlerUrl) { 518 this.unresolvedDocHandlerUrl = unresolvedDocHandlerUrl; 519 } 520 521 public void setResolvedDocHandlerUrl(String resolvedDocumentHandlerUrl) { 522 this.resolvedDocumentHandlerUrl = resolvedDocumentHandlerUrl; 523 } 524 525 public void setHelpDefinitionUrl(String helpDefinitionUrl) { 526 this.helpDefinitionUrl = helpDefinitionUrl; 527 } 528 529 public void setDocSearchHelpUrl(String docSearchHelpUrl) { 530 this.docSearchHelpUrl = docSearchHelpUrl; 531 } 532 533 public void setPostProcessorName(String postProcessorName) { 534 this.postProcessorName = postProcessorName; 535 } 536 537 public void setApplicationId(String applicationId) { 538 this.applicationId = applicationId; 539 } 540 541 public void setCurrent(boolean current) { 542 this.current = current; 543 } 544 545 public void setBlanketApproveGroupId(String blanketApproveGroupId) { 546 this.blanketApproveGroupId = blanketApproveGroupId; 547 } 548 549 public void setSuperUserGroupId(String superUserGroupId) { 550 this.superUserGroupId = superUserGroupId; 551 } 552 553 public void setPolicies(Map<DocumentTypePolicy, String> policies) { 554 this.policies = policies; 555 } 556 557 public void setDocumentTypeAttributes(List<DocumentTypeAttribute.Builder> documentTypeAttributes) { 558 this.documentTypeAttributes = documentTypeAttributes; 559 } 560 561 public void setVersionNumber(Long versionNumber) { 562 this.versionNumber = versionNumber; 563 } 564 565 public void setAuthorizer(String authorizer) { 566 this.authorizer = authorizer; 567 } 568 } 569 570 /** 571 * Defines some internal constants used on this class. 572 */ 573 static class Constants { 574 final static String ROOT_ELEMENT_NAME = "documentType"; 575 final static String TYPE_NAME = "DocumentTypeType"; 576 } 577 578 /** 579 * A private class which exposes constants which define the XML element names to use when this 580 * object is marshalled to XML. 581 */ 582 static class Elements { 583 final static String ID = "id"; 584 final static String NAME = "name"; 585 final static String DOCUMENT_TYPE_VERSION = "documentTypeVersion"; 586 final static String LABEL = "label"; 587 final static String DESCRIPTION = "description"; 588 final static String PARENT_ID = "parentId"; 589 final static String ACTIVE = "active"; 590 final static String UNRESOLVED_DOC_HANDLER_URL = "unresolvedDocHandlerUrl"; 591 final static String RESOLVED_DOC_HANDLER_URL = "resolvedDocumentHandlerUrl"; 592 final static String HELP_DEFINITION_URL = "helpDefinitionUrl"; 593 final static String DOC_SEARCH_HELP_URL = "docSearchHelpUrl"; 594 final static String POST_PROCESSOR_NAME = "postProcessorName"; 595 final static String APPLICATION_ID = "applicationId"; 596 final static String CURRENT = "current"; 597 final static String BLANKET_APPROVE_GROUP_ID = "blanketApproveGroupId"; 598 final static String SUPER_USER_GROUP_ID = "superUserGroupId"; 599 final static String POLICIES = "policies"; 600 final static String DOCUMENT_TYPE_ATTRIBUTES = "documentTypeAttributes"; 601 final static String DOCUMENT_TYPE_ATTRIBUTE = "documentTypeAttribute"; 602 final static String AUTHORIZER = "authorizer"; 603 } 604 605 public static class Cache { 606 public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + DocumentType.Constants.TYPE_NAME; 607 } 608}