1 23 24 package org.hammurapi.results.persistent.jdbc; 25 26 import java.sql.SQLException ; 27 import java.util.Collection ; 28 import java.util.Date ; 29 import java.util.HashSet ; 30 import java.util.Set ; 31 import java.util.StringTokenizer ; 32 33 import org.hammurapi.HammurapiException; 34 import org.hammurapi.Violation; 35 import org.hammurapi.Waiver; 36 import org.hammurapi.WaiverEntry; 37 import org.hammurapi.WaiverSet; 38 import org.hammurapi.results.persistent.jdbc.sql.WaivedViolationJoined; 39 40 import com.pavelvlasov.convert.Converter; 41 import com.pavelvlasov.review.Signed; 42 43 48 public class DetailedResults extends NamedResults implements org.hammurapi.results.DetailedResults { 49 50 55 public DetailedResults(int id, ResultsFactory factory) throws SQLException { 56 super(id, factory); 57 } 58 59 DetailedResults(String name, WaiverSet waiverSet, ResultsFactory factory) throws SQLException { 60 super(name, waiverSet, factory); 61 } 62 63 public Waiver addViolation(final Violation violation) throws HammurapiException { 64 final Waiver waiver=super.addViolation(violation); 65 if (waiver!=null) { 66 insertViolation( 67 violation, 68 WAIVED_VIOLATION, 69 new ViolationConfigurator() { 70 public void setViolationInfo(org.hammurapi.results.persistent.jdbc.sql.Violation sqlViolation) { 71 String reason = waiver.getReason(); 72 if (reason!=null) { 73 sqlViolation.setWaiverReason(new Integer (factory.addMessage(reason))); 74 } 75 76 Date expirationDate = waiver.getExpirationDate(); 77 if (expirationDate!=null) { 78 sqlViolation.setWaiverExpires(new java.sql.Date (expirationDate.getTime())); 79 } 80 } 81 }); 82 } 83 return waiver; 84 } 85 86 public Collection getViolations() { 87 return factory.getResultsEngine().getViolationJoined(getId(), violationConverter); 88 } 89 90 private Converter waivedViolationConverter=new Converter() { 91 public Object convert(Object o) { 92 final WaivedViolationJoined wvj=(WaivedViolationJoined) o; 93 final Violation violation=(Violation) violationConverter.convert(o); 94 95 final Set signatures=new HashSet (); 96 final String signature=wvj.getSignature(); 97 if (signature!=null) { 98 StringTokenizer st=new StringTokenizer (signature,"|"); 99 while (st.hasMoreTokens()) { 100 signatures.add(st.nextToken()); 101 } 102 } 103 Date waiverExpires = wvj.getWaiverExpires(); 104 final java.util.Date expirationDate = waiverExpires==null ? null : new Date (waiverExpires.getTime()); 105 106 return new WaiverEntry() { 107 108 111 private static final long serialVersionUID = -5416258427336694577L; 112 113 public Waiver getWaiver() { 114 return new Waiver() { 115 public String getInspectorName() { 116 return violation.getDescriptor().getName(); 117 } 118 119 public java.util.Date getExpirationDate() { 120 return expirationDate; 121 } 122 123 public String getReason() { 124 return wvj.getWaiverReason(); 125 } 126 127 public boolean waive(Violation v, boolean peek) { 128 if (violation.getDescriptor().getName().equals(v.getDescriptor().getName())) { 129 if (signature==null) { 130 return true; 131 } 132 133 String vSignature = ((Signed) violation.getSource()).getSignature(); 134 if (violation.getSource() instanceof Signed && signatures.contains(vSignature)) { 135 if (!peek) { 136 signatures.remove(vSignature); 137 } 138 return true; 139 } 140 } 141 return false; 142 } 143 144 public boolean isActive() { 145 return !signatures.isEmpty(); 146 } 147 148 public Collection getSignatures() { 149 return signatures; 150 } 151 }; 152 } 153 154 public Violation getViolation() { 155 return violation; 156 } 157 }; 158 } 159 }; 160 161 public Collection getWaivedViolations() { 162 return factory.getResultsEngine().getWaivedViolationJoined(getId(), waivedViolationConverter); 163 } 164 } 165 | Popular Tags |