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