001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; 004import gov.nist.secauto.metaschema.core.model.IBoundObject; 005import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 006import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 007import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; 008import gov.nist.secauto.metaschema.core.util.ObjectUtils; 009import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; 010import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; 011import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 012import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 013import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 014import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 015import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 016import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 017import gov.nist.secauto.oscal.lib.model.control.profile.AbstractProfileSelectControlById; 018import java.lang.Override; 019import java.lang.String; 020import java.util.LinkedList; 021import java.util.List; 022import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 023import org.apache.commons.lang3.builder.ToStringStyle; 024 025/** 026 * Select a control or controls from an imported control set. 027 */ 028@MetaschemaAssembly( 029 formalName = "Select Control", 030 description = "Select a control or controls from an imported control set.", 031 name = "select-control-by-id", 032 moduleClass = OscalProfileModule.class, 033 remarks = "If `with-child-controls` is \"yes\" on the call to a control, no sibling `call`elements need to be used to call any controls appearing within it. Since generally, this is how control enhancements are represented (as controls within controls), this provides a way to include controls with all their dependent controls (enhancements) without having to call them individually." 034) 035public class ProfileSelectControlById extends AbstractProfileSelectControlById implements IBoundObject { 036 private final IMetaschemaData __metaschemaData; 037 038 /** 039 * "When a control is included, whether its child (dependent) controls are also included." 040 */ 041 @BoundFlag( 042 formalName = "Include Contained Controls with Control", 043 description = "When a control is included, whether its child (dependent) controls are also included.", 044 name = "with-child-controls", 045 typeAdapter = TokenAdapter.class, 046 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "yes", description = "Include child controls with an included control."), @AllowedValue(value = "no", description = "When importing a control, only include child controls that are also explicitly called.")})) 047 ) 048 private String _withChildControls; 049 050 @BoundField( 051 formalName = "Match Controls by Identifier", 052 description = "Selecting a control by its ID given as a literal.", 053 useName = "with-id", 054 maxOccurs = -1, 055 groupAs = @GroupAs(name = "with-ids", inJson = JsonGroupAsBehavior.LIST), 056 typeAdapter = TokenAdapter.class 057 ) 058 private List<String> _withIds; 059 060 @BoundAssembly( 061 formalName = "Match Controls by Pattern", 062 description = "Selecting a set of controls by matching their IDs with a wildcard pattern.", 063 useName = "matching", 064 maxOccurs = -1, 065 groupAs = @GroupAs(name = "matching", inJson = JsonGroupAsBehavior.LIST) 066 ) 067 private List<Matching> _matching; 068 069 public ProfileSelectControlById() { 070 this(null); 071 } 072 073 public ProfileSelectControlById(IMetaschemaData data) { 074 this.__metaschemaData = data; 075 } 076 077 @Override 078 public IMetaschemaData getMetaschemaData() { 079 return __metaschemaData; 080 } 081 082 public String getWithChildControls() { 083 return _withChildControls; 084 } 085 086 public void setWithChildControls(String value) { 087 _withChildControls = value; 088 } 089 090 public List<String> getWithIds() { 091 return _withIds; 092 } 093 094 public void setWithIds(List<String> value) { 095 _withIds = value; 096 } 097 098 /** 099 * Add a new {@link String} item to the underlying collection. 100 * @param item the item to add 101 * @return {@code true} 102 */ 103 public boolean addWithId(String item) { 104 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 105 if (_withIds == null) { 106 _withIds = new LinkedList<>(); 107 } 108 return _withIds.add(value); 109 } 110 111 /** 112 * Remove the first matching {@link String} item from the underlying collection. 113 * @param item the item to remove 114 * @return {@code true} if the item was removed or {@code false} otherwise 115 */ 116 public boolean removeWithId(String item) { 117 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 118 return _withIds != null && _withIds.remove(value); 119 } 120 121 public List<Matching> getMatching() { 122 return _matching; 123 } 124 125 public void setMatching(List<Matching> value) { 126 _matching = value; 127 } 128 129 /** 130 * Add a new {@link Matching} item to the underlying collection. 131 * @param item the item to add 132 * @return {@code true} 133 */ 134 public boolean addMatching(Matching item) { 135 Matching value = ObjectUtils.requireNonNull(item,"item cannot be null"); 136 if (_matching == null) { 137 _matching = new LinkedList<>(); 138 } 139 return _matching.add(value); 140 } 141 142 /** 143 * Remove the first matching {@link Matching} item from the underlying collection. 144 * @param item the item to remove 145 * @return {@code true} if the item was removed or {@code false} otherwise 146 */ 147 public boolean removeMatching(Matching item) { 148 Matching value = ObjectUtils.requireNonNull(item,"item cannot be null"); 149 return _matching != null && _matching.remove(value); 150 } 151 152 @Override 153 public String toString() { 154 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 155 } 156}