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.action; 017 018import java.util.Collection; 019import java.util.Collections; 020import java.util.Set; 021 022import javax.xml.bind.annotation.XmlAccessType; 023import javax.xml.bind.annotation.XmlAccessorType; 024import javax.xml.bind.annotation.XmlAnyElement; 025import javax.xml.bind.annotation.XmlElement; 026import javax.xml.bind.annotation.XmlElementWrapper; 027import javax.xml.bind.annotation.XmlRootElement; 028import javax.xml.bind.annotation.XmlType; 029 030import org.apache.commons.lang.StringUtils; 031import org.kuali.rice.core.api.CoreConstants; 032import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 033import org.w3c.dom.Element; 034 035@XmlRootElement(name = AdHocRevoke.Constants.ROOT_ELEMENT_NAME) 036@XmlAccessorType(XmlAccessType.NONE) 037@XmlType(name = AdHocRevoke.Constants.TYPE_NAME, propOrder = { 038 AdHocRevoke.Elements.NODE_NAMES, 039 AdHocRevoke.Elements.PRINCIPAL_IDS, 040 AdHocRevoke.Elements.GROUP_IDS, 041 CoreConstants.CommonElements.FUTURE_ELEMENTS 042}) 043public final class AdHocRevoke extends AbstractDataTransferObject { 044 045 private static final long serialVersionUID = 5848714514445793355L; 046 047 @XmlElementWrapper(name = Elements.NODE_NAMES, required = false) 048 @XmlElement(name = Elements.NODE_NAME, required = false) 049 private final Set<String> nodeNames; 050 051 @XmlElementWrapper(name = Elements.PRINCIPAL_IDS, required = false) 052 @XmlElement(name = Elements.PRINCIPAL_ID, required = false) 053 private final Set<String> principalIds; 054 055 @XmlElementWrapper(name = Elements.GROUP_IDS, required = false) 056 @XmlElement(name = Elements.GROUP_ID, required = false) 057 private final Set<String> groupIds; 058 059 @SuppressWarnings("unused") 060 @XmlAnyElement 061 private final Collection<Element> _futureElements = null; 062 063 /** 064 * Private constructor used only by JAXB. 065 */ 066 private AdHocRevoke() { 067 this.nodeNames = null; 068 this.principalIds = null; 069 this.groupIds = null; 070 } 071 072 073 private AdHocRevoke(Set<String> nodeNames, Set<String> principalIds, Set<String> groupIds) { 074 this.nodeNames = nodeNames; 075 this.principalIds = principalIds; 076 this.groupIds = groupIds; 077 } 078 079 public static AdHocRevoke create(Set<String> nodeNames, Set<String> principalIds, Set<String> groupIds) { 080 return new AdHocRevoke(nodeNames, principalIds, groupIds); 081 } 082 083 public static AdHocRevoke createRevokeFromPrincipal(String principalId) { 084 if (StringUtils.isBlank(principalId)) { 085 throw new IllegalArgumentException("principalId was null or blank"); 086 } 087 return create(null, Collections.singleton(principalId), null); 088 } 089 090 public static AdHocRevoke createRevokeFromGroup(String groupId) { 091 if (StringUtils.isBlank(groupId)) { 092 throw new IllegalArgumentException("groupId was null or blank"); 093 } 094 return create(null, null, Collections.singleton(groupId)); 095 } 096 097 public static AdHocRevoke createRevokeAtNode(String nodeName) { 098 if (StringUtils.isBlank(nodeName)) { 099 throw new IllegalArgumentException("nodeName was null or blank"); 100 } 101 return create(Collections.singleton(nodeName), null, null); 102 } 103 104 public Set<String> getNodeNames() { 105 if (nodeNames == null) { 106 return Collections.emptySet(); 107 } 108 return Collections.unmodifiableSet(nodeNames); 109 } 110 111 public Set<String> getPrincipalIds() { 112 if (principalIds == null) { 113 return Collections.emptySet(); 114 } 115 return Collections.unmodifiableSet(principalIds); 116 } 117 118 public Set<String> getGroupIds() { 119 if (groupIds == null) { 120 return Collections.emptySet(); 121 } 122 return Collections.unmodifiableSet(groupIds); 123 } 124 125 /** 126 * Defines some internal constants used on this class. 127 */ 128 static class Constants { 129 final static String ROOT_ELEMENT_NAME = "adHocRevoke"; 130 final static String TYPE_NAME = "AdHocRevokeType"; 131 } 132 133 /** 134 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 135 */ 136 static class Elements { 137 final static String NODE_NAMES = "nodeNames"; 138 final static String NODE_NAME = "nodeName"; 139 final static String PRINCIPAL_IDS = "principalIds"; 140 final static String PRINCIPAL_ID = "principalId"; 141 final static String GROUP_IDS = "groupIds"; 142 final static String GROUP_ID = "groupId"; 143 } 144 145}