001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023:
024: package org.hammurapi.results.persistent.jdbc;
025:
026: import java.sql.SQLException;
027: import java.util.Collection;
028: import java.util.Date;
029: import java.util.HashSet;
030: import java.util.Set;
031: import java.util.StringTokenizer;
032:
033: import org.hammurapi.HammurapiException;
034: import org.hammurapi.Violation;
035: import org.hammurapi.Waiver;
036: import org.hammurapi.WaiverEntry;
037: import org.hammurapi.WaiverSet;
038: import org.hammurapi.results.persistent.jdbc.sql.WaivedViolationJoined;
039:
040: import com.pavelvlasov.convert.Converter;
041: import com.pavelvlasov.review.Signed;
042:
043: /**
044: *
045: * @author Pavel Vlasov
046: * @version $Revision: 1.9 $
047: */
048: public class DetailedResults extends NamedResults implements
049: org.hammurapi.results.DetailedResults {
050:
051: /**
052: * @param id
053: * @param factory
054: * @throws SQLException
055: */
056: public DetailedResults(int id, ResultsFactory factory)
057: throws SQLException {
058: super (id, factory);
059: }
060:
061: DetailedResults(String name, WaiverSet waiverSet,
062: ResultsFactory factory) throws SQLException {
063: super (name, waiverSet, factory);
064: }
065:
066: public Waiver addViolation(final Violation violation)
067: throws HammurapiException {
068: final Waiver waiver = super .addViolation(violation);
069: if (waiver != null) {
070: insertViolation(violation, WAIVED_VIOLATION,
071: new ViolationConfigurator() {
072: public void setViolationInfo(
073: org.hammurapi.results.persistent.jdbc.sql.Violation sqlViolation) {
074: String reason = waiver.getReason();
075: if (reason != null) {
076: sqlViolation
077: .setWaiverReason(new Integer(
078: factory
079: .addMessage(reason)));
080: }
081:
082: Date expirationDate = waiver
083: .getExpirationDate();
084: if (expirationDate != null) {
085: sqlViolation
086: .setWaiverExpires(new java.sql.Date(
087: expirationDate
088: .getTime()));
089: }
090: }
091: });
092: }
093: return waiver;
094: }
095:
096: public Collection getViolations() {
097: return factory.getResultsEngine().getViolationJoined(getId(),
098: violationConverter);
099: }
100:
101: private Converter waivedViolationConverter = new Converter() {
102: public Object convert(Object o) {
103: final WaivedViolationJoined wvj = (WaivedViolationJoined) o;
104: final Violation violation = (Violation) violationConverter
105: .convert(o);
106:
107: final Set signatures = new HashSet();
108: final String signature = wvj.getSignature();
109: if (signature != null) {
110: StringTokenizer st = new StringTokenizer(signature, "|");
111: while (st.hasMoreTokens()) {
112: signatures.add(st.nextToken());
113: }
114: }
115: Date waiverExpires = wvj.getWaiverExpires();
116: final java.util.Date expirationDate = waiverExpires == null ? null
117: : new Date(waiverExpires.getTime());
118:
119: return new WaiverEntry() {
120:
121: /**
122: * Comment for <code>serialVersionUID</code>
123: */
124: private static final long serialVersionUID = -5416258427336694577L;
125:
126: public Waiver getWaiver() {
127: return new Waiver() {
128: public String getInspectorName() {
129: return violation.getDescriptor().getName();
130: }
131:
132: public java.util.Date getExpirationDate() {
133: return expirationDate;
134: }
135:
136: public String getReason() {
137: return wvj.getWaiverReason();
138: }
139:
140: public boolean waive(Violation v, boolean peek) {
141: if (violation
142: .getDescriptor()
143: .getName()
144: .equals(v.getDescriptor().getName())) {
145: if (signature == null) {
146: return true;
147: }
148:
149: String vSignature = ((Signed) violation
150: .getSource()).getSignature();
151: if (violation.getSource() instanceof Signed
152: && signatures
153: .contains(vSignature)) {
154: if (!peek) {
155: signatures.remove(vSignature);
156: }
157: return true;
158: }
159: }
160: return false;
161: }
162:
163: public boolean isActive() {
164: return !signatures.isEmpty();
165: }
166:
167: public Collection getSignatures() {
168: return signatures;
169: }
170: };
171: }
172:
173: public Violation getViolation() {
174: return violation;
175: }
176: };
177: }
178: };
179:
180: public Collection getWaivedViolations() {
181: return factory.getResultsEngine().getWaivedViolationJoined(
182: getId(), waivedViolationConverter);
183: }
184: }
|