001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar 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 GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.core.review; 021 022 import com.google.common.collect.Lists; 023 import org.sonar.core.persistence.DatabaseUtils; 024 025 import java.util.Collection; 026 import java.util.List; 027 028 /** 029 * @since 2.13 030 */ 031 public final class ReviewQuery { 032 private Boolean manualViolation; 033 private Boolean manualSeverity; 034 private Integer resourceId; 035 private Integer userId; 036 private List<Integer> violationPermanentIds; 037 private Integer ruleId; 038 private String status; 039 private String resolution; 040 041 private ReviewQuery() { 042 } 043 044 private ReviewQuery(ReviewQuery other, List<Integer> permanentIds) { 045 this.manualViolation = other.manualViolation; 046 this.manualSeverity = other.manualSeverity; 047 this.resourceId = other.resourceId; 048 this.userId = other.userId; 049 this.violationPermanentIds = permanentIds; 050 this.ruleId = other.ruleId; 051 this.status = other.status; 052 this.resolution = other.resolution; 053 } 054 055 public static ReviewQuery create() { 056 return new ReviewQuery(); 057 } 058 059 public Boolean getManualViolation() { 060 return manualViolation; 061 } 062 063 public ReviewQuery setManualViolation(Boolean manualViolation) { 064 this.manualViolation = manualViolation; 065 return this; 066 } 067 068 public Integer getResourceId() { 069 return resourceId; 070 } 071 072 public ReviewQuery setResourceId(Integer resourceId) { 073 this.resourceId = resourceId; 074 return this; 075 } 076 077 public String getStatus() { 078 return status; 079 } 080 081 public ReviewQuery setStatus(String status) { 082 this.status = status; 083 return this; 084 } 085 086 public Integer getUserId() { 087 return userId; 088 } 089 090 public ReviewQuery setUserId(Integer userId) { 091 this.userId = userId; 092 return this; 093 } 094 095 public Collection<Integer> getViolationPermanentIds() { 096 return violationPermanentIds; 097 } 098 099 public ReviewQuery setViolationPermanentIds(List<Integer> l) { 100 this.violationPermanentIds = l; 101 return this; 102 } 103 104 public Integer getRuleId() { 105 return ruleId; 106 } 107 108 public ReviewQuery setRuleId(Integer ruleId) { 109 this.ruleId = ruleId; 110 return this; 111 } 112 113 public String getResolution() { 114 return resolution; 115 } 116 117 public ReviewQuery setResolution(String resolution) { 118 this.resolution = resolution; 119 return this; 120 } 121 122 public Boolean getManualSeverity() { 123 return manualSeverity; 124 } 125 126 public ReviewQuery setManualSeverity(boolean b) { 127 this.manualSeverity = b; 128 return this; 129 } 130 131 boolean needToPartitionQuery() { 132 return violationPermanentIds != null && violationPermanentIds.size() > DatabaseUtils.MAX_IN_ELEMENTS; 133 } 134 135 ReviewQuery[] partition() { 136 List<List<Integer>> partitions = Lists.partition(violationPermanentIds, DatabaseUtils.MAX_IN_ELEMENTS); 137 ReviewQuery[] result = new ReviewQuery[partitions.size()]; 138 for (int index = 0; index < partitions.size(); index++) { 139 result[index] = new ReviewQuery(this, partitions.get(index)); 140 } 141 142 return result; 143 } 144 }