001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; 004import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter; 005import gov.nist.secauto.metaschema.core.model.IBoundObject; 006import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 007import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 008import gov.nist.secauto.metaschema.core.util.ObjectUtils; 009import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 010import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 011import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 012import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 013import java.lang.Override; 014import java.lang.String; 015import java.util.LinkedList; 016import java.util.List; 017import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 018import org.apache.commons.lang3.builder.ToStringStyle; 019 020/** 021 * A formal or informal expression of a constraint or test. 022 */ 023@MetaschemaAssembly( 024 formalName = "Constraint", 025 description = "A formal or informal expression of a constraint or test.", 026 name = "parameter-constraint", 027 moduleClass = OscalControlCommonModule.class 028) 029public class ParameterConstraint implements IBoundObject { 030 private final IMetaschemaData __metaschemaData; 031 032 @BoundField( 033 formalName = "Constraint Description", 034 description = "A textual summary of the constraint to be applied.", 035 useName = "description", 036 typeAdapter = MarkupMultilineAdapter.class 037 ) 038 private MarkupMultiline _description; 039 040 @BoundAssembly( 041 formalName = "Constraint Test", 042 description = "A test expression which is expected to be evaluated by a tool.", 043 useName = "test", 044 maxOccurs = -1, 045 groupAs = @GroupAs(name = "tests", inJson = JsonGroupAsBehavior.LIST) 046 ) 047 private List<Test> _tests; 048 049 public ParameterConstraint() { 050 this(null); 051 } 052 053 public ParameterConstraint(IMetaschemaData data) { 054 this.__metaschemaData = data; 055 } 056 057 @Override 058 public IMetaschemaData getMetaschemaData() { 059 return __metaschemaData; 060 } 061 062 public MarkupMultiline getDescription() { 063 return _description; 064 } 065 066 public void setDescription(MarkupMultiline value) { 067 _description = value; 068 } 069 070 public List<Test> getTests() { 071 return _tests; 072 } 073 074 public void setTests(List<Test> value) { 075 _tests = value; 076 } 077 078 /** 079 * Add a new {@link Test} item to the underlying collection. 080 * @param item the item to add 081 * @return {@code true} 082 */ 083 public boolean addTest(Test item) { 084 Test value = ObjectUtils.requireNonNull(item,"item cannot be null"); 085 if (_tests == null) { 086 _tests = new LinkedList<>(); 087 } 088 return _tests.add(value); 089 } 090 091 /** 092 * Remove the first matching {@link Test} item from the underlying collection. 093 * @param item the item to remove 094 * @return {@code true} if the item was removed or {@code false} otherwise 095 */ 096 public boolean removeTest(Test item) { 097 Test value = ObjectUtils.requireNonNull(item,"item cannot be null"); 098 return _tests != null && _tests.remove(value); 099 } 100 101 @Override 102 public String toString() { 103 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 104 } 105 106 /** 107 * A test expression which is expected to be evaluated by a tool. 108 */ 109 @MetaschemaAssembly( 110 formalName = "Constraint Test", 111 description = "A test expression which is expected to be evaluated by a tool.", 112 name = "test", 113 moduleClass = OscalControlCommonModule.class 114 ) 115 public static class Test implements IBoundObject { 116 private final IMetaschemaData __metaschemaData; 117 118 @BoundField( 119 formalName = "Constraint test", 120 description = "A formal (executable) expression of a constraint.", 121 useName = "expression", 122 minOccurs = 1 123 ) 124 private String _expression; 125 126 @BoundField( 127 formalName = "Remarks", 128 description = "Additional commentary about the containing object.", 129 useName = "remarks", 130 typeAdapter = MarkupMultilineAdapter.class 131 ) 132 private MarkupMultiline _remarks; 133 134 public Test() { 135 this(null); 136 } 137 138 public Test(IMetaschemaData data) { 139 this.__metaschemaData = data; 140 } 141 142 @Override 143 public IMetaschemaData getMetaschemaData() { 144 return __metaschemaData; 145 } 146 147 public String getExpression() { 148 return _expression; 149 } 150 151 public void setExpression(String value) { 152 _expression = value; 153 } 154 155 public MarkupMultiline getRemarks() { 156 return _remarks; 157 } 158 159 public void setRemarks(MarkupMultiline value) { 160 _remarks = value; 161 } 162 163 @Override 164 public String toString() { 165 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 166 } 167 } 168}